commit 9d0c33e

Collin Lefeber  ·  2023-02-28 14:18:11 +0000 UTC
parent c9121e5
config: add status color sub-directive

* adds "status" to color config parsing
* unifies ConfigColors types across app and buffer configs
* use Status color for event foreground colors
5 files changed,  +34, -36
M app.go
M app.go
+21, -24
  1@@ -143,10 +143,7 @@ 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-			Nicks:  cfg.Colors.Nicks,
  8-		},
  9+		Colors: cfg.Colors,
 10 	})
 11 	if err != nil {
 12 		return
 13@@ -154,7 +151,7 @@ func NewApp(cfg Config) (app *App, err error) {
 14 	app.win.SetPrompt(ui.Styled(">",
 15 		tcell.
 16 			StyleDefault.
 17-			Foreground(tcell.Color(app.cfg.Colors.Prompt))),
 18+			Foreground(app.cfg.Colors.Prompt)),
 19 	)
 20 
 21 	app.initWindow()
 22@@ -765,7 +762,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 23 	case irc.SelfNickEvent:
 24 		var body ui.StyledStringBuilder
 25 		body.WriteString(fmt.Sprintf("%s\u2192%s", ev.FormerNick, s.Nick()))
 26-		textStyle := tcell.StyleDefault.Foreground(tcell.ColorGray)
 27+		textStyle := tcell.StyleDefault.Foreground(app.cfg.Colors.Status)
 28 		arrowStyle := tcell.StyleDefault
 29 		body.AddStyle(0, textStyle)
 30 		body.AddStyle(len(ev.FormerNick), arrowStyle)
 31@@ -773,7 +770,7 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 32 		app.addStatusLine(netID, ui.Line{
 33 			At:        msg.TimeOrNow(),
 34 			Head:      "--",
 35-			HeadColor: tcell.ColorGray,
 36+			HeadColor: app.cfg.Colors.Status,
 37 			Body:      body.StyledString(),
 38 			Highlight: true,
 39 			Readable:  true,
 40@@ -858,9 +855,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 41 		app.win.AddLine(netID, buffer, ui.Line{
 42 			At:        msg.TimeOrNow(),
 43 			Head:      "--",
 44-			HeadColor: tcell.ColorGray,
 45+			HeadColor: app.cfg.Colors.Status,
 46 			Notify:    notify,
 47-			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
 48+			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
 49 			Highlight: notify == ui.NotifyHighlight,
 50 			Readable:  true,
 51 		})
 52@@ -1192,7 +1189,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
 53 	case irc.UserNickEvent:
 54 		var body ui.StyledStringBuilder
 55 		body.WriteString(fmt.Sprintf("%s\u2192%s", ev.FormerNick, ev.User))
 56-		textStyle := tcell.StyleDefault.Foreground(tcell.ColorGray)
 57+		textStyle := tcell.StyleDefault.Foreground(app.cfg.Colors.Status)
 58 		arrowStyle := tcell.StyleDefault
 59 		body.AddStyle(0, textStyle)
 60 		body.AddStyle(len(ev.FormerNick), arrowStyle)
 61@@ -1200,7 +1197,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
 62 		return ui.Line{
 63 			At:        ev.Time,
 64 			Head:      "--",
 65-			HeadColor: tcell.ColorGray,
 66+			HeadColor: app.cfg.Colors.Status,
 67 			Body:      body.StyledString(),
 68 			Mergeable: true,
 69 			Data:      []irc.Event{ev},
 70@@ -1211,12 +1208,12 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
 71 		body.Grow(len(ev.User) + 1)
 72 		body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGreen))
 73 		body.WriteByte('+')
 74-		body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
 75+		body.SetStyle(tcell.StyleDefault.Foreground(app.cfg.Colors.Status))
 76 		body.WriteString(ev.User)
 77 		return ui.Line{
 78 			At:        ev.Time,
 79 			Head:      "--",
 80-			HeadColor: tcell.ColorGray,
 81+			HeadColor: app.cfg.Colors.Status,
 82 			Body:      body.StyledString(),
 83 			Mergeable: true,
 84 			Data:      []irc.Event{ev},
 85@@ -1227,12 +1224,12 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
 86 		body.Grow(len(ev.User) + 1)
 87 		body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorRed))
 88 		body.WriteByte('-')
 89-		body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
 90+		body.SetStyle(tcell.StyleDefault.Foreground(app.cfg.Colors.Status))
 91 		body.WriteString(ev.User)
 92 		return ui.Line{
 93 			At:        ev.Time,
 94 			Head:      "--",
 95-			HeadColor: tcell.ColorGray,
 96+			HeadColor: app.cfg.Colors.Status,
 97 			Body:      body.StyledString(),
 98 			Mergeable: true,
 99 			Data:      []irc.Event{ev},
100@@ -1243,12 +1240,12 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
101 		body.Grow(len(ev.User) + 1)
102 		body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorRed))
103 		body.WriteByte('-')
104-		body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
105+		body.SetStyle(tcell.StyleDefault.Foreground(app.cfg.Colors.Status))
106 		body.WriteString(ev.User)
107 		return ui.Line{
108 			At:        ev.Time,
109 			Head:      "--",
110-			HeadColor: tcell.ColorGray,
111+			HeadColor: app.cfg.Colors.Status,
112 			Body:      body.StyledString(),
113 			Mergeable: true,
114 			Data:      []irc.Event{ev},
115@@ -1260,9 +1257,9 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
116 		return ui.Line{
117 			At:        ev.Time,
118 			Head:      "--",
119-			HeadColor: tcell.ColorGray,
120+			HeadColor: app.cfg.Colors.Status,
121 			Notify:    ui.NotifyUnread,
122-			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
123+			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
124 			Readable:  true,
125 		}
126 	case irc.ModeChangeEvent:
127@@ -1272,8 +1269,8 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
128 		return ui.Line{
129 			At:        ev.Time,
130 			Head:      "--",
131-			HeadColor: tcell.ColorGray,
132-			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
133+			HeadColor: app.cfg.Colors.Status,
134+			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
135 			Mergeable: mergeable,
136 			Data:      []irc.Event{ev},
137 			Readable:  true,
138@@ -1484,7 +1481,7 @@ func (app *App) updatePrompt() {
139 		prompt = ui.Styled(">",
140 			tcell.
141 				StyleDefault.
142-				Foreground(tcell.Color(app.cfg.Colors.Prompt)),
143+				Foreground(app.cfg.Colors.Prompt),
144 		)
145 	} else if s == nil {
146 		prompt = ui.Styled("<offline>",
147@@ -1514,8 +1511,8 @@ func (app *App) printTopic(netID, buffer string) (ok bool) {
148 	app.win.AddLine(netID, buffer, ui.Line{
149 		At:        time.Now(),
150 		Head:      "--",
151-		HeadColor: tcell.ColorGray,
152-		Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
153+		HeadColor: app.cfg.Colors.Status,
154+		Body:      ui.Styled(body, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
155 	})
156 	return true
157 }
+3, -3
 1@@ -401,13 +401,13 @@ func commandDoNames(app *App, args []string) (err error) {
 2 		return fmt.Errorf("this is not a channel")
 3 	}
 4 	var sb ui.StyledStringBuilder
 5-	sb.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
 6+	sb.SetStyle(tcell.StyleDefault.Foreground(app.cfg.Colors.Status))
 7 	sb.WriteString("Names: ")
 8 	for _, name := range s.Names(buffer) {
 9 		if name.PowerLevel != "" {
10 			sb.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGreen))
11 			sb.WriteString(name.PowerLevel)
12-			sb.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
13+			sb.SetStyle(tcell.StyleDefault.Foreground(app.cfg.Colors.Status))
14 		}
15 		sb.WriteString(name.Name.Name)
16 		sb.WriteByte(' ')
17@@ -417,7 +417,7 @@ func commandDoNames(app *App, args []string) (err error) {
18 	app.win.AddLine(netID, buffer, ui.Line{
19 		At:        time.Now(),
20 		Head:      "--",
21-		HeadColor: tcell.ColorGray,
22+		HeadColor: app.cfg.Colors.Status,
23 		Body:      body,
24 	})
25 	return nil
+6, -9
 1@@ -47,12 +47,6 @@ func parseColor(s string, c *tcell.Color) error {
 2 	return nil
 3 }
 4 
 5-type ConfigColors struct {
 6-	Prompt tcell.Color
 7-	Unread tcell.Color
 8-	Nicks  ui.ColorScheme
 9-}
10-
11 type Config struct {
12 	Addr     string
13 	Nick     string
14@@ -75,7 +69,7 @@ type Config struct {
15 	MemberColEnabled bool
16 	TextMaxWidth     int
17 
18-	Colors ConfigColors
19+	Colors ui.ConfigColors
20 
21 	Debug bool
22 }
23@@ -108,7 +102,8 @@ func Defaults() Config {
24 		MemberColWidth:   16,
25 		MemberColEnabled: true,
26 		TextMaxWidth:     0,
27-		Colors: ConfigColors{
28+		Colors: ui.ConfigColors{
29+			Status: tcell.ColorGray,
30 			Prompt: tcell.ColorDefault,
31 			Unread: tcell.ColorDefault,
32 			Nicks:  ui.ColorSchemeBase,
33@@ -340,8 +335,10 @@ func unmarshal(filename string, cfg *Config) (err error) {
34 					cfg.Colors.Prompt = color
35 				case "unread":
36 					cfg.Colors.Unread = color
37+				case "status":
38+					cfg.Colors.Status = color
39 				default:
40-					return fmt.Errorf("unknown directive %q", child.Name)
41+					return fmt.Errorf("unknown colors directive %q", child.Name)
42 				}
43 			}
44 		case "debug":
+2, -0
1@@ -169,6 +169,8 @@ colors {
2 :  color for ">"-prompt that appears in command mode
3 |  unread
4 :  foreground color for unread buffer names in buffer lists
5+|  status
6+:  foreground color for status event lines (e.g. join, part, nick changes) in buffers
7 |  nicks
8 :  color scheme for user nicks, either "base" (the default, 16 colors) or "extended" (256 colors)
9 
+2, -0
1@@ -24,6 +24,8 @@ type Config struct {
2 }
3 
4 type ConfigColors struct {
5+	Status tcell.Color
6+	Prompt tcell.Color
7 	Unread tcell.Color
8 	Nicks  ColorScheme
9 }