gbonsai

[DORMANT] a port of cbonsai to go
git clone git://git.figbert.com/gbonsai.git
Log | Files | Refs | README | LICENSE

commit 3b2de06973c8e199b102fdf5d77654aa55da9d51
parent 2415e2c569863079e50f18cd2f24f96493773eb1
Author: FIGBERT <figbert@figbert.com>
Date:   Wed,  8 Dec 2021 11:54:12 -0800

Place the pot at the center bottom of the screen

Diffstat:
Mart.go | 10+++++-----
Mmain.go | 17+++++++++++++++--
2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/art.go b/art.go @@ -17,9 +17,9 @@ func base(baseType int) string { out.WriteString(green.Render("___________")) out.WriteString(gray.Render(":") + "\n") - out.WriteString(gray.Render(" \\ /") + "\n") - out.WriteString(gray.Render(" \\_________________________/") + "\n") - out.WriteString(gray.Render(" (_) (_)") + "\n") + out.WriteString(gray.Render("\\ /") + "\n") + out.WriteString(gray.Render("\\_________________________/") + "\n") + out.WriteString(gray.Render("(_) (_)")) gray.UnsetBold() green.UnsetBold() @@ -30,8 +30,8 @@ func base(baseType int) string { out.WriteString(bright_cyan.Render("./~~~\\.")) out.WriteString(green.Render("---")) out.WriteString(gray.Render(")") + "\n") - out.WriteString(gray.Render(" ( )") + "\n") - out.WriteString(gray.Render(" (_________)") + "\n") + out.WriteString(gray.Render("( )") + "\n") + out.WriteString(gray.Render("(_________)")) } return out.String() diff --git a/main.go b/main.go @@ -6,9 +6,13 @@ import ( "time" tea "github.com/charmbracelet/bubbletea" + gloss "github.com/charmbracelet/lipgloss" ) -type model struct{} +type model struct { + width int + height int +} func (m model) Init() tea.Cmd { return nil @@ -16,6 +20,9 @@ func (m model) Init() tea.Cmd { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { + case tea.WindowSizeMsg: + m.width = msg.Width + m.height = msg.Height case tea.KeyMsg: if msg.Type == tea.KeyCtrlC || msg.String() == "q" { return m, tea.Quit @@ -25,7 +32,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m model) View() string { - return base(rand.Intn(2)) + return gloss.Place( + m.width, + m.height, + gloss.Center, + gloss.Bottom, + base(rand.Intn(2)), + ) } func main() {