base-files/profile: Add universal resize function
PATCH 1/2 base-files/profile: Add universal resize function
Using an editor or any kind of command line that wraps beyond the column width of the session on a serial port is quite problematic unless you are using an 80x24 session.
The original /etc/profile tried to use the resize binary if it was available. The problem is that you only get the resize binary if xterm, or busybox is installed.
This updated /etc/profile will add a resize function available to the shell when no xterm or busybox resize binary is found. More care is taken in this new version to test that terminal is interactive. The EDITOR and SHLVL environment variables are checked to prevent resize from running necessarily.
The function definitions are not indented intentionally to keep them to the 80 column width.
--- .../base-files/base-files/profile | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-)
meta/recipes-core/base-files/base-files/profile +41 -7
@@ -2,7 +2,6 @@ # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). PATH="/usr/local/bin:/usr/bin:/bin" -EDITOR="vi" # needed for packages like cron, git-commit [ "$TERM" ] || TERM="vt100" # Basic terminal capab. For screen etc. # Add /sbin & co to $PATH for the root user
@@ -20,13 +19,48 @@ if [ -d /etc/profile.d ]; then unset i fi -# Make sure we are on a serial console (i.e. the device used starts with -# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which tries do -# use ssh -case $(tty 2>/dev/null) in - /dev/tty[A-z]*) [ -x @BINDIR@/resize ] && @BINDIR@/resize >/dev/null;; -esac +if [ -t 0 -a $# -eq 0 ]; then + if [ ! -x @BINDIR@/resize ] ; then + if [ -n "$BASH_VERSION" ] ; then +# Optimized resize funciton for bash +resize() { + local x y + IFS='[;' read -t 2 -p $(printf '\e7\e[r\e[999;999H\e[6n\e8') -sd R _ y x _ + [ -n "$y" ] && \ + echo -e "COLUMNS=$x;\nLINES=$y;\nexport COLUMNS LINES;" && \ + stty cols $x rows $y +} + else +# Portable resize function for ash/bash/dash/ksh +# with subshell to avoid local variables +resize() { + (o=$(stty -g) + stty -echo raw min 0 time 2 + printf '\0337\033[r\033[999;999H\033[6n\0338' + if echo R | read -d R x 2> /dev/null; then + IFS='[;R' read -t 2 -d R -r z y x _ + else + IFS='[;R' read -r _ y x _ + fi + stty "$o" + [ -z "$y" ] && y=${z##*[}&&x=${y##*;}&&y=${y%%;*} + [ -n "$y" ] && \ + echo "COLUMNS=$x;"&&echo "LINES=$y;"&&echo "export COLUMNS LINES;"&& \ + stty cols $x rows $y) +} + fi + fi + # Use the EDITOR not being set as a trigger to call resize + # and only do this for /dev/tty[A-z] which are typically + # serial ports + if [ -z "$EDITOR" -a "$SHLVL" = 1 ] ; then + case $(tty 2>/dev/null) in + /dev/tty[A-z]*) resize >/dev/null;; + esac + fi +fi +EDITOR="vi" # needed for packages like cron, git-commit export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM umask 022
Signature · 1 line
2.17.1
PATCH 2/2 systemd-serialgetty: Switch to TERM=linux
Long ago in commit 473ff65c2f69de4ece3204fadfae7c5cb992149a (serial-getty service: Add xterm as default TERM), the xterm became the default for the serial port terminal.
Using the version of vim.tiny in oe-core master with the serial port connected in xterm version 322 (which is one of the most widely deployed versions at the current time) causes artifacts and missed characters.
The example sequence is the following:
* Start vim
* Press "i" to enter input mode
* Type "123"
* Press Escape to enter command mode
* Press "a" to enter append mode
* Type "456"
At this point if you are using xterm less than version 535 you will see on your screen "12456" instead of "123456".
Changing the TERM variable to "linux" will still allow you to have all the same functionality with colorization, ansi character escapes etc..., but will avoid the extra xterm specific escape sequence that only exists in the most recent versions of xterm.
--- .../systemd/systemd-serialgetty/[email protected] | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-core/systemd/systemd-serialgetty/[email protected] +1 -1
@@ -29,7 +29,7 @@ Conflicts=rescue.service Before=rescue.service [Service] -Environment="TERM=xterm" +Environment="TERM=linux" ExecStart=-/sbin/agetty -8 -L %I @BAUDRATE@ $TERM Type=idle Restart=always
Signature · 1 line
2.17.1
Re: [OE-core] [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux
Why not have it configurable as already done with BAUDRATE?
Especially as it doesn't change the behavior for user without the mentioned prerequisites
Quoted 48 lines · Jason Wessel
Long ago in commit
473ff65c2f69de4ece3204fadfae7c5cb992149a(serial-getty service: Add xterm as default TERM), the xterm became the default for the serial port terminal.Using the version of vim.tiny in oe-core master with the serial port connected in xterm version 322 (which is one of the most widely deployed versions at the current time) causes artifacts and missed characters.
The example sequence is the following:
* Start vim
* Press "i" to enter input mode
* Type "123"
* Press Escape to enter command mode
* Press "a" to enter append mode
* Type "456"At this point if you are using xterm less than version 535 you will see on your screen "12456" instead of "123456".
Changing the TERM variable to "linux" will still allow you to have all the same functionality with colorization, ansi character escapes etc..., but will avoid the extra xterm specific escape sequence that only exists in the most recent versions of xterm.
Signed-off-by Jason Wessel <[email protected]>--- .../systemd/systemd-serialgetty/[email protected] | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)meta/recipes-core/systemd/systemd-serialgetty/[email protected] +1
-1@@ -29,7 +29,7 @@ Conflicts=rescue.service Before=rescue.service [Service] -Environment="TERM=xterm" +Environment="TERM=linux" ExecStart=-/sbin/agetty -8 -L %I @BAUDRATE@ $TERM Type=idle Restart=always
Re: [OE-core] [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux
Quoted 4 lines · Konrad Weihmann
Why not have it configurable as already done with BAUDRATE? Especially as it doesn't change the behavior for user without the mentioned prerequisites
Good idea. That seems like a perfectly reasonable ask for a v2 patch.
I would still change the default to "linux" as it is broken and the defaults for the oe-core should work for the broad range of users.
Jason.
Quoted 49 lines · Jason Wessel
Quoted 48 lines
Long ago in commit
473ff65c2f69de4ece3204fadfae7c5cb992149a(serial-getty service: Add xterm as default TERM), the xterm became the default for the serial port terminal.Using the version of vim.tiny in oe-core master with the serial port connected in xterm version 322 (which is one of the most widely deployed versions at the current time) causes artifacts and missed characters.
The example sequence is the following:
* Start vim
* Press "i" to enter input mode
* Type "123"
* Press Escape to enter command mode
* Press "a" to enter append mode
* Type "456"At this point if you are using xterm less than version 535 you will see on your screen "12456" instead of "123456".
Changing the TERM variable to "linux" will still allow you to have all the same functionality with colorization, ansi character escapes etc..., but will avoid the extra xterm specific escape sequence that only exists in the most recent versions of xterm.
Signed-off-by Jason Wessel <[email protected]>--- .../systemd/systemd-serialgetty/[email protected] | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)meta/recipes-core/systemd/systemd-serialgetty/[email protected] +1
-1@@ -29,7 +29,7 @@ Conflicts=rescue.service Before=rescue.service [Service] -Environment="TERM=xterm" +Environment="TERM=linux" ExecStart=-/sbin/agetty -8 -L %I @BAUDRATE@ $TERM Type=idle Restart=always