Upgrade to Bubble Tea v0.12.2 and Bubbles v0.7.5

This commit is contained in:
Christian Rocha 2020-11-13 16:17:50 -05:00 committed by Christian Rocha
parent 7722b6e6bc
commit fb5a81f4d6
6 changed files with 36 additions and 39 deletions

4
go.mod
View file

@ -4,8 +4,8 @@ go 1.13
require ( require (
github.com/alecthomas/chroma v0.8.0 // indirect github.com/alecthomas/chroma v0.8.0 // indirect
github.com/charmbracelet/bubbles v0.7.1 github.com/charmbracelet/bubbles v0.7.5
github.com/charmbracelet/bubbletea v0.12.1 github.com/charmbracelet/bubbletea v0.12.2
github.com/charmbracelet/charm v0.8.2 github.com/charmbracelet/charm v0.8.2
github.com/charmbracelet/glamour v0.2.1-0.20200829234023-6c0e29c4dae5 github.com/charmbracelet/glamour v0.2.1-0.20200829234023-6c0e29c4dae5
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac

8
go.sum
View file

@ -43,12 +43,12 @@ github.com/calmh/randomart v1.1.0 h1:evl+iwc10LXtHdMZhzLxmsCQVmWnkXs44SbC6Uk0Il8
github.com/calmh/randomart v1.1.0/go.mod h1:DQUbPVyP+7PAs21w/AnfMKG5NioxS3TbZ2F9MSK/jFM= github.com/calmh/randomart v1.1.0/go.mod h1:DQUbPVyP+7PAs21w/AnfMKG5NioxS3TbZ2F9MSK/jFM=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/charmbracelet/bubbles v0.6.0/go.mod h1:MxySU+YRGbAhZQJavZlW2os+fIeOW69MI3iXqA+2/WA= github.com/charmbracelet/bubbles v0.6.0/go.mod h1:MxySU+YRGbAhZQJavZlW2os+fIeOW69MI3iXqA+2/WA=
github.com/charmbracelet/bubbles v0.7.1 h1:qvXoIh7ItTA+IA+IO2xxuI9ntp+uVprDAK+IoMzC5OI= github.com/charmbracelet/bubbles v0.7.5 h1:N6TiahuRt2iGNE5gYxKBQ5/C6Lc8xxSp5LY9QJ09mS4=
github.com/charmbracelet/bubbles v0.7.1/go.mod h1:UV3dot0XR45cnQX2d8gtohfUFMepquRG2WE56LPKWNc= github.com/charmbracelet/bubbles v0.7.5/go.mod h1:IRTORFvhEI6OUH7WhN2Ks8Z8miNGimk1BE6cmHijOkM=
github.com/charmbracelet/bubbletea v0.10.3/go.mod h1:fB1bVmlaXBYYv4G0jtuGSP/m8V2sMM97pq7QqQnubWI= github.com/charmbracelet/bubbletea v0.10.3/go.mod h1:fB1bVmlaXBYYv4G0jtuGSP/m8V2sMM97pq7QqQnubWI=
github.com/charmbracelet/bubbletea v0.10.5/go.mod h1:Nay5oWkkSZvc6E/be+W3nDFXAsVytNUNKV9jbXcuae0= github.com/charmbracelet/bubbletea v0.10.5/go.mod h1:Nay5oWkkSZvc6E/be+W3nDFXAsVytNUNKV9jbXcuae0=
github.com/charmbracelet/bubbletea v0.12.1 h1:t21pkG2IDBRduPbt2J64Dx5yt8yIidAkXwhhrc11SzY= github.com/charmbracelet/bubbletea v0.12.2 h1:y9Yo2Pv8tcm3mAJsWONGsmHhzrbNxJVxpVtemikxE9A=
github.com/charmbracelet/bubbletea v0.12.1/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg= github.com/charmbracelet/bubbletea v0.12.2/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg=
github.com/charmbracelet/charm v0.8.2 h1:sYJhP7YopJUvjWE8VKlNrcAHAaRZsEgKn8z2FoIhHOI= github.com/charmbracelet/charm v0.8.2 h1:sYJhP7YopJUvjWE8VKlNrcAHAaRZsEgKn8z2FoIhHOI=
github.com/charmbracelet/charm v0.8.2/go.mod h1:xi3evUxj8hw+dMApaXRczb2SiEzrn8a3NYobj0off+c= github.com/charmbracelet/charm v0.8.2/go.mod h1:xi3evUxj8hw+dMApaXRczb2SiEzrn8a3NYobj0off+c=
github.com/charmbracelet/glamour v0.2.1-0.20200829234023-6c0e29c4dae5 h1:XgXVfMdJTNTq/ajMvwiB1OW3Tg/TXHtM3tYr/vYF76w= github.com/charmbracelet/glamour v0.2.1-0.20200829234023-6c0e29c4dae5 h1:XgXVfMdJTNTq/ajMvwiB1OW3Tg/TXHtM3tYr/vYF76w=

View file

@ -244,7 +244,7 @@ func (m pagerModel) Update(msg tea.Msg) (pagerModel, tea.Cmd) {
m.textInput.CursorEnd() m.textInput.CursorEnd()
} }
return m, textinput.Blink(m.textInput) return m, textinput.Blink
case "s": case "s":
if m.authStatus != authOK { if m.authStatus != authOK {
break break
@ -257,7 +257,7 @@ func (m pagerModel) Update(msg tea.Msg) (pagerModel, tea.Cmd) {
cmds = append( cmds = append(
cmds, cmds,
stashDocument(m.cc, m.currentDocument), stashDocument(m.cc, m.currentDocument),
spinner.Tick(m.spinner), spinner.Tick,
) )
} }
case "?": case "?":
@ -270,7 +270,7 @@ func (m pagerModel) Update(msg tea.Msg) (pagerModel, tea.Cmd) {
case spinner.TickMsg: case spinner.TickMsg:
if m.state == pagerStateStashing || m.spinner.Visible() { if m.state == pagerStateStashing || m.spinner.Visible() {
newSpinnerModel, cmd := spinner.Update(msg, m.spinner) newSpinnerModel, cmd := m.spinner.Update(msg)
m.spinner = newSpinnerModel m.spinner = newSpinnerModel
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
} else if m.state == pagerStateStashSuccess && !m.spinner.Visible() { } else if m.state == pagerStateStashSuccess && !m.spinner.Visible() {
@ -319,10 +319,10 @@ func (m pagerModel) Update(msg tea.Msg) (pagerModel, tea.Cmd) {
switch m.state { switch m.state {
case pagerStateSetNote: case pagerStateSetNote:
m.textInput, cmd = textinput.Update(msg, m.textInput) m.textInput, cmd = m.textInput.Update(msg)
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
default: default:
m.viewport, cmd = viewport.Update(msg, m.viewport) m.viewport, cmd = m.viewport.Update(msg)
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
} }
@ -331,7 +331,7 @@ func (m pagerModel) Update(msg tea.Msg) (pagerModel, tea.Cmd) {
func (m pagerModel) View() string { func (m pagerModel) View() string {
var b strings.Builder var b strings.Builder
fmt.Fprint(&b, viewport.View(m.viewport)+"\n") fmt.Fprint(&b, m.viewport.View()+"\n")
// Footer // Footer
switch m.state { switch m.state {
@ -383,7 +383,7 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
var statusIndicator string var statusIndicator string
if m.state == pagerStateStashing || m.state == pagerStateStashSuccess { if m.state == pagerStateStashing || m.state == pagerStateStashSuccess {
if m.spinner.Visible() { if m.spinner.Visible() {
statusIndicator = statusBarNoteStyle(" ") + spinner.View(m.spinner) statusIndicator = statusBarNoteStyle(" ") + m.spinner.View()
} }
} else if isStashed && showStatusMessage { } else if isStashed && showStatusMessage {
statusIndicator = statusBarMessageStashIconStyle(" " + pagerStashIcon) statusIndicator = statusBarMessageStashIconStyle(" " + pagerStashIcon)
@ -442,7 +442,7 @@ func (m pagerModel) statusBarView(b *strings.Builder) {
func (m pagerModel) setNoteView(b *strings.Builder) { func (m pagerModel) setNoteView(b *strings.Builder) {
fmt.Fprint(b, noteHeading) fmt.Fprint(b, noteHeading)
fmt.Fprint(b, textinput.View(m.textInput)) fmt.Fprint(b, m.textInput.View())
} }
func (m pagerModel) helpView() (s string) { func (m pagerModel) helpView() (s string) {

View file

@ -306,7 +306,7 @@ func (m *stashModel) moveCursorDown() {
func newStashModel(cfg *Config, as authStatus) stashModel { func newStashModel(cfg *Config, as authStatus) stashModel {
sp := spinner.NewModel() sp := spinner.NewModel()
sp.Frames = spinner.Line sp.Spinner = spinner.Line
sp.ForegroundColor = common.SpinnerColor.String() sp.ForegroundColor = common.SpinnerColor.String()
sp.HideFor = time.Millisecond * 50 sp.HideFor = time.Millisecond * 50
sp.MinimumLifetime = time.Millisecond * 180 sp.MinimumLifetime = time.Millisecond * 180
@ -399,7 +399,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
m.spinner.Visible() m.spinner.Visible()
if condition { if condition {
newSpinnerModel, cmd := spinner.Update(msg, m.spinner) newSpinnerModel, cmd := m.spinner.Update(msg)
m.spinner = newSpinnerModel m.spinner = newSpinnerModel
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
} }
@ -484,7 +484,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
cmds = append(cmds, loadRemoteMarkdown(m.cc, md.ID, md.markdownType)) cmds = append(cmds, loadRemoteMarkdown(m.cc, md.ID, md.markdownType))
} }
cmds = append(cmds, spinner.Tick(m.spinner)) cmds = append(cmds, spinner.Tick)
// Search through your notes // Search through your notes
case "/": case "/":
@ -495,7 +495,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
m.state = stashStateSearchNotes m.state = stashStateSearchNotes
m.searchInput.CursorEnd() m.searchInput.CursorEnd()
m.searchInput.Focus() m.searchInput.Focus()
return m, textinput.Blink(m.searchInput) return m, textinput.Blink
// Set note // Set note
case "m": case "m":
@ -514,7 +514,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
m.state = stashStateSettingNote m.state = stashStateSettingNote
m.noteInput.SetValue(md.Note) m.noteInput.SetValue(md.Note)
m.noteInput.CursorEnd() m.noteInput.CursorEnd()
return m, textinput.Blink(m.noteInput) return m, textinput.Blink
} }
// Stash // Stash
@ -546,7 +546,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
if m.loadingDone() && !m.spinner.Visible() { if m.loadingDone() && !m.spinner.Visible() {
m.spinner.Start() m.spinner.Start()
cmds = append(cmds, spinner.Tick(m.spinner)) cmds = append(cmds, spinner.Tick)
} }
// Prompt for deletion // Prompt for deletion
@ -577,19 +577,17 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
// Update paginator. Pagination key handling is done here, but it could // Update paginator. Pagination key handling is done here, but it could
// also be moved up to this level, in which case we'd use model methods // also be moved up to this level, in which case we'd use model methods
// like model.PageUp(). // like model.PageUp().
newPaginatorModel, cmd := paginator.Update(msg, m.paginator) newPaginatorModel, cmd := m.paginator.Update(msg)
m.paginator = newPaginatorModel m.paginator = newPaginatorModel
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
// Extra paginator keystrokes // Extra paginator keystrokes
if key, ok := msg.(tea.KeyMsg); ok { if key, ok := msg.(tea.KeyMsg); ok {
if key.Type == tea.KeyRune { switch key.String() {
switch key.Rune { case "b", "u":
case 'b', 'u': m.paginator.PrevPage()
m.paginator.PrevPage() case "f", "d":
case 'f', 'd': m.paginator.NextPage()
m.paginator.NextPage()
}
} }
} }
@ -699,7 +697,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
} }
// Update the search text input component // Update the search text input component
newSearchInputModel, cmd := textinput.Update(msg, m.searchInput) newSearchInputModel, cmd := m.searchInput.Update(msg)
m.searchInput = newSearchInputModel m.searchInput = newSearchInputModel
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
@ -732,7 +730,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
} }
// Update the note text input component // Update the note text input component
newNoteInputModel, cmd := textinput.Update(msg, m.noteInput) newNoteInputModel, cmd := m.noteInput.Update(msg)
m.noteInput = newNoteInputModel m.noteInput = newNoteInputModel
cmds = append(cmds, cmd) cmds = append(cmds, cmd)
@ -756,12 +754,12 @@ func stashView(m stashModel) string {
case stashStateShowingError: case stashStateShowingError:
return errorView(m.err, false) return errorView(m.err, false)
case stashStateLoadingDocument: case stashStateLoadingDocument:
s += " " + spinner.View(m.spinner) + " Loading document..." s += " " + m.spinner.View() + " Loading document..."
case stashStateReady, stashStateSettingNote, stashStatePromptDelete, stashStateSearchNotes, stashStateShowFiltered: case stashStateReady, stashStateSettingNote, stashStatePromptDelete, stashStateSearchNotes, stashStateShowFiltered:
loadingIndicator := " " loadingIndicator := " "
if !m.localOnly() && (!m.loadingDone() || m.loadingFromNetwork || m.spinner.Visible()) { if !m.localOnly() && (!m.loadingDone() || m.loadingFromNetwork || m.spinner.Visible()) {
loadingIndicator = spinner.View(m.spinner) loadingIndicator = m.spinner.View()
} }
// We need to fill any empty height with newlines so the footer reaches // We need to fill any empty height with newlines so the footer reaches
@ -794,18 +792,18 @@ func stashView(m stashModel) string {
// If we're filtering we replace the logo with the search field // If we're filtering we replace the logo with the search field
if m.state == stashStateSearchNotes || m.state == stashStateShowFiltered { if m.state == stashStateSearchNotes || m.state == stashStateShowFiltered {
logoOrSearch = textinput.View(m.searchInput) logoOrSearch = m.searchInput.View()
} }
var pagination string var pagination string
if m.paginator.TotalPages > 1 { if m.paginator.TotalPages > 1 {
pagination = paginator.View(m.paginator) pagination = m.paginator.View()
// If the dot pagination is wider than the width of the window // If the dot pagination is wider than the width of the window
// switch to the arabic paginator. // switch to the arabic paginator.
if ansi.PrintableRuneWidth(pagination) > m.terminalWidth-stashViewHorizontalPadding { if ansi.PrintableRuneWidth(pagination) > m.terminalWidth-stashViewHorizontalPadding {
m.paginator.Type = paginator.Arabic m.paginator.Type = paginator.Arabic
pagination = common.Subtle(paginator.View(m.paginator)) pagination = common.Subtle(m.paginator.View())
} }
// We could also look at m.stashFullyLoaded and add an indicator // We could also look at m.stashFullyLoaded and add an indicator

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/charmbracelet/bubbles/textinput"
rw "github.com/mattn/go-runewidth" rw "github.com/mattn/go-runewidth"
) )
@ -61,7 +60,7 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) {
case stashStateSettingNote: case stashStateSettingNote:
gutter = dullYellowFg(verticalLine) gutter = dullYellowFg(verticalLine)
icon = "" icon = ""
title = textinput.View(m.noteInput) title = m.noteInput.View()
date = dullYellowFg(date) date = dullYellowFg(date)
default: default:
gutter = dullFuchsiaFg(verticalLine) gutter = dullFuchsiaFg(verticalLine)

View file

@ -171,7 +171,7 @@ func (m *model) unloadDocument() []tea.Cmd {
} }
if !m.stash.loadingDone() || m.stash.loadingFromNetwork { if !m.stash.loadingDone() || m.stash.loadingFromNetwork {
batch = append(batch, spinner.Tick(m.stash.spinner)) batch = append(batch, spinner.Tick)
} }
return batch return batch
} }
@ -213,7 +213,7 @@ func (m model) Init() tea.Cmd {
if m.cfg.DocumentTypes&StashedDocuments != 0 || m.cfg.DocumentTypes&NewsDocuments != 0 { if m.cfg.DocumentTypes&StashedDocuments != 0 || m.cfg.DocumentTypes&NewsDocuments != 0 {
cmds = append(cmds, cmds = append(cmds,
newCharmClient, newCharmClient,
spinner.Tick(m.stash.spinner), spinner.Tick,
) )
} }