From 7199a7f29d83838b7edb4d86e024a6060624048d Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 22 Mar 2024 14:04:05 -0400 Subject: [PATCH] chore(examples): use lipgloss for indentation Fixes: a6f77ff8cdfc --- examples/go.mod | 2 +- examples/tui-daemon-combo/main.go | 8 +++++--- examples/views/main.go | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 5f01de8302..26f09e0f65 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -12,7 +12,6 @@ require ( github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 github.com/lucasb-eyer/go-colorful v1.2.0 github.com/mattn/go-isatty v0.0.20 - github.com/muesli/reflow v0.3.0 ) require ( @@ -31,6 +30,7 @@ require ( github.com/microcosm-cc/bluemonday v1.0.21 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/rivo/uniseg v0.4.6 // indirect diff --git a/examples/tui-daemon-combo/main.go b/examples/tui-daemon-combo/main.go index 07364065b9..876ec419f3 100644 --- a/examples/tui-daemon-combo/main.go +++ b/examples/tui-daemon-combo/main.go @@ -13,10 +13,12 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/mattn/go-isatty" - "github.com/muesli/reflow/indent" ) -var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render +var ( + helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render + mainStyle = lipgloss.NewStyle().MarginLeft(1) +) func main() { var ( @@ -118,7 +120,7 @@ func (m model) View() string { s += "\n" } - return indent.String(s, 1) + return mainStyle.Render(s) } // processFinishedMsg is sent when a pretend process completes. diff --git a/examples/views/main.go b/examples/views/main.go index d908387b33..7a231a28ac 100644 --- a/examples/views/main.go +++ b/examples/views/main.go @@ -17,7 +17,6 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/fogleman/ease" "github.com/lucasb-eyer/go-colorful" - "github.com/muesli/reflow/indent" ) const ( @@ -34,7 +33,8 @@ var ( ticksStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("79")) checkboxStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("212")) progressEmpty = subtleStyle.Render(progressEmptyChar) - dot = lipgloss.NewStyle().Foreground(lipgloss.Color("236")).Render(dotChar) + dotStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("236")).Render(dotChar) + mainStyle = lipgloss.NewStyle().MarginLeft(2) // Gradient colors we'll use for the progress bar ramp = makeRampStyles("#B14FFF", "#00FFA3", progressBarWidth) @@ -109,7 +109,7 @@ func (m model) View() string { } else { s = chosenView(m) } - return indent.String("\n"+s+"\n\n", 2) + return mainStyle.Render("\n" + s + "\n\n") } // Sub-update functions @@ -185,8 +185,8 @@ func choicesView(m model) string { tpl := "What to do today?\n\n" tpl += "%s\n\n" tpl += "Program quits in %s seconds\n\n" - tpl += subtleStyle.Render("j/k, up/down: select") + dot + - subtleStyle.Render("enter: choose") + dot + + tpl += subtleStyle.Render("j/k, up/down: select") + dotStyle + + subtleStyle.Render("enter: choose") + dotStyle + subtleStyle.Render("q, esc: quit") choices := fmt.Sprintf(