summaryrefslogtreecommitdiffstats
path: root/src/tui
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2023-10-26 00:22:28 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2023-10-26 00:49:16 +0900
commitd02b9442a56ec03dbb905d432762cf545603ef07 (patch)
treefdf5878111abb8693a559fff355e499c49378782 /src/tui
parentbac385b59ccef279400689d406bf270cfdee06f3 (diff)
(Experimental) Improve Sixel graphics support (#2544)
Progress: * Sixel image can now be displayed with other text, and is scrollable * If an image can't be displayed entirely due to the scroll offset, fzf will render a wireframe to indicate that an image should be displayed * Renamed $FZF_PREVIEW_{WIDTH,HEIGHT} to $FZF_PREVIEW_PIXEL_{WIDTH,HEIGHT} for clarity * Added bin/fzf-preview.sh script to demonstrate how to display an image using Kitty or Sixel protocol An example: ls *.jpg | fzf --preview='seq $((FZF_PREVIEW_LINES*9/10)); fzf-preview.sh {}; seq 100' A known issue: * If you reduce the size of the preview window, the image may extend beyond the preview window
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/dummy.go4
-rw-r--r--src/tui/light.go4
-rw-r--r--src/tui/light_unix.go6
-rw-r--r--src/tui/tcell.go5
-rw-r--r--src/tui/tui.go12
5 files changed, 16 insertions, 15 deletions
diff --git a/src/tui/dummy.go b/src/tui/dummy.go
index d893a747..13c2aeec 100644
--- a/src/tui/dummy.go
+++ b/src/tui/dummy.go
@@ -38,9 +38,7 @@ 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) Size() TermSize { return TermSize{} }
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 6b7eaaf4..e5080d1d 100644
--- a/src/tui/light.go
+++ b/src/tui/light.go
@@ -1092,7 +1092,9 @@ func (w *LightWindow) CFill(fg Color, bg Color, attr Attr, text string) FillRetu
}
func (w *LightWindow) FinishFill() {
- w.MoveAndClear(w.posy, w.posx)
+ if w.posy < w.height {
+ w.MoveAndClear(w.posy, w.posx)
+ }
for y := w.posy + 1; y < w.height; y++ {
w.MoveAndClear(y, 0)
}
diff --git a/src/tui/light_unix.go b/src/tui/light_unix.go
index 4ca847b4..46188869 100644
--- a/src/tui/light_unix.go
+++ b/src/tui/light_unix.go
@@ -110,10 +110,10 @@ func (r *LightRenderer) getch(nonblock bool) (int, bool) {
return int(b[0]), true
}
-func (r *LightRenderer) Size() (termSize, error) {
+func (r *LightRenderer) Size() TermSize {
ws, err := unix.IoctlGetWinsize(int(r.ttyin.Fd()), unix.TIOCGWINSZ)
if err != nil {
- return termSize{}, err
+ return TermSize{}
}
- return termSize{int(ws.Row), int(ws.Col), int(ws.Xpixel), int(ws.Ypixel)}, nil
+ return TermSize{int(ws.Row), int(ws.Col), int(ws.Xpixel), int(ws.Ypixel)}
}
diff --git a/src/tui/tcell.go b/src/tui/tcell.go
index 54feaf16..cd723e32 100644
--- a/src/tui/tcell.go
+++ b/src/tui/tcell.go
@@ -203,9 +203,10 @@ func (r *FullscreenRenderer) Refresh() {
// noop
}
-func (r *FullscreenRenderer) Size() (termSize, error) {
+// TODO: Pixel width and height not implemented
+func (r *FullscreenRenderer) Size() TermSize {
cols, lines := _screen.Size()
- return termSize{lines, cols, 0, 0}, error("Not implemented")
+ return TermSize{lines, cols, 0, 0}
}
func (r *FullscreenRenderer) GetChar() Event {
diff --git a/src/tui/tui.go b/src/tui/tui.go
index 69ae8a1a..2ebb5e72 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -473,11 +473,11 @@ func MakeTransparentBorder() BorderStyle {
bottomRight: ' '}
}
-type termSize struct {
- Lines int
- Columns int
- Width int
- Height int
+type TermSize struct {
+ Lines int
+ Columns int
+ PxWidth int
+ PxHeight int
}
type Renderer interface {
@@ -497,7 +497,7 @@ type Renderer interface {
MaxX() int
MaxY() int
- Size() (termSize, error)
+ Size() TermSize
NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window
}