cmatrix icon indicating copy to clipboard operation
cmatrix copied to clipboard

On using `-l`, `setfont` and custom fonts in Ubuntu (and possibly Debian)

Open MestreLion opened this issue 3 years ago • 1 comments

I'm using the 1.2a cmatrix on Ubuntu 18.04. I'm aware this is an old version, but upon inspecting both current git code and Debian and Ubuntu most recent packages I believe the scenario is the same:

  • When using cmatrix -l, it runs setfont matrix. This leads to loading /usr/share/consolefonts/matrix.fnt. The FNT font is an improvement over the default font, but the best result is using setfont matrix.psf by hand before cmatrix -l, as /usr/share/consolefonts/matrix.psf.gz comes with the Unicode mapping. The PSF version really makes almost all characters Japanese, it's a much much better experience!

  • When exiting, cmatrix -l runs setfont with no parameters, as an attempt to restore the default TTY font. But... Ubuntu (and possibly Debian) has no default font, at least in the way setfont expects. It prints Cannot find default font and leaves the TTY with the matrix font.

    • This is not a cmatrix issue per-se, as (I guess) Ubuntu/Debian are supposed to have a /usr/share/consolefonts/default font/symlink. Creating such symlink with sudo ln -s Lat15-Fixed16.psf.gz /usr/share/consolefonts/default works, but this makes an assumption about the system's actual default font.
    • Instead of guessing and resetting to a default font, would be much better if cmatrix simply restored to previous one. It would work even if user has changed his default font in ~/.bashrc or similar. setfont has no way to know/tell the current font in use, but it can save it (and its mapping) to a file with -O!
    • So IMHO the best solution is to save the current font to a temp file, load the matrix one, then restore the temp file. I've tested this using a shell wrapper and it works perfectly:
matrix() {
	if ! [[ "$TERM" == "linux" ]]; then
		cmatrix -sbu8
		return
	fi
	local default=$(mktemp) && trap 'rm -f -- "$default"' RETURN
	setfont -O "$default" matrix.psf  # Backup current font, set matrix PSF font
	cmatrix -sblu8 2>/dev/null  # silence "Cannot find default font". Or just replace -l with -x
	setfont "$default"
}

Maybe the same strategy could be done by cmatrix itself?

MestreLion avatar Apr 03 '21 21:04 MestreLion

Also, it would be great if cmake or its README could provide some instructions on how to use the X11 font mtx.pcf.gz on xterm or gnome-terminal. By default Ubuntu/Debian disables bitmaps fonts under X11, so it would be great to have the steps to enable its use.

MestreLion avatar Apr 03 '21 22:04 MestreLion