Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

SIGWINCHで画面サイズが変更された場合を検知

実際のところ

www.linuxcommand.org
を写経し一部改造しつつ実験。

 #!/bin/bash

redraw() {
   local str width height length
   width=$(tput cols)
   height=$(tput lines)
   str="Width = $width Height = $height"
   length=${#str}
   clear
   tput cup $((height / 2)) $(((width / 2) - (length / 2)))
   echo "$str"
   tput cup $((height / 2 + 1)) $(((width / 2) - (length / 2)))
   tput smul;
   echo "And you?"
   tput rmul

}

trap redraw WINCH

redraw
while true; do
    :
done

実行してみると
f:id:shuzo_kino:20211215234010p:plain

SIGWINCHをtrapしたことで、変形後の値を読み取って
f:id:shuzo_kino:20211215233852p:plain