tinker2much
Posts: 767
Joined: Wed Jun 20, 2018 12:38 am

[SOLVED] serial console more than 80x24?

Mon Sep 05, 2022 5:44 pm

I bought a USB UART serial console cable during the recent Pimoroni sale https://shop.pimoroni.com/products/usb- ... =288389664; I had a spare Pi Zero and a spare sd card, so time to play. I got connected without too much trouble, using "screen" from a Debian laptop. But the console seems to be set to 80x24; its like a smaller viewport within the larger screen display. You can sort of see this when I do an "ls -l" in a full directory, see attached.
2022-09-05-123523_1334x693_scrot.png
2022-09-05-123523_1334x693_scrot.png (112 KiB) Viewed 1264 times
. This is even more obvious when I invoke "mc" (midnight commander) - see other attached image.
2022-09-05-123223_1334x693_scrot.png
2022-09-05-123223_1334x693_scrot.png (132.1 KiB) Viewed 1264 times
.

Is this configurable, and where? On the Zero, on the laptop, in screen?
Last edited by tinker2much on Mon Sep 05, 2022 9:01 pm, edited 1 time in total.

memjr
Posts: 3640
Joined: Fri Aug 21, 2020 5:59 pm

Re: serial console more than 80x24?

Mon Sep 05, 2022 5:57 pm

If that is configurable, it'll be in one of these 2 files (system vs user config)
Customizing Screen
Like many Linux applications, Screen uses a customizable configuration file. Find the system-wide configuration file at /etc/screenrc. The user’s configuration file is located at ~/.screenrc.
And user manual https://www.gnu.org/software/screen/manual/screen.html

Try this:

https://www.gnu.org/software/screen/man ... indow-Size

tinker2much
Posts: 767
Joined: Wed Jun 20, 2018 12:38 am

Re: serial console more than 80x24?

Mon Sep 05, 2022 6:16 pm

With either of screen's width or height commands, I get "Your termcap does not specify how to change the terminal's width|height to ..."

I have the feeling that the problem is what's appearing IN the screen window, not the screen window itself. IOW, the contents not the container. Which would have to be fiddled with on the sending zero?

memjr
Posts: 3640
Joined: Fri Aug 21, 2020 5:59 pm

Re: serial console more than 80x24?

Mon Sep 05, 2022 6:19 pm

Dumb question: did you try to change the settings of your terminal? Not just drag to corner of the window to make it longer and wider, but actually change it's default settings.

cleverca22
Posts: 8615
Joined: Sat Aug 18, 2012 2:33 pm

Re: serial console more than 80x24?

Mon Sep 05, 2022 6:46 pm

the problem is that the serial terminal emulator, is not informing the remote (linux on rpi) end about the resizing
so the remote linux is just stuck defaulting to 80x24

Code: Select all

echo "stty rows $(tput lines) cols $(tput cols)"
the 2 tput commands, send ansii control codes to ask the terminal emulator what the width/height are
the stty command then modifies the tty on the remote linux, to change the dimensions

you can also just run the "resize" command from the xterm package to do the same thing

User avatar
jojopi
Posts: 3913
Joined: Tue Oct 11, 2011 8:38 pm

Re: serial console more than 80x24?

Mon Sep 05, 2022 7:52 pm

cleverca22 wrote:
Mon Sep 05, 2022 6:46 pm
the 2 tput commands, send ansii control codes to ask the terminal emulator what the width/height are
They do not. tput lines and cols just print the currently-assumed terminal size, which is the very thing we are trying to correct.

The resize program from the xterm package, however does attempt to query the terminal emulator using escape sequences.

cleverca22
Posts: 8615
Joined: Sat Aug 18, 2012 2:33 pm

Re: serial console more than 80x24?

Mon Sep 05, 2022 8:38 pm

jojopi wrote:
Mon Sep 05, 2022 7:52 pm
They do not. tput lines and cols just print the currently-assumed terminal size, which is the very thing we are trying to correct.
oops, right, i forgot how that command was meant to be used, and why the echo is there

you where meant to run that before you start the serial terminal program, to get the LOCAL terminal size
and it prints out an stty command, that you copy, then paste into the terminal after you connect
jojopi wrote:
Mon Sep 05, 2022 7:52 pm
The resize program from the xterm package, however does attempt to query the terminal emulator using escape sequences.
yep, thats far simpler, and can be used repeatedly as you resize, its just slightly confusing that its in the xterm package

tinker2much
Posts: 767
Joined: Wed Jun 20, 2018 12:38 am

Re: serial console more than 80x24?

