diff options
Diffstat (limited to '')
| -rw-r--r-- | cmd/irc/main.go | 17 | ||||
| -rw-r--r-- | ui/buffers.go | 15 | ||||
| -rw-r--r-- | ui/ui.go | 6 |
3 files changed, 25 insertions, 13 deletions
diff --git a/cmd/irc/main.go b/cmd/irc/main.go index e2cd5f3..955ccb5 100644 --- a/cmd/irc/main.go +++ b/cmd/irc/main.go @@ -39,7 +39,7 @@ func main() { defer app.Close() addr := cfg.Addr - app.AddLine(ui.Home, ui.NewLineNow("--", fmt.Sprintf("Connecting to %s...", addr))) + app.AddLine(ui.Home, ui.NewLineNow("--", fmt.Sprintf("Connecting to %s...", addr)), false) conn, err := tls.Dial("tcp", addr, nil) if err != nil { @@ -70,32 +70,33 @@ func main() { func handleIRCEvent(app *ui.UI, s *irc.Session, ev irc.Event) { switch ev := ev.(type) { case irc.RegisteredEvent: - app.AddLine("", ui.NewLineNow("--", "Connected to the server")) + app.AddLine("", ui.NewLineNow("--", "Connected to the server"), false) case irc.SelfJoinEvent: app.AddBuffer(ev.Channel) case irc.UserJoinEvent: line := fmt.Sprintf("\x033+\x0314%s", ev.Nick) - app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true)) + app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true), false) case irc.SelfPartEvent: app.RemoveBuffer(ev.Channel) case irc.UserPartEvent: line := fmt.Sprintf("\x034-\x0314%s", ev.Nick) - app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true)) + app.AddLine(ev.Channel, ui.NewLine(ev.Time, "", line, true), false) case irc.QueryMessageEvent: if ev.Command == "PRIVMSG" { l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, false) - app.AddLine(ui.Home, l) + app.AddLine(ui.Home, l, true) app.TypingStop(ui.Home, ev.Nick) } else if ev.Command == "NOTICE" { l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, true) - app.AddLine("", l) + app.AddLine("", l, true) app.TypingStop("", ev.Nick) } else { panic("unknown command") } case irc.ChannelMessageEvent: l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, ev.Command == "NOTICE") - app.AddLine(ev.Channel, l) + isHighlight := strings.Contains(strings.ToLower(ev.Content), strings.ToLower(s.Nick())) + app.AddLine(ev.Channel, l, isHighlight) app.TypingStop(ev.Channel, ev.Nick) case irc.QueryTypingEvent: if ev.State == 1 || ev.State == 2 { @@ -246,7 +247,7 @@ func handleInput(app *ui.UI, s *irc.Session, buffer, content string) { s.PrivMsg(buffer, args) if !s.HasCapability("echo-message") { - app.AddLine(buffer, ui.NewLineNow(s.Nick(), args)) + app.AddLine(buffer, ui.NewLineNow(s.Nick(), args), false) } case "QUOTE": s.SendRaw(args) diff --git a/ui/buffers.go b/ui/buffers.go index 068894e..0592b65 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -334,7 +334,7 @@ func (bs *bufferList) Remove(title string) (ok bool) { return } -func (bs *bufferList) AddLine(title string, line Line) { +func (bs *bufferList) AddLine(title string, line Line, isHighlight bool) { idx := bs.idx(title) if idx < 0 { return @@ -359,6 +359,9 @@ func (bs *bufferList) AddLine(title string, line Line) { if !line.isStatus && idx != bs.current { b.unread = true } + if isHighlight && idx != bs.current { + b.highlights++ + } } func (bs *bufferList) AddLines(title string, lines []Line) { @@ -504,7 +507,7 @@ func (bs *bufferList) drawTitleList(screen tcell.Screen, y int) { for _, b := range bs.list { width := StringWidth(b.title) if 0 < b.highlights { - width += int(math.Log10(float64(b.highlights))) + 1 + width += int(math.Log10(float64(b.highlights))) + 3 } widths = append(widths, width) } @@ -529,7 +532,11 @@ func (bs *bufferList) drawTitleList(screen tcell.Screen, y int) { printString(screen, &x, y, st, b.title) if 0 < b.highlights { st = st.Foreground(tcell.ColorRed).Reverse(true) + screen.SetContent(x, y, ' ', nil, st) + x++ printNumber(screen, &x, y, st, b.highlights) + screen.SetContent(x, y, ' ', nil, st) + x++ } x += 2 i = (i + 1) % len(bs.list) @@ -547,7 +554,11 @@ func (bs *bufferList) drawTitleList(screen tcell.Screen, y int) { printString(screen, &x, y, st, b.title) if 0 < b.highlights { st = st.Foreground(tcell.ColorRed).Reverse(true) + screen.SetContent(x, y, ' ', nil, st) + x++ printNumber(screen, &x, y, st, b.highlights) + screen.SetContent(x, y, ' ', nil, st) + x++ } x -= widths[i] i = (i - 1 + len(bs.list)) % len(bs.list) @@ -46,7 +46,7 @@ func New() (ui *UI, err error) { hmIdx := rand.Intn(len(homeMessages)) ui.bs = newBufferList(w, h) ui.bs.Add(Home) - ui.bs.AddLine("", NewLineNow("--", homeMessages[hmIdx])) + ui.bs.AddLine("", NewLineNow("--", homeMessages[hmIdx]), false) ui.e = newEditor(w) @@ -113,8 +113,8 @@ func (ui *UI) RemoveBuffer(title string) { } } -func (ui *UI) AddLine(buffer string, line Line) { - ui.bs.AddLine(buffer, line) +func (ui *UI) AddLine(buffer string, line Line, isHighlight bool) { + ui.bs.AddLine(buffer, line, isHighlight) ui.draw() } |
