mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-18 06:09:11 +02:00
Properly truncate fullwidth/double-byte chars
This commit is contained in:
parent
9179515e62
commit
562d02dc43
2 changed files with 4 additions and 11 deletions
|
|
@ -266,14 +266,13 @@ func pagerStatusBarView(b *strings.Builder, m pagerModel) {
|
|||
if len(noteText) == 0 {
|
||||
noteText = "(No title)"
|
||||
}
|
||||
noteText = truncate(" "+noteText+" ", max(
|
||||
0,
|
||||
noteText = truncate(" "+noteText+" ", max(0,
|
||||
m.width-len(logoText)-len(percentText)-len(helpNoteText),
|
||||
))
|
||||
|
||||
// Empty space
|
||||
emptyCell := te.String(" ").Background(statusBarBg.Color()).String()
|
||||
padding := max(0, m.width-len(logoText)-len(noteText)-len(percentText)-len(helpNoteText))
|
||||
padding := max(0, m.width-len(logoText)-runewidth.StringWidth(noteText)-len(percentText)-len(helpNoteText))
|
||||
emptySpace := strings.Repeat(emptyCell, padding)
|
||||
|
||||
fmt.Fprintf(b, "%s%s%s%s%s",
|
||||
|
|
|
|||
10
ui/stash.go
10
ui/stash.go
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/charmbracelet/charm"
|
||||
"github.com/charmbracelet/charm/ui/common"
|
||||
"github.com/dustin/go-humanize"
|
||||
runewidth "github.com/mattn/go-runewidth"
|
||||
te "github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
|
@ -587,14 +588,7 @@ func wrapMarkdowns(t markdownType, md []*charm.Markdown) (m []*markdown) {
|
|||
}
|
||||
|
||||
func truncate(str string, num int) string {
|
||||
s := str
|
||||
if len(str) > num {
|
||||
if num > 1 {
|
||||
num -= 1
|
||||
}
|
||||
s = str[0:num] + "…"
|
||||
}
|
||||
return s
|
||||
return runewidth.Truncate(str, num, "…")
|
||||
}
|
||||
|
||||
var magnitudes = []humanize.RelTimeMagnitude{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue