Update examples for Bubbles v0.8.0

This commit is contained in:
Christian Rocha 2020-10-31 20:58:24 -04:00
parent 02a0509e34
commit 5d34c88692
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
3 changed files with 10 additions and 9 deletions

View File

@ -89,16 +89,17 @@ func (e example) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "q", "ctrl+c": case "q", "ctrl+c":
return e, tea.Quit return e, tea.Quit
default: default:
vp, _ := viewport.Update(msg, e.viewport) vp, cmd := e.viewport.Update(msg)
e.viewport = vp e.viewport = vp
return e, cmd
} }
} default:
return e, nil return e, nil
}
} }
func (e example) View() string { func (e example) View() string {
return viewport.View(e.viewport) + e.helpView() return e.viewport.View() + e.helpView()
} }
func (e example) helpView() string { func (e example) helpView() string {

View File

@ -126,7 +126,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// * Recieves messages from the Bubble Tea runtime // * Recieves messages from the Bubble Tea runtime
// * Returns commands to the Bubble Tea runtime // * Returns commands to the Bubble Tea runtime
// //
m.viewport, cmd = viewport.Update(msg, m.viewport) m.viewport, cmd = m.viewport.Update(msg)
if useHighPerformanceRenderer { if useHighPerformanceRenderer {
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
} }
@ -154,5 +154,5 @@ func (m model) View() string {
footerBot = strings.Repeat(" ", gapSize) + footerBot footerBot = strings.Repeat(" ", gapSize) + footerBot
footer := fmt.Sprintf("%s\n%s\n%s", footerTop, footerMid, footerBot) footer := fmt.Sprintf("%s\n%s\n%s", footerTop, footerMid, footerBot)
return fmt.Sprintf("%s\n%s\n%s", header, viewport.View(m.viewport), footer) return fmt.Sprintf("%s\n%s\n%s", header, m.viewport.View(), footer)
} }

View File

@ -37,7 +37,7 @@ func initialModel() model {
} }
func (m model) Init() tea.Cmd { func (m model) Init() tea.Cmd {
return spinner.Tick(m.spinner) return spinner.Tick
} }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
@ -62,7 +62,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
default: default:
var cmd tea.Cmd var cmd tea.Cmd
m.spinner, cmd = spinner.Update(msg, m.spinner) m.spinner, cmd = m.spinner.Update(msg)
return m, cmd return m, cmd
} }
@ -73,7 +73,7 @@ func (m model) View() string {
return m.err.Error() return m.err.Error()
} }
s := termenv. s := termenv.
String(spinner.View(m.spinner)). String(m.spinner.View()).
Foreground(term.Color("205")). Foreground(term.Color("205")).
String() String()
str := fmt.Sprintf("\n\n %s Loading forever...press q to quit\n\n", s) str := fmt.Sprintf("\n\n %s Loading forever...press q to quit\n\n", s)