Skip to content

Consider use of CSI 18(9?) t seq for querying the current terminal size #37526

@bam80

Description

@bam80

Currently, the terminal size is queried with CUP/CPR pair of sequences:

CSI Ps ; Ps H
Cursor Position [row;column] (default = [1,1]) (CUP).

CSI Ps n Device Status Report (DSR).
Ps = 6 ⇒ Report Cursor Position (CPR) [row;column].
Result is CSI r ; c R

This method works, but it's rather some kind of workaround which is not ideal.

Consider using dedicated Window manipulation (XTWINOPS) sequences for that:

CSI Ps ; Ps ; Ps t
Window manipulation (XTWINOPS), dtterm, extended by xterm.

Ps = 1 8 ⇒ Report the size of the text area in characters.
Result is CSI 8 ; height ; width t

or

Ps = 1 9 ⇒ Report the size of the screen in characters.
Result is CSI 9 ; height ; width t

Here is some historical background for that.

Sample script:

$ cat /usr/local/etc/profile.d/ttyS-init.sh
if [ $(tty) = /dev/ttyS0 ]; then
  TERM=xterm-256color

  old=$(stty -g)
  stty raw -echo min 0 time 5

  printf '\033[18t' > /dev/tty
  IFS=';t' read -r _ rows cols _ < /dev/tty

  stty "$old"

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

@poettering @ThomasDickey

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFE 🎁Request for Enhancement, i.e. a feature requestpid1util-lib

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions