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
85
86
87
|
package main
import (
"citrons.xyz/talk/client/window"
"citrons.xyz/talk/tui"
"zgo.at/termfo/keys"
"os"
)
func (a *application) getWin() window.Window {
win := a.windowCache.Open(a.currentWindow)
if win == nil {
return emptyWindow {a.currentWindow}
}
return win
}
func (a *application) onInput(ev tui.Event) {
tui.Selected = "input"
win := a.getWin()
win.Input().Update(ev)
buf := win.Buffer()
buf.Scroll(-ev.Mouse.Scroll * 2)
scroll := tui.Size().Height - 5
switch ev.Key {
case keys.PageUp:
buf.Scroll(scroll)
case keys.PageDown:
buf.Scroll(-scroll)
case keys.Enter:
input := win.Input()
if !input.IsEmpty() {
is, text := isCommand(input.Text())
if !is {
win.Send(text)
} else {
a.processCommand(text)
input.SetText("")
}
}
case 'h' | keys.Ctrl:
a.currentWindow = cmdWindowLocation {}
}
}
func (a *application) showNickBox() {
tui.Push("username", tui.Box {Width: tui.TextSize, Height: tui.TextSize})
tui.Text("[", nil)
name := a.getNick()
name = string([]rune(name)[:8])
tui.Text(name, nil)
tui.Text("] ", nil)
tui.Pop()
}
func (a *application) show() {
tui.Clear()
s := tui.Size()
tui.Push("", tui.Box {
Width: tui.BoxSize(s.Width), Height: tui.BoxSize(s.Height),
Style: &tui.Style {Fg: tui.White, Bg: colorDefault[false]},
})
a.getWin().Buffer().Show("buffer")
tui.Push("status", tui.Box {
Width: tui.Fill, Height: tui.BoxSize(1), Dir: tui.Right,
Style: &tui.Style {Bg: tui.White, Fg: tui.Black},
})
a.getWin().ShowStatusLine()
tui.Pop()
tui.Push("input container", tui.Box {
Width: tui.Fill, Height: tui.Children, Dir: tui.Right,
})
a.showNickBox()
a.getWin().Input().Show("input")
tui.Pop()
tui.Pop()
tui.DrawLayout()
if tui.Present() != nil {
os.Exit(-1)
}
}
|