From 185bfa0b57c9937c5fd2c901c950c95a03e42a67 Mon Sep 17 00:00:00 2001 From: An Ko Date: Sun, 6 Sep 2015 19:39:32 +0200 Subject: [PATCH] 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. --- cava.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cava.c b/cava.c index 62af974..013204b 100644 --- a/cava.c +++ b/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) {