More robust "are we running in a TTY" check

Previously the return value of the setfont program was used, which sets
the font used in a Linux console.  In a PTY (e.g. terminal emulator), it
generally fails, but who knows, it might not.

This commit makes the check a little closer to the source of the
information, by checking what device stdin is connected to: is it one of
/dev/tty* or something else?  If it's /dev/tty*, we're in a console and
deploy the font hack.

May help with karlstav/cava#68.
master
An Ko 11 years ago
parent 9712160d1d
commit 185bfa0b57
  1. 12
      cava.c

@ -552,10 +552,14 @@ Options:\n\
pr = fftw_plan_dft_r2c_1d(M, inr, *outr, FFTW_MEASURE);
}
virt = system("setfont cava.psf >/dev/null 2>&1");
if (virt == 0) system("setterm -blank 0");
// Check if we're running in a console
virt = strncmp(ttyname(0), "/dev/tty", 8);
if (virt == 0) {
system("setfont cava.psf >/dev/null 2>&1");
system("echo yep > /tmp/testing123");
system("setterm -blank 0");
}
//output: start ncurses mode
if (om == 1 || om == 2) {

Loading…
Cancel
Save