~taiite/public-inbox

senpai: feat: add config option for unread buffer text color v2 PROPOSED

Tim Culverhouse: 1
 feat: add config option for unread buffer text color

 5 files changed, 39 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/31367/mbox | git am -3
Learn more about email & git

[PATCH senpai v2] feat: add config option for unread buffer text color Export this patch

This patch adds the ability to set a config option for changing the
foreground text color of unread buffers
---
v2: fixed merge conflicts with latest HEAD

 app.go           |  1 +
 config.go        | 18 ++++++++++++++++++
 doc/senpai.5.scd |  2 ++
 ui/buffers.go    |  8 ++++++--
 ui/ui.go         | 14 ++++++++++++--
 5 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/app.go b/app.go
index 863b5ab..5d0b131 100644
--- a/app.go
+++ b/app.go
@@ -134,6 +134,7 @@ func NewApp(cfg Config) (app *App, err error) {
		MergeLine: func(former *ui.Line, addition ui.Line) {
			app.mergeLine(former, addition)
		},
		Colors: &cfg.Colors,
	})
	if err != nil {
		return
diff --git a/config.go b/config.go
index c537623..208a233 100644
--- a/config.go
+++ b/config.go
@@ -12,6 +12,7 @@ import (
	"github.com/gdamore/tcell/v2"

	"git.sr.ht/~emersion/go-scfg"
	"git.sr.ht/~taiite/senpai/ui"
)

type Color tcell.Color
@@ -48,6 +49,13 @@ func parseColor(s string, c *Color) error {

type ConfigColors struct {
	Prompt Color
	Unread Color
}

func (cc *ConfigColors) GetUIColors() ui.Colors {
	return ui.Colors{
		Unread: tcell.Color(cc.Unread),
	}
}

type Config struct {
@@ -103,6 +111,7 @@ func Defaults() (cfg Config, err error) {
		MemberColEnabled: true,
		Colors: ConfigColors{
			Prompt: Color(tcell.ColorDefault),
			Unread: Color(tcell.ColorDefault),
		},
		Debug: false,
	}
@@ -278,6 +287,15 @@ func unmarshal(filename string, cfg *Config) (err error) {
					if err = parseColor(prompt, &cfg.Colors.Prompt); err != nil {
						return err
					}
				case "unread":
					var unread string
					if err := child.ParseParams(&unread); err != nil {
						return err
					}

					if err = parseColor(unread, &cfg.Colors.Unread); err != nil {
						return err
					}
				default:
					return fmt.Errorf("unknown directive %q", child.Name)
				}
diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd
index e75513d..2d481e8 100644
--- a/doc/senpai.5.scd
+++ b/doc/senpai.5.scd
@@ -150,6 +150,8 @@ colors {
:< *Description*
|  prompt
:  color for ">"-prompt that appears in command mode
|  unread
:  color for unread buffers

*debug*
	Dump all sent and received data to the home buffer, useful for debugging.
diff --git a/ui/buffers.go b/ui/buffers.go
index 69d1aa0..9629a58 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -531,7 +531,7 @@ func (bs *BufferList) cur() *buffer {
	return &bs.list[bs.current]
}

func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int, offset *int) {
func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int, offset *int, uicolors UIColors) {
	if y0+len(bs.list)-*offset < height {
		*offset = y0 + len(bs.list) - height
		if *offset < 0 {
@@ -544,6 +544,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
	clearArea(screen, x0, y0, width, height)

	indexPadding := 1 + int(math.Ceil(math.Log10(float64(len(bs.list)))))
	colors := uicolors.GetUIColors()
	for i, b := range bs.list[*offset:] {
		bi := *offset + i
		x := x0
@@ -551,6 +552,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
		st := tcell.StyleDefault
		if b.unread {
			st = st.Bold(true)
			st = st.Foreground(colors.Unread)
		}
		if bi == bs.current || bi == bs.clicked {
			st = st.Reverse(true)
@@ -593,7 +595,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
	}
}

func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int) {
func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int, uicolors UIColors) {
	x := x0

	for i, b := range bs.list {
@@ -601,8 +603,10 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt
			break
		}
		st := tcell.StyleDefault
		colors := uicolors.GetUIColors()
		if b.unread {
			st = st.Bold(true)
			st = st.Foreground(colors.Unread)
		} else if i == bs.current {
			st = st.Underline(true)
		}
diff --git a/ui/ui.go b/ui/ui.go
index 1498949..df3a18e 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -19,8 +19,18 @@ type Config struct {
	AutoComplete     func(cursorIdx int, text []rune) []Completion
	Mouse            bool
	MergeLine        func(former *Line, addition Line)
	Colors         UIColors
}

type UIColors interface {
	GetUIColors() Colors
}

type Colors struct {
	Unread tcell.Color
}


type UI struct {
	screen tcell.Screen
	Events chan tcell.Event
@@ -415,9 +425,9 @@ func (ui *UI) Draw(members []irc.Member) {

	ui.bs.DrawTimeline(ui.screen, ui.channelWidth, 0, ui.config.NickColWidth)
	if ui.channelWidth == 0 {
		ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.memberWidth)
		ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.memberWidth, ui.config.Colors)
	} else {
		ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.channelWidth, h, &ui.channelOffset)
		ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.channelWidth, h, &ui.channelOffset, ui.config.Colors)
	}
	if ui.memberWidth != 0 {
		ui.drawVerticalMemberList(ui.screen, w-ui.memberWidth, 0, ui.memberWidth, h, members, &ui.memberOffset)
-- 
2.36.0
Thanks for the patch.

Refactored and merged as 80d5d8b35b450f7183fd46beedd7316f307c2b8d (the 
behavior was not changed).