okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
6e82811
main
1// Which terminals get thumbnails depends on the environment and, under tmux, 2// on the attached client and a tmux option; the e2e suite runs in neither, so 3// a wrong branch here would only show as missing or garbled thumbnails. 4package tui 5 6import "testing" 7 8func TestDetectGraphics (t * testing.T ) { 9for _ ,test := range []struct { 10name string 11env map [string ]string 12client string 13passthrough string 14want graphics 15 }{ 16 {name :"kitty" ,env :map [string ]string {"TERM" :"xterm-kitty" },want :graphics {supported :true }}, 17 {name :"ghostty" ,env :map [string ]string {"TERM_PROGRAM" :"ghostty" },want :graphics {supported :true }}, 18 {name :"plain terminal" ,env :map [string ]string {"TERM" :"xterm-256color" }}, 19 {name :"tmux in kitty" ,env :map [string ]string {"TMUX" :"/tmp/tmux" ,"TERM" :"tmux-256color" },client :"xterm-kitty" ,passthrough :"on" ,want :graphics {supported :true ,wrapped :true }}, 20 {name :"tmux without passthrough" ,env :map [string ]string {"TMUX" :"/tmp/tmux" ,"KITTY_WINDOW_ID" :"1" },client :"xterm-ghostty" ,passthrough :"off" ,want :graphics {hint :"image thumbnails need tmux's allow-passthrough: set -g allow-passthrough on" }}, 21 {name :"tmux in a plain terminal" ,env :map [string ]string {"TMUX" :"/tmp/tmux" ,"KITTY_WINDOW_ID" :"1" },client :"xterm-256color" ,passthrough :"on" }, 22 } { 23t .Run (test .name ,func (t * testing.T ) { 24got := detectGraphics (func (key string )string {return test .env [key ] },func (args ... string )string { 25if args [0 ]== "display-message" { 26return test .client 27 } 28return test .passthrough 29 }) 30if got != test .want { 31t .Fatalf ("got %+v, want %+v" ,got ,test .want ) 32 } 33 }) 34 } 35} 36 37func TestThumbnailCellsKeepTheAspectInsideTheArea (t * testing.T ) { 38for _ ,test := range []struct {width ,height ,cols ,rows int }{ 39 {1200 ,400 ,12 ,2 },// wide: full width, few rows 40 {800 ,800 ,8 ,4 },// square: twice as many columns as rows 41 {100 ,1000 ,1 ,4 },// tall: one column 42 {4000 ,10 ,12 ,1 }, 43 } { 44if cols ,rows := thumbnailCells (test .width ,test .height );cols != test .cols || rows != test .rows { 45t .Errorf ("%dx%d: got %dx%d cells, want %dx%d" ,test .width ,test .height ,cols ,rows ,test .cols ,test .rows ) 46 } 47 } 48}