summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-01-21 02:52:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-01-21 02:54:41 +0900
commit16f647393838ea3eb0778a45178323aea21b67a0 (patch)
tree71f117d5d727b204f3e7f418ab8e68e1f5cbb437 /src/tui
parent66546208b2d29257b736302592f9566952e29905 (diff)
Change mattn/go-runewidth dependency to rivo/uniseg for accurate results
Related #3588 #3588 #3567
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/light.go15
-rw-r--r--src/tui/tcell.go11
-rw-r--r--src/tui/tui.go6
3 files changed, 18 insertions, 14 deletions
diff --git a/src/tui/light.go b/src/tui/light.go
index ae7cc0cb..5092371d 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -10,8 +10,7 @@ import (
"time"
"unicode/utf8"
- "github.com/junegunn/go-runewidth"
- "github.com/rivo/uniseg"
+ "github.com/junegunn/uniseg"
"golang.org/x/term"
)
@@ -804,7 +803,7 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
if w.preview {
color = ColPreviewBorder
}
- hw := runewidth.RuneWidth(w.border.top)
+ hw := runeWidth(w.border.top)
if top {
w.Move(0, 0)
w.CPrint(color, repeat(w.border.top, w.width/hw))
@@ -842,13 +841,13 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) {
if w.preview {
color = ColPreviewBorder
}
- hw := runewidth.RuneWidth(w.border.top)
- tcw := runewidth.RuneWidth(w.border.topLeft) + runewidth.RuneWidth(w.border.topRight)
- bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight)
+ hw := runeWidth(w.border.top)
+ tcw := runeWidth(w.border.topLeft) + runeWidth(w.border.topRight)
+ bcw := runeWidth(w.border.bottomLeft) + runeWidth(w.border.bottomRight)
rem := (w.width - tcw) % hw
w.CPrint(color, string(w.border.topLeft)+repeat(w.border.top, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))
if !onlyHorizontal {
- vw := runewidth.RuneWidth(w.border.left)
+ vw := runeWidth(w.border.left)
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
w.CPrint(color, string(w.border.left))
@@ -1020,7 +1019,7 @@ func wrapLine(input string, prefixLength int, max int, tabstop int) []wrappedLin
} else if rs[0] == '\r' {
w++
} else {
- w = runewidth.StringWidth(str)
+ w = uniseg.StringWidth(str)
}
width += w
diff --git a/src/tui/tcell.go b/src/tui/tcell.go
index d1180ac7..917dc9cb 100644
--- a/src/tui/tcell.go
+++ b/src/tui/tcell.go
@@ -10,8 +10,7 @@ import (
"github.com/gdamore/tcell/v2/encoding"
"github.com/junegunn/fzf/src/util"
- "github.com/junegunn/go-runewidth"
- "github.com/rivo/uniseg"
+ "github.com/junegunn/uniseg"
)
func HasFullscreenRenderer() bool {
@@ -738,7 +737,7 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
style = w.normal.style()
}
- hw := runewidth.RuneWidth(w.borderStyle.top)
+ hw := runeWidth(w.borderStyle.top)
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderTop:
max := right - 2*hw
@@ -773,7 +772,7 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
}
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderRight:
- vw := runewidth.RuneWidth(w.borderStyle.right)
+ vw := runeWidth(w.borderStyle.right)
for y := top; y < bot; y++ {
_screen.SetContent(right-vw, y, w.borderStyle.right, nil, style)
}
@@ -782,8 +781,8 @@ func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble:
_screen.SetContent(left, top, w.borderStyle.topLeft, nil, style)
- _screen.SetContent(right-runewidth.RuneWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)
+ _screen.SetContent(right-runeWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)
_screen.SetContent(left, bot-1, w.borderStyle.bottomLeft, nil, style)
- _screen.SetContent(right-runewidth.RuneWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)
+ _screen.SetContent(right-runeWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)
}
}
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 74129c16..a937e2b4 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -5,6 +5,8 @@ import (
"os"
"strconv"
"time"
+
+ "github.com/junegunn/uniseg"
)
// Types of user action
@@ -812,3 +814,7 @@ func initPalette(theme *ColorTheme) {
ColPreviewScrollbar = pair(theme.PreviewScrollbar, theme.PreviewBg)
ColPreviewSpinner = pair(theme.Spinner, theme.PreviewBg)
}
+
+func runeWidth(r rune) int {
+ return uniseg.StringWidth(string(r))
+}