summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-06-02 17:38:27 -0500
committercitrons <citrons@mondecitronne.com>2025-06-07 16:02:14 -0500
commit035344054768562bee7db12e02e3bec1c8409210 (patch)
tree8e1c116daa1f3db6ff242b532c9ad87439f57fed /client
parent5a9d7f9db6212260dd18a45d6279d1377daa5857 (diff)
window history
Diffstat (limited to 'client')
-rw-r--r--client/application.go12
-rw-r--r--client/channel_window.go1
-rw-r--r--client/command.go2
-rw-r--r--client/navigation.go38
-rw-r--r--client/ui.go10
5 files changed, 58 insertions, 5 deletions
diff --git a/client/application.go b/client/application.go
index fb12717..35f38c8 100644
--- a/client/application.go
+++ b/client/application.go
@@ -17,6 +17,7 @@ type application struct {
cache object.ObjCache
windowCache window.WindowCache
currentWindow window.Location
+ windowHist []window.Location
cmdWindow cmdWindow
prompts []window.Prompt
}
@@ -24,7 +25,7 @@ type application struct {
func newApplication(serverAddress string) *application {
var app application
app.Client = client.New(serverAddress)
- app.currentWindow = app.cmdWindow.Location()
+ app.goTo(app.cmdWindow.Location())
app.cache = object.NewCache(&app)
app.windowCache = window.NewCache()
@@ -68,6 +69,11 @@ func (a *application) OnEvent(cmd proto.Command) {
}
case "delete":
a.cache.Gone(cmd.Target)
+ cl := channelLocation {cmd.Target}
+ if a.windowCache.Get(cl) != nil {
+ a.windowCache.Evict(cl)
+ a.removeFromHistory(cl)
+ }
}
}
@@ -164,7 +170,7 @@ func (a *application) join(channelName string) {
a.Request(proto.NewCmd("join", ch.Id), func(response proto.Command) {
switch response.Kind {
case "ok":
- a.currentWindow = channelLocation {id: ch.Id}
+ a.goTo(channelLocation {id: ch.Id})
case "fail":
if len(response.Args) > 0 {
f := proto.Fail(response.Args[0])
@@ -182,7 +188,7 @@ func (a *application) createChannel(name string) {
case "create":
if len(response.Args) > 0 {
ch := response.Args[0]
- a.currentWindow = channelLocation {id: ch.Id}
+ a.goTo(channelLocation {id: ch.Id})
}
case "fail":
if len(response.Args) > 0 {
diff --git a/client/channel_window.go b/client/channel_window.go
index 485daf3..6ec9ea0 100644
--- a/client/channel_window.go
+++ b/client/channel_window.go
@@ -110,6 +110,7 @@ func (cw *channelWindow) Send(text string) {
func (cw *channelWindow) leaveChannel() {
globalApp.Request(proto.NewCmd("leave", cw.location.id), nil)
globalApp.windowCache.Evict(cw.location)
+ globalApp.removeFromHistory(cw.location)
}
func (cw *channelWindow) renameChannel(newName string) {
diff --git a/client/command.go b/client/command.go
index 253f3d6..0db7f33 100644
--- a/client/command.go
+++ b/client/command.go
@@ -141,7 +141,7 @@ func (a *application) doCommand(command string, args []string, text string) {
a.cmdWindow.Buffer().Add(hm)
}
case "debug":
- a.currentWindow = debugWindowLocation{}
+ a.goTo(debugWindowLocation{})
case "quit":
a.quit = true
default:
diff --git a/client/navigation.go b/client/navigation.go
new file mode 100644
index 0000000..e418445
--- /dev/null
+++ b/client/navigation.go
@@ -0,0 +1,38 @@
+package main
+
+import (
+ "citrons.xyz/talk/client/window"
+)
+
+func (a *application) removeFromHistory(location window.Location) {
+ for i := len(a.windowHist) - 1; i >= 0; i-- {
+ if a.windowHist[i] != location {
+ continue
+ }
+ if i < len(a.windowHist) - 1 {
+ a.windowHist = append(a.windowHist[:i], a.windowHist[i + 1:]...)
+ } else {
+ a.windowHist = a.windowHist[:i]
+ }
+ break
+ }
+}
+
+func (a *application) traverseHistory(direction int) {
+ var i int
+ for i = 0; i < len(a.windowHist); i++ {
+ if a.windowHist[i] == a.currentWindow {
+ break
+ }
+ }
+ i += direction
+ if i >= 0 && i < len(a.windowHist) {
+ a.currentWindow = a.windowHist[i]
+ }
+}
+
+func (a *application) goTo(location window.Location) {
+ a.removeFromHistory(location)
+ a.windowHist = append(a.windowHist, location)
+ a.currentWindow = location
+}
diff --git a/client/ui.go b/client/ui.go
index f3a79c6..014c7e9 100644
--- a/client/ui.go
+++ b/client/ui.go
@@ -22,11 +22,15 @@ func (a *application) pushPrompt(p window.Prompt) {
func (a *application) removePrompt(p window.Prompt) {
for i := len(a.prompts) - 1; i >= 0; i-- {
+ if p != a.prompts[i] {
+ continue
+ }
if i < len(a.prompts) - 1 {
a.prompts = append(a.prompts[:i], a.prompts[i + 1:]...)
} else {
a.prompts = a.prompts[:i]
}
+ break
}
}
@@ -63,8 +67,12 @@ func (a *application) onInput(ev tui.Event) {
input.SetText("")
}
}
+ case 'p' | keys.Ctrl:
+ a.traverseHistory(-1)
+ case 'n' | keys.Ctrl:
+ a.traverseHistory(1)
case '0' | keys.Alt:
- a.currentWindow = cmdWindowLocation {}
+ a.goTo(cmdWindowLocation{})
}
}