commit 80d5d8b
Tim Culverhouse
·
2022-04-20 14:38:56 +0000 UTC
parent 7c18ce7
Add a config option for unread buffer text color This patch adds the ability to set a config option for changing the foreground text color of unread buffers (This was refactored slightly by delthas.)
5 files changed,
+37,
-20
M
app.go
+3,
-0
1@@ -134,6 +134,9 @@ func NewApp(cfg Config) (app *App, err error) {
2 MergeLine: func(former *ui.Line, addition ui.Line) {
3 app.mergeLine(former, addition)
4 },
5+ Colors: ui.ConfigColors{
6+ Unread: cfg.Colors.Unread,
7+ },
8 })
9 if err != nil {
10 return
+20,
-16
1@@ -14,16 +14,14 @@ import (
2 "git.sr.ht/~emersion/go-scfg"
3 )
4
5-type Color tcell.Color
6-
7-func parseColor(s string, c *Color) error {
8+func parseColor(s string, c *tcell.Color) error {
9 if strings.HasPrefix(s, "#") {
10 hex, err := strconv.ParseInt(s[1:], 16, 32)
11 if err != nil {
12 return err
13 }
14
15- *c = Color(tcell.NewHexColor(int32(hex)))
16+ *c = tcell.NewHexColor(int32(hex))
17 return nil
18 }
19
20@@ -33,7 +31,7 @@ func parseColor(s string, c *Color) error {
21 }
22
23 if code == -1 {
24- *c = Color(tcell.ColorDefault)
25+ *c = tcell.ColorDefault
26 return nil
27 }
28
29@@ -41,13 +39,14 @@ func parseColor(s string, c *Color) error {
30 return fmt.Errorf("color code must be between 0-255. If you meant to use true colors, use #aabbcc notation")
31 }
32
33- *c = Color(tcell.PaletteColor(code))
34+ *c = tcell.PaletteColor(code)
35
36 return nil
37 }
38
39 type ConfigColors struct {
40- Prompt Color
41+ Prompt tcell.Color
42+ Unread tcell.Color
43 }
44
45 type Config struct {
46@@ -102,7 +101,8 @@ func Defaults() (cfg Config, err error) {
47 MemberColWidth: 16,
48 MemberColEnabled: true,
49 Colors: ConfigColors{
50- Prompt: Color(tcell.ColorDefault),
51+ Prompt: tcell.ColorDefault,
52+ Unread: tcell.ColorDefault,
53 },
54 Debug: false,
55 }
56@@ -268,16 +268,20 @@ func unmarshal(filename string, cfg *Config) (err error) {
57 }
58 case "colors":
59 for _, child := range d.Children {
60+ var colorStr string
61+ if err := child.ParseParams(&colorStr); err != nil {
62+ return err
63+ }
64+
65+ var color tcell.Color
66+ if err = parseColor(colorStr, &color); err != nil {
67+ return err
68+ }
69 switch child.Name {
70 case "prompt":
71- var prompt string
72- if err := child.ParseParams(&prompt); err != nil {
73- return err
74- }
75-
76- if err = parseColor(prompt, &cfg.Colors.Prompt); err != nil {
77- return err
78- }
79+ cfg.Colors.Prompt = color
80+ case "unread":
81+ cfg.Colors.Unread = color
82 default:
83 return fmt.Errorf("unknown directive %q", child.Name)
84 }
+2,
-0
1@@ -150,6 +150,8 @@ colors {
2 :< *Description*
3 | prompt
4 : color for ">"-prompt that appears in command mode
5+| unread
6+: foreground color for unread buffer names in buffer lists
7
8 *debug*
9 Dump all sent and received data to the home buffer, useful for debugging.
+6,
-3
1@@ -195,6 +195,8 @@ type buffer struct {
2 }
3
4 type BufferList struct {
5+ colors ConfigColors
6+
7 list []buffer
8 overlay *buffer
9 current int
10@@ -210,8 +212,9 @@ type BufferList struct {
11
12 // NewBufferList returns a new BufferList.
13 // Call Resize() once before using it.
14-func NewBufferList(mergeLine func(*Line, Line)) BufferList {
15+func NewBufferList(colors ConfigColors, mergeLine func(*Line, Line)) BufferList {
16 return BufferList{
17+ colors: colors,
18 list: []buffer{},
19 clicked: -1,
20 doMergeLine: mergeLine,
21@@ -550,7 +553,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
22 y := y0 + i
23 st := tcell.StyleDefault
24 if b.unread {
25- st = st.Bold(true)
26+ st = st.Bold(true).Foreground(bs.colors.Unread)
27 }
28 if bi == bs.current || bi == bs.clicked {
29 st = st.Reverse(true)
30@@ -644,7 +647,7 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt
31 }
32 st := tcell.StyleDefault
33 if b.unread {
34- st = st.Bold(true)
35+ st = st.Bold(true).Foreground(bs.colors.Unread)
36 } else if i == bs.current {
37 st = st.Underline(true)
38 }
M
ui/ui.go
+6,
-1
1@@ -19,6 +19,11 @@ type Config struct {
2 AutoComplete func(cursorIdx int, text []rune) []Completion
3 Mouse bool
4 MergeLine func(former *Line, addition Line)
5+ Colors ConfigColors
6+}
7+
8+type ConfigColors struct {
9+ Unread tcell.Color
10 }
11
12 type UI struct {
13@@ -84,7 +89,7 @@ func New(config Config) (ui *UI, err error) {
14 close(ui.Events)
15 }()
16
17- ui.bs = NewBufferList(ui.config.MergeLine)
18+ ui.bs = NewBufferList(config.Colors, ui.config.MergeLine)
19 ui.e = NewEditor(ui.config.AutoComplete)
20 ui.Resize()
21