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
|
package senpai
import (
"hash/fnv"
"strings"
"time"
"git.sr.ht/~taiite/senpai/ui"
"github.com/gdamore/tcell/v2"
)
var Home = "home"
const welcomeMessage = "senpai dev build. See senpai(1) for a list of keybindings and commands. Private messages and status notices go here."
func (app *App) initWindow() {
app.win.AddBuffer(Home)
app.win.AddLine(Home, false, ui.Line{
Head: "--",
Body: ui.PlainString(welcomeMessage),
At: time.Now(),
})
}
func (app *App) queueStatusLine(line ui.Line) {
if line.At.IsZero() {
line.At = time.Now()
}
app.events <- event{
src: uiEvent,
content: line,
}
}
func (app *App) addStatusLine(line ui.Line) {
buffer := app.win.CurrentBuffer()
if buffer != Home {
app.win.AddLine(Home, false, line)
}
app.win.AddLine(buffer, false, line)
}
func (app *App) setStatus() {
if app.s == nil {
return
}
ts := app.s.Typings(app.win.CurrentBuffer())
status := ""
if 3 < len(ts) {
status = "several people are typing..."
} else {
verb := " is typing..."
if 1 < len(ts) {
verb = " are typing..."
status = strings.Join(ts[:len(ts)-1], ", ") + " and "
}
if 0 < len(ts) {
status += ts[len(ts)-1] + verb
}
}
app.win.SetStatus(status)
}
func identColor(ident string) tcell.Color {
h := fnv.New32()
_, _ = h.Write([]byte(ident))
return tcell.Color((h.Sum32()%15)+1) + tcell.ColorValid
}
func identString(ident string) ui.StyledString {
color := identColor(ident)
style := tcell.StyleDefault.Foreground(color)
return ui.Styled(ident, style)
}
|