mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
Cleanup pager status bar view thanks to the latest updates in reflow
This commit is contained in:
parent
f52311af88
commit
1200b86729
3 changed files with 17 additions and 8 deletions
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require (
|
|||
github.com/mattn/go-runewidth v0.0.9
|
||||
github.com/meowgorithm/babyenv v1.2.1
|
||||
github.com/muesli/gitcha v0.0.0-20200714001838-c071c3c6c6e1
|
||||
github.com/muesli/reflow v0.1.1-0.20200715144030-a312cb5b2d8d
|
||||
github.com/muesli/termenv v0.5.3-0.20200715143749-3facc679bc62
|
||||
github.com/spf13/cobra v0.0.7
|
||||
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
|
||||
|
|
4
go.sum
4
go.sum
|
@ -93,10 +93,10 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
|
|||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/muesli/gitcha v0.0.0-20200714001838-c071c3c6c6e1 h1:UhmEuW8xAMA+CdXQgYQ9Iilnhyf+uNYWCJSotCldI7o=
|
||||
github.com/muesli/gitcha v0.0.0-20200714001838-c071c3c6c6e1/go.mod h1:o3FpDWpvjmTm4Tzzrgq1ZhtYrplVPSpdgav7+YzaLLs=
|
||||
github.com/muesli/reflow v0.1.0 h1:oQdpLfO56lr5pgLvqD0TcjW85rDjSYSBVdiG1Ch1ddM=
|
||||
github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=
|
||||
github.com/muesli/reflow v0.1.1-0.20200715144030-a312cb5b2d8d h1:ok5jhmKQze1yERN73u46EZhUH4vgC1z4qfeFJ8iOwvg=
|
||||
github.com/muesli/reflow v0.1.1-0.20200715144030-a312cb5b2d8d/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=
|
||||
github.com/muesli/termenv v0.5.2/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/muesli/termenv v0.5.3-0.20200625163851-04b5c30e4c04 h1:Wr876oXlAk6avTWi0daXAriOr+r5fqIuyDmtNc/KwY0=
|
||||
github.com/muesli/termenv v0.5.3-0.20200625163851-04b5c30e4c04/go.mod h1:O1/I6sw+6KcrgAmcs6uiUVr7Lui+DNVbHTzt9Lm/PlI=
|
||||
github.com/muesli/termenv v0.5.3-0.20200715143749-3facc679bc62 h1:W1+qXP5nmjE+c6IG2xQGs1tUit2NZXAKqBiYM4zf/vg=
|
||||
github.com/muesli/termenv v0.5.3-0.20200715143749-3facc679bc62/go.mod h1:SohX91w6swWA4AYU+QmPx+aSgXhWO0juiyID9UZmbpA=
|
||||
|
|
20
ui/pager.go
20
ui/pager.go
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/charmbracelet/charm/ui/common"
|
||||
"github.com/charmbracelet/glamour"
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
"github.com/muesli/reflow/ansi"
|
||||
te "github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
@ -255,16 +256,14 @@ func pagerView(m pagerModel) string {
|
|||
|
||||
func pagerStatusBarView(b *strings.Builder, m pagerModel) {
|
||||
// Logo
|
||||
logoText := " Glow "
|
||||
logo := glowLogoView(logoText)
|
||||
logo := glowLogoView(" Glow ")
|
||||
|
||||
// Scroll percent
|
||||
scrollPercent := math.Max(0.0, math.Min(1.0, m.viewport.ScrollPercent()))
|
||||
percentText := fmt.Sprintf(" %3.f%% ", scrollPercent*100)
|
||||
|
||||
// "Help" note
|
||||
helpNoteText := " ? Help "
|
||||
helpNote := statusBarHelpStyle(helpNoteText)
|
||||
helpNote := statusBarHelpStyle(" ? Help ")
|
||||
|
||||
// Note
|
||||
noteText := m.currentDocument.Note
|
||||
|
@ -272,12 +271,21 @@ func pagerStatusBarView(b *strings.Builder, m pagerModel) {
|
|||
noteText = "(No title)"
|
||||
}
|
||||
noteText = truncate(" "+noteText+" ", max(0,
|
||||
m.width-len(logoText)-len(percentText)-len(helpNoteText),
|
||||
m.width-
|
||||
ansi.PrintableRuneWidth(logo)-
|
||||
ansi.PrintableRuneWidth(percentText)-
|
||||
ansi.PrintableRuneWidth(helpNote),
|
||||
))
|
||||
|
||||
// Empty space
|
||||
emptyCell := te.String(" ").Background(statusBarBg.Color()).String()
|
||||
padding := max(0, m.width-len(logoText)-runewidth.StringWidth(noteText)-len(percentText)-len(helpNoteText))
|
||||
padding := max(0,
|
||||
m.width-
|
||||
ansi.PrintableRuneWidth(logo)-
|
||||
ansi.PrintableRuneWidth(noteText)-
|
||||
ansi.PrintableRuneWidth(percentText)-
|
||||
ansi.PrintableRuneWidth(helpNote),
|
||||
)
|
||||
emptySpace := strings.Repeat(emptyCell, padding)
|
||||
|
||||
fmt.Fprintf(b, "%s%s%s%s%s",
|
||||
|
|
Loading…
Reference in a new issue