You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, thanks for the blogpost about termsize, it got me started on some yak shaving I didn't intend to do today... :-)
While reading your post I figured there should be a way to do it without python at all.
Here's a way to do it, I thought you might be interested.
#!/bin/bash
set -eu
# Reset term to initial state on exit
stty_ori=$(stty -g)
function atexit {
stty $stty_ori
}
trap atexit EXIT
# Turn echo off to avoid writing term size on the screen
stty -echo
# Use bash's "read" to send the control seq to the term and read its answer
# 7: save cursor pos
# [r: scroll screen
# [x;yH: set cursor pos
# [6n: get cursor pos
read -p $'\e7\e[r\e[9999;9999H\e[6n' -d R termsize
# Strip leading control char + [ (e.g. \e[x;yH)
termsize=${termsize#??}
# Reset cursor pos
echo -en '\e8'
# Actually resize the terminal
stty $(echo $termsize | sed 's/^/rows /; s/;/ cols /')
That is what is odd... I am using BASH, on Pi OS. I was able to get around it by embedding the following in my .bashrc script file. Still testing this it will force the (agetty) based serial console (say opened with putty) to the desired rows and columns but is not perfect, if you happen to have the putty (COM) session smaller than 60 x 200 it will resize the terminal window and everything seems to honor it... but if serial console is bigger than 60 x 200 it does not seem to shrink the (putty) terminal window (which I expected). I can live with the issue, since typically putty defaults to 24x80 on serial consoles.
if [ $(tty) = "/dev/ttyS0" ]; then
stty rows 60 cols 200
echo -e "\033[8;60;200t"
fi
The big headache is that agetty just does not seem to have any easy way to be changed, looking at the C source code. It defaults to 24x80 but only it the agetty executable does not get a valid terminal size returned
1395 /* Check for terminal size and if not found set default */
1396 if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == 0) {
1397 if (ws.ws_row == 0)
1398 ws.ws_row = 24;
1399 if (ws.ws_col == 0)
1400 ws.ws_col = 80;
1401 if (ioctl(STDIN_FILENO, TIOCSWINSZ, &ws))
1402 debug("TIOCSWINSZ ioctl failed\n");
1403 }
Would be nice if agetty could be changed to honor say a configuration file in say /etc/default, or such that would allow a default rows and columns values to be set and consistently honored.
Activity
wrljet commentedon Dec 30, 2020
That works well, too. Thanks.
Jibun-no-Kage commentedon Jan 28, 2024
Fails on Pi OS Bookwarn with the following message...
6: function: not found
jraby commentedon Jan 28, 2024
The script only works with
bash, it relies on bash'sreadbuilt-in (specifically its-doption)Jibun-no-Kage commentedon Jan 28, 2024
That is what is odd... I am using BASH, on Pi OS. I was able to get around it by embedding the following in my .bashrc script file. Still testing this it will force the (agetty) based serial console (say opened with putty) to the desired rows and columns but is not perfect, if you happen to have the putty (COM) session smaller than 60 x 200 it will resize the terminal window and everything seems to honor it... but if serial console is bigger than 60 x 200 it does not seem to shrink the (putty) terminal window (which I expected). I can live with the issue, since typically putty defaults to 24x80 on serial consoles.
The big headache is that agetty just does not seem to have any easy way to be changed, looking at the C source code. It defaults to 24x80 but only it the agetty executable does not get a valid terminal size returned
Would be nice if agetty could be changed to honor say a configuration file in say /etc/default, or such that would allow a default rows and columns values to be set and consistently honored.