From 0360e8872e405ca1bbd09d290e9e1b87b4be60e4 Mon Sep 17 00:00:00 2001 From: karlstav Date: Fri, 9 Sep 2016 17:09:55 +0200 Subject: [PATCH] removed check if in tty if ouput is raw ti fix #110 --- cava.c | 35 +++++++++++++++++++---------------- output/terminal_bcircle.c | 4 ++-- output/terminal_ncurses.c | 10 +++++----- output/terminal_noncurses.c | 8 ++++---- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cava.c b/cava.c index 396eb42..4f75dc7 100644 --- a/cava.c +++ b/cava.c @@ -559,7 +559,7 @@ int main(int argc, char **argv) int flast[200]; int flastd[200]; int sleep = 0; - int i, n, o, height, h, w, c, rest, inAVirtualConsole, silence, fp, fptest; + int i, n, o, height, h, w, c, rest, inAtty, silence, fp, fptest; float temp; double inr[2 * (M / 2 + 1)]; fftw_complex outr[M / 2 + 1][2]; @@ -625,15 +625,7 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co n = 0; } - // Check if we're running in a Virtual console todo: replace virtual console with terminal emulator - inAVirtualConsole = 1; - if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAVirtualConsole = 0; - - if (!inAVirtualConsole) { - system("setfont cava.psf >/dev/null 2>&1"); - system("echo yep > /tmp/testing123"); - system("setterm -blank 0"); - } + @@ -645,6 +637,19 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co validate_config(); + if (om != 4) { + // Check if we're running in a Virtual console todo: replace virtual console with terminal emulator + inAtty = 0; + if (strncmp(ttyname(0), "/dev/tty", 8) == 0 || strcmp(ttyname(0), "/dev/console") == 0) inAtty = 1; + + if (inAtty) { + system("setfont cava.psf >/dev/null 2>&1"); + system("echo yep > /tmp/testing123"); + system("setterm -blank 0"); + } + } + + //input: init audio.format = -1; audio.rate = 0; @@ -740,10 +745,8 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co //output: start ncurses mode if (om == 1 || om == 2) { init_terminal_ncurses(col, bgcol); + get_terminal_dim_ncurses(&w, &h); } - - // output: get terminal's geometry - if (om == 1 || om == 2) get_terminal_dim_ncurses(&w, &h); #endif if (om == 3) get_terminal_dim_noncurses(&w, &h); @@ -1065,16 +1068,16 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co switch (om) { case 1: #ifdef NCURSES - rc = draw_terminal_ncurses(inAVirtualConsole, h, w, bars, bw, bs, rest, f, flastd); + rc = draw_terminal_ncurses(inAtty, h, w, bars, bw, bs, rest, f, flastd); break; #endif case 2: #ifdef NCURSES - rc = draw_terminal_bcircle(inAVirtualConsole, h, w, f); + rc = draw_terminal_bcircle(inAtty, h, w, f); break; #endif case 3: - rc = draw_terminal_noncurses(inAVirtualConsole, h, w, bars, bw, bs, rest, f, flastd); + rc = draw_terminal_noncurses(inAtty, h, w, bars, bw, bs, rest, f, flastd); break; case 4: rc = print_raw_out(bars, fp, is_bin, bit_format, ascii_range, bar_delim, frame_delim,f); diff --git a/output/terminal_bcircle.c b/output/terminal_bcircle.c index 9de6764..f2cb2ff 100644 --- a/output/terminal_bcircle.c +++ b/output/terminal_bcircle.c @@ -36,12 +36,12 @@ void get_terminal_dim_bcircle(int *w, int *h) { } -int draw_terminal_bcircle(int virt, int h, int w, int f[200]) { +int draw_terminal_bcircle(int tty, int h, int w, int f[200]) { const wchar_t* bars[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"}; // output: check if terminal has been resized - if (virt != 0) { + if (!tty) { if ( LINES != h || COLS != w) { return -1; } diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c index 8f1d5bd..cb38c0e 100644 --- a/output/terminal_ncurses.c +++ b/output/terminal_ncurses.c @@ -30,13 +30,13 @@ void get_terminal_dim_ncurses(int *w, int *h) { } -int draw_terminal_ncurses(int virt, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) { +int draw_terminal_ncurses(int tty, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) { int i, n, q; const wchar_t* bh[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584", L"\u2585", L"\u2586", L"\u2587", L"\u2588"}; // output: check if terminal has been resized - if (virt != 0) { + if (!tty) { if ( LINES != h || COLS != w) { return -1; } @@ -47,16 +47,16 @@ int draw_terminal_ncurses(int virt, int h, int w, int bars, int bw, int bs, int for (i = 0; i < bars; i++) { if(f[i] > flastd[i]){//higher then last one - if (virt == 0) for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvprintw((h - n), i*bw + q + i*bs + rest, "%d",8); + if (tty) for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvprintw((h - n), i*bw + q + i*bs + rest, "%d",8); else for (n = flastd[i] / 8; n < f[i] / 8; n++) for (q = 0; q < bw; q++) mvaddwstr((h - n), i*bw + q + i*bs + rest, bh[7]); if (f[i] % 8 != 0) { - if (virt == 0) for (q = 0; q < bw; q++) mvprintw( (h - n), i*bw + q + i*bs + rest, "%d",(f[i] % 8) ); + if (tty) for (q = 0; q < bw; q++) mvprintw( (h - n), i*bw + q + i*bs + rest, "%d",(f[i] % 8) ); else for (q = 0; q < bw; q++) mvaddwstr( (h - n), i*bw + q + i*bs + rest, bh[(f[i] % 8) - 1]); } }else if(f[i] < flastd[i]){//lower then last one for (n = f[i] / 8; n < flastd[i]/8 + 1; n++) for (q = 0; q < bw; q++) mvaddstr( (h - n), i*bw + q + i*bs + rest, " "); if (f[i] % 8 != 0) { - if (virt == 0) for (q = 0; q < bw; q++) mvprintw((h - f[i] / 8), i*bw + q + i*bs + rest, "%d",(f[i] % 8) ); + if (tty) for (q = 0; q < bw; q++) mvprintw((h - f[i] / 8), i*bw + q + i*bs + rest, "%d",(f[i] % 8) ); else for (q = 0; q < bw; q++) mvaddwstr((h - f[i] / 8), i*bw + q + i*bs + rest, bh[(f[i] % 8) - 1]); } } diff --git a/output/terminal_noncurses.c b/output/terminal_noncurses.c index 730592f..e571e84 100644 --- a/output/terminal_noncurses.c +++ b/output/terminal_noncurses.c @@ -105,14 +105,14 @@ void get_terminal_dim_noncurses(int *w, int *h) { } -int draw_terminal_noncurses(int virt, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) { +int draw_terminal_noncurses(int tty, int h, int w, int bars, int bw, int bs, int rest, int f[200], int flastd[200]) { int c, move, n, o; struct winsize dim; // output: check if terminal has been resized - if (virt != 0) { + if (!tty) { ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim); @@ -142,11 +142,11 @@ int draw_terminal_noncurses(int virt, int h, int w, int bars, int bw, int bs, in else move += bw; } else if (c > 7) { if (n > flastd[o] / 8 - 1) { - if (virt == 0) printf("%d", ttybarstring[7]); // block tty + if (tty) printf("%d", ttybarstring[7]); // block tty else printf("%ls", barstring[0]); //block } else move += bw; } else { - if (virt == 0) printf("%d", ttybarstring[c - 1]); // fractioned block tty + if (tty) printf("%d", ttybarstring[c - 1]); // fractioned block tty else printf("%ls", barstring[c] ); // fractioned block vt }