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
Provenance
- Commit
42f02ed- Tree
12bbefa- Author
Christian Rocha <christian@rocha.is>- Committer
Christian Rocha <christian@rocha.is>- Parent
ebf80eb
6 files changed+33 added−33 removed
modified:examples/pipe/main.go+2 added-1 removed
14 unmodified lines15 "strings"16 17 "github.com/charmbracelet/bubbles/textinput"18 tea "github.com/charmbracelet/bubbletea"19+ "github.com/charmbracelet/lipgloss"20 )21 22 func main() {23 stat, err := os.Stdin.Stat()35 unmodified lines59 60 func 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 linesmodified:examples/spinner/main.go+2 added
7 unmodified lines8 "os"9 10 "github.com/charmbracelet/bubbles/spinner"11 tea "github.com/charmbracelet/bubbletea"12+ "github.com/charmbracelet/lipgloss"13 "github.com/muesli/termenv"14 )15 16 var color = termenv.ColorProfile().Color16 unmodified lines33 34 func 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 }40 41 func (m model) Init() tea.Cmd {42 unmodified linesmodified:examples/spinners/main.go+5 added-5 removed
4 unmodified lines5 "os"6 7 "github.com/charmbracelet/bubbles/spinner"8 tea "github.com/charmbracelet/bubbletea"9- "github.com/muesli/termenv"9+ "github.com/charmbracelet/lipgloss"10 )11 12 var (13 // Available spinners8 unmodified lines22 spinner.Moon,23 spinner.Monkey,24 }25 26- 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 )30 31 func main() {32 m := model{}47 unmodified lines80 }81 82 func (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 }87 88 func (m model) View() (s string) {12 unmodified linesmodified:examples/textinputs/main.go+13 added-16 removed
7 unmodified lines8 "os"9 10 "github.com/charmbracelet/bubbles/textinput"11 tea "github.com/charmbracelet/bubbletea"12- te "github.com/muesli/termenv"12+ "github.com/charmbracelet/lipgloss"13 )14 15-const focusedTextColor = "205"16-15 var (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()19+20+ focusedSubmitButton = "[ " + focusedStyle.Render("Submit") + " ]"21+ blurredSubmitButton = "[ " + blurredButtonStyle.Render("Submit") + " ]"22 )23 24 func main() {25 if err := tea.NewProgram(initialModel()).Start(); err != nil {13 unmodified lines39 func 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 = 3246 47 email := textinput.NewModel()48 email.Placeholder = "Email"50- email.Prompt = blurredPrompt49 email.CharLimit = 6450 51 password := textinput.NewModel()52 password.Placeholder = "Password"55- password.Prompt = blurredPrompt53 password.EchoMode = textinput.EchoPassword54 password.EchoCharacter = '•'55 password.CharLimit = 3256 47 unmodified lines104 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 }117 118 m.nameInput = inputs[0]119 m.emailInput = inputs[1]57 unmodified linesmodified:examples/go.mod+3 added-3 removed
1 unmodified line2 3 go 1.134 5 require (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 )17 18 replace github.com/charmbracelet/bubbletea => ../modified:examples/go.sum+8 added-8 removed
7 unmodified lines8 github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=9 github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=10 github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=11 github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=12-github.com/charmbracelet/bubbles v0.7.6 h1:SCAp4ZEUf2tBNEsufo+Xxxu2dvbFhYSDPrX45toQZrM=13-github.com/charmbracelet/bubbles v0.7.6/go.mod h1:0D4XRYK0tjo8JMvflz1obpVcOikNZSG46SFauoZj22s=12+github.com/charmbracelet/bubbles v0.7.7 h1:eVsAYiAJskifXaqHpPzbOZS1srMaTnuiTazC6uukBbA=13+github.com/charmbracelet/bubbles v0.7.7/go.mod h1:5WX1sSSjNCgCrzvRMN/z23HxvWaa+AI16Ch0KPZPeDs=14 github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=15 github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=16+github.com/charmbracelet/lipgloss v0.1.2 h1:D+LUMg34W7n2pkuMrevKVxT7HXqnoRHm7IoomkX3/ZU=17+github.com/charmbracelet/lipgloss v0.1.2/go.mod h1:5D8zradw52m7QmxRF6QgwbwJi9je84g8MkWiGN07uKg=18 github.com/containerd/console v1.0.1 h1:u7SFAJyRqWcG6ogaMAx3KjSTy1e3hT9QxqX7Jco7dRc=19 github.com/containerd/console v1.0.1/go.mod h1:XUsP6YE/mKtz6bxc+I8UiKKTP04qjQL4qcS3XoQ5xkw=20 github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=21 github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=12 unmodified lines34 github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=35 github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=36 github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=37 github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=36-github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=38 github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=39+github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=40+github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=41 github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=42 github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=43 github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=41-github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVhUqLX8=44 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk=45 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=46 github.com/muesli/termenv v0.6.0/go.mod h1:SohX91w6swWA4AYU+QmPx+aSgXhWO0juiyID9UZmbpA=45-github.com/muesli/termenv v0.7.4/go.mod h1:pZ7qY9l3F7e5xsAOS0zCew2tME+p7bWeBkotCEcIIcc=47 github.com/muesli/termenv v0.8.1 h1:9q230czSP3DHVpkaPDXGp0TOfAwyjyYwXlUCQxQSaBk=48 github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0=49 github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=50 github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=26 unmodified lines77 golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=78 golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=79 golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=80 golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=80-golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=81-golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1 h1:/DtoiOYKoQCcIFXQjz07RnWNPRCbqmSXSpgEzhC9ZHM=82-golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=81+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=82+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=83 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=