summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-05-16 23:45:31 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-05-16 23:45:31 +0900
commit43436e48e0dacb51f9ab3da84b4c1ec697b744da (patch)
tree6e4465fdcad864ea4a79dd52307519ce43d10467 /src/tui
parent5a391024059e055f9e21b997ff77e1b4ba5302c5 (diff)
Add new border style: 'block'
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/light.go24
-rw-r--r--src/tui/tui.go58
2 files changed, 56 insertions, 26 deletions
diff --git a/src/tui/light.go b/src/tui/light.go
index 411238d4..bc44b4f8 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -745,7 +745,7 @@ func (w *LightWindow) DrawHBorder() {
func (w *LightWindow) drawBorder(onlyHorizontal bool) {
switch w.border.shape {
- case BorderRounded, BorderSharp, BorderBold, BorderDouble:
+ case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderDouble:
w.drawBorderAround(onlyHorizontal)
case BorderHorizontal:
w.drawBorderHorizontal(true, true)
@@ -776,14 +776,14 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
if w.preview {
color = ColPreviewBorder
}
- hw := runewidth.RuneWidth(w.border.horizontal)
+ hw := runewidth.RuneWidth(w.border.top)
if top {
w.Move(0, 0)
- w.CPrint(color, repeat(w.border.horizontal, w.width/hw))
+ w.CPrint(color, repeat(w.border.top, w.width/hw))
}
if bottom {
w.Move(w.height-1, 0)
- w.CPrint(color, repeat(w.border.horizontal, w.width/hw))
+ w.CPrint(color, repeat(w.border.bottom, w.width/hw))
}
}
@@ -799,11 +799,11 @@ func (w *LightWindow) drawBorderVertical(left, right bool) {
for y := 0; y < w.height; y++ {
w.Move(y, 0)
if left {
- w.CPrint(color, string(w.border.vertical))
+ w.CPrint(color, string(w.border.left))
}
w.CPrint(color, repeat(' ', width))
if right {
- w.CPrint(color, string(w.border.vertical))
+ w.CPrint(color, string(w.border.right))
}
}
}
@@ -814,23 +814,23 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) {
if w.preview {
color = ColPreviewBorder
}
- hw := runewidth.RuneWidth(w.border.horizontal)
+ 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)
rem := (w.width - tcw) % hw
- w.CPrint(color, string(w.border.topLeft)+repeat(w.border.horizontal, (w.width-tcw)/hw)+repeat(' ', rem)+string(w.border.topRight))
+ 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.vertical)
+ vw := runewidth.RuneWidth(w.border.left)
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
- w.CPrint(color, string(w.border.vertical))
+ w.CPrint(color, string(w.border.left))
w.CPrint(color, repeat(' ', w.width-vw*2))
- w.CPrint(color, string(w.border.vertical))
+ w.CPrint(color, string(w.border.right))
}
}
w.Move(w.height-1, 0)
rem = (w.width - bcw) % hw
- w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.horizontal, (w.width-bcw)/hw)+repeat(' ', rem)+string(w.border.bottomRight))
+ w.CPrint(color, string(w.border.bottomLeft)+repeat(w.border.bottom, (w.width-bcw)/hw)+repeat(' ', rem)+string(w.border.bottomRight))
}
func (w *LightWindow) csi(code string) string {
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 5fd27d0f..63bdfa83 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -312,6 +312,7 @@ const (
BorderRounded
BorderSharp
BorderBold
+ BorderBlock
BorderDouble
BorderHorizontal
BorderVertical
@@ -339,8 +340,10 @@ func (s BorderShape) HasTop() bool {
type BorderStyle struct {
shape BorderShape
- horizontal rune
- vertical rune
+ top rune
+ bottom rune
+ left rune
+ right rune
topLeft rune
topRight rune
bottomLeft rune
@@ -353,8 +356,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
if !unicode {
return BorderStyle{
shape: shape,
- horizontal: '-',
- vertical: '|',
+ top: '-',
+ bottom: '-',
+ left: '|',
+ right: '|',
topLeft: '+',
topRight: '+',
bottomLeft: '+',
@@ -365,8 +370,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
case BorderSharp:
return BorderStyle{
shape: shape,
- horizontal: '─',
- vertical: '│',
+ top: '─',
+ bottom: '─',
+ left: '│',
+ right: '│',
topLeft: '┌',
topRight: '┐',
bottomLeft: '└',
@@ -375,18 +382,37 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
case BorderBold:
return BorderStyle{
shape: shape,
- horizontal: '━',
- vertical: '┃',
+ top: '━',
+ bottom: '━',
+ left: '┃',
+ right: '┃',
topLeft: '┏',
topRight: '┓',
bottomLeft: '┗',
bottomRight: '┛',
}
+ case BorderBlock:
+ // ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
+ // ▌ ▐
+ // ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟
+ return BorderStyle{
+ shape: shape,
+ top: '▀',
+ bottom: '▄',
+ left: '▌',
+ right: '▐',
+ topLeft: '▛',
+ topRight: '▜',
+ bottomLeft: '▙',
+ bottomRight: '▟',
+ }
case BorderDouble:
return BorderStyle{
shape: shape,
- horizontal: '═',
- vertical: '║',
+ top: '═',
+ bottom: '═',
+ left: '║',
+ right: '║',
topLeft: '╔',
topRight: '╗',
bottomLeft: '╚',
@@ -395,8 +421,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
}
return BorderStyle{
shape: shape,
- horizontal: '─',
- vertical: '│',
+ top: '─',
+ bottom: '─',
+ left: '│',
+ right: '│',
topLeft: '╭',
topRight: '╮',
bottomLeft: '╰',
@@ -407,8 +435,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
func MakeTransparentBorder() BorderStyle {
return BorderStyle{
shape: BorderRounded,
- horizontal: ' ',
- vertical: ' ',
+ top: ' ',
+ bottom: ' ',
+ left: ' ',
+ right: ' ',
topLeft: ' ',
topRight: ' ',
bottomLeft: ' ',