diff --git a/go.mod b/go.mod index 04cf4fb..2360c5d 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 56d847a..600d915 100644 --- a/go.sum +++ b/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= diff --git a/ui/pager.go b/ui/pager.go index bb9caf8..9399cc4 100644 --- a/ui/pager.go +++ b/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",