diff options
Diffstat (limited to 'src/tui/light.go')
-rw-r--r-- | src/tui/light.go | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/tui/light.go b/src/tui/light.go index 91b4c18e..d3e3faba 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -10,7 +10,8 @@ import ( "time" "unicode/utf8" - "github.com/junegunn/fzf/src/util" + "github.com/mattn/go-runewidth" + "github.com/rivo/uniseg" "golang.org/x/term" ) @@ -50,7 +51,7 @@ func (r *LightRenderer) stderrInternal(str string, allowNLCR bool) { } bytes = bytes[sz:] } - r.queued += string(runes) + r.queued.WriteString(string(runes)) } func (r *LightRenderer) csi(code string) { @@ -58,9 +59,9 @@ func (r *LightRenderer) csi(code string) { } func (r *LightRenderer) flush() { - if len(r.queued) > 0 { - fmt.Fprint(os.Stderr, r.queued) - r.queued = "" + if r.queued.Len() > 0 { + fmt.Fprint(os.Stderr, r.queued.String()) + r.queued.Reset() } } @@ -82,7 +83,7 @@ type LightRenderer struct { escDelay int fullscreen bool upOneLine bool - queued string + queued strings.Builder y int x int maxHeightFunc func(int) int @@ -889,20 +890,26 @@ func wrapLine(input string, prefixLength int, max int, tabstop int) []wrappedLin lines := []wrappedLine{} width := 0 line := "" - for _, r := range input { - w := util.RuneWidth(r, prefixLength+width, 8) - width += w - str := string(r) - if r == '\t' { + gr := uniseg.NewGraphemes(input) + for gr.Next() { + rs := gr.Runes() + str := string(rs) + var w int + if len(rs) == 1 && rs[0] == '\t' { + w = tabstop - (prefixLength+width)%tabstop str = repeat(' ', w) + } else { + w = runewidth.StringWidth(str) } + width += w + if prefixLength+width <= max { line += str } else { lines = append(lines, wrappedLine{string(line), width - w}) line = str prefixLength = 0 - width = util.RuneWidth(r, prefixLength, 8) + width = w } } lines = append(lines, wrappedLine{string(line), width}) |