diff options
Diffstat (limited to 'src/tui')
-rw-r--r-- | src/tui/dummy.go | 3 | ||||
-rw-r--r-- | src/tui/light.go | 11 | ||||
-rw-r--r-- | src/tui/light_unix.go | 17 | ||||
-rw-r--r-- | src/tui/tcell.go | 10 | ||||
-rw-r--r-- | src/tui/tui.go | 10 |
5 files changed, 48 insertions, 3 deletions
diff --git a/src/tui/dummy.go b/src/tui/dummy.go index 352e2b09..d893a747 100644 --- a/src/tui/dummy.go +++ b/src/tui/dummy.go @@ -38,6 +38,9 @@ func (r *FullscreenRenderer) Clear() {} func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false } func (r *FullscreenRenderer) Refresh() {} func (r *FullscreenRenderer) Close() {} +func (r *FullscreenRenderer) Size() (termSize, error) { + return termSize{}, nil +} func (r *FullscreenRenderer) GetChar() Event { return Event{} } func (r *FullscreenRenderer) MaxX() int { return 0 } diff --git a/src/tui/light.go b/src/tui/light.go index cc828fa9..6b7eaaf4 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -32,7 +32,7 @@ var offsetRegexp *regexp.Regexp = regexp.MustCompile("(.*)\x1b\\[([0-9]+);([0-9] var offsetRegexpBegin *regexp.Regexp = regexp.MustCompile("^\x1b\\[[0-9]+;[0-9]+R") func (r *LightRenderer) PassThrough(str string) { - r.queued.WriteString(str) + r.queued.WriteString("\x1b7" + str + "\x1b8") r.flush() } @@ -756,6 +756,10 @@ func (r *LightRenderer) NewWindow(top int, left int, width int, height int, prev return w } +func (w *LightWindow) DrawBorder() { + w.drawBorder(false) +} + func (w *LightWindow) DrawHBorder() { w.drawBorder(true) } @@ -1095,7 +1099,8 @@ func (w *LightWindow) FinishFill() { } func (w *LightWindow) Erase() { - w.drawBorder(false) - // We don't erase the window here to avoid flickering during scroll + w.DrawBorder() + w.Move(0, 0) + w.FinishFill() w.Move(0, 0) } diff --git a/src/tui/light_unix.go b/src/tui/light_unix.go index 6dc058c8..b9e433cc 100644 --- a/src/tui/light_unix.go +++ b/src/tui/light_unix.go @@ -8,6 +8,7 @@ import ( "os/exec" "strings" "syscall" + "unsafe" "github.com/junegunn/fzf/src/util" "golang.org/x/term" @@ -108,3 +109,19 @@ func (r *LightRenderer) getch(nonblock bool) (int, bool) { } return int(b[0]), true } + +type window struct { + lines uint16 + columns uint16 + width uint16 + height uint16 +} + +func (r *LightRenderer) Size() (termSize, error) { + w := new(window) + _, _, err := syscall.Syscall(syscall.SYS_IOCTL, r.ttyin.Fd(), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(w))) + if err != 0 { + return termSize{}, err + } + return termSize{int(w.lines), int(w.columns), int(w.width), int(w.height)}, nil +} diff --git a/src/tui/tcell.go b/src/tui/tcell.go index 0c3d4694..54feaf16 100644 --- a/src/tui/tcell.go +++ b/src/tui/tcell.go @@ -203,6 +203,11 @@ func (r *FullscreenRenderer) Refresh() { // noop } +func (r *FullscreenRenderer) Size() (termSize, error) { + cols, lines := _screen.Size() + return termSize{lines, cols, 0, 0}, error("Not implemented") +} + func (r *FullscreenRenderer) GetChar() Event { ev := _screen.PollEvent() switch ev := ev.(type) { @@ -541,6 +546,7 @@ func fill(x, y, w, h int, n ColorPair, r rune) { } func (w *TcellWindow) Erase() { + w.drawBorder(false) fill(w.left-1, w.top, w.width+1, w.height-1, w.normal, ' ') } @@ -692,6 +698,10 @@ func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn { return w.fillString(str, NewColorPair(fg, bg, a)) } +func (w *TcellWindow) DrawBorder() { + w.drawBorder(false) +} + func (w *TcellWindow) DrawHBorder() { w.drawBorder(true) } diff --git a/src/tui/tui.go b/src/tui/tui.go index 4625e9b5..69ae8a1a 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -473,6 +473,13 @@ func MakeTransparentBorder() BorderStyle { bottomRight: ' '} } +type termSize struct { + Lines int + Columns int + Width int + Height int +} + type Renderer interface { Init() Resize(maxHeightFunc func(int) int) @@ -490,6 +497,8 @@ type Renderer interface { MaxX() int MaxY() int + Size() (termSize, error) + NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window } @@ -499,6 +508,7 @@ type Window interface { Width() int Height() int + DrawBorder() DrawHBorder() Refresh() FinishFill() |