m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-18 08:13:40 -05:00

Add more --border options; default changed to "rounded"

--border option now takes an optional argument that defines the style

  - rounded (new default)
  - sharp
  - horizontal (previous default)
This commit is contained in:
Junegunn Choi
2020-03-05 20:15:15 +09:00
parent 99f1e02766
commit d9b1211191
6 changed files with 150 additions and 90 deletions

View File

@@ -105,6 +105,7 @@ type LightRenderer struct {
type LightWindow struct {
renderer *LightRenderer
colored bool
preview bool
border BorderStyle
top int
left int
@@ -681,6 +682,7 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, prev
w := &LightWindow{
renderer: r,
colored: r.theme != nil,
preview: preview,
border: borderStyle,
top: top,
left: left,
@@ -704,7 +706,7 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, prev
func (w *LightWindow) drawBorder() {
switch w.border.shape {
case BorderAround:
case BorderRounded, BorderSharp:
w.drawBorderAround()
case BorderHorizontal:
w.drawBorderHorizontal()
@@ -720,16 +722,20 @@ func (w *LightWindow) drawBorderHorizontal() {
func (w *LightWindow) drawBorderAround() {
w.Move(0, 0)
w.CPrint(ColPreviewBorder, AttrRegular,
color := ColBorder
if w.preview {
color = ColPreviewBorder
}
w.CPrint(color, AttrRegular,
string(w.border.topLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.topRight))
for y := 1; y < w.height-1; y++ {
w.Move(y, 0)
w.CPrint(ColPreviewBorder, AttrRegular, string(w.border.vertical))
w.CPrint(ColPreviewBorder, AttrRegular, repeat(' ', w.width-2))
w.CPrint(ColPreviewBorder, AttrRegular, string(w.border.vertical))
w.CPrint(color, AttrRegular, string(w.border.vertical))
w.CPrint(color, AttrRegular, repeat(' ', w.width-2))
w.CPrint(color, AttrRegular, string(w.border.vertical))
}
w.Move(w.height-1, 0)
w.CPrint(ColPreviewBorder, AttrRegular,
w.CPrint(color, AttrRegular,
string(w.border.bottomLeft)+repeat(w.border.horizontal, w.width-2)+string(w.border.bottomRight))
}

View File

@@ -28,6 +28,7 @@ type Attr tcell.Style
type TcellWindow struct {
color bool
preview bool
top int
left int
width int
@@ -418,6 +419,7 @@ func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int,
}
return &TcellWindow{
color: r.theme != nil,
preview: preview,
top: top,
left: left,
width: width,
@@ -591,7 +593,7 @@ func (w *TcellWindow) drawBorder() {
var style tcell.Style
if w.color {
if w.borderStyle.shape == BorderAround {
if w.preview {
style = ColPreviewBorder.style()
} else {
style = ColBorder.style()
@@ -605,7 +607,7 @@ func (w *TcellWindow) drawBorder() {
_screen.SetContent(x, bot-1, w.borderStyle.horizontal, nil, style)
}
if w.borderStyle.shape == BorderAround {
if w.borderStyle.shape != BorderHorizontal {
for y := top; y < bot; y++ {
_screen.SetContent(left, y, w.borderStyle.vertical, nil, style)
_screen.SetContent(right-1, y, w.borderStyle.vertical, nil, style)

View File

@@ -210,7 +210,8 @@ type BorderShape int
const (
BorderNone BorderShape = iota
BorderAround
BorderRounded
BorderSharp
BorderHorizontal
)
@@ -228,14 +229,25 @@ 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: '╯',
}
}
return BorderStyle{
shape: shape,
horizontal: '─',
vertical: '│',
topLeft: '',
topRight: '',
bottomLeft: '',
bottomRight: '',
topLeft: '',
topRight: '',
bottomLeft: '',
bottomRight: '',
}
}
return BorderStyle{
@@ -251,7 +263,7 @@ func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
func MakeTransparentBorder() BorderStyle {
return BorderStyle{
shape: BorderAround,
shape: BorderRounded,
horizontal: ' ',
vertical: ' ',
topLeft: ' ',