summaryrefslogtreecommitdiff
path: root/ui/buffers.go
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2021-10-20 17:33:10 +0200
committerHubert Hirtz <hubert@hirtz.pm>2021-10-24 12:57:24 +0200
commit9fb4378753ddec61a504a0dec403f40d6def7e90 (patch)
tree32955930be2d97614f3ec6290f67d0556769a16e /ui/buffers.go
parentRemove draft file (diff)
Support for soju.im/bouncer-networks
This patch also disable the highlight on reconnect. This might be an issue (the user would want to know when senpai is online again?), but with multiple connections, it's bothersome to have to unread all of them on start (it wasn't a problem with only one connection since it was read instantly). Now, lastbuffer.txt also contains the network ID, otherwise the user might end up on another buffer with the same name. This patch does not extend /r to support multiple networks (it will send the message to the latest query, whatever the current displayed network is).
Diffstat (limited to 'ui/buffers.go')
-rw-r--r--ui/buffers.go79
1 files changed, 61 insertions, 18 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index 8fdd4b6..06bd7e9 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -172,6 +172,8 @@ func (l *Line) NewLines(width int) []int {
}
type buffer struct {
+ netID string
+ netName string
title string
highlights int
unread bool
@@ -239,15 +241,39 @@ func (bs *BufferList) Previous() {
bs.list[bs.current].unread = false
}
-func (bs *BufferList) Add(title string) (i int, added bool) {
+func (bs *BufferList) Add(netID, netName, title string) (i int, added bool) {
lTitle := strings.ToLower(title)
+ gotNetID := false
for i, b := range bs.list {
- if strings.ToLower(b.title) == lTitle {
- return i, false
+ lbTitle := strings.ToLower(b.title)
+ if b.netID == netID {
+ gotNetID = true
+ if lbTitle == lTitle {
+ return i, false
+ }
+ } else if gotNetID || (b.netID == netID && lbTitle < lTitle) {
+ b := buffer{
+ netID: netID,
+ netName: netName,
+ title: title,
+ }
+ bs.list = append(bs.list[:i+1], bs.list[i:]...)
+ bs.list[i] = b
+ if i <= bs.current && bs.current < len(bs.list) {
+ bs.current++
+ }
+ return i, true
}
}
- bs.list = append(bs.list, buffer{title: title})
+ if netName == "" {
+ netName = netID
+ }
+ bs.list = append(bs.list, buffer{
+ netID: netID,
+ netName: netName,
+ title: title,
+ })
return len(bs.list) - 1, true
}
@@ -266,8 +292,8 @@ func (bs *BufferList) Remove(title string) (ok bool) {
return
}
-func (bs *BufferList) AddLine(title string, notify NotifyType, line Line) {
- idx := bs.idx(title)
+func (bs *BufferList) AddLine(netID, title string, notify NotifyType, line Line) {
+ idx := bs.idx(netID, title)
if idx < 0 {
return
}
@@ -303,8 +329,8 @@ func (bs *BufferList) AddLine(title string, notify NotifyType, line Line) {
}
}
-func (bs *BufferList) AddLines(title string, before, after []Line) {
- idx := bs.idx(title)
+func (bs *BufferList) AddLines(netID, title string, before, after []Line) {
+ idx := bs.idx(netID, title)
if idx < 0 {
return
}
@@ -326,8 +352,9 @@ func (bs *BufferList) AddLines(title string, before, after []Line) {
}
}
-func (bs *BufferList) Current() (title string) {
- return bs.list[bs.current].title
+func (bs *BufferList) Current() (netID, title string) {
+ b := &bs.list[bs.current]
+ return b.netID, b.title
}
func (bs *BufferList) ScrollUp(n int) {
@@ -352,14 +379,10 @@ func (bs *BufferList) IsAtTop() bool {
return b.isAtTop
}
-func (bs *BufferList) idx(title string) int {
- if title == "" {
- return bs.current
- }
-
+func (bs *BufferList) idx(netID, title string) int {
lTitle := strings.ToLower(title)
for i, b := range bs.list {
- if strings.ToLower(b.title) == lTitle {
+ if b.netID == netID && strings.ToLower(b.title) == lTitle {
return i
}
}
@@ -391,7 +414,18 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
x = x0 + indexPadding
}
- title := truncate(b.title, width-(x-x0), "\u2026")
+ var title string
+ if b.title == "" {
+ title = b.netName
+ } else {
+ if i == bs.clicked {
+ screen.SetContent(x, y, ' ', nil, tcell.StyleDefault.Reverse(true))
+ screen.SetContent(x+1, y, ' ', nil, tcell.StyleDefault.Reverse(true))
+ }
+ x += 2
+ title = b.title
+ }
+ title = truncate(title, width-(x-x0), "\u2026")
printString(screen, &x, y, Styled(title, st))
if i == bs.clicked {
@@ -427,8 +461,17 @@ func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, widt
if i == bs.clicked {
st = st.Reverse(true)
}
- title := truncate(b.title, width-x, "\u2026")
+
+ var title string
+ if b.title == "" {
+ st = st.Dim(true)
+ title = b.netName
+ } else {
+ title = b.title
+ }
+ title = truncate(title, width-x, "\u2026")
printString(screen, &x, y0, Styled(title, st))
+
if 0 < b.highlights {
st = st.Foreground(tcell.ColorRed).Reverse(true)
screen.SetContent(x, y0, ' ', nil, st)