Intro
My server is sometimes plugged into my TV as a display. I almost always use it over SSH, but I thought it would be cool if it also could display status info on the TV.
btopis a great tool for displaying system diagnostics- But it looks terrible without 256-color support
- Which is provided by terminal emulators in the X server, but not by the TTY
- And also my TV is 4K, so the TTY text is unreadable
So we need a way to get 256-color and vector font support in TTY without installing graphical packages.
Solution
fbterm enables frame-buffer terminal emulation. It supports TTF, so I can run fbterm -s 40 to display the font in a larger size.
colortest is a package that makes it easy to check colors. I was also testing commands like btop and neofetch to roughly check color support. colortest is a better way to be sure. Run colortest-256 to check for 256-color support
fc-list displays installed fonts, so fc-list | grep -i mono shows all the installed monospace fonts. Not all of these seem to work as inputs to fbterm, but I want to check on that later. This is interesting, though, because if they did work consistently, we could possibly install powerline/nerd fonts to add support for decorative characters.
The following is a procedure to open a working terminal with full support. We have to use tmux, the terminal multiplexer, because the TTY won’t support colors without both fbterm and tmux both. The tmux shell will have color support.
fbterm -s 30
export TERM=fbterm
tmux
After launching fbterm, the variable $TERM is still linux, which has 8-color support. Setting TERM ups the color support to 256, but when rendering the special color characters, the TTY text encoding seems to go wild. I suspect that tmux has better Unicode support, and handles these color characters correctly.
We can reduce this to one line like so:
exec fbterm -s 35 -- bash -c 'TERM=fbterm tmux'
fbterm reads commands from STDIN, causing it to launch tmux with the correct
TERM variable. This won’t quite work simply as a launch script, however.
Here’s what I added to .bashrc:
if [ -z "$FBTERM" ] && [ "$(tty)" = "/dev/tty1" ]; then
exec fbterm -s 35 -- bash -c 'export TERM=fbterm && tmux new-session -d "btop; exec bash" && tmux attach'
fi
We have to explicitly create the new tmux session so that it’s a separate process. Otherwise, btop gets bundled in with the parent process so that when btop exits, it closes tmux and lands in fbterm. The key here is ;exec bash, which keeps the tmux session alive.
Auto-login
Run this to edit the TTY configuration:
systemctl edit getty@tty1
Add these lines to the file that is opened, which will override the default settings for the getty process:
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin username %I 38400
So after a couple hours of fiddling, the server boots up with btop running in
full color on tty1, with access to other TTYs as usual, and it does not
auto-login on SSH. It’s pretty neat! Now, I can just switch my TV source to the
server to display a live diagnostics dashboard. With tmux, I could create a
multiplex with another CLI dashboard to display both side-by-side, as well.