1package main
2
3// Handles drawing the splash screen (introduction) that appears when the editor
4// starts with no files.
5
6import (
7 "github.com/nsf/termbox-go"
8)
9
10// drawIntro clears the screen and draws an informational box with version and basic commands.
11func (e *Editor) drawIntro() {
12 w, h := termbox.Size()
13
14 // Define specific attributes for the intro screen elements.
15 const (
16 cTitle = termbox.Attribute(254) | termbox.AttrBold
17 cText = termbox.Attribute(248)
18 cVersion = termbox.Attribute(239)
19 cSubtext = termbox.Attribute(248)
20 cKey = termbox.Attribute(254)
21 cLink = termbox.Attribute(248) | termbox.AttrUnderline
22 )
23
24 // List of lines to display in the intro box.
25 lines := []struct {
26 text string
27 fg termbox.Attribute
28 }{
29 {"qwe editor", cTitle},
30 {Version, cVersion},
31 {"", cText},
32 {"", cText},
33 {"By Mitja Felicijan et al.", cText},
34 {"Small, opinionated modal text editor", cSubtext},
35 {"", cText},
36 {" type :q<Enter> to exit", cKey},
37 {" type :help<Enter> for help", cKey},
38 {"", cText},
39 {"https://github.com/mitjafelicijan/qwe-editor", cLink},
40 }
41
42 // Calculate the maximum line length to center the box.
43 maxLen := 0
44 for _, line := range lines {
45 if len(line.text) > maxLen {
46 maxLen = len(line.text)
47 }
48 }
49
50 boxWidth := maxLen + 2
51 boxHeight := len(lines)
52
53 // Center point for the box.
54 startX := (w - boxWidth) / 2
55 startY := (h - boxHeight) / 2
56
57 _, bg := GetThemeColor(ColorDefault)
58 for i, line := range lines {
59 // Center each line individually within the box.
60 lineX := startX + (maxLen-len(line.text))/2
61 lineY := startY + i
62 for j, char := range line.text {
63 termbox.SetCell(lineX+j, lineY, char, line.fg, bg)
64 }
65 }
66}