blob: c768da9c5410382d20bccca9abfbf88a9e01d390 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
package window
import (
"citrons.xyz/talk/client/buffer"
"citrons.xyz/talk/tui"
)
type Location interface {
CreateWindow() Window
}
type Window interface {
Prompt
Location() Location
Kill()
Buffer() *buffer.Buffer
ShowComposingReply()
OnNavigate()
}
type Prompt interface {
Input() *tui.TextInput
Send(text string)
ShowStatusLine()
}
type WindowCache struct {
windows map[Location]Window
}
func NewCache() WindowCache {
return WindowCache {make(map[Location]Window)}
}
func (wc *WindowCache) Open(l Location) Window {
if wc.windows[l] == nil {
wc.windows[l] = l.CreateWindow()
}
return wc.windows[l]
}
func (wc *WindowCache) Evict(l Location) {
if wc.windows[l] != nil {
wc.windows[l].Kill()
}
delete(wc.windows, l)
}
func (wc *WindowCache) Get(l Location) Window {
return wc.windows[l]
}
func (wc *WindowCache) ForAll(do func(Window)) {
for _, window := range wc.windows {
do(window)
}
}
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() {}
func (w *DefaultWindow) ShowComposingReply() {}
func (w *DefaultWindow) OnNavigate() {}
|