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
|
package main
// Handles drawing the splash screen (introduction) that appears when the editor
// starts with no files.
import (
"github.com/nsf/termbox-go"
)
// drawIntro clears the screen and draws an informational box with version and basic commands.
func (e *Editor) drawIntro() {
w, h := termbox.Size()
// Define specific attributes for the intro screen elements.
const (
cTitle = termbox.Attribute(254) | termbox.AttrBold
cText = termbox.Attribute(248)
cVersion = termbox.Attribute(239)
cSubtext = termbox.Attribute(248)
cKey = termbox.Attribute(254)
cLink = termbox.Attribute(248) | termbox.AttrUnderline
)
// List of lines to display in the intro box.
lines := []struct {
text string
fg termbox.Attribute
}{
{"qwe editor", cTitle},
{Version, cVersion},
{"", cText},
{"", cText},
{"By Mitja Felicijan et al.", cText},
{"Small, opinionated modal text editor", cSubtext},
{"", cText},
{" type :q<Enter> to exit", cKey},
{" type :help<Enter> for help", cKey},
{"", cText},
{"https://github.com/mitjafelicijan/qwe-editor", cLink},
}
// Calculate the maximum line length to center the box.
maxLen := 0
for _, line := range lines {
if len(line.text) > maxLen {
maxLen = len(line.text)
}
}
boxWidth := maxLen + 2
boxHeight := len(lines)
// Center point for the box.
startX := (w - boxWidth) / 2
startY := (h - boxHeight) / 2
_, bg := GetThemeColor(ColorDefault)
for i, line := range lines {
// Center each line individually within the box.
lineX := startX + (maxLen-len(line.text))/2
lineY := startY + i
for j, char := range line.text {
termbox.SetCell(lineX+j, lineY, char, line.fg, bg)
}
}
}
|