[PATCH senpai] 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
---
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 1144560..cf45423 100644
--- a/app.go
+++ b/app.go
@@ -127,6 +127,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 35857ba..c22de94 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 {
@@ -99,6 +107,7 @@ func Defaults() (cfg Config, err error) {
MemberColWidth: 0,
Colors: ConfigColors{
Prompt: Color(tcell.ColorDefault),
+ Unread: Color(tcell.ColorDefault),
},
Debug: false,
}
@@ -264,6 +273,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 1ccb921..2fd74b6 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -449,7 +449,7 @@ func (bs *BufferList) idx(netID, title string) int {
return -1
}
-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 {
@@ -462,6 +462,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
@@ -469,6 +470,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)
@@ -511,7 +513,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 {
@@ -519,8 +521,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 7e02812..bb44c88 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -16,8 +16,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
@@ -340,9 +350,9 @@ func (ui *UI) Draw(members []irc.Member) {
ui.bs.DrawTimeline(ui.screen, ui.config.ChanColWidth, 0, ui.config.NickColWidth)
if ui.config.ChanColWidth == 0 {
- ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.config.MemberColWidth)
+ ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.config.MemberColWidth, ui.config.Colors)
} else {
- ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h, &ui.channelOffset)
+ ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h, &ui.channelOffset, ui.config.Colors)
}
if ui.config.MemberColWidth != 0 {
drawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset)
--
2.35.1