summaryrefslogtreecommitdiff
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-02-04 21:51:22 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-02-04 21:51:22 +0900
commit4b700192c1f07aa6ba8d0ed7cb9c1b1dcb6f7ddb (patch)
tree611efbf17b9b8e0f71a2d2d68992d3efc9a0378b /src/tui
parentfe83589ade42e1d6c24b792ec0fa303f07e953e1 (diff)
downloadfzf-4b700192c1f07aa6ba8d0ed7cb9c1b1dcb6f7ddb.tar.gz
Add --border option to draw horizontal lines above and below the finder
Goes well with --height
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/dummy.go2
-rw-r--r--src/tui/light.go30
-rw-r--r--src/tui/ncurses.go5
-rw-r--r--src/tui/tcell.go59
-rw-r--r--src/tui/tui.go10
5 files changed, 66 insertions, 40 deletions
diff --git a/src/tui/dummy.go b/src/tui/dummy.go
index 01179c89..60a23fb6 100644
--- a/src/tui/dummy.go
+++ b/src/tui/dummy.go
@@ -40,6 +40,6 @@ func (r *FullscreenRenderer) MaxY() int { return 0 }
func (r *FullscreenRenderer) RefreshWindows(windows []Window) {}
-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {
+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
return nil
}
diff --git a/src/tui/light.go b/src/tui/light.go
index 2ce0d5ff..9465c49a 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -95,7 +95,7 @@ type LightRenderer struct {
type LightWindow struct {
renderer *LightRenderer
colored bool
- border bool
+ border BorderStyle
top int
left int
width int
@@ -600,11 +600,11 @@ func (r *LightRenderer) IsOptimized() bool {
return false
}
-func (r *LightRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {
+func (r *LightRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
w := &LightWindow{
renderer: r,
colored: r.theme != nil,
- border: border,
+ border: borderStyle,
top: top,
left: left,
width: width,
@@ -614,13 +614,27 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, bord
if r.theme != nil {
w.bg = r.theme.Bg
}
- if w.border {
- w.drawBorder()
- }
+ w.drawBorder()
return w
}
func (w *LightWindow) drawBorder() {
+ switch w.border {
+ case BorderAround:
+ w.drawBorderAround()
+ case BorderHorizontal:
+ w.drawBorderHorizontal()
+ }
+}
+
+func (w *LightWindow) drawBorderHorizontal() {
+ w.Move(0, 0)
+ w.CPrint(ColBorder, AttrRegular, repeat("─", w.width))
+ w.Move(w.height-1, 0)
+ w.CPrint(ColBorder, AttrRegular, repeat("─", w.width))
+}
+
+func (w *LightWindow) drawBorderAround() {
w.Move(0, 0)
w.CPrint(ColBorder, AttrRegular, "┌"+repeat("─", w.width-2)+"┐")
for y := 1; y < w.height-1; y++ {
@@ -854,9 +868,7 @@ func (w *LightWindow) FinishFill() {
}
func (w *LightWindow) Erase() {
- if w.border {
- w.drawBorder()
- }
+ w.drawBorder()
// We don't erase the window here to avoid flickering during scroll
w.Move(0, 0)
}
diff --git a/src/tui/ncurses.go b/src/tui/ncurses.go
index 978b2e72..4b88b447 100644
--- a/src/tui/ncurses.go
+++ b/src/tui/ncurses.go
@@ -189,12 +189,13 @@ func (r *FullscreenRenderer) Close() {
C.delscreen(_screen)
}
-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {
+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
win := C.newwin(C.int(height), C.int(width), C.int(top), C.int(left))
if r.theme != nil {
C.wbkgd(win, C.chtype(C.COLOR_PAIR(C.int(ColNormal.index()))))
}
- if border {
+ // FIXME Does not implement BorderHorizontal
+ if borderStyle != BorderNone {
pair, attr := _colorFn(ColBorder, 0)
C.wcolor_set(win, pair, nil)
C.wattron(win, attr)
diff --git a/src/tui/tcell.go b/src/tui/tcell.go
index aa67ae1a..964c19e1 100644
--- a/src/tui/tcell.go
+++ b/src/tui/tcell.go
@@ -27,15 +27,15 @@ func (p ColorPair) style() tcell.Style {
type Attr tcell.Style
type TcellWindow struct {
- color bool
- top int
- left int
- width int
- height int
- lastX int
- lastY int
- moveCursor bool
- border bool
+ color bool
+ top int
+ left int
+ width int
+ height int
+ lastX int
+ lastY int
+ moveCursor bool
+ borderStyle BorderStyle
}
func (w *TcellWindow) Top() int {
@@ -61,8 +61,11 @@ func (w *TcellWindow) Refresh() {
}
w.lastX = 0
w.lastY = 0
- if w.border {
- w.drawBorder()
+ switch w.borderStyle {
+ case BorderAround:
+ w.drawBorder(true)
+ case BorderHorizontal:
+ w.drawBorder(false)
}
}
@@ -377,15 +380,15 @@ func (r *FullscreenRenderer) RefreshWindows(windows []Window) {
_screen.Show()
}
-func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, border bool) Window {
+func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
// TODO
return &TcellWindow{
- color: r.theme != nil,
- top: top,
- left: left,
- width: width,
- height: height,
- border: border}
+ color: r.theme != nil,
+ top: top,
+ left: left,
+ width: width,
+ height: height,
+ borderStyle: borderStyle}
}
func (w *TcellWindow) Close() {
@@ -536,7 +539,7 @@ func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
return w.fillString(str, ColorPair{fg, bg, -1}, a)
}
-func (w *TcellWindow) drawBorder() {
+func (w *TcellWindow) drawBorder(around bool) {
left := w.left
right := left + w.width
top := w.top
@@ -554,13 +557,15 @@ func (w *TcellWindow) drawBorder() {
_screen.SetContent(x, bot-1, tcell.RuneHLine, nil, style)
}
- for y := top; y < bot; y++ {
- _screen.SetContent(left, y, tcell.RuneVLine, nil, style)
- _screen.SetContent(right-1, y, tcell.RuneVLine, nil, style)
- }
+ if around {
+ for y := top; y < bot; y++ {
+ _screen.SetContent(left, y, tcell.RuneVLine, nil, style)
+ _screen.SetContent(right-1, y, tcell.RuneVLine, nil, style)
+ }
- _screen.SetContent(left, top, tcell.RuneULCorner, nil, style)
- _screen.SetContent(right-1, top, tcell.RuneURCorner, nil, style)
- _screen.SetContent(left, bot-1, tcell.RuneLLCorner, nil, style)
- _screen.SetContent(right-1, bot-1, tcell.RuneLRCorner, nil, style)
+ _screen.SetContent(left, top, tcell.RuneULCorner, nil, style)
+ _screen.SetContent(right-1, top, tcell.RuneURCorner, nil, style)
+ _screen.SetContent(left, bot-1, tcell.RuneLLCorner, nil, style)
+ _screen.SetContent(right-1, bot-1, tcell.RuneLRCorner, nil, style)
+ }
}
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 2508aa68..f8d905ab 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -195,6 +195,14 @@ type MouseEvent struct {
Mod bool
}
+type BorderStyle int
+
+const (
+ BorderNone BorderStyle = iota
+ BorderAround
+ BorderHorizontal
+)
+
type Renderer interface {
Init()
Pause()
@@ -211,7 +219,7 @@ type Renderer interface {
DoesAutoWrap() bool
IsOptimized() bool
- NewWindow(top int, left int, width int, height int, border bool) Window
+ NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window
}
type Window interface {