parent
478cf4995a
commit
12c11a1232
7 changed files with 180 additions and 69 deletions
@ -1,7 +1,5 @@ |
||||
|
||||
int init_terminal_ncurses(int col, int bgcol); |
||||
int get_terminal_height_ncurses(void); |
||||
int get_terminal_width_ncurses(void); |
||||
void get_terminal_dim_ncurses(int *w, int *h); |
||||
int draw_terminal_ncurses(int virt, int height, int width, int bands, int bw, int rest, int f[200], int flastd[200]); |
||||
void cleanup_terminal_ncurses(void); |
||||
|
||||
@ -0,0 +1,142 @@ |
||||
#include <locale.h> |
||||
#include <wchar.h> |
||||
#include <stdio.h> |
||||
#include <termios.h> |
||||
#include <unistd.h> |
||||
|
||||
int setecho(int fd, int onoff) { |
||||
|
||||
struct termios t; |
||||
|
||||
if (tcgetattr(fd, &t) == -1) |
||||
return -1; |
||||
|
||||
if (onoff == 0) |
||||
t.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); |
||||
else |
||||
t.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL); |
||||
|
||||
if (tcsetattr(fd, TCSANOW, &t) == -1) |
||||
return -1; |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
int init_terminal_noncurses(int col, int bgcol, int w, int h) { |
||||
|
||||
int n, i; |
||||
|
||||
col += 30; |
||||
bgcol += 40; |
||||
|
||||
system("setterm -cursor off"); |
||||
system("setterm -blank 0"); |
||||
|
||||
|
||||
// output: reset console
|
||||
printf("\033[0m\n"); |
||||
system("clear"); |
||||
|
||||
printf("\033[%dm", col); //setting color
|
||||
|
||||
|
||||
printf("\033[1m"); //setting "bright" color mode, looks cooler... I think
|
||||
|
||||
if (bgcol != 0) |
||||
printf("\033[%dm", bgcol); |
||||
{ |
||||
for (n = (h); n >= 0; n--) { |
||||
for (i = 0; i < w; i++) { |
||||
|
||||
printf(" "); //setting backround color
|
||||
|
||||
} |
||||
printf("\n"); |
||||
} |
||||
printf("\033[%dA", h); //moving cursor back up
|
||||
} |
||||
|
||||
setecho(STDIN_FILENO, 0); |
||||
|
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
||||
void get_terminal_dim_noncurses(int *w, int *h) { |
||||
|
||||
struct winsize dim; |
||||
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim); |
||||
|
||||
*h = (int)dim.ws_row; |
||||
*w = (int)dim.ws_col; |
||||
|
||||
system("clear"); //clearing in case of resieze
|
||||
} |
||||
|
||||
|
||||
int draw_terminal_noncurses(int virt, int h, int w, int bands, int bw, int rest, int f[200], int flastd[200]) { |
||||
int c, move, i, n, o; |
||||
struct winsize dim; |
||||
|
||||
|
||||
// output: check if terminal has been resized
|
||||
if (virt != 0) { |
||||
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim); |
||||
|
||||
if ( (int)dim.ws_row != h || (int)dim.ws_col != w) { |
||||
return -1;
|
||||
}
|
||||
} |
||||
|
||||
for (n = h - 2; n >= 0; n--) { |
||||
|
||||
move = rest; //center adjustment
|
||||
for (o = 0; o < bands; o++) { |
||||
|
||||
// output: draw and move to another one, check whether we're not too far
|
||||
|
||||
if (f[o] != flastd[o]) { //change?
|
||||
if (move != 0)printf("\033[%dC", move); |
||||
move = 0; |
||||
c = f[o] - n * 8; |
||||
|
||||
for (i = 0; i < bw; i++) { |
||||
if (c < 1) { |
||||
printf(" "); //blank
|
||||
} else if (c > 7) { |
||||
if (virt == 0) printf("%d", 8); // block tty
|
||||
else printf("\u2588"); //block
|
||||
} else {
|
||||
if (virt == 0) printf("%d", c); // fractioned block tty
|
||||
else printf("%lc", L'\u2580' + c); // fractioned block vt
|
||||
} |
||||
} |
||||
|
||||
|
||||
} else move += bw; //no change, moving along
|
||||
|
||||
move++;//move to next bar
|
||||
} |
||||
|
||||
printf("\n"); |
||||
|
||||
} |
||||
|
||||
printf("\033[%dA", h); |
||||
return 0; |
||||
} |
||||
|
||||
// general: cleanup
|
||||
void cleanup_terminal_noncurses(void) |
||||
{ |
||||
setecho(STDIN_FILENO, 1); |
||||
printf("\033[0m\n"); |
||||
system("setfont /usr/share/consolefonts/Lat2-Fixed16.psf.gz >/dev/null 2>&1"); |
||||
system("setterm -cursor on"); |
||||
system("setterm -blank 10"); |
||||
system("clear"); |
||||
|
||||
} |
||||
@ -0,0 +1,4 @@ |
||||
int init_terminal_noncurses(int col, int bgcol, int w, int h); |
||||
void get_terminal_dim_noncurses(int *w, int *h); |
||||
int draw_terminal_noncurses(int virt, int height, int width, int bands, int bw, int rest, int f[200], int flastd[200]); |
||||
void cleanup_terminal_noncurses(void); |
||||
@ -1,48 +0,0 @@ |
||||
int draw_terminal_printf(int height, int width, int bars) { |
||||
for (n = (height - 1); n >= 0; n--) { |
||||
o = 0; |
||||
move = rest / 2; //center adjustment
|
||||
for (i = 0; i < width; i++) { |
||||
|
||||
// output: check if we're already at the next bar
|
||||
if (i != 0 && i % bw == 0) { |
||||
o++; |
||||
if (o < bands)move++; |
||||
} |
||||
|
||||
// output: draw and move to another one, check whether we're not too far
|
||||
if (o < bands) { |
||||
if (f[o] - n < 0.125) { //blank
|
||||
if (matrix[i][n] != 0) { //change?
|
||||
if (move != 0)printf("\033[%dC", move); |
||||
move = 0; |
||||
printf(" "); |
||||
} else move++; //no change, moving along
|
||||
matrix[i][n] = 0; |
||||
} else if (f[o] - n > 1) { //color
|
||||
if (matrix[i][n] != 1) { //change?
|
||||
if (move != 0)printf("\033[%dC", move); |
||||
move = 0; |
||||
printf("\u2588"); |
||||
} else move++; //no change, moving along
|
||||
matrix[i][n] = 1; |
||||
} else { //top color, finding fraction
|
||||
if (move != 0)printf("\033[%dC", move); |
||||
move = 0; |
||||
c = ((((f[o] - (float)n) - 0.125) / 0.875 * 7) + 1); |
||||
if (0 < c && c < 8) { |
||||
if (virt == 0)printf("%d", c); |
||||
else printf("%lc", L'\u2580' + c); |
||||
} else printf(" "); |
||||
matrix[i][n] = 2; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
printf("\n"); |
||||
|
||||
} |
||||
|
||||
printf("\033[%dA", height); |
||||
} |
||||
@ -1 +0,0 @@ |
||||
int draw_terminal_printf(int height, int width, int bars); |
||||
Loading…
Reference in new issue