iambumblehead / thu.sh

bash script to render thumbnails for various types of file
GNU General Public License v3.0
1 stars 0 forks source link

detecting cell size #26

Closed iambumblehead closed 3 months ago

iambumblehead commented 4 months ago

per https://github.com/vifm/vifm/issues/419#issuecomment-1983049450

not sure about doing it from a bash script, but cell dimentions could be determined from terminal window resolution and number of its lines and columns

google-searching shows that this returns rows and columns stty size and this does work here in foot terminal and xterm. There is also $LINES and $COLUMNS env vars.

But how should window resolution should be detected

cmd=$(printf '%b' "${TMUX:+\\ePtmux;\\e}\\e[14t${TMUX:+\\e\\\\}")
IFS=";" read -a REPLY -s -t 2 -d "S" -p $cmd >&2
echo "${REPLY[2]}x${REPLY[1]}"

update: the function above does not return resolution from vifm-spawned script call :(

iambumblehead commented 4 months ago

https://codeberg.org/dnkl/foot/issues/1636

iambumblehead commented 4 months ago

@xaizek to loop you in

iambumblehead commented 4 months ago

I tried this from the bash bible again and this time it work. I must have done something wrong the last time I tried using it...

get_window_size() {
    # Usage: get_window_size
    printf '%b' "${TMUX:+\\ePtmux;\\e}\\e[14t${TMUX:+\\e\\\\}"
    IFS=';t' read -d t -t 0.05 -sra term_size
    printf '%s\n' "${term_size[1]}x${term_size[2]}"
}
iambumblehead commented 4 months ago

it looks like the above function only returns a valid value interrmittently

$ resolution_window_get
469x696
$ resolution_window_get
^[[4;469;696t469x696
$ resolution_window_get
469x696
$ resolution_window_get
469x696
$ resolution_window_get
^[[4;469;696t469x696
$ resolution_window_get
^[[4;469;696t469x696
$ resolution_window_get
^[[4;469;696t469x696
$ resolution_window_get
^[[4;469;696t469x696
$ resolution_window_get
469x696
iambumblehead commented 3 months ago

the script still needs to be updated to use terminal-reported cell size but a separate/new issue and PR can be created for that.