From 5a8dbc6347b3541e84fe669b22c17ad3b715e258 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 21 Jan 2026 20:22:09 +0100 Subject: Engage! --- intro.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 intro.go (limited to 'intro.go') 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 to exit", cKey}, + {" type :help 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) + } + } +} -- cgit v1.2.3