summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/buffers.go79
-rw-r--r--ui/ui.go27
2 files changed, 81 insertions, 25 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)
diff --git a/ui/ui.go b/ui/ui.go
index d1007cb..5f87fe3 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -82,7 +82,7 @@ func (ui *UI) Close() {
ui.screen.Fini()
}
-func (ui *UI) CurrentBuffer() string {
+func (ui *UI) CurrentBuffer() (netID, title string) {
return ui.bs.Current()
}
@@ -147,8 +147,8 @@ func (ui *UI) IsAtTop() bool {
return ui.bs.IsAtTop()
}
-func (ui *UI) AddBuffer(title string) (i int, added bool) {
- return ui.bs.Add(title)
+func (ui *UI) AddBuffer(netID, netName, title string) (i int, added bool) {
+ return ui.bs.Add(netID, netName, title)
}
func (ui *UI) RemoveBuffer(title string) {
@@ -156,12 +156,12 @@ func (ui *UI) RemoveBuffer(title string) {
ui.memberOffset = 0
}
-func (ui *UI) AddLine(buffer string, notify NotifyType, line Line) {
- ui.bs.AddLine(buffer, notify, line)
+func (ui *UI) AddLine(netID, buffer string, notify NotifyType, line Line) {
+ ui.bs.AddLine(netID, buffer, notify, line)
}
-func (ui *UI) AddLines(buffer string, before, after []Line) {
- ui.bs.AddLines(buffer, before, after)
+func (ui *UI) AddLines(netID, buffer string, before, after []Line) {
+ ui.bs.AddLines(netID, buffer, before, after)
}
func (ui *UI) JumpBuffer(sub string) bool {
@@ -188,6 +188,19 @@ func (ui *UI) JumpBufferIndex(i int) bool {
return false
}
+func (ui *UI) JumpBufferNetwork(netID, sub string) bool {
+ subLower := strings.ToLower(sub)
+ for i, b := range ui.bs.list {
+ if b.netID == netID && strings.Contains(strings.ToLower(b.title), subLower) {
+ if ui.bs.To(i) {
+ ui.memberOffset = 0
+ }
+ return true
+ }
+ }
+ return false
+}
+
func (ui *UI) SetStatus(status string) {
ui.status = status
}