gbonsai

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

commit 00da45048a0ea3c24bfe359c3a9ce4e476a8cd82
parent 3b2de06973c8e199b102fdf5d77654aa55da9d51
Author: FIGBERT <figbert@figbert.com>
Date:   Thu,  9 Dec 2021 21:51:11 -0800

Add initial config to Bubble Tea model

Diffstat:
Mart.go | 4++--
Mmain.go | 9++-------
Amodel.go | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/art.go b/art.go @@ -6,7 +6,7 @@ func base(baseType int) string { var out strings.Builder switch baseType { - case 0: + case 1: gray.Bold(true) green.Bold(true) bright_cyan.Bold(true) @@ -24,7 +24,7 @@ func base(baseType int) string { gray.UnsetBold() green.UnsetBold() bright_cyan.UnsetBold() - case 1: + case 2: out.WriteString(gray.Render("(")) out.WriteString(green.Render("---")) out.WriteString(bright_cyan.Render("./~~~\\.")) diff --git a/main.go b/main.go @@ -9,11 +9,6 @@ import ( gloss "github.com/charmbracelet/lipgloss" ) -type model struct { - width int - height int -} - func (m model) Init() tea.Cmd { return nil } @@ -37,13 +32,13 @@ func (m model) View() string { m.height, gloss.Center, gloss.Bottom, - base(rand.Intn(2)), + base(m.conf.base), ) } func main() { rand.Seed(time.Now().UnixNano()) - if err := tea.NewProgram(model{}, tea.WithAltScreen()).Start(); err != nil { + if err := tea.NewProgram(initialModel(), tea.WithAltScreen()).Start(); err != nil { log.Fatal(err) } } diff --git a/model.go b/model.go @@ -0,0 +1,58 @@ +package main + +import "os" + +type model struct { + width int + height int + conf config +} + +type config struct { + live bool + infinite bool + screensaver bool + printTree bool + verbose bool + + life int + multiplier int + base int + seed int + targetBranchCount int + + timeStep float64 + timeWait float64 + + message string + saveFile string + loadFile string + + leaves [64]string +} + +func initialModel() model { + var userCache string + if cache, err := os.UserCacheDir(); err == nil { + userCache = cache + "/gbonsai" + } else if home, err := os.UserHomeDir(); err == nil { + userCache = home + "/.cache/gbonsai" + } else if current, err := os.Getwd(); err == nil { + userCache = current + "/.gbonsai" + } + + c := config{ + life: 32, + multiplier: 5, + base: 1, + seed: 0, + targetBranchCount: 0, + + timeStep: 0.03, + timeWait: 4, + + saveFile: userCache, + loadFile: userCache, + } + return model{conf: c} +}