gbonsai

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

commit 5ca82c7be8ff880e6ce16b5e64ab014392b9b187
parent 1a07c56b3bbeaff2b1dfc531cfe6fc4a12ca8dae
Author: FIGBERT <figbert@figbert.com>
Date:   Wed,  8 Dec 2021 10:28:30 -0800

Add basic colors and bubbletea color demo

Diffstat:
Mgo.mod | 19+++++++++++++++++++
Ago.sum | 33+++++++++++++++++++++++++++++++++
Mmain.go | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Astyles.go | 20++++++++++++++++++++
4 files changed, 137 insertions(+), 2 deletions(-)

diff --git a/go.mod b/go.mod @@ -1,3 +1,22 @@ module github.com/FIGBERT/gbonsai go 1.17 + +require ( + github.com/charmbracelet/bubbletea v0.19.1 + github.com/charmbracelet/lipgloss v0.4.0 +) + +require ( + github.com/containerd/console v1.0.2 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.13 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect + github.com/muesli/reflow v0.3.0 // indirect + github.com/muesli/termenv v0.9.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/rivo/uniseg v0.2.0 // indirect + golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect + golang.org/x/term v0.0.0-20210422114643-f5beecf764ed // indirect +) diff --git a/go.sum b/go.sum @@ -0,0 +1,33 @@ +github.com/charmbracelet/bubbletea v0.19.1 h1:VHuzkJbnTAkxhOfi9+Lb5PYfNM9+Oh+qhP8uDX5ReOU= +github.com/charmbracelet/bubbletea v0.19.1/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA= +github.com/charmbracelet/lipgloss v0.4.0 h1:768h64EFkGUr8V5yAKV7/Ta0NiVceiPaV+PphaW1K9g= +github.com/charmbracelet/lipgloss v0.4.0/go.mod h1:vmdkHvce7UzX6xkyf4cca8WlwdQ5RQr8fzta+xl7BOM= +github.com/containerd/console v1.0.2 h1:Pi6D+aZXM+oUw1czuKgH5IJ+y0jhYcwBJfx5/Ghn9dE= +github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA= +github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= +github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ= +github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= +github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/termenv v0.9.0 h1:wnbOaGz+LUR3jNT0zOzinPnyDaCZUQRZj9GxK8eRVl8= +github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0= +golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/main.go b/main.go @@ -1,7 +1,70 @@ package main -import "fmt" +import ( + "log" + "strings" + + tea "github.com/charmbracelet/bubbletea" + gloss "github.com/charmbracelet/lipgloss" +) + +type model struct{} + +func (m model) Init() tea.Cmd { + return nil +} + +func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + if msg.Type == tea.KeyCtrlC || msg.String() == "q" { + return m, tea.Quit + } + } + return m, nil +} + +func (m model) View() string { + style := gloss.NewStyle().Foreground(black) + + var out strings.Builder + out.WriteString(style.Render("a") + " ") + style.Foreground(blue) + out.WriteString(style.Render("a") + " ") + style.Foreground(green) + out.WriteString(style.Render("a") + " ") + style.Foreground(cyan) + out.WriteString(style.Render("a") + "\n") + style.Foreground(red) + out.WriteString(style.Render("a") + " ") + style.Foreground(magenta) + out.WriteString(style.Render("a") + " ") + style.Foreground(brown) + out.WriteString(style.Render("a") + " ") + style.Foreground(light_gray) + out.WriteString(style.Render("a") + "\n") + style.Foreground(gray) + out.WriteString(style.Render("a") + " ") + style.Foreground(bright_blue) + out.WriteString(style.Render("a") + " ") + style.Foreground(bright_green) + out.WriteString(style.Render("a") + " ") + style.Foreground(bright_cyan) + out.WriteString(style.Render("a") + "\n") + style.Foreground(bright_red) + out.WriteString(style.Render("a") + " ") + style.Foreground(bright_magenta) + out.WriteString(style.Render("a") + " ") + style.Foreground(yellow) + out.WriteString(style.Render("a") + " ") + style.Foreground(bright_white) + out.WriteString(style.Render("a") + " ") + + return out.String() +} func main() { - fmt.Println("bonsai tree here") + if err := tea.NewProgram(model{}).Start(); err != nil { + log.Fatal(err) + } } diff --git a/styles.go b/styles.go @@ -0,0 +1,20 @@ +package main + +import gloss "github.com/charmbracelet/lipgloss" + +var black = gloss.Color("0") +var blue = gloss.Color("1") +var green = gloss.Color("2") +var cyan = gloss.Color("3") +var red = gloss.Color("4") +var magenta = gloss.Color("5") +var brown = gloss.Color("6") +var light_gray = gloss.Color("7") +var gray = gloss.Color("8") +var bright_blue = gloss.Color("9") +var bright_green = gloss.Color("10") +var bright_cyan = gloss.Color("11") +var bright_red = gloss.Color("12") +var bright_magenta = gloss.Color("13") +var yellow = gloss.Color("14") +var bright_white = gloss.Color("15")