Skip to content
Myr

Update spinner, textinput and pipe examples for Bubbles v0.7.7

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent ebf80eb · Browse files · 6 files+33 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+33 added−33 removed

  • other:+33 added−33 removed

6 files+33 added−33 removed

modified:examples/pipe/main.go+2 added-1 removed
14 unmodified lines
15 "strings"1617 "github.com/charmbracelet/bubbles/textinput"18 tea "github.com/charmbracelet/bubbletea"19 "github.com/charmbracelet/lipgloss"20)2122func main() {23 stat, err := os.Stdin.Stat()
35 unmodified lines
5960func newModel(initialValue string) (m model) {61 i := textinput.NewModel()62 i.Prompt = ""62 i.CursorColor = "63"63 i.CursorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("63"))64 i.Width = 4865 i.SetValue(initialValue)66 i.CursorEnd()67 i.Focus()
28 unmodified lines
modified:examples/spinner/main.go+2 added
7 unmodified lines
8 "os"910 "github.com/charmbracelet/bubbles/spinner"11 tea "github.com/charmbracelet/bubbletea"12 "github.com/charmbracelet/lipgloss"13 "github.com/muesli/termenv"14)1516var color = termenv.ColorProfile().Color
16 unmodified lines
3334func initialModel() model {35 s := spinner.NewModel()36 s.Spinner = spinner.Dot37 s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))38 return model{spinner: s}39}4041func (m model) Init() tea.Cmd {
42 unmodified lines
modified:examples/spinners/main.go+5 added-5 removed
4 unmodified lines
5 "os"67 "github.com/charmbracelet/bubbles/spinner"8 tea "github.com/charmbracelet/bubbletea"9 "github.com/muesli/termenv"9 "github.com/charmbracelet/lipgloss"10)1112var (13 // Available spinners
8 unmodified lines
22 spinner.Moon,23 spinner.Monkey,24 }2526 color = termenv.ColorProfile().Color27 textStyle = termenv.Style{}.Foreground(color("252")).Styled28 helpStyle = termenv.Style{}.Foreground(color("241")).Styled26 textStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("252")).Render27 spinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("69"))28 helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).Render29)3031func main() {32 m := model{}
47 unmodified lines
80}8182func (m *model) resetSpinner() {83 m.spinner = spinner.NewModel()84 m.spinner.ForegroundColor = "69"84 m.spinner.Style = spinnerStyle85 m.spinner.Spinner = spinners[m.index]86}8788func (m model) View() (s string) {
12 unmodified lines
modified:examples/textinputs/main.go+13 added-16 removed
7 unmodified lines
8 "os"910 "github.com/charmbracelet/bubbles/textinput"11 tea "github.com/charmbracelet/bubbletea"12 te "github.com/muesli/termenv"12 "github.com/charmbracelet/lipgloss"13)1415const focusedTextColor = "205"1615var (18 color = te.ColorProfile().Color19 focusedPrompt = te.String("> ").Foreground(color("205")).String()20 blurredPrompt = "> "21 focusedSubmitButton = "[ " + te.String("Submit").Foreground(color("205")).String() + " ]"22 blurredSubmitButton = "[ " + te.String("Submit").Foreground(color("240")).String() + " ]"16 focusedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))17 blurredButtonStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))18 noStyle = lipgloss.NewStyle()1920 focusedSubmitButton = "[ " + focusedStyle.Render("Submit") + " ]"21 blurredSubmitButton = "[ " + blurredButtonStyle.Render("Submit") + " ]"22)2324func main() {25 if err := tea.NewProgram(initialModel()).Start(); err != nil {
13 unmodified lines
39func initialModel() model {40 name := textinput.NewModel()41 name.Placeholder = "Nickname"42 name.Focus()44 name.Prompt = focusedPrompt45 name.TextColor = focusedTextColor43 name.PromptStyle = focusedStyle44 name.TextStyle = focusedStyle45 name.CharLimit = 324647 email := textinput.NewModel()48 email.Placeholder = "Email"50 email.Prompt = blurredPrompt49 email.CharLimit = 645051 password := textinput.NewModel()52 password.Placeholder = "Password"55 password.Prompt = blurredPrompt53 password.EchoMode = textinput.EchoPassword54 password.EchoCharacter = '•'55 password.CharLimit = 3256
47 unmodified lines
104 for i := 0; i <= len(inputs)-1; i++ {105 if i == m.index {106 // Set focused state107 inputs[i].Focus()111 inputs[i].Prompt = focusedPrompt112 inputs[i].TextColor = focusedTextColor108 inputs[i].PromptStyle = focusedStyle109 inputs[i].TextStyle = focusedStyle110 continue111 }112 // Remove focused state113 inputs[i].Blur()117 inputs[i].Prompt = blurredPrompt118 inputs[i].TextColor = ""114 inputs[i].PromptStyle = noStyle115 inputs[i].TextStyle = noStyle116 }117118 m.nameInput = inputs[0]119 m.emailInput = inputs[1]
57 unmodified lines
modified:examples/go.mod+3 added-3 removed
1 unmodified line
23go 1.1345require (6 github.com/charmbracelet/bubbles v0.7.66 github.com/charmbracelet/bubbles v0.7.77 github.com/charmbracelet/bubbletea v0.13.18 github.com/charmbracelet/glamour v0.2.09 github.com/charmbracelet/lipgloss v0.1.210 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf177611 github.com/lucasb-eyer/go-colorful v1.2.012 github.com/mattn/go-isatty v0.0.1212 github.com/mattn/go-runewidth v0.0.1013 github.com/mattn/go-runewidth v0.0.1214 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df6815 github.com/muesli/termenv v0.8.115 golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1 // indirect16)1718replace github.com/charmbracelet/bubbletea => ../
modified:examples/go.sum+8 added-8 removed
7 unmodified lines
8github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=9github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=10github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=11github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=12github.com/charmbracelet/bubbles v0.7.6 h1:SCAp4ZEUf2tBNEsufo+Xxxu2dvbFhYSDPrX45toQZrM=13github.com/charmbracelet/bubbles v0.7.6/go.mod h1:0D4XRYK0tjo8JMvflz1obpVcOikNZSG46SFauoZj22s=12github.com/charmbracelet/bubbles v0.7.7 h1:eVsAYiAJskifXaqHpPzbOZS1srMaTnuiTazC6uukBbA=13github.com/charmbracelet/bubbles v0.7.7/go.mod h1:5WX1sSSjNCgCrzvRMN/z23HxvWaa+AI16Ch0KPZPeDs=14github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=15github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=16github.com/charmbracelet/lipgloss v0.1.2 h1:D+LUMg34W7n2pkuMrevKVxT7HXqnoRHm7IoomkX3/ZU=17github.com/charmbracelet/lipgloss v0.1.2/go.mod h1:5D8zradw52m7QmxRF6QgwbwJi9je84g8MkWiGN07uKg=18github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=19github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=20github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=21github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
12 unmodified lines
34github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=35github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=36github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=37github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=36github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=38github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=39github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=40github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=41github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=42github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=43github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=41github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVhUqLX8=44github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=45github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=46github.com/muesli/termenv v0.6.0/go.mod h1:SohX91w6swWA4AYU+QmPx+aSgXhWO0juiyID9UZmbpA=45github.com/muesli/termenv v0.7.4/go.mod h1:pZ7qY9l3F7e5xsAOS0zCew2tME+p7bWeBkotCEcIIcc=47github.com/muesli/termenv v0.8.1 h1:9q230czSP3DHVpkaPDXGp0TOfAwyjyYwXlUCQxQSaBk=48github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0=49github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=50github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
26 unmodified lines
77golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=78golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=79golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=80golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=80golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=81golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1 h1:/DtoiOYKoQCcIFXQjz07RnWNPRCbqmSXSpgEzhC9ZHM=82golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=81golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=82golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=83golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=