commit 2c7bc6a
delthas
·
2021-07-13 22:13:46 +0000 UTC
parent fbe14ad
Add notify types for fine-grained control of unread/highlight state Namely, we want the unread light to show up only on actual messages, not commands etc. This opens the way for not showing an unread light when printing topic on join.
5 files changed,
+45,
-31
M
app.go
+14,
-8
1@@ -405,7 +405,7 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) {
2 input := app.win.InputEnter()
3 err := app.handleInput(buffer, input)
4 if err != nil {
5- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
6+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyUnread, ui.Line{
7 At: time.Now(),
8 Head: "!!",
9 HeadColor: tcell.ColorRed,
10@@ -468,7 +468,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
11 body.WriteString(" as ")
12 body.WriteString(app.s.Nick())
13 }
14- app.win.AddLine(Home, false, ui.Line{
15+ app.win.AddLine(Home, ui.NotifyUnread, ui.Line{
16 At: msg.TimeOrNow(),
17 Head: "--",
18 Body: body.StyledString(),
19@@ -499,7 +499,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
20 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
21 body.WriteString(ev.User)
22 for _, c := range app.s.ChannelsSharedWith(ev.User) {
23- app.win.AddLine(c, false, ui.Line{
24+ app.win.AddLine(c, ui.NotifyNone, ui.Line{
25 At: msg.TimeOrNow(),
26 Head: "--",
27 HeadColor: tcell.ColorGray,
28@@ -522,7 +522,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
29 body.WriteByte('+')
30 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
31 body.WriteString(ev.User)
32- app.win.AddLine(ev.Channel, false, ui.Line{
33+ app.win.AddLine(ev.Channel, ui.NotifyNone, ui.Line{
34 At: msg.TimeOrNow(),
35 Head: "--",
36 HeadColor: tcell.ColorGray,
37@@ -538,7 +538,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
38 body.WriteByte('-')
39 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
40 body.WriteString(ev.User)
41- app.win.AddLine(ev.Channel, false, ui.Line{
42+ app.win.AddLine(ev.Channel, ui.NotifyNone, ui.Line{
43 At: msg.TimeOrNow(),
44 Head: "--",
45 HeadColor: tcell.ColorGray,
46@@ -553,7 +553,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
47 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
48 body.WriteString(ev.User)
49 for _, c := range ev.Channels {
50- app.win.AddLine(c, false, ui.Line{
51+ app.win.AddLine(c, ui.NotifyNone, ui.Line{
52 At: msg.TimeOrNow(),
53 Head: "--",
54 HeadColor: tcell.ColorGray,
55@@ -567,7 +567,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
56 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
57 body.WriteString("Topic changed to: ")
58 body.WriteString(ev.Topic)
59- app.win.AddLine(ev.Channel, false, ui.Line{
60+ app.win.AddLine(ev.Channel, ui.NotifyUnread, ui.Line{
61 At: msg.TimeOrNow(),
62 Head: "--",
63 HeadColor: tcell.ColorGray,
64@@ -575,7 +575,13 @@ func (app *App) handleIRCEvent(ev interface{}) {
65 })
66 case irc.MessageEvent:
67 buffer, line, hlNotification := app.formatMessage(ev)
68- app.win.AddLine(buffer, hlNotification, line)
69+ var notify ui.NotifyType
70+ if hlNotification {
71+ notify = ui.NotifyHighlight
72+ } else {
73+ notify = ui.NotifyUnread
74+ }
75+ app.win.AddLine(buffer, notify, line)
76 if hlNotification {
77 app.notifyHighlight(buffer, ev.User, line.Body.String())
78 }
+15,
-15
1@@ -140,7 +140,7 @@ func noCommand(app *App, buffer, content string) error {
2 Content: content,
3 Time: time.Now(),
4 })
5- app.win.AddLine(buffer, false, line)
6+ app.win.AddLine(buffer, ui.NotifyNone, line)
7 }
8
9 return nil
10@@ -149,7 +149,7 @@ func noCommand(app *App, buffer, content string) error {
11 func commandDoHelp(app *App, buffer string, args []string) (err error) {
12 t := time.Now()
13 if len(args) == 0 {
14- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
15+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
16 At: t,
17 Head: "--",
18 Body: ui.PlainString("Available commands:"),
19@@ -158,22 +158,22 @@ func commandDoHelp(app *App, buffer string, args []string) (err error) {
20 if cmd.Desc == "" {
21 continue
22 }
23- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
24+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
25 At: t,
26 Body: ui.PlainSprintf(" \x02%s\x02 %s", cmdName, cmd.Usage),
27 })
28- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
29+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
30 At: t,
31 Body: ui.PlainSprintf(" %s", cmd.Desc),
32 })
33- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
34+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
35 At: t,
36 })
37 }
38 } else {
39 search := strings.ToUpper(args[0])
40 found := false
41- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
42+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
43 At: t,
44 Head: "--",
45 Body: ui.PlainSprintf("Commands that match \"%s\":", search),
46@@ -189,21 +189,21 @@ func commandDoHelp(app *App, buffer string, args []string) (err error) {
47 usage.SetStyle(tcell.StyleDefault)
48 usage.WriteByte(' ')
49 usage.WriteString(cmd.Usage)
50- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
51+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
52 At: t,
53 Body: usage.StyledString(),
54 })
55- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
56+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
57 At: t,
58 Body: ui.PlainSprintf(" %s", cmd.Desc),
59 })
60- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
61+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
62 At: t,
63 })
64 found = true
65 }
66 if !found {
67- app.win.AddLine(app.win.CurrentBuffer(), false, ui.Line{
68+ app.win.AddLine(app.win.CurrentBuffer(), ui.NotifyNone, ui.Line{
69 At: t,
70 Body: ui.PlainSprintf(" no command matches %q", args[0]),
71 })
72@@ -236,7 +236,7 @@ func commandDoMe(app *App, buffer string, args []string) (err error) {
73 Content: content,
74 Time: time.Now(),
75 })
76- app.win.AddLine(buffer, false, line)
77+ app.win.AddLine(buffer, ui.NotifyNone, line)
78 }
79 return
80 }
81@@ -254,7 +254,7 @@ func commandDoMsg(app *App, buffer string, args []string) (err error) {
82 Content: content,
83 Time: time.Now(),
84 })
85- app.win.AddLine(buffer, false, line)
86+ app.win.AddLine(buffer, ui.NotifyNone, line)
87 }
88 return
89 }
90@@ -274,7 +274,7 @@ func commandDoNames(app *App, buffer string, args []string) (err error) {
91 }
92 body := sb.StyledString()
93 // TODO remove last space
94- app.win.AddLine(buffer, false, ui.Line{
95+ app.win.AddLine(buffer, ui.NotifyNone, ui.Line{
96 At: time.Now(),
97 Head: "--",
98 HeadColor: tcell.ColorGray,
99@@ -351,7 +351,7 @@ func commandDoR(app *App, buffer string, args []string) (err error) {
100 Content: args[0],
101 Time: time.Now(),
102 })
103- app.win.AddLine(buffer, false, line)
104+ app.win.AddLine(buffer, ui.NotifyNone, line)
105 }
106 return
107 }
108@@ -366,7 +366,7 @@ func commandDoTopic(app *App, buffer string, args []string) (err error) {
109 } else {
110 body = fmt.Sprintf("Topic (by %s, %s): %s", who, at.Local().Format("Mon Jan 2 15:04:05"), topic)
111 }
112- app.win.AddLine(buffer, false, ui.Line{
113+ app.win.AddLine(buffer, ui.NotifyNone, ui.Line{
114 At: time.Now(),
115 Head: "--",
116 HeadColor: tcell.ColorGray,
+11,
-3
1@@ -16,6 +16,14 @@ type point struct {
2 Split bool
3 }
4
5+type NotifyType int
6+
7+const (
8+ NotifyNone NotifyType = iota
9+ NotifyUnread
10+ NotifyHighlight
11+)
12+
13 type Line struct {
14 At time.Time
15 Head string
16@@ -251,7 +259,7 @@ func (bs *BufferList) Remove(title string) (ok bool) {
17 return
18 }
19
20-func (bs *BufferList) AddLine(title string, highlight bool, line Line) {
21+func (bs *BufferList) AddLine(title string, notify NotifyType, line Line) {
22 idx := bs.idx(title)
23 if idx < 0 {
24 return
25@@ -280,10 +288,10 @@ func (bs *BufferList) AddLine(title string, highlight bool, line Line) {
26 }
27 }
28
29- if !line.Mergeable && idx != bs.current {
30+ if notify != NotifyNone && idx != bs.current {
31 b.unread = true
32 }
33- if highlight && idx != bs.current {
34+ if notify == NotifyHighlight && idx != bs.current {
35 b.highlights++
36 }
37 }
M
ui/ui.go
+2,
-2
1@@ -136,8 +136,8 @@ func (ui *UI) RemoveBuffer(title string) {
2 _ = ui.bs.Remove(title)
3 }
4
5-func (ui *UI) AddLine(buffer string, highlight bool, line Line) {
6- ui.bs.AddLine(buffer, highlight, line)
7+func (ui *UI) AddLine(buffer string, notify NotifyType, line Line) {
8+ ui.bs.AddLine(buffer, notify, line)
9 }
10
11 func (ui *UI) AddLines(buffer string, lines []Line) {
+3,
-3
1@@ -15,7 +15,7 @@ const welcomeMessage = "senpai dev build. See senpai(1) for a list of keybinding
2
3 func (app *App) initWindow() {
4 app.win.AddBuffer(Home)
5- app.win.AddLine(Home, false, ui.Line{
6+ app.win.AddLine(Home, ui.NotifyNone, ui.Line{
7 Head: "--",
8 Body: ui.PlainString(welcomeMessage),
9 At: time.Now(),
10@@ -35,9 +35,9 @@ func (app *App) queueStatusLine(line ui.Line) {
11 func (app *App) addStatusLine(line ui.Line) {
12 buffer := app.win.CurrentBuffer()
13 if buffer != Home {
14- app.win.AddLine(Home, false, line)
15+ app.win.AddLine(Home, ui.NotifyNone, line)
16 }
17- app.win.AddLine(buffer, false, line)
18+ app.win.AddLine(buffer, ui.NotifyNone, line)
19 }
20
21 func (app *App) setStatus() {