diff --git a/go.mod b/go.mod index 622d352..087369d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/charmbracelet/glow go 1.13 require ( - github.com/charmbracelet/bubbles v0.0.0-20200526000837-87c7cd778f80 + github.com/charmbracelet/bubbles v0.0.0-20200602224800-12b2758d50f2 github.com/charmbracelet/bubbletea v0.7.1-0.20200528144715-b10f6d679158 github.com/charmbracelet/charm v0.5.1 github.com/charmbracelet/glamour v0.2.0 @@ -13,5 +13,5 @@ require ( github.com/spf13/cobra v0.0.7 golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect - golang.org/x/sys v0.0.0-20200523222454-059865788121 + golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34 ) diff --git a/go.sum b/go.sum index 0776bcc..837b176 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,8 @@ github.com/calmh/randomart v1.1.0/go.mod h1:DQUbPVyP+7PAs21w/AnfMKG5NioxS3TbZ2F9 github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/charmbracelet/bubbles v0.0.0-20200526000837-87c7cd778f80 h1:cfaoL1+tHPABTLEAg831PIFG96teW69Wamz9M025r5M= github.com/charmbracelet/bubbles v0.0.0-20200526000837-87c7cd778f80/go.mod h1:/AeLRFlL2Uf4X7U5LjnswTII6u4maPzMm1+vZfeUJKc= +github.com/charmbracelet/bubbles v0.0.0-20200602224800-12b2758d50f2 h1:JDEhuhIiBwpnd/3f0o/4pjYobUTnTU+sxvDMCDC/D78= +github.com/charmbracelet/bubbles v0.0.0-20200602224800-12b2758d50f2/go.mod h1:/AeLRFlL2Uf4X7U5LjnswTII6u4maPzMm1+vZfeUJKc= github.com/charmbracelet/bubbletea v0.6.4-0.20200525234836-3b8b011b5a26/go.mod h1:BTzHOUvUlKecQz7ZB8NgPRWi2Z8NRCV04qwyFOfO1Kk= github.com/charmbracelet/bubbletea v0.7.0 h1:nf0FEQCCc1e0qRGgpnz08QFsy25eDitzVwxV+Z/p4UI= github.com/charmbracelet/bubbletea v0.7.0/go.mod h1:BTzHOUvUlKecQz7ZB8NgPRWi2Z8NRCV04qwyFOfO1Kk= @@ -180,6 +182,8 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34 h1:u6CI7A++8r4SItZHYe2cWeAEndN4p1p+3Oum/Ft2EzM= +golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/ui/stash.go b/ui/stash.go index bf09ec3..a7880fe 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -19,7 +19,7 @@ import ( const ( stashViewItemHeight = 3 - stashViewTopPadding = 5 + stashViewTopPadding = 7 stashViewBottomPadding = 4 stashViewHorizontalPadding = 6 setNotePromptText = "Memo: " @@ -132,6 +132,9 @@ func (m stashModel) markdownIndex() int { // return the current selected markdown in the stash func (m stashModel) selectedMarkdown() *markdown { + if len(m.markdowns) == 0 { + return nil + } return m.markdowns[m.markdownIndex()] } @@ -395,20 +398,30 @@ func stashView(m stashModel) string { case stashStateSettingNote: fallthrough case stashStatePromptDelete: - if len(m.markdowns) == 0 { - s += stashEmtpyView(m) - break + + var stashView string + var stashViewHeight int + if len(m.markdowns) > 0 { + stashView = stashPopulatedView(m) + stashViewHeight = strings.Count(stashView, "\n") + 1 } // We need to fill any empty height with newlines so the footer reaches // the bottom. - numBlankLines := max(0, (m.terminalHeight-stashViewTopPadding-stashViewBottomPadding)%stashViewItemHeight) + //numBlankLines := max(0, (m.terminalHeight-stashViewTopPadding-stashViewBottomPadding)%stashViewItemHeight) + numBlankLines := max(0, (m.terminalHeight-stashViewTopPadding-stashViewBottomPadding)-stashViewHeight) blankLines := "" if numBlankLines > 0 { blankLines = strings.Repeat("\n", numBlankLines) } - header := "Here’s your markdown stash:" + var header string + if len(m.markdowns) > 0 { + header = "Here’s your markdown stash:" + } else { + header = "Nothing stashed yet. To stash you can " + common.Code("glow stash path/to/file.md") + "." + } + switch m.state { case stashStatePromptDelete: header = te.String("Delete this item? ").Foreground(common.Red.Color()).String() + @@ -430,7 +443,7 @@ func stashView(m stashModel) string { " %s\n\n %s\n\n%s\n\n%s %s\n\n %s", glowLogoView(" Glow "), header, - stashPopulatedView(m), + stashView, blankLines, pagination, stashHelpView(m), @@ -481,7 +494,8 @@ func stashPopulatedView(m stashModel) string { func stashHelpView(m stashModel) string { var ( h []string - isNews bool = m.selectedMarkdown().markdownType == newsMarkdown + md = m.selectedMarkdown() + isNews = md != nil && md.markdownType == newsMarkdown ) if m.state == stashStateSettingNote {