-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwindow.go
113 lines (102 loc) · 2.32 KB
/
window.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package senpai
import (
"fmt"
"strconv"
"strings"
"time"
"git.sr.ht/~delthas/senpai/ui"
)
const welcomeMessage = "Welcome to senpai! To get started, use the Help buttons, or enter /help for a list of commands."
func (app *App) initWindow() {
app.win.AddBuffer("", "(home)", "")
app.win.AddLine("", "", ui.Line{
Head: "--",
Body: ui.PlainString(welcomeMessage),
At: time.Now(),
})
}
type statusLine struct {
netID string
line ui.Line
}
func (app *App) queueStatusLine(netID string, line ui.Line) {
if line.At.IsZero() {
line.At = time.Now()
}
app.events <- event{
src: "*",
content: statusLine{
netID: netID,
line: line,
},
}
}
func (app *App) addStatusLine(netID string, line ui.Line) {
currentNetID, buffer := app.win.CurrentBuffer()
if currentNetID == netID && buffer != "" {
app.win.AddLine(netID, buffer, line)
}
app.win.AddLine(netID, "", line)
}
func (app *App) setStatus() {
if app.imageLoading && app.win.ImageReady() {
app.imageLoading = false
app.imageOverlay = true
}
if app.uploadingProgress != nil {
app.win.SetStatus(fmt.Sprintf("Uploading file (%02.1f%%)...", *app.uploadingProgress*100))
return
}
if app.imageLoading {
app.win.SetStatus("Loading image...")
return
}
netID, buffer := app.win.CurrentBuffer()
s := app.sessions[netID]
if s == nil {
return
}
ts := s.Typings(buffer)
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 (app *App) setBufferNumbers() {
input := app.win.InputContent()
if !isCommand(input) {
app.win.FilterBuffers(false, "")
return
}
cmd, arg, _ := strings.Cut(string(input[1:]), " ")
if cmd == "" || !strings.HasPrefix("buffer", cmd) {
app.win.FilterBuffers(false, "")
return
}
if _, err := strconv.Atoi(arg); err == nil {
// Do not filter buffers if we are passing a buffer index
arg = ""
}
app.win.FilterBuffers(true, arg)
}
func (app *App) clearBufferCommand() {
input := app.win.InputContent()
if !isCommand(input) {
return
}
cmd, _, _ := strings.Cut(string(input[1:]), " ")
if cmd == "" || !strings.HasPrefix("buffer", cmd) {
return
}
app.win.InputClear()
}