summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/channel_window.go19
-rw-r--r--client/cmd_window.go53
-rw-r--r--client/command.go4
-rw-r--r--client/window/window.go23
4 files changed, 40 insertions, 59 deletions
diff --git a/client/channel_window.go b/client/channel_window.go
index e5b50c3..b516775 100644
--- a/client/channel_window.go
+++ b/client/channel_window.go
@@ -14,9 +14,8 @@ type channelLocation struct {
}
type channelWindow struct {
+ window.DefaultWindow
location channelLocation
- buf buffer.Buffer
- input tui.TextInput
watchedUsers map[string]bool
loadingHistory bool
endOfHistory bool
@@ -66,7 +65,7 @@ func (cw *channelWindow) isGone(uid string) bool {
}
func (cw *channelWindow) put(msg proto.Object) {
- cw.buf.Add(channelMsg {msg, cw})
+ cw.Buf.Add(channelMsg {msg, cw})
}
func (cw *channelWindow) Location() window.Location {
@@ -81,14 +80,10 @@ func (cw *channelWindow) Kill() {
}
func (cw *channelWindow) Buffer() *buffer.Buffer {
- if cw.buf.AtTop() {
+ if cw.Buf.AtTop() {
cw.loadMoreHistory()
}
- return &cw.buf
-}
-
-func (cw *channelWindow) Input() *tui.TextInput {
- return &cw.input
+ return &cw.Buf
}
func (cw *channelWindow) Send(text string) {
@@ -110,7 +105,7 @@ func (cw *channelWindow) Send(text string) {
}
msg := proto.Object {"m", "", map[string]string {"": text}}
globalApp.Request(proto.NewCmd("p", cw.location.id, msg), cb)
- cw.input.SetText("")
+ cw.In.SetText("")
}
func (cw *channelWindow) leaveChannel() {
@@ -139,7 +134,7 @@ func (cw *channelWindow) loadMoreHistory() {
cw.loadingHistory = true
rq := proto.Object {Fields: make(map[string]string)}
- top := cw.buf.Top()
+ top := cw.Buf.Top()
if top != nil {
rq.Kind = "before"
rq.Fields[""] = top.Msg().(channelMsg).Object.Id
@@ -154,7 +149,7 @@ func (cw *channelWindow) loadMoreHistory() {
cw.endOfHistory = true
}
for i := len(response.Args) - 1; i >= 0; i-- {
- cw.buf.AddTop(channelMsg {response.Args[i], cw})
+ cw.Buf.AddTop(channelMsg {response.Args[i], cw})
}
case "fail":
cw.endOfHistory = true
diff --git a/client/cmd_window.go b/client/cmd_window.go
index 66245a0..fe6e60a 100644
--- a/client/cmd_window.go
+++ b/client/cmd_window.go
@@ -10,9 +10,7 @@ import (
type cmdWindowLocation struct {}
type cmdWindow struct {
- buf buffer.Buffer
- input tui.TextInput
- login bool
+ window.DefaultWindow
}
type logMsg struct {
@@ -65,50 +63,20 @@ func (w *cmdWindow) Location() window.Location {
return cmdWindowLocation {}
}
-func (w *cmdWindow) Kill() {}
-
-func (w *cmdWindow) Buffer() *buffer.Buffer {
- return &w.buf
-}
-
-func (w *cmdWindow) Input() *tui.TextInput {
- return &w.input
-}
-
func (w *cmdWindow) Send(text string) {
- if w.login {
- w.login = false
- previousText := w.input.Text()
- w.input.SetText("")
- globalApp.auth(text, func(success bool) {
- if !success {
- w.loginMode()
- w.input.SetText(previousText)
- }
- })
- }
if text == ":wq" {
globalApp.quit = true
}
}
func (w *cmdWindow) ShowStatusLine() {
- if !w.login {
- tui.Text("command window", &tui.Style {
- Bg: tui.White, Fg: tui.Black, Italic: true,
- })
- } else {
- tui.Text("[", nil)
- tui.Text("login", &tui.Style {
- Bg: tui.White, Fg: tui.Blue, Bold: true,
- })
- tui.Text("]", nil)
- tui.Text(" username:", nil)
- }
+ tui.Text("command window", &tui.Style {
+ Bg: tui.White, Fg: tui.Black, Italic: true,
+ })
}
func (w *cmdWindow) showPreview() {
- bottom := w.buf.Bottom()
+ bottom := w.Buf.Bottom()
if bottom == nil {
return
}
@@ -141,22 +109,17 @@ func (w *cmdWindow) showPreview() {
tui.Pop()
}
-func (w *cmdWindow) loginMode() {
- w.login = true
- w.input.SetText("")
-}
-
func (w *cmdWindow) info(f string, a ...any) {
lastIndex++
- w.buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logInfo})
+ w.Buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logInfo})
}
func (w *cmdWindow) err(f string, a ...any) {
lastIndex++
- w.buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logErr})
+ w.Buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logErr})
}
func (w *cmdWindow) cmd(f string, a ...any) {
lastIndex++
- w.buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logCmd})
+ w.Buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logCmd})
}
diff --git a/client/command.go b/client/command.go
index 253cf59..2c146e9 100644
--- a/client/command.go
+++ b/client/command.go
@@ -90,7 +90,7 @@ func (a *application) doCommand(command string, args []string, text string) {
switch win.(type) {
case *channelWindow:
win.(*channelWindow).userList(func(msg userListMsg) {
- a.cmdWindow.buf.Add(msg)
+ a.cmdWindow.Buffer().Add(msg)
})
}
case "create":
@@ -122,7 +122,7 @@ func (a *application) doCommand(command string, args []string, text string) {
if !ok {
a.cmdWindow.err("unknown command: /" + cmd)
} else {
- a.cmdWindow.buf.Add(hm)
+ a.cmdWindow.Buffer().Add(hm)
}
case "quit":
a.quit = true
diff --git a/client/window/window.go b/client/window/window.go
index ba72026..014bb7a 100644
--- a/client/window/window.go
+++ b/client/window/window.go
@@ -47,3 +47,26 @@ func (wc *WindowCache) Evict(l Location) {
func (wc *WindowCache) Get(l Location) Window {
return wc.windows[l]
}
+
+type DefaultWindow struct {
+ In tui.TextInput
+ Buf buffer.Buffer
+}
+
+func (dw *DefaultWindow) Location() Location {
+ return nil
+}
+
+func (w *DefaultWindow) Buffer() *buffer.Buffer {
+ return &w.Buf
+}
+
+func (dw *DefaultWindow) Kill() {}
+
+func (w *DefaultWindow) Input() *tui.TextInput {
+ return &w.In
+}
+
+func (w *DefaultWindow) Send(text string) {}
+
+func (w *DefaultWindow) ShowStatusLine() {}