summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-06-06 00:49:26 -0500
committercitrons <citrons@mondecitronne.com>2025-06-07 16:02:18 -0500
commit553ebc26cda61b567418205f7ee60be122b3c84f (patch)
treecad5406e0b7a8ffd9dacf4dd6a08edd83c2dd4bc
parent83f34e602b050a90816de00e381c78f76831a027 (diff)
clickable, draggable channel list
-rw-r--r--client/application.go3
-rw-r--r--client/channel_list.go42
-rw-r--r--client/main.go17
3 files changed, 49 insertions, 13 deletions
diff --git a/client/application.go b/client/application.go
index 6d44be0..b1fbf5b 100644
--- a/client/application.go
+++ b/client/application.go
@@ -19,6 +19,7 @@ type application struct {
currentWindow window.Location
windowHist []window.Location
channelList channelList
+ redraw bool
cmdWindow cmdWindow
prompts []window.Prompt
activePaste <-chan string
@@ -33,6 +34,8 @@ func newApplication(serverAddress string) *application {
app.cmdWindow.info("welcome! type /help for help. try: /join talk")
app.cmdWindow.info("connecting to %s", app.Client.Address)
+
+ app.redraw = true
return &app
}
diff --git a/client/channel_list.go b/client/channel_list.go
index 10b07f1..6ac2141 100644
--- a/client/channel_list.go
+++ b/client/channel_list.go
@@ -11,6 +11,7 @@ type channelList []channelListEntry
type channelListEntry struct {
name string
location channelLocation
+ clicked bool
}
func (cl *channelList) Len() int {
@@ -31,7 +32,7 @@ func (cl *channelList) setChannels(cs []proto.Object) {
*cl = nil
for _, c := range cs {
*cl = append(*cl, channelListEntry {
- c.Fields[""], channelLocation {c.Id},
+ c.Fields[""], channelLocation {c.Id}, false,
})
}
sort.Sort(cl)
@@ -76,28 +77,59 @@ func (cl *channelList) traverse(direction int) {
func (cl *channelList) add(name string, location channelLocation) {
cl.remove(location)
- entry := channelListEntry {name, location}
+ entry := channelListEntry {name, location, false}
*cl = append([]channelListEntry {entry}, *cl...)
}
func (cl *channelList) show() {
- tui.Push("channel list", tui.Box {Width: 12, Height: tui.Fill})
+ mouse := 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}
+ } else if entry.clicked {
+ style = &tui.Style {Fg: tui.Black, Bg: tui.BrightBlack}
}
- tui.Push("channel list." + entry.location.id, tui.Box {
+ mouse := tui.Push("channel list." + entry.location.id, tui.Box {
Width: tui.Fill, Height: 1, NoWrap: true, Style: style,
})
+
+ if mouse.Pressed {
+ globalApp.redraw = true
+ entry.clicked = true
+ }
+ if mouse.Released {
+ globalApp.redraw = true
+ if entry.clicked {
+ globalApp.goTo(entry.location)
+ } else {
+ for j, entry2 := range *cl {
+ if entry2.clicked {
+ entry2.clicked = false
+ (*cl)[j] = entry
+ entry = entry2
+ }
+ }
+ }
+ }
+
ch := globalApp.cache.Get(entry.location.id)
if ch != nil {
entry.name = ch.Fields[""]
- (*cl)[i] = entry
}
+
tui.Text(entry.name, nil)
tui.Pop()
+
+ (*cl)[i] = entry
+ }
+ if mouse.ReleasedAnywhere {
+ for i, entry := range *cl {
+ globalApp.redraw = globalApp.redraw || entry.clicked
+ entry.clicked = false
+ (*cl)[i] = entry
+ }
}
tui.Pop()
}
diff --git a/client/main.go b/client/main.go
index 5993cf6..707cf7e 100644
--- a/client/main.go
+++ b/client/main.go
@@ -28,19 +28,21 @@ func main() {
defer globalApp.Stop()
drawTick := time.Tick(time.Second / 60)
- redraw := true
for {
select {
case m := <-globalApp.Messages():
m.Handle(globalApp)
- redraw = true
+ globalApp.redraw = true
case e := <-tui.Events():
globalApp.onInput(e)
- redraw = true
+ globalApp.redraw = true
case <-drawTick:
- if redraw {
- for i := 0; i < 2; i++ {
- // some information takes two passes to propogate
+ if globalApp.redraw {
+ globalApp.show()
+ tui.DrawLayout()
+ // multi-pass
+ for globalApp.redraw {
+ globalApp.redraw = false
tui.Clear()
globalApp.show()
tui.DrawLayout()
@@ -48,12 +50,11 @@ func main() {
if tui.Present() != nil {
os.Exit(-1)
}
- redraw = false
}
case text := <-globalApp.activePaste:
globalApp.onPaste(text)
globalApp.activePaste = nil
- redraw = true
+ globalApp.redraw = true
}
if globalApp.quit == true {
return