Mon Sep 05, 2022 9:01 pm

I ran the following on the local terminal:

Code: Select all

echo "stty rows $(tput lines) cols $(tput cols)"
Which returned the following:

Code: Select all

stty rows 33 cols 132
I cut that from the local terminal and pasted it into the serial terminal, and that did it. Now mc looks like this:
2022-09-05-155731_1334x692_scrot.png
2022-09-05-155731_1334x692_scrot.png (156.13 KiB) Viewed 1133 times
.
You guys are great, thank you very much!

User avatar
ukscone
Forum Moderator
Forum Moderator
Posts: 4533
Joined: Fri Jul 29, 2011 2:51 pm

Re: [SOLVED] serial console more than 80x24?

Mon Sep 25, 2023 3:59 pm

if you install the xterm package then the command resize will set the serial console to the size of your console window. you can also put

Code: Select all

    rsz() {
        if [[ -t 0 && $# -eq 0 ]];then
                local IFS='[;' escape geometry x y
                echo -ne '\e7\e[r\e[999;999H\e[6n\e8'
                read -t 5 -sd R escape geometry
                x=${geometry##*;} y=${geometry%%;*}
                if [[ ${COLUMNS} -eq ${x} && ${LINES} -eq ${y} ]];then
                        echo "${TERM} ${x}x${y}"
                else
                        echo "${COLUMNS}x${LINES} -> ${x}x${y}"
                        stty cols ${x} rows ${y}
                fi
        else
                print 'Usage: rsz'
        fi
    }


    case $( /usr/bin/tty ) in
            /dev/ttyAMA0|/dev/ttyAMA10|/dev/ttyO0|/dev/ttyS0) export LANG=C
                                                rsz
                                                ;;
    esac
into /etc/profile.d/serial-console.sh

and it should automatically resize/set your console window size

Thomas Nittel
Posts: 2
Joined: Mon Sep 25, 2023 12:27 pm
Location: 75217 Birkenfeld, Germany

Re: [SOLVED] serial console more than 80x24?

Mon Sep 25, 2023 4:16 pm

If the following lines are added to /etc/bash.bashrc the columns and rows of a serial console will automatically be adjusted to the screen size. So, the Midnight Commander will fill the whole screen which it finds at start. This solution was originally posted at https://unix.stackexchange.com/a/680244

Code: Select all

# resize function for connected serial console
resize() {
  old=$(stty -g)
  stty raw -echo min 0 time 5

  printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
  IFS='[;R' read -r _ rows cols _ < /dev/tty

  stty "$old"

  #echo "cols:$cols"
  #echo "rows:$rows"
  stty cols "$cols" rows "$rows"
}

ALL_COMMANDS_FINISHED=1

PreCommands() {
  if [ "$ALL_COMMANDS_FINISHED" = '1' ]; then
    ALL_COMMANDS_FINISHED=0
    resize
    #echo "1->0"
  fi
}

PostCommands() {
  ALL_COMMANDS_FINISHED=1
}

# if login thru tty*
if [[ $(tty) == /dev/tty* ]]; then
  # PreCommands is called before every single command on a command line
  trap PreCommands DEBUG
  # PostCommands is called after all commands on a command line are finished
  PROMPT_COMMAND="PostCommands"
fi
The Midnight Commander at the serial terminal will start with color and mouse support if the following line is added to /etc/bash.bashrc (see https://midnight-commander.org/wiki/doc/faq):

Code: Select all

alias mc='mc -x -c'
To enable root to use the alias the following line can be added to /etc/bash.bashrc:

Code: Select all

alias sudo='sudo -E '
I use 2023-05-03-raspios-bullseye-arm64-lite and PuTTY 0.77 under Windows 10 Pro 22H2.
Attachments
mcAtSerialLineUnderPuTTYmod.jpg
mcAtSerialLineUnderPuTTYmod.jpg (94.53 KiB) Viewed 729 times
Last edited by Thomas Nittel on Mon Sep 25, 2023 4:22 pm, edited 1 time in total.

cleverca22
Posts: 8615
Joined: Sat Aug 18, 2012 2:33 pm

Re: [SOLVED] serial console more than 80x24?

Mon Sep 25, 2023 4:22 pm

tinker2much wrote:
Mon Sep 05, 2022 9:01 pm
echo "stty rows $(tput lines) cols $(tput cols)"
ukscone wrote:
Mon Sep 25, 2023 3:59 pm
if you install the xterm package then the command resize will set the serial console to the size of your console window. you can also put
both duplicate answers, i already said the same thing back in this thread, in 2022

Return to “Advanced users”