diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 20:22:09 +0100 |
| commit | 5a8dbc6347b3541e84fe669b22c17ad3b715e258 (patch) | |
| tree | b148c450939688caaaeb4adac6f2faa1eaffe649 /intro.go | |
| download | qwe-editor-5a8dbc6347b3541e84fe669b22c17ad3b715e258.tar.gz | |
Engage!
Diffstat (limited to 'intro.go')
| -rw-r--r-- | intro.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/intro.go b/intro.go new file mode 100644 index 0000000..3b313a1 --- /dev/null +++ b/intro.go @@ -0,0 +1,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) + } + } +} |
