From 01ae621f116bd4a3ef951a3816e11615c61b8c36 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 6 Nov 2022 14:38:31 +0900 Subject: [PATCH] Add --border=[bold|double] and --preview-window=border-[bold|double] --- CHANGELOG.md | 2 ++ man/man1/fzf.1 | 14 +++++++++++- src/options.go | 10 ++++++++- src/terminal.go | 10 ++++----- src/tui/light.go | 2 +- src/tui/tcell.go | 10 ++++----- src/tui/tui.go | 57 +++++++++++++++++++++++++++++++++--------------- 7 files changed, 75 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd79535f..ed589c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ CHANGELOG - Separator can be disabled by adding `:nosep` to `--info` - `--info=nosep` - `--info=inline:nosep` +- Added `--border=bold` and `--border=double` along with + `--preview-window=border-bold` and `--preview-window=border-double` 0.34.0 ------ diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 8a534ee4..13976a26 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .. -.TH fzf 1 "Oct 2022" "fzf 0.35.0" "fzf - a command-line fuzzy finder" +.TH fzf 1 "Nov 2022" "fzf 0.35.0" "fzf - a command-line fuzzy finder" .SH NAME fzf - a command-line fuzzy finder @@ -211,6 +211,10 @@ Draw border around the finder .br .BR sharp " Border with sharp corners" .br +.BR bold " Border with bold lines" +.br +.BR double " Border with double lines" +.br .BR horizontal " Horizontal lines above and below the finder" .br .BR vertical " Vertical lines on each side of the finder" @@ -236,6 +240,10 @@ following \fB--border\fR options. .br .B * sharp .br +.B * bold +.br +.B * double +.br .B * horizontal .br .BR "* top" " (up)" @@ -539,6 +547,10 @@ Should be used with one of the following \fB--preview-window\fR options. .br .B * border-sharp .br +.B * border-bold +.br +.B * border-double +.br .B * border-horizontal .br .B * border-top diff --git a/src/options.go b/src/options.go index 1b57fe16..7df861c5 100644 --- a/src/options.go +++ b/src/options.go @@ -509,6 +509,10 @@ func parseBorder(str string, optional bool) tui.BorderShape { return tui.BorderRounded case "sharp": return tui.BorderSharp + case "bold": + return tui.BorderBold + case "double": + return tui.BorderDouble case "horizontal": return tui.BorderHorizontal case "vertical": @@ -527,7 +531,7 @@ func parseBorder(str string, optional bool) tui.BorderShape { if optional && str == "" { return tui.BorderRounded } - errorExit("invalid border style (expected: rounded|sharp|horizontal|vertical|top|bottom|left|right|none)") + errorExit("invalid border style (expected: rounded|sharp|bold|double|horizontal|vertical|top|bottom|left|right|none)") } return tui.BorderNone } @@ -1308,6 +1312,10 @@ func parsePreviewWindow(opts *previewOpts, input string) { opts.border = tui.BorderRounded case "sharp", "border-sharp": opts.border = tui.BorderSharp + case "border-bold": + opts.border = tui.BorderBold + case "border-double": + opts.border = tui.BorderDouble case "noborder", "border-none": opts.border = tui.BorderNone case "border-horizontal": diff --git a/src/terminal.go b/src/terminal.go index 57055c17..d81f79dc 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -605,7 +605,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { func borderLines(shape tui.BorderShape) int { switch shape { - case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp: + case tui.BorderHorizontal, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: return 2 case tui.BorderTop, tui.BorderBottom: return 1 @@ -847,7 +847,7 @@ func (t *Terminal) adjustMarginAndPadding() (int, int, [4]int, [4]int) { if idx == 3 { extraMargin[idx] += 2 } - case tui.BorderRounded, tui.BorderSharp: + case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: extraMargin[idx] += 1 + idx%2 } marginInt[idx] = sizeSpecToInt(idx, sizeSpec) + extraMargin[idx] @@ -939,7 +939,7 @@ func (t *Terminal) resizeWindows() { t.border = t.tui.NewWindow( marginInt[0], marginInt[3], width+2, height, false, tui.MakeBorderStyle(tui.BorderRight, t.unicode)) - case tui.BorderRounded, tui.BorderSharp: + case tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: t.border = t.tui.NewWindow( marginInt[0]-1, marginInt[3]-2, width+4, height+2, false, tui.MakeBorderStyle(t.borderShape, t.unicode)) @@ -969,7 +969,7 @@ func (t *Terminal) resizeWindows() { } t.pborder = t.tui.NewWindow(y, x, w, h, true, previewBorder) switch previewOpts.border { - case tui.BorderSharp, tui.BorderRounded: + case tui.BorderSharp, tui.BorderRounded, tui.BorderBold, tui.BorderDouble: pwidth -= 4 pheight -= 2 x += 2 @@ -1057,7 +1057,7 @@ func (t *Terminal) resizeWindows() { } switch borderShape { - case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp: + case tui.BorderHorizontal, tui.BorderTop, tui.BorderBottom, tui.BorderRounded, tui.BorderSharp, tui.BorderBold, tui.BorderDouble: var col int if opts.column == 0 { col = util.Max(0, (window.Width()-length)/2) diff --git a/src/tui/light.go b/src/tui/light.go index 20b7b9d5..5ebd5933 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -712,7 +712,7 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, prev func (w *LightWindow) drawBorder() { switch w.border.shape { - case BorderRounded, BorderSharp: + case BorderRounded, BorderSharp, BorderBold, BorderDouble: w.drawBorderAround() case BorderHorizontal: w.drawBorderHorizontal(true, true) diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 3614477a..a82bf944 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -705,31 +705,31 @@ func (w *TcellWindow) drawBorder() { } switch shape { - case BorderRounded, BorderSharp, BorderHorizontal, BorderTop: + case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderHorizontal, BorderTop: for x := left; x < right; x++ { _screen.SetContent(x, top, w.borderStyle.horizontal, nil, style) } } switch shape { - case BorderRounded, BorderSharp, BorderHorizontal, BorderBottom: + case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderHorizontal, BorderBottom: for x := left; x < right; x++ { _screen.SetContent(x, bot-1, w.borderStyle.horizontal, nil, style) } } switch shape { - case BorderRounded, BorderSharp, BorderVertical, BorderLeft: + case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderLeft: for y := top; y < bot; y++ { _screen.SetContent(left, y, w.borderStyle.vertical, nil, style) } } switch shape { - case BorderRounded, BorderSharp, BorderVertical, BorderRight: + case BorderRounded, BorderSharp, BorderBold, BorderDouble, BorderVertical, BorderRight: for y := top; y < bot; y++ { _screen.SetContent(right-1, y, w.borderStyle.vertical, nil, style) } } switch shape { - case BorderRounded, BorderSharp: + 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(left, bot-1, w.borderStyle.bottomLeft, nil, style) diff --git a/src/tui/tui.go b/src/tui/tui.go index 793d410a..31afa5bb 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -294,6 +294,8 @@ const ( BorderNone BorderShape = iota BorderRounded BorderSharp + BorderBold + BorderDouble BorderHorizontal BorderVertical BorderTop @@ -315,18 +317,19 @@ type BorderStyle struct { type BorderCharacter int func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle { - if unicode { - if shape == BorderRounded { - return BorderStyle{ - shape: shape, - horizontal: '─', - vertical: '│', - topLeft: '╭', - topRight: '╮', - bottomLeft: '╰', - bottomRight: '╯', - } + if !unicode { + return BorderStyle{ + shape: shape, + horizontal: '-', + vertical: '|', + topLeft: '+', + topRight: '+', + bottomLeft: '+', + bottomRight: '+', } + } + switch shape { + case BorderSharp: return BorderStyle{ shape: shape, horizontal: '─', @@ -336,15 +339,35 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle { bottomLeft: '└', bottomRight: '┘', } + case BorderBold: + return BorderStyle{ + shape: shape, + horizontal: '━', + vertical: '┃', + topLeft: '┏', + topRight: '┓', + bottomLeft: '┗', + bottomRight: '┛', + } + case BorderDouble: + return BorderStyle{ + shape: shape, + horizontal: '═', + vertical: '║', + topLeft: '╔', + topRight: '╗', + bottomLeft: '╚', + bottomRight: '╝', + } } return BorderStyle{ shape: shape, - horizontal: '-', - vertical: '|', - topLeft: '+', - topRight: '+', - bottomLeft: '+', - bottomRight: '+', + horizontal: '─', + vertical: '│', + topLeft: '╭', + topRight: '╮', + bottomLeft: '╰', + bottomRight: '╯', } }