diff options
Diffstat (limited to 'client/channel_list.go')
| -rw-r--r-- | client/channel_list.go | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/client/channel_list.go b/client/channel_list.go new file mode 100644 index 0000000..5903792 --- /dev/null +++ b/client/channel_list.go @@ -0,0 +1,99 @@ +package main + +import ( + "citrons.xyz/talk/proto" + "citrons.xyz/talk/tui" + "sort" +) + +type channelList []channelListEntry + +type channelListEntry struct { + name string + location channelLocation +} + +func (cl *channelList) Len() int { + return len(*cl) +} + +func (cl *channelList) Less(i, j int) bool { + return (*cl)[i].name < (*cl)[j].name +} + +func (cl *channelList) Swap(i, j int) { + x := (*cl)[i] + (*cl)[i] = (*cl)[j] + (*cl)[j] = x +} + +func (cl *channelList) setChannels(cs []proto.Object) { + *cl = nil + for _, c := range cs { + *cl = append(*cl, channelListEntry { + c.Fields[""], channelLocation {c.Id}, + }) + } + sort.Sort(cl) +} + +func (cl *channelList) remove(location channelLocation) { + for i := len(*cl) - 1; i >= 0; i-- { + if (*cl)[i].location != location { + continue + } + if i < len(*cl) - 1 { + *cl = append((*cl)[:i], (*cl)[i + 1:]...) + } else { + *cl = (*cl)[:i] + } + break + } +} + +func (cl *channelList) traverse(direction int) { + var i int + for i = 0; i < len(*cl); i++ { + if (*cl)[i].location == globalApp.currentWindow { + break + } + } + if i == len(*cl) { + i = 0 + } else { + i += direction + i %= len(*cl) + if i < 0 { + i = len(*cl) + i + } + } + globalApp.goTo((*cl)[i].location) +} + +func (cl *channelList) add(name string, location channelLocation) { + cl.remove(location) + entry := channelListEntry {name, location} + *cl = append([]channelListEntry {entry}, *cl...) +} + +func (cl *channelList) show() { + tui.Push("channel list", tui.Box {Width: 12, Height: tui.Fill}) + for i, entry := range *cl { + var style *tui.Style + if entry.location == globalApp.currentWindow { + style = &tui.Style {Fg: tui.Black, Bg: tui.White} + } + + tui.Push("channel list." + entry.location.id, tui.Box { + Width: tui.Fill, Height: 1, NoWrap: true, Style: style, + }) + ch := globalApp.cache.Get(entry.location.id) + if ch != nil { + entry.name = ch.Fields[""] + (*cl)[i] = entry + } + tui.Text(entry.name, nil) + tui.Pop() + } + tui.Pop() +} |
