commit 6585251
Hubert Hirtz
·
2020-08-04 09:53:45 +0000 UTC
parent 4790252
Show nick highlights
3 files changed,
+25,
-13
+9,
-8
1@@ -39,7 +39,7 @@ func main() {
2 defer app.Close()
3
4 addr := cfg.Addr
5- app.AddLine(ui.Home, ui.NewLineNow("--", fmt.Sprintf("Connecting to %s...", addr)))
6+ app.AddLine(ui.Home, ui.NewLineNow("--", fmt.Sprintf("Connecting to %s...", addr)), false)
7
8 conn, err := tls.Dial("tcp", addr, nil)
9 if err != nil {
10@@ -70,32 +70,33 @@ func main() {
11 func handleIRCEvent(app *ui.UI, s *irc.Session, ev irc.Event) {
12 switch ev := ev.(type) {
13 case irc.RegisteredEvent:
14- app.AddLine("", ui.NewLineNow("--", "Connected to the server"))
15+ app.AddLine("", ui.NewLineNow("--", "Connected to the server"), false)
16 case irc.SelfJoinEvent:
17 app.AddBuffer(ev.Channel)
18 case irc.UserJoinEvent:
19 line := fmt.Sprintf("\x033+\x0314%s", ev.Nick)
20- app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true))
21+ app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true), false)
22 case irc.SelfPartEvent:
23 app.RemoveBuffer(ev.Channel)
24 case irc.UserPartEvent:
25 line := fmt.Sprintf("\x034-\x0314%s", ev.Nick)
26- app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true))
27+ app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true), false)
28 case irc.QueryMessageEvent:
29 if ev.Command == "PRIVMSG" {
30 l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, false)
31- app.AddLine(ui.Home, l)
32+ app.AddLine(ui.Home, l, true)
33 app.TypingStop(ui.Home, ev.Nick)
34 } else if ev.Command == "NOTICE" {
35 l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, true)
36- app.AddLine("", l)
37+ app.AddLine("", l, true)
38 app.TypingStop("", ev.Nick)
39 } else {
40 panic("unknown command")
41 }
42 case irc.ChannelMessageEvent:
43 l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, ev.Command == "NOTICE")
44- app.AddLine(ev.Channel, l)
45+ isHighlight := strings.Contains(strings.ToLower(ev.Content), strings.ToLower(s.Nick()))
46+ app.AddLine(ev.Channel, l, isHighlight)
47 app.TypingStop(ev.Channel, ev.Nick)
48 case irc.QueryTypingEvent:
49 if ev.State == 1 || ev.State == 2 {
50@@ -246,7 +247,7 @@ func handleInput(app *ui.UI, s *irc.Session, buffer, content string) {
51
52 s.PrivMsg(buffer, args)
53 if !s.HasCapability("echo-message") {
54- app.AddLine(buffer, ui.NewLineNow(s.Nick(), args))
55+ app.AddLine(buffer, ui.NewLineNow(s.Nick(), args), false)
56 }
57 case "QUOTE":
58 s.SendRaw(args)
+13,
-2
1@@ -334,7 +334,7 @@ func (bs *bufferList) Remove(title string) (ok bool) {
2 return
3 }
4
5-func (bs *bufferList) AddLine(title string, line Line) {
6+func (bs *bufferList) AddLine(title string, line Line, isHighlight bool) {
7 idx := bs.idx(title)
8 if idx < 0 {
9 return
10@@ -359,6 +359,9 @@ func (bs *bufferList) AddLine(title string, line Line) {
11 if !line.isStatus && idx != bs.current {
12 b.unread = true
13 }
14+ if isHighlight && idx != bs.current {
15+ b.highlights++
16+ }
17 }
18
19 func (bs *bufferList) AddLines(title string, lines []Line) {
20@@ -504,7 +507,7 @@ func (bs *bufferList) drawTitleList(screen tcell.Screen, y int) {
21 for _, b := range bs.list {
22 width := StringWidth(b.title)
23 if 0 < b.highlights {
24- width += int(math.Log10(float64(b.highlights))) + 1
25+ width += int(math.Log10(float64(b.highlights))) + 3
26 }
27 widths = append(widths, width)
28 }
29@@ -529,7 +532,11 @@ func (bs *bufferList) drawTitleList(screen tcell.Screen, y int) {
30 printString(screen, &x, y, st, b.title)
31 if 0 < b.highlights {
32 st = st.Foreground(tcell.ColorRed).Reverse(true)
33+ screen.SetContent(x, y, ' ', nil, st)
34+ x++
35 printNumber(screen, &x, y, st, b.highlights)
36+ screen.SetContent(x, y, ' ', nil, st)
37+ x++
38 }
39 x += 2
40 i = (i + 1) % len(bs.list)
41@@ -547,7 +554,11 @@ func (bs *bufferList) drawTitleList(screen tcell.Screen, y int) {
42 printString(screen, &x, y, st, b.title)
43 if 0 < b.highlights {
44 st = st.Foreground(tcell.ColorRed).Reverse(true)
45+ screen.SetContent(x, y, ' ', nil, st)
46+ x++
47 printNumber(screen, &x, y, st, b.highlights)
48+ screen.SetContent(x, y, ' ', nil, st)
49+ x++
50 }
51 x -= widths[i]
52 i = (i - 1 + len(bs.list)) % len(bs.list)
M
ui/ui.go
+3,
-3
1@@ -46,7 +46,7 @@ func New() (ui *UI, err error) {
2 hmIdx := rand.Intn(len(homeMessages))
3 ui.bs = newBufferList(w, h)
4 ui.bs.Add(Home)
5- ui.bs.AddLine("", NewLineNow("--", homeMessages[hmIdx]))
6+ ui.bs.AddLine("", NewLineNow("--", homeMessages[hmIdx]), false)
7
8 ui.e = newEditor(w)
9
10@@ -113,8 +113,8 @@ func (ui *UI) RemoveBuffer(title string) {
11 }
12 }
13
14-func (ui *UI) AddLine(buffer string, line Line) {
15- ui.bs.AddLine(buffer, line)
16+func (ui *UI) AddLine(buffer string, line Line, isHighlight bool) {
17+ ui.bs.AddLine(buffer, line, isHighlight)
18 ui.draw()
19 }
20