summaryrefslogtreecommitdiff
path: root/client/channel_list.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/channel_list.go')
-rw-r--r--client/channel_list.go46
1 files changed, 9 insertions, 37 deletions
diff --git a/client/channel_list.go b/client/channel_list.go
index b8bf962..2c7c51c 100644
--- a/client/channel_list.go
+++ b/client/channel_list.go
@@ -91,27 +91,17 @@ func (cl *channelList) remove(location channelLocation) {
}
func (cl *channelList) traverse(direction int) int {
- if len(*cl) == 0 {
- return 0
- }
-
- var i int
- for i = 0; i < len(*cl); i++ {
+ next := 0
+ for i := 0; i < len(*cl); i++ {
if (*cl)[i].location == globalApp.currentWindow {
+ next = i + direction
break
}
}
- if i == len(*cl) {
- i = 0
- } else {
- i += direction
- i %= len(*cl)
- if i < 0 {
- i = len(*cl) + i
- }
+ if next >= 0 && next < len(*cl) {
+ globalApp.goTo((*cl)[next].location)
}
- globalApp.goTo((*cl)[i].location)
- return i
+ return next
}
func (cl *channelList) add(name string, location channelLocation) {
@@ -120,7 +110,8 @@ func (cl *channelList) add(name string, location channelLocation) {
*cl = append([]channelListEntry {entry}, *cl...)
}
-func (cl *channelList) show(scroll *tui.ScrollState) {
+func (cl *channelList) show(
+ scroll *tui.ScrollState, menu func(channelLocation)) {
mouse := tui.Push("channel list", tui.Box {
Width: 12, Height: tui.Fill, Overflow: true, Scroll: scroll,
})
@@ -158,26 +149,7 @@ func (cl *channelList) show(scroll *tui.ScrollState) {
}
}
}
-
- switch {
- case tui.MenuOption("list"):
- w := globalApp.windowCache.Open(entry.location)
- switch w.(type) {
- case *channelWindow:
- w.(*channelWindow).userList(func(msg userListMsg) {
- globalApp.cmdWindow.Buffer().Add(msg)
- })
- }
- case tui.MenuOption("leave"):
- w := globalApp.windowCache.Open(entry.location)
- switch w.(type) {
- case *channelWindow:
- defer w.(*channelWindow).leaveChannel()
- }
- if entry.location == globalApp.currentWindow {
- globalApp.goTo(cmdWindowLocation {})
- }
- }
+ menu(entry.location)
ch := globalApp.cache.Get(entry.location.id)
if ch != nil {