blob: 014bb7a1be4788c085934a341d621192bd0cb0e6 (
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
|
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
}
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]
}
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() {}
|