Sixel and Kitty image support on Windows binary (#2544)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent d0466fa · Browse files · 8 files·+59 added−16 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+59 added−16 removed
- other:+59 added−16 removed
Provenance
- Commit
68db9cb- Tree
4c70d76- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
d0466fa
8 files changed+59 added−16 removed
modified:src/tui/dummy.go+2 added-1 removed
31 unmodified lines32 func (r *FullscreenRenderer) Init() {}33 func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}34 func (r *FullscreenRenderer) Pause(bool) {}35 func (r *FullscreenRenderer) Resume(bool, bool) {}36-func (r *FullscreenRenderer) PassThrough(string) {}36+func (r *FullscreenRenderer) PassThrough(int, int, string) {}37+func (r *FullscreenRenderer) Sync(bool) {}38 func (r *FullscreenRenderer) Clear() {}39 func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }40 func (r *FullscreenRenderer) Refresh() {}41 func (r *FullscreenRenderer) Close() {}12 unmodified linesmodified:src/tui/light.go+6 added-2 removed
29 unmodified lines30 31 var offsetRegexp *regexp.Regexp = regexp.MustCompile("(.*)\x1b\\[([0-9]+);([0-9]+)R")32 var offsetRegexpBegin *regexp.Regexp = regexp.MustCompile("^\x1b\\[[0-9]+;[0-9]+R")33 34-func (r *LightRenderer) PassThrough(str string) {35- r.queued.WriteString("\x1b7" + str + "\x1b8")34+func (r *LightRenderer) PassThrough(y int, x int, data string) {35+ r.queued.WriteString("\x1b7" + data + "\x1b8")36 }37 38+func (r *LightRenderer) Sync(bool) {39+ // No-op40+}41+42 func (r *LightRenderer) stderr(str string) {43 r.stderrInternal(str, true, "")44 }45 1074 unmodified linesmodified:src/tui/tcell.go+19 added-6 removed
96 unmodified lines97 AttrRegular = Attr(1 << 7)98 AttrClear = Attr(1 << 8)99 )100 101-func (r *FullscreenRenderer) PassThrough(str string) {102- // No-op103- // https://github.com/gdamore/tcell/issues/363#issuecomment-680665073101+func (r *FullscreenRenderer) PassThrough(y int, x int, data string) {102+ tty, _ := _screen.Tty()103+ ti, err := tcell.LookupTerminfo(os.Getenv("TERM"))104+ if err != nil {105+ return106+ }107+ ti.TPuts(tty, ti.TGoto(x, y))108+ ti.TPuts(tty, data)109 }110 111+func (r *FullscreenRenderer) Sync(hard bool) {112+ if hard {113+ _screen.Sync()114+ } else {115+ _screen.Show()116+ }117+}118+119 func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}120 121 func (r *FullscreenRenderer) defaultTheme() *ColorTheme {122 if _screen.Colors() >= 256 {96 unmodified lines219 func (r *FullscreenRenderer) Refresh() {220 // noop221 }222 210-// TODO: Pixel width and height not implemented223 func (r *FullscreenRenderer) Size() TermSize {212- cols, lines := _screen.Size()213- return TermSize{lines, cols, 0, 0}224+ tty, _ := _screen.Tty()225+ ws, _ := tty.WindowSize()226+ return TermSize{ws.Height, ws.Width, ws.PixelWidth, ws.PixelHeight}227 }228 229 func (r *FullscreenRenderer) GetChar() Event {230 ev := _screen.PollEvent()572 unmodified linesmodified:src/tui/tui.go+2 added-1 removed
487 unmodified lines488 Clear()489 RefreshWindows(windows []Window)490 Refresh()491 Close()492- PassThrough(string)492+ PassThrough(y int, x int, data string)493+ Sync(bool)494 NeedScrollbarRedraw() bool495 496 GetChar() Event497 317 unmodified linesmodified:src/terminal.go+7 added-1 removed
1936 unmodified lines1937 func (t *Terminal) renderPreviewArea(unchanged bool) {1938 if t.previewed.wipe && t.previewed.version != t.previewer.version {1939 t.previewed.wipe = false1940 t.pwindow.Erase()1941+ // Required for tcell to clear the previous image1942+ t.tui.Sync(true)1943 } else if unchanged {1944 t.pwindow.MoveAndClear(0, 0) // Clear scroll offset display1945 } else {1946 t.previewed.filled = false115 unmodified lines2062 wiped = true2063 for i := y + 1; i < height; i++ {2064 t.pwindow.MoveAndClear(i, 0)2065 }2066+ // Required for tcell to clear the previous text2067+ if !t.previewed.sixel {2068+ t.tui.Sync(false)2069+ }2070 }2071 sixel = sixel || isSixel2072 if idx == 0 {2073 t.pwindow.MoveAndClear(y, x)2074 } else {2075 t.pwindow.Move(y, x)2076 }2071- t.tui.PassThrough(passThrough)2077+ t.tui.PassThrough(t.pwindow.Top()+y, t.pwindow.Left()+x, passThrough)2078 2079 if requiredLines > 0 {2080 if y+requiredLines == height {2081 t.pwindow.Move(height-1, maxWidth-1)1935 unmodified linesmodified:CHANGELOG.md+3 added-2 removed
1 CHANGELOG2 =========3 4-0.43.14+0.44.05 ------6-- (Experimental) Sixel image support in preview window (not available on Windows)6+- (Experimental) Sixel image support in preview window7 - [bin/fzf-preview.sh](bin/fzf-preview.sh) is added to demonstrate how to8 display an image using Kitty image protocol or Sixel. You can use it9 like so:10 ```sh11 fzf --preview='fzf-preview.sh {}'12 ```13+- (Experimental) Sixel and Kitty image support now also available on Windows14 - Bug fixes15 16 0.43.017 ------1733 unmodified linesmodified:go.mod+4 added-3 removed
1 module github.com/junegunn/fzf2 3 require (4- github.com/gdamore/tcell/v2 v2.5.44+ // go get github.com/gdamore/tcell/v2@8a50441ee1fd29b18a4a7d51e98423a17ec8ef4c5+ github.com/gdamore/tcell/v2 v2.6.1-0.20231031224054-8a50441ee1fd6 github.com/mattn/go-isatty v0.0.177 github.com/mattn/go-runewidth v0.0.148 github.com/mattn/go-shellwords v1.0.129 github.com/rivo/uniseg v0.4.44 unmodified lines14 15 require (16 github.com/gdamore/encoding v1.0.0 // indirect17 github.com/lucasb-eyer/go-colorful v1.2.0 // indirect17- golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect18- golang.org/x/text v0.5.0 // indirect18+ golang.org/x/sync v0.1.0 // indirect19+ golang.org/x/text v0.12.0 // indirect20 )21 22 go 1.17modified:go.sum+16 added
1 github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=2 github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=3 github.com/gdamore/tcell/v2 v2.5.4 h1:TGU4tSjD3sCL788vFNeJnTdzpNKIw1H5dgLnJRQVv/k=4 github.com/gdamore/tcell/v2 v2.5.4/go.mod h1:dZgRy5v4iMobMEcWNYBtREnDZAT9DYmfqIkrgEMxLyw=5+github.com/gdamore/tcell/v2 v2.6.1-0.20231031224054-8a50441ee1fd h1:DzX6TtJGRMP+AMlU+U4JEgoAVR/gwPNrz3JqPnEm3PM=6+github.com/gdamore/tcell/v2 v2.6.1-0.20231031224054-8a50441ee1fd/go.mod h1:pwzJMyH4Hd0AZMJkWQ+/g01dDvYWEvmJuaiRU71Xl8k=7 github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=8 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=9 github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=10 github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=1 unmodified line12 github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=13 github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=14 github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=15 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=16+github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=17 github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=18 github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=19 github.com/saracen/walker v0.1.3 h1:YtcKKmpRPy6XJTHJ75J2QYXXZYWnZNQxPCVqZSHVV/g=20 github.com/saracen/walker v0.1.3/go.mod h1:FU+7qU8DeQQgSZDmmThMJi93kPkLFgy0oVAcLxurjIk=21 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=22 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=23 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=24 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=25+golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=26 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=27 golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=28 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=29+golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=30 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=31 golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=32 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=33 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=34+golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=35+golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=36 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=37 golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=38 golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=39 golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=40 golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=41 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=42+golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=43+golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=44+golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=45 golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=46 golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=47 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=48 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=49+golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=50+golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=51 golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=52 golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=53 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=54 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=55 golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=56 golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=57 golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=58+golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=59+golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=60+golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=61 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=62 golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=63 golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=64+golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=65 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=