mirror of
https://github.com/charmbracelet/glow
synced 2024-10-15 04:02:54 +00:00
Apply fine-grained spinner display rules to file listing view
This commit is contained in:
parent
60b1d6a6df
commit
912c80651a
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ go 1.13
|
|||
|
||||
require (
|
||||
github.com/alecthomas/chroma v0.8.0 // indirect
|
||||
github.com/charmbracelet/bubbles v0.5.2-0.20200825000354-e8526ec4ef07
|
||||
github.com/charmbracelet/bubbles v0.5.2-0.20200825133643-5f7c8b537514
|
||||
github.com/charmbracelet/bubbletea v0.10.3
|
||||
github.com/charmbracelet/charm v0.7.1-0.20200821194648-662b3ca6fc7e
|
||||
github.com/charmbracelet/glamour v0.2.1-0.20200820173154-593dda41c59f
|
||||
|
|
4
go.sum
4
go.sum
|
@ -21,8 +21,8 @@ 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/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/charmbracelet/bubbles v0.5.1/go.mod h1:xmZpdK4/Sn3bGgBKK40YPmM9Hf4taFGgKkLqSdAb0FA=
|
||||
github.com/charmbracelet/bubbles v0.5.2-0.20200825000354-e8526ec4ef07 h1:UDzKMYtj4Yy8/YDGCpTiZzbI0Ai0O9SGZM3R5oer4Dk=
|
||||
github.com/charmbracelet/bubbles v0.5.2-0.20200825000354-e8526ec4ef07/go.mod h1:MxySU+YRGbAhZQJavZlW2os+fIeOW69MI3iXqA+2/WA=
|
||||
github.com/charmbracelet/bubbles v0.5.2-0.20200825133643-5f7c8b537514 h1:bX+1jBgHjwf6X42XOZF5LZEHHU8AuCaXIjgoEFB8pM0=
|
||||
github.com/charmbracelet/bubbles v0.5.2-0.20200825133643-5f7c8b537514/go.mod h1:MxySU+YRGbAhZQJavZlW2os+fIeOW69MI3iXqA+2/WA=
|
||||
github.com/charmbracelet/bubbletea v0.9.1-0.20200713153904-2f53eeb54b90/go.mod h1:wjGGC5pyYvpuls0so+w4Zv+aZQW7RoPvsi9UBcDlSl8=
|
||||
github.com/charmbracelet/bubbletea v0.10.3 h1:arYCVde6OHbejtz08VOtAjsw4LlMR9pQhJCkqk3bwr8=
|
||||
github.com/charmbracelet/bubbletea v0.10.3/go.mod h1:fB1bVmlaXBYYv4G0jtuGSP/m8V2sMM97pq7QqQnubWI=
|
||||
|
|
|
@ -135,6 +135,7 @@ func newPagerModel(glamourStyle string) pagerModel {
|
|||
sp := spinner.NewModel()
|
||||
sp.ForegroundColor = statusBarNoteFg.String()
|
||||
sp.BackgroundColor = statusBarBg.String()
|
||||
sp.HideFor = time.Millisecond * 50
|
||||
sp.MinimumLifetime = time.Millisecond * 180
|
||||
|
||||
return pagerModel{
|
||||
|
@ -278,11 +279,11 @@ func pagerUpdate(msg tea.Msg, m pagerModel) (pagerModel, tea.Cmd) {
|
|||
}
|
||||
|
||||
case spinner.TickMsg:
|
||||
if m.state == pagerStateStashing || !m.spinner.MinimumLifetimeReached() {
|
||||
if m.state == pagerStateStashing || m.spinner.Visible() {
|
||||
newSpinnerModel, cmd := spinner.Update(msg, m.spinner)
|
||||
m.spinner = newSpinnerModel
|
||||
cmds = append(cmds, cmd)
|
||||
} else if m.state == pagerStateStashSuccess && m.spinner.MinimumLifetimeReached() {
|
||||
} else if m.state == pagerStateStashSuccess && !m.spinner.Visible() {
|
||||
m.state = pagerStateBrowse
|
||||
m.currentDocument = *m.stashedDocument
|
||||
m.stashedDocument = nil
|
||||
|
@ -308,7 +309,7 @@ func pagerUpdate(msg tea.Msg, m pagerModel) (pagerModel, tea.Cmd) {
|
|||
// message in the main update function where we're adding this stashed
|
||||
// item to the stash listing.
|
||||
m.state = pagerStateStashSuccess
|
||||
if m.spinner.MinimumLifetimeReached() {
|
||||
if !m.spinner.Visible() {
|
||||
m.state = pagerStateBrowse
|
||||
m.currentDocument = markdown(msg)
|
||||
cmd := m.showStatusMessage("Stashed!")
|
||||
|
@ -389,7 +390,7 @@ func pagerStatusBarView(b *strings.Builder, m pagerModel) {
|
|||
// Status indicator; spinner or stash dot
|
||||
var statusIndicator string
|
||||
if m.state == pagerStateStashing || m.state == pagerStateStashSuccess {
|
||||
if !m.spinner.Hidden() {
|
||||
if m.spinner.Visible() {
|
||||
statusIndicator = statusBarNoteStyle(" ") + spinner.View(m.spinner)
|
||||
}
|
||||
} else if isStashed && showStatusMessage {
|
||||
|
|
36
ui/stash.go
36
ui/stash.go
|
@ -132,9 +132,10 @@ type stashModel struct {
|
|||
terminalHeight int
|
||||
stashFullyLoaded bool // have we loaded everything from the server?
|
||||
loadingFromNetwork bool // are we currently loading something from the network?
|
||||
loaded loadedState // what's loaded? we find out with bitmasking
|
||||
loaded loadedState // tracks news, stash and local files loading; we find out with bitmasking
|
||||
|
||||
// Paths to files being stashed. We treat this like a set.
|
||||
// Paths to files being stashed. We treat this like a set, ignoring the
|
||||
// value portion with an empty struct.
|
||||
filesStashing map[string]struct{}
|
||||
|
||||
// This is just the index of the current page in view. To get the index
|
||||
|
@ -248,9 +249,12 @@ func (m *stashModel) hideStatusMessage() {
|
|||
// INIT
|
||||
|
||||
func newStashModel() stashModel {
|
||||
s := spinner.NewModel()
|
||||
s.Frames = spinner.Line
|
||||
s.ForegroundColor = common.SpinnerColor.String()
|
||||
sp := spinner.NewModel()
|
||||
sp.Frames = spinner.Line
|
||||
sp.ForegroundColor = common.SpinnerColor.String()
|
||||
sp.HideFor = time.Millisecond * 50
|
||||
sp.MinimumLifetime = time.Millisecond * 180
|
||||
sp.Start()
|
||||
|
||||
p := paginator.NewModel()
|
||||
p.Type = paginator.Dots
|
||||
|
@ -263,7 +267,7 @@ func newStashModel() stashModel {
|
|||
ni.Focus()
|
||||
|
||||
m := stashModel{
|
||||
spinner: s,
|
||||
spinner: sp,
|
||||
noteInput: ni,
|
||||
page: 1,
|
||||
paginator: p,
|
||||
|
@ -327,7 +331,8 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
condition := !m.loaded.done() ||
|
||||
m.loadingFromNetwork ||
|
||||
m.state == stashStateLoadingDocument ||
|
||||
len(m.filesStashing) > 0
|
||||
len(m.filesStashing) > 0 ||
|
||||
m.spinner.Visible()
|
||||
|
||||
if condition {
|
||||
newSpinnerModel, cmd := spinner.Update(msg, m.spinner)
|
||||
|
@ -442,18 +447,23 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) {
|
|||
break
|
||||
}
|
||||
|
||||
// If we're busy stashing this don't do it again
|
||||
_, exists := m.filesStashing[md.localPath]
|
||||
_, exists := m.filesStashing[md.localPath] // is the file currently being stashed?
|
||||
|
||||
if exists || (md.markdownType != localMarkdown) || md.localPath == "" {
|
||||
if md.markdownType == localMarkdown && md.localPath == "" {
|
||||
log.Printf("refusing to load markdown; local path is empty: %#v", md)
|
||||
log.Printf("refusing to stash markdown; local path is empty: %#v", md)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Checks passed; perform the stash
|
||||
m.filesStashing[md.localPath] = struct{}{}
|
||||
cmds = append(cmds, stashDocument(m.cc, *md), spinner.Tick(m.spinner))
|
||||
cmds = append(cmds, stashDocument(m.cc, *md))
|
||||
|
||||
if m.loaded.done() && !m.spinner.Visible() {
|
||||
m.spinner.Start()
|
||||
cmds = append(cmds, spinner.Tick(m.spinner))
|
||||
}
|
||||
|
||||
// Prompt for deletion
|
||||
case "x":
|
||||
|
@ -598,7 +608,7 @@ func stashView(m stashModel) string {
|
|||
case stashStateReady, stashStateSettingNote, stashStatePromptDelete:
|
||||
|
||||
loadingIndicator := ""
|
||||
if !m.loaded.done() || m.loadingFromNetwork || len(m.filesStashing) > 0 {
|
||||
if !m.loaded.done() || m.loadingFromNetwork || m.spinner.Visible() {
|
||||
loadingIndicator = spinner.View(m.spinner)
|
||||
}
|
||||
|
||||
|
@ -623,7 +633,7 @@ func stashView(m stashModel) string {
|
|||
}
|
||||
|
||||
// Only draw the normal header if we're not using the header area for
|
||||
// something else (like a prompt)
|
||||
// something else (like a prompt or status message)
|
||||
if header == "" {
|
||||
header = stashHeaderView(m)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue