Add new border style: 'block'

pull/3299/head
Junegunn Choi 1 year ago
parent 5a39102405
commit 43436e48e0
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -3,6 +3,8 @@ CHANGELOG
0.41.0 0.41.0
------ ------
- Added color name `preview-border` and `preview-scrollbar`
- Added new border style `block` which uses [block elements](https://en.wikipedia.org/wiki/Block_Elements)
- Bug fixes and improvements - Bug fixes and improvements
0.40.0 0.40.0

@ -63,7 +63,7 @@ const usage = `usage: fzf [options]
(default: 10) (default: 10)
--layout=LAYOUT Choose layout: [default|reverse|reverse-list] --layout=LAYOUT Choose layout: [default|reverse|reverse-list]
--border[=STYLE] Draw border around the finder --border[=STYLE] Draw border around the finder
[rounded|sharp|horizontal|vertical| [rounded|sharp|bold|block|double|horizontal|vertical|
top|bottom|left|right|none] (default: rounded) top|bottom|left|right|none] (default: rounded)
--border-label=LABEL Label to print on the border --border-label=LABEL Label to print on the border
--border-label-pos=COL Position of the border label --border-label-pos=COL Position of the border label
@ -544,6 +544,8 @@ func parseBorder(str string, optional bool) tui.BorderShape {
return tui.BorderSharp return tui.BorderSharp
case "bold": case "bold":
return tui.BorderBold return tui.BorderBold
case "block":
return tui.BorderBlock
case "double": case "double":
return tui.BorderDouble return tui.BorderDouble
case "horizontal": case "horizontal":
@ -564,7 +566,7 @@ func parseBorder(str string, optional bool) tui.BorderShape {
if optional && str == "" { if optional && str == "" {
return tui.DefaultBorderShape return tui.DefaultBorderShape
} }
errorExit("invalid border style (expected: rounded|sharp|bold|double|horizontal|vertical|top|bottom|left|right|none)") errorExit("invalid border style (expected: rounded|sharp|bold|block|double|horizontal|vertical|top|bottom|left|right|none)")
} }
return tui.BorderNone return tui.BorderNone
} }
@ -1430,6 +1432,8 @@ func parsePreviewWindowImpl(opts *previewOpts, input string, exit func(string))
opts.border = tui.BorderSharp opts.border = tui.BorderSharp
case "border-bold": case "border-bold":
opts.border = tui.BorderBold opts.border = tui.BorderBold
case "border-block":
opts.border = tui.BorderBlock
case "border-double": case "border-double":
opts.border = tui.BorderDouble opts.border = tui.BorderDouble
case "noborder", "border-none": case "noborder", "border-none":

@ -717,7 +717,7 @@ func (t *Terminal) environ() []string {
func borderLines(shape tui.BorderShape) int { func borderLines(shape tui.BorderShape) int {
switch shape { switch shape {
case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:
return 2 return 2
case tui.BorderTop, tui.BorderBottom: case tui.BorderTop, tui.BorderBottom:
return 1 return 1
@ -1073,7 +1073,7 @@ func (t *Terminal) adjustMarginAndPadding() (int, int, [4]int, [4]int) {
if idx == 3 { if idx == 3 {
extraMargin[idx] += 1 + bw extraMargin[idx] += 1 + bw
} }
case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:
extraMargin[idx] += 1 + bw*(idx%2) extraMargin[idx] += 1 + bw*(idx%2)
} }
marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx] marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx]
@ -1166,7 +1166,7 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
t.border = t.tui.NewWindow( t.border = t.tui.NewWindow(
marginInt[0], marginInt[3], width+(1+bw), height, marginInt[0], marginInt[3], width+(1+bw), height,
false, tui.MakeBorderStyle(tui.BorderRight, t.unicode)) false, tui.MakeBorderStyle(tui.BorderRight, t.unicode))
case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:
t.border = t.tui.NewWindow( t.border = t.tui.NewWindow(
marginInt[0]-1, marginInt[3]-(1+bw), width+(1+bw)*2, height+2, marginInt[0]-1, marginInt[3]-(1+bw), width+(1+bw)*2, height+2,
false, tui.MakeBorderStyle(t.borderShape, t.unicode)) false, tui.MakeBorderStyle(t.borderShape, t.unicode))
@ -1200,7 +1200,7 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
} }
t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder) t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder)
switch previewOpts.border { switch previewOpts.border {
case tui.BorderSharp, tui.BorderRounded, tui.BorderBold, tui.BorderDouble: case tui.BorderSharp, tui.BorderRounded, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:
pwidth -= (1 + bw) * 2 pwidth -= (1 + bw) * 2
pheight -= 2 pheight -= 2
x += 1 + bw x += 1 + bw
@ -1342,7 +1342,7 @@ func (t *Terminal) printLabel(window tui.Window, render labelPrinter, opts label
} }
switch borderShape { switch borderShape {
case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderBlock, tui.BorderDouble:
if redrawBorder { if redrawBorder {
window.DrawHBorder() window.DrawHBorder()
} }

@ -745,7 +745,7 @@ func (w *LightWindow) DrawHBorder() {
func (w *LightWindow) drawBorder(onlyHorizontal bool) { func (w *LightWindow) drawBorder(onlyHorizontal bool) {
switch w.border.shape { switch w.border.shape {
case BorderRounded, BorderSharp, BorderBold, BorderDouble: case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderDouble:
w.drawBorderAround(onlyHorizontal) w.drawBorderAround(onlyHorizontal)
case BorderHorizontal: case BorderHorizontal:
w.drawBorderHorizontal(true, true) w.drawBorderHorizontal(true, true)
@ -776,14 +776,14 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) {
if w.preview { if w.preview {
color = ColPreviewBorder color = ColPreviewBorder
} }
hw := runewidth.RuneWidth(w.border.horizontal) hw := runewidth.RuneWidth(w.border.top)
if top { if top {
w.Move(0, 0) 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 { if bottom {
w.Move(w.height-1, 0) 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++ { for y := 0; y < w.height; y++ {
w.Move(y, 0) w.Move(y, 0)
if left { if left {
w.CPrint(color, string(w.border.vertical)) w.CPrint(color, string(w.border.left))
} }
w.CPrint(color, repeat(' ', width)) w.CPrint(color, repeat(' ', width))
if right { 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 { if w.preview {
color = ColPreviewBorder 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) tcw := runewidth.RuneWidth(w.border.topLeft) + runewidth.RuneWidth(w.border.topRight)
bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight) bcw := runewidth.RuneWidth(w.border.bottomLeft) + runewidth.RuneWidth(w.border.bottomRight)
rem := (w.width - tcw) % hw 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 { if !onlyHorizontal {
vw := runewidth.RuneWidth(w.border.vertical) vw := runewidth.RuneWidth(w.border.left)
for y := 1; y < w.height-1; y++ { for y := 1; y < w.height-1; y++ {
w.Move(y, 0) 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, 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) w.Move(w.height-1, 0)
rem = (w.width - bcw) % hw 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 { func (w *LightWindow) csi(code string) string {

@ -312,6 +312,7 @@ const (
BorderRounded BorderRounded
BorderSharp BorderSharp
BorderBold BorderBold
BorderBlock
BorderDouble BorderDouble
BorderHorizontal BorderHorizontal
BorderVertical BorderVertical
@ -339,8 +340,10 @@ func (s BorderShape) HasTop() bool {
type BorderStyle struct { type BorderStyle struct {
shape BorderShape shape BorderShape
horizontal rune top rune
vertical rune bottom rune
left rune
right rune
topLeft rune topLeft rune
topRight rune topRight rune
bottomLeft rune bottomLeft rune
@ -353,8 +356,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
if !unicode { if !unicode {
return BorderStyle{ return BorderStyle{
shape: shape, shape: shape,
horizontal: '-', top: '-',
vertical: '|', bottom: '-',
left: '|',
right: '|',
topLeft: '+', topLeft: '+',
topRight: '+', topRight: '+',
bottomLeft: '+', bottomLeft: '+',
@ -365,8 +370,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
case BorderSharp: case BorderSharp:
return BorderStyle{ return BorderStyle{
shape: shape, shape: shape,
horizontal: '─', top: '─',
vertical: '│', bottom: '─',
left: '│',
right: '│',
topLeft: '┌', topLeft: '┌',
topRight: '┐', topRight: '┐',
bottomLeft: '└', bottomLeft: '└',
@ -375,18 +382,37 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
case BorderBold: case BorderBold:
return BorderStyle{ return BorderStyle{
shape: shape, shape: shape,
horizontal: '━', top: '━',
vertical: '┃', bottom: '━',
left: '┃',
right: '┃',
topLeft: '┏', topLeft: '┏',
topRight: '┓', topRight: '┓',
bottomLeft: '┗', bottomLeft: '┗',
bottomRight: '┛', bottomRight: '┛',
} }
case BorderBlock:
// ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
// ▌ ▐
// ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟
return BorderStyle{
shape: shape,
top: '▀',
bottom: '▄',
left: '▌',
right: '▐',
topLeft: '▛',
topRight: '▜',
bottomLeft: '▙',
bottomRight: '▟',
}
case BorderDouble: case BorderDouble:
return BorderStyle{ return BorderStyle{
shape: shape, shape: shape,
horizontal: '═', top: '═',
vertical: '║', bottom: '═',
left: '║',
right: '║',
topLeft: '╔', topLeft: '╔',
topRight: '╗', topRight: '╗',
bottomLeft: '╚', bottomLeft: '╚',
@ -395,8 +421,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
} }
return BorderStyle{ return BorderStyle{
shape: shape, shape: shape,
horizontal: '─', top: '─',
vertical: '│', bottom: '─',
left: '│',
right: '│',
topLeft: '╭', topLeft: '╭',
topRight: '╮', topRight: '╮',
bottomLeft: '╰', bottomLeft: '╰',
@ -407,8 +435,10 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
func MakeTransparentBorder() BorderStyle { func MakeTransparentBorder() BorderStyle {
return BorderStyle{ return BorderStyle{
shape: BorderRounded, shape: BorderRounded,
horizontal: ' ', top: ' ',
vertical: ' ', bottom: ' ',
left: ' ',
right: ' ',
topLeft: ' ', topLeft: ' ',
topRight: ' ', topRight: ' ',
bottomLeft: ' ', bottomLeft: ' ',

Loading…
Cancel
Save