Terminals: Difference between revisions
No edit summary |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 36: | Line 36: | ||
bind -f ~/.inputrc | bind -f ~/.inputrc | ||
</pre> | </pre> | ||
To have this apply to all users (and to see the default configuration), take a look at and/or modify this file: <tt>/etc/inputrc | |||
</tt> | |||
==Framebuffer Scrollback Buffer== | ==Framebuffer Scrollback Buffer== | ||
| Line 50: | Line 51: | ||
* Open the serial connection (e.g. with minicom or screen) | * Open the serial connection (e.g. with minicom or screen) | ||
* Set TTY rows and cols:<pre>stty rows 41 cols 190</pre> | * Set TTY rows and cols:<pre>stty rows 41 cols 190</pre> | ||
Alternatively, you can use a script to dynamically fix this. I have <tt>fixtty.sh</tt>: | |||
<pre> | |||
#!/bin/sh | |||
# | |||
# fixtty.sh | |||
# Fixes the terminal size of a serial terminal | |||
# Arguments: | |||
# -v Enable verbose mode | |||
if [ "$1" = "-v" ] ; then | |||
VERBOSE=1 | |||
else | |||
VERBOSE=0 | |||
fi | |||
if [ "$TERM" = "vt220" ] ; then | |||
echo Suggestion: set TERM to something more useful like linux, xterm, xterm-256color, etc | |||
fi | |||
old=$(stty -g) | |||
if [ $VERBOSE -eq 1 ] ; then | |||
echo "Old TTY settings: '$old'" | |||
fi | |||
stty raw -echo min 0 time 5 | |||
if [ -f /dev/tty ] ; then | |||
exit 0 | |||
fi | |||
printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty | |||
IFS='[;R' read -r _ rows cols _ < /dev/tty | |||
stty "$old" | |||
if [ $VERBOSE -eq 1 ] ; then | |||
echo "executing 'stty cols '$cols' rows '$rows'" | |||
fi | |||
stty cols "$cols" rows "$rows" | |||
exit $? | |||
</pre> | |||
Latest revision as of 17:34, 10 July 2025
Linux Virtual Console
Enabling Key Bindings
One annoyance I have with the default configuration of the virtual console is that it doesn't enable the Ctrl+Left and Ctrl+Right key bindings to move to the previous/next word. Here is how you can do that:
- Determine the escape sequences that are being generated when you press Ctrl+Left and Ctrl+Right. Within a virtual terminal, run the cat command and then: press Ctrl+Left, a few spaces, then Ctrl+Right. The escape sequences will be output. Make a note of those. Then press Ctrl+C to exit. For example:
jeremy@thinkpadx1gen6 ~ $ cat ^[[D ^[[C
- In your ~/.inputrc file, add the following (replacing the escape sequences below with your own if they are different):
# Allow ctrl+left and ctrl+right keys to move to previous/next word in virtual terminal # The \e here represents the beginning escape sequence: ^[ # Ctrl + Left "\e[D": backward-word # Ctrl + Right "\e[C": forward-word
Note that the key sequences being sent by those key combinations are different within an X11 session. In my case the X11 bindings are already set up by default, but here they are for reference:
# Allow ctrl+left and ctrl+right keys to move to previous/next word in X11 "\e[1;5D": backward-word "\e[1;5C": forward-word
The changes will take effect the next time you open a terminal. If you want the changes to take effect immediately, run this:
bind -f ~/.inputrc
To have this apply to all users (and to see the default configuration), take a look at and/or modify this file: /etc/inputrc
Framebuffer Scrollback Buffer
To increase the size of the framebuffer scrollback buffer, use the fbcon kernel parameter:
fbcon=scrollback:Nk
Where N is a number. The default: N=32k
Serial Terminals
Dealing with a serial TTY smaller than your terminal
- Open tmux
- Press Ctrl+B q to see the tmux pane size (e.g. 190x41)
- Open the serial connection (e.g. with minicom or screen)
- Set TTY rows and cols:
stty rows 41 cols 190
Alternatively, you can use a script to dynamically fix this. I have fixtty.sh:
#!/bin/sh # # fixtty.sh # Fixes the terminal size of a serial terminal # Arguments: # -v Enable verbose mode if [ "$1" = "-v" ] ; then VERBOSE=1 else VERBOSE=0 fi if [ "$TERM" = "vt220" ] ; then echo Suggestion: set TERM to something more useful like linux, xterm, xterm-256color, etc fi old=$(stty -g) if [ $VERBOSE -eq 1 ] ; then echo "Old TTY settings: '$old'" fi stty raw -echo min 0 time 5 if [ -f /dev/tty ] ; then exit 0 fi printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty IFS='[;R' read -r _ rows cols _ < /dev/tty stty "$old" if [ $VERBOSE -eq 1 ] ; then echo "executing 'stty cols '$cols' rows '$rows'" fi stty cols "$cols" rows "$rows" exit $?