commit b4f3d87
Hubert Hirtz
·
2021-09-11 17:29:44 +0000 UTC
parent 75349a8
Random code improvements/tidying
3 files changed,
+10,
-12
M
app.go
+9,
-9
1@@ -515,7 +515,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
2 // TODO: support autojoining channels with keys
3 app.s.Join(channel, "")
4 }
5- body := new(ui.StyledStringBuilder)
6+ var body ui.StyledStringBuilder
7 body.WriteString("Connected to the server")
8 if app.s.Nick() != app.cfg.Nick {
9 body.WriteString(" as ")
10@@ -527,7 +527,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
11 Body: body.StyledString(),
12 })
13 case irc.SelfNickEvent:
14- body := new(ui.StyledStringBuilder)
15+ var body ui.StyledStringBuilder
16 body.Grow(len(ev.FormerNick) + 4 + len(app.s.Nick()))
17 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
18 body.WriteString(ev.FormerNick)
19@@ -543,7 +543,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
20 Highlight: true,
21 })
22 case irc.UserNickEvent:
23- body := new(ui.StyledStringBuilder)
24+ var body ui.StyledStringBuilder
25 body.Grow(len(ev.FormerNick) + 4 + len(ev.User))
26 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
27 body.WriteString(ev.FormerNick)
28@@ -579,7 +579,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
29 app.printTopic(ev.Channel)
30 }
31 case irc.UserJoinEvent:
32- body := new(ui.StyledStringBuilder)
33+ var body ui.StyledStringBuilder
34 body.Grow(len(ev.User) + 1)
35 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGreen))
36 body.WriteByte('+')
37@@ -595,7 +595,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
38 case irc.SelfPartEvent:
39 app.win.RemoveBuffer(ev.Channel)
40 case irc.UserPartEvent:
41- body := new(ui.StyledStringBuilder)
42+ var body ui.StyledStringBuilder
43 body.Grow(len(ev.User) + 1)
44 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorRed))
45 body.WriteByte('-')
46@@ -609,7 +609,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
47 Mergeable: true,
48 })
49 case irc.UserQuitEvent:
50- body := new(ui.StyledStringBuilder)
51+ var body ui.StyledStringBuilder
52 body.Grow(len(ev.User) + 1)
53 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorRed))
54 body.WriteByte('-')
55@@ -625,7 +625,7 @@ func (app *App) handleIRCEvent(ev interface{}) {
56 })
57 }
58 case irc.TopicChangeEvent:
59- body := new(ui.StyledStringBuilder)
60+ var body ui.StyledStringBuilder
61 body.Grow(len(ev.Topic) + 18)
62 body.SetStyle(tcell.StyleDefault.Foreground(tcell.ColorGray))
63 body.WriteString("Topic changed to: ")
64@@ -846,11 +846,11 @@ func (app *App) formatMessage(ev irc.MessageEvent) (buffer string, line ui.Line,
65 }
66
67 content := strings.TrimSuffix(ev.Content, "\x01")
68- content = strings.TrimRightFunc(ev.Content, unicode.IsSpace)
69+ content = strings.TrimRightFunc(content, unicode.IsSpace)
70 if isAction {
71 content = content[7:]
72 }
73- body := new(ui.StyledStringBuilder)
74+ var body ui.StyledStringBuilder
75 if isNotice {
76 color := identColor(ev.User)
77 body.SetStyle(tcell.StyleDefault.Foreground(color))
+0,
-2
1@@ -408,7 +408,6 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
2 }
3 screen.SetContent(x0+width, y, 0x2590, nil, st)
4 }
5- y++
6 }
7 }
8
9@@ -472,7 +471,6 @@ func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width,
10 }
11 name := truncate(m.Name.Name, width-(x-x0), "\u2026")
12 printString(screen, &x, y, Styled(name, st))
13- y++
14 }
15 }
16
+1,
-1
1@@ -447,7 +447,7 @@ func runeToLower(r rune) rune {
2 // runeOffset returns the rune index of the rune starting at byte i in string s
3 func runeOffset(s string, pos int) int {
4 n := 0
5- for i, _ := range s {
6+ for i := range s {
7 if i >= pos {
8 return n
9 }