# xterm-info - type, display screen, xterm window, and text position and size info # type features VT420wpSeNThcrl ^[[c ^[[?64;1;2;4;6;9;15;21;22;28;29c$ # type version mintty v3.5.1-0 ^[[>c ^[[>77;30501;0c$ # type attributes ^[[=c $ # window position 3 px 210+120 ^[[13t ^[[3;210;120t$ # window size 4 px 875x881 ^[[14;2t ^[[4;881;875t$ # text position 3 px 219+152 ^[[13;2t ^[[3;219;152t$ # text size 4 px 840x840 ^[[14t ^[[4;840;840t$ # text chars 8 ch 120x60 ^[[18t ^[[8;60;120t$ # char size 6 px 7x14 ^[[16t ^[[6;14;7t$ # screen chars 9 ch 274x77 ^[[19t ^[[9;77;274t$ # screen size 5 px 1920x1080 ^[[15t ^[[5;1080;1920t$ # window status 1 open ^[[11t ^[[1t$ xterm-info ( ) { local p r n s x y h w d u v f t read -d c -N 80 -p $'\E[c' -s -t 1 r f='type features' n=${r#$'\E[?'} n=${n%c} s=${n#*\;} n=${n%%\;*} case $n in 1) t=VT100 [ 2 -eq $s ] && t=VT100av [ 0 -eq $s ] && t=VT101 ;; 6) t=VT102;; 62) t=VT220;; 63) t=VT320;; 64) t=VT420;; 65) t=VT525;; 77) t=mintty;; esac d='' for u in ${s//\;/\ } do case $u in 1) d+=w;; # wide 132 columns support 2) d+=p;; # Printer 3) d+=R;; # ReGIS graphics 4) d+=S;; # Sixel graphics 6) d+=e;; # Selective erase 8) d+=k;; # User-defined keys 9) d+=N;; # National Replacement Character sets 15) d+=T;; # Technical characters 16) d+=L;; # Locator port i.e. pen, mouse, etc. 17) d+=q;; # Terminal state interrogation 18) d+=W;; # User windows 21) d+=h;; # Horizontal scrolling 22) d+=c;; # ANSI color, e.g., VT525 28) d+=r;; # Rectangular editing 29) d+=l;; # ANSI text locator i.e. DEC locator mode for pen, mouse esac done [ $((${#t}+${#d})) -lt 8 ] && d+=$'\t' # pad short feature list echo "$f"$'\t'"$t$d"$'\t^[[c\t\t'"$(cat -A <<< ${r})" read -d c -N 80 -p $'\E[>c' -s -t 1 r f='type version' n=${r#$'\E[>'} n=${n%c} v=${n#*\;} u=${v#*\;} v=${v%\;*} v=${v//0/.} n=${n%%\;*} case $n in 0) t=VT100;; 1) t=VT220;; 2) t=VT240;; 18) t=VT330;; 19) t=VT340;; 24) t=VT320;; 41) t=VT420;; 61) t=VT510;; 64) t=VT520;; 65) t=VT525;; 77) t=mintty;; esac echo "$f"$'\t'"$t v$v-$u"$'\t^[[>c\t\t'"$(cat -A <<< ${r})" for p in 13 14\;2 13\;2 14 18 16 19 15 11 do x=''; y=''; h=''; w=''; d=''; u=''; v=''; f=''; r=''; t=$'\t' read -d t -N 80 -p $'\E['"$p"'t' -s -t 1 r if [ -n "$r" ]; then # 16 and 15 may not respond # [ $p = 11 ] && echo ${#r} "$r" | cat -A && echo && set -vx n=${r#$'\E['} n=${n%t} s=${n#[0-9]\;} n=${n%%\;*} if [ $n -ge 3 ]; then h=${s%\;*} w=${s#*\;} d='x' u='px' [ $n -ge 8 ] && u='ch' s='' fi else # 16 and 15 may not respond n=$(($p-10)) d='x' u='px' fi case $n in 3) x=$h y=$w h='' w='' d='+' if [ $p = 13 ] then f='window position' else f='text position' t='' fi ;; 4) if [ $p = 14 ] then f='text size' ht=$h # save to calc char size wt=$w else f='window size' hw=$h # save to derive window status open/max ww=$w t='' fi ;; 8) f='text chars' hc=$h # save to calc char size wc=$w ch=$(($ht/$hc)) # save default char size cw=$(($wt/$wc)) hs=$h # default screen size < windows size ws=$w ;; 6) f='char size' [ -z "$h" ] && h=$ch # saved char size [ -z "$w" ] && w=$cw [ -z "$r" ] && r="^[[$n;$h;$w"t ;; 9) f='screen chars' hc=$h # save to calc screen size wc=$w hs=$(($hc*$ch)) # save default screen size ws=$(($wc*$cw)) ;; 5) f='screen size' [ -z "$h" ] && h=$(((($hs-1)/8+1)*8)) # saved screen size [ -z "$w" ] && w=$(((($ws-1)/8+1)*8)) # round bits up to bytes [ -z "$r" ] && r="^[[$n;$h;$w"t hs=$h # save to derive window status open/max ws=$w ;; 1|2) f='window status' if [ $n = 2 ] then s='icon' elif [ -n "$ws" ] && [ $ww -ge $ws ] && \ [ -n "$hs" ] && [ $hw -ge $hs ] then s='max' else s='open' fi u=$'\t' ;; esac echo "$f"$'\t'"$n $s$u $x$w$d$h$y"$'\t^[['"${p}t$t"$'\t'"$(cat -A <<< ${r})" # set +vx done }