summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-01-16 01:22:02 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-01-16 01:26:39 +0900
commit0c5956c43c1604d8e4364f08369dc4c58295ef3c (patch)
tree1c7a4601c7b2b108febefdde6cab9117ebe144f4 /src/tui
parent1c83b3969185393f0427463a39ef1523c273c16c (diff)
Better support for Windows terminals
* Default border style on Windows is changed to `sharp` because some Windows terminals are not capable of displaying `rounded` border characters correctly. * If your terminal emulator renders each box-drawing character with 2 columns, set `RUNEWIDTH_EASTASIAN` environment variable to `1`.
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/dummy.go3
-rw-r--r--src/tui/light.go19
-rw-r--r--src/tui/tcell.go17
-rw-r--r--src/tui/tui.go1
4 files changed, 30 insertions, 10 deletions
diff --git a/src/tui/dummy.go b/src/tui/dummy.go
index adecd6fc..7a02a8af 100644
--- a/src/tui/dummy.go
+++ b/src/tui/dummy.go
@@ -8,6 +8,8 @@ func HasFullscreenRenderer() bool {
return false
}
+var DefaultBorderShape BorderShape = BorderRounded
+
func (a Attr) Merge(b Attr) Attr {
return a | b
}
@@ -32,6 +34,7 @@ func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}
func (r *FullscreenRenderer) Pause(bool) {}
func (r *FullscreenRenderer) Resume(bool, bool) {}
func (r *FullscreenRenderer) Clear() {}
+func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }
func (r *FullscreenRenderer) Refresh() {}
func (r *FullscreenRenderer) Close() {}
diff --git a/src/tui/light.go b/src/tui/light.go
index c41de480..578118b7 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -651,6 +651,10 @@ func (r *LightRenderer) Clear() {
r.flush()
}
+func (r *LightRenderer) NeedScrollbarRedraw() bool {
+ return false
+}
+
func (r *LightRenderer) RefreshWindows(windows []Window) {
r.flush()
}
@@ -743,13 +747,14 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
if w.preview {
color = ColPreviewBorder
}
+ hw := runewidth.RuneWidth(w.border.horizontal)
if top {
w.Move(0, 0)
- w.CPrint(color, repeat(w.border.horizontal, w.width))
+ w.CPrint(color, repeat(w.border.horizontal, w.width/hw))
}
if bottom {
w.Move(w.height-1, 0)
- w.CPrint(color, repeat(w.border.horizontal, w.width))
+ w.CPrint(color, repeat(w.border.horizontal, w.width/hw))
}
}
@@ -780,15 +785,19 @@ func (w *LightWindow) drawBorderAround() {
if w.preview {
color = ColPreviewBorder
}
- w.CPrint(color, string(w.border.topLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.topRight))
+ hw := runewidth.RuneWidth(w.border.horizontal)
+ vw := runewidth.RuneWidth(w.border.vertical)
+ tcw := runewidth.RuneWidth(w.border.topLeft) + runewidth.RuneWidth(w.border.topRight)
+ bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight)
+ w.CPrint(color, string(w.border.topLeft)+repeat(w.border.horizontal, (w.width-tcw)/hw)+string(w.border.topRight))
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
w.CPrint(color, string(w.border.vertical))
- w.CPrint(color, repeat(' ', w.width-2))
+ w.CPrint(color, repeat(' ', w.width-vw*2))
w.CPrint(color, string(w.border.vertical))
}
w.Move(w.height-1, 0)
- w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.bottomRight))
+ w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.horizontal, (w.width-bcw)/hw)+string(w.border.bottomRight))
}
func (w *LightWindow) csi(code string) {
diff --git a/src/tui/tcell.go b/src/tui/tcell.go
index 82d72995..f1f18e24 100644
--- a/src/tui/tcell.go
+++ b/src/tui/tcell.go
@@ -17,6 +17,8 @@ func HasFullscreenRenderer() bool {
return true
}
+var DefaultBorderShape BorderShape = BorderSharp
+
func asTcellColor(color Color) tcell.Color {
if color == colDefault {
return tcell.ColorDefault
@@ -187,6 +189,10 @@ func (r *FullscreenRenderer) Clear() {
_screen.Clear()
}
+func (r *FullscreenRenderer) NeedScrollbarRedraw() bool {
+ return true
+}
+
func (r *FullscreenRenderer) Refresh() {
// noop
}
@@ -686,15 +692,16 @@ func (w *TcellWindow) drawBorder() {
style = w.normal.style()
}
+ hw := runewidth.RuneWidth(w.borderStyle.horizontal)
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderHorizontal, BorderTop:
- for x := left; x < right; x++ {
+ for x := left; x <= right-hw; x += hw {
_screen.SetContent(x, top, w.borderStyle.horizontal, nil, style)
}
}
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderHorizontal, BorderBottom:
- for x := left; x < right; x++ {
+ for x := left; x <= right-hw; x += hw {
_screen.SetContent(x, bot-1, w.borderStyle.horizontal, nil, style)
}
}
@@ -707,14 +714,14 @@ func (w *TcellWindow) drawBorder() {
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderRight:
for y := top; y < bot; y++ {
- _screen.SetContent(right-1, y, w.borderStyle.vertical, nil, style)
+ _screen.SetContent(right-hw, y, w.borderStyle.vertical, nil, style)
}
}
switch shape {
case BorderRounded, BorderSharp, BorderBold, BorderDouble:
_screen.SetContent(left, top, w.borderStyle.topLeft, nil, style)
- _screen.SetContent(right-1, top, w.borderStyle.topRight, nil, style)
+ _screen.SetContent(right-runewidth.RuneWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)
_screen.SetContent(left, bot-1, w.borderStyle.bottomLeft, nil, style)
- _screen.SetContent(right-1, bot-1, w.borderStyle.bottomRight, nil, style)
+ _screen.SetContent(right-runewidth.RuneWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)
}
}
diff --git a/src/tui/tui.go b/src/tui/tui.go
index c6a65d82..5a86453b 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -410,6 +410,7 @@ type Renderer interface {
RefreshWindows(windows []Window)
Refresh()
Close()
+ NeedScrollbarRedraw() bool
GetChar() Event