summaryrefslogtreecommitdiff
path: root/output
diff options
context:
space:
mode:
authorLasse Flygenring-Harrsen <Lasse@Flygenring-Harrsen.com>2020-07-09 00:42:03 +0200
committerLasse Flygenring-Harrsen <Lasse@Flygenring-Harrsen.com>2020-07-09 00:42:03 +0200
commit6d2fa862858dafdea29fc2e4a3dc39c3dbb17f2e (patch)
treeb03c3dc5c5c08129ed7f0642dd3e64d75aa866e0 /output
Import Upstream version 0.7.1
Diffstat (limited to 'output')
-rw-r--r--output/raw.c48
-rw-r--r--output/raw.h2
-rw-r--r--output/terminal_bcircle.c85
-rw-r--r--output/terminal_bcircle.h6
-rw-r--r--output/terminal_ncurses.c280
-rw-r--r--output/terminal_ncurses.h8
-rw-r--r--output/terminal_noncurses.c287
-rw-r--r--output/terminal_noncurses.h5
8 files changed, 721 insertions, 0 deletions
diff --git a/output/raw.c b/output/raw.c
new file mode 100644
index 0000000..eaef8ee
--- /dev/null
+++ b/output/raw.c
@@ -0,0 +1,48 @@
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int16_t buf_16;
+int8_t buf_8;
+
+int print_raw_out(int bars_count, int fd, int is_binary, int bit_format, int ascii_range,
+ char bar_delim, char frame_delim, int const f[200]) {
+ if (is_binary) {
+ for (int i = 0; i < bars_count; i++) {
+ int f_limited = f[i];
+ if (f_limited > (pow(2, bit_format) - 1))
+ f_limited = pow(2, bit_format) - 1;
+
+ switch (bit_format) {
+ case 16:
+ buf_16 = f_limited;
+ write(fd, &buf_16, sizeof(int16_t));
+ break;
+ case 8:
+ buf_8 = f_limited;
+ write(fd, &buf_8, sizeof(int8_t));
+ break;
+ }
+ }
+ } else { // ascii
+ for (int i = 0; i < bars_count; i++) {
+ int f_ranged = f[i];
+ if (f_ranged > ascii_range)
+ f_ranged = ascii_range;
+
+ // finding size of number-string in byte
+ int bar_height_size = 2; // a number + \0
+ if (f_ranged != 0)
+ bar_height_size += floor(log10(f_ranged));
+
+ char bar_height[bar_height_size];
+ snprintf(bar_height, bar_height_size, "%d", f_ranged);
+
+ write(fd, bar_height, bar_height_size - 1);
+ write(fd, &bar_delim, sizeof(bar_delim));
+ }
+ write(fd, &frame_delim, sizeof(frame_delim));
+ }
+ return 0;
+}
diff --git a/output/raw.h b/output/raw.h
new file mode 100644
index 0000000..f2f50cf
--- /dev/null
+++ b/output/raw.h
@@ -0,0 +1,2 @@
+int print_raw_out(int bars_count, int fd, int is_binary, int bit_format, int ascii_range,
+ char bar_delim, char frame_delim, int const f[200]);
diff --git a/output/terminal_bcircle.c b/output/terminal_bcircle.c
new file mode 100644
index 0000000..90363cb
--- /dev/null
+++ b/output/terminal_bcircle.c
@@ -0,0 +1,85 @@
+#include "output/terminal_bcircle.h"
+
+#include <curses.h>
+#include <locale.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+#ifndef M_PI
+#define M_PI 3.141592
+#endif
+#define DEGTORAD(deg) (deg * (180.0f / M_PI))
+#define DOT 0x2588
+
+int init_terminal_bcircle(int col, int bgcol) {
+
+ initscr();
+ curs_set(0);
+ timeout(0);
+ noecho();
+ start_color();
+ use_default_colors();
+ init_pair(1, col, bgcol);
+ if (bgcol != -1)
+ bkgd(COLOR_PAIR(1));
+ attron(COLOR_PAIR(1));
+ // attron(A_BOLD);
+ return 0;
+}
+
+void get_terminal_dim_bcircle(int *w, int *h) {
+
+ getmaxyx(stdscr, *h, *w);
+ clear(); // clearing in case of resieze
+}
+
+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 (!tty) {
+ if (LINES != h || COLS != w) {
+ return -1;
+ }
+ }
+
+ float deg, width, height;
+ int y, x;
+
+ /* Convert to int */
+ width = f[1] / 10;
+ height = f[1] / 15;
+
+ int oy, ox;
+ oy = LINES / 2 - height / 2;
+ ox = COLS / 2 - width / 2;
+ for (x = 0; x < COLS; x++) {
+ for (y = 0; y < LINES; y++) {
+ mvaddstr(y, x, " ");
+ }
+ }
+ /* Draw circle */
+ for (deg = 0; deg < 360.0f; deg += 1.0f) {
+ x = ox + width + (int)(width * cos(DEGTORAD(deg)));
+ y = oy + height + (int)(height * sin(DEGTORAD(deg)));
+
+ mvaddwstr(y, x, bars[7]);
+ }
+
+ refresh();
+ return 0;
+}
+
+// general: cleanup
+void cleanup_terminal_bcircle(void) {
+ echo();
+ system("setfont >/dev/null 2>&1");
+ system("setfont /usr/share/consolefonts/Lat2-Fixed16.psf.gz >/dev/null 2>&1");
+ system("setterm -blank 10");
+ endwin();
+ system("clear");
+}
diff --git a/output/terminal_bcircle.h b/output/terminal_bcircle.h
new file mode 100644
index 0000000..87bbe0f
--- /dev/null
+++ b/output/terminal_bcircle.h
@@ -0,0 +1,6 @@
+#pragma once
+
+int init_terminal_bcircle(int col, int bgcol);
+void get_terminal_dim_bcircle(int *w, int *h);
+int draw_terminal_bcircle(int virt, int height, int width, int f[200]);
+void cleanup_terminal_bcircle(void);
diff --git a/output/terminal_ncurses.c b/output/terminal_ncurses.c
new file mode 100644
index 0000000..061a507
--- /dev/null
+++ b/output/terminal_ncurses.c
@@ -0,0 +1,280 @@
+#include "output/terminal_ncurses.h"
+
+#include <curses.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "util.h"
+
+int gradient_size = 64;
+
+struct colors {
+ NCURSES_COLOR_T color;
+ NCURSES_COLOR_T R;
+ NCURSES_COLOR_T G;
+ NCURSES_COLOR_T B;
+};
+
+#define COLOR_REDEFINITION -2
+
+#define MAX_COLOR_REDEFINITION 256
+
+// static struct colors the_color_redefinitions[MAX_COLOR_REDEFINITION];
+
+static void parse_color(char *color_string, struct colors *color) {
+ if (color_string[0] == '#') {
+ if (!can_change_color()) {
+ cleanup_terminal_ncurses();
+ fprintf(stderr, "Your terminal can not change color definitions, "
+ "please use one of the predefined colors.\n");
+ exit(EXIT_FAILURE);
+ }
+ color->color = COLOR_REDEFINITION;
+ sscanf(++color_string, "%02hx%02hx%02hx", &color->R, &color->G, &color->B);
+ }
+}
+/*
+static void remember_color_definition(NCURSES_COLOR_T color_number) {
+ int index = color_number - 1; // array starts from zero and colors - not
+ if(the_color_redefinitions[index].color == 0) {
+ the_color_redefinitions[index].color = color_number;
+ color_content(color_number,
+ &the_color_redefinitions[index].R,
+ &the_color_redefinitions[index].G,
+ &the_color_redefinitions[index].B);
+ }
+}
+*/
+// ncurses use color range [0, 1000], and we - [0, 255]
+#define CURSES_COLOR_COEFFICIENT(X) ((X)*1000.0 / 0xFF + 0.5)
+#define COLORS_STRUCT_NORMALIZE(X) \
+ CURSES_COLOR_COEFFICIENT(X.R), CURSES_COLOR_COEFFICIENT(X.G), CURSES_COLOR_COEFFICIENT(X.B)
+
+static NCURSES_COLOR_T change_color_definition(NCURSES_COLOR_T color_number,
+ char *const color_string,
+ NCURSES_COLOR_T predef_color) {
+ struct colors color = {0};
+ parse_color(color_string, &color);
+ NCURSES_COLOR_T return_color_number = predef_color;
+ if (color.color == COLOR_REDEFINITION) {
+ // remember_color_definition(color_number);
+ init_color(color_number, COLORS_STRUCT_NORMALIZE(color));
+ return_color_number = color_number;
+ }
+ return return_color_number;
+}
+
+void init_terminal_ncurses(char *const fg_color_string, char *const bg_color_string,
+ int predef_fg_color, int predef_bg_color, int gradient,
+ int gradient_count, char **gradient_colors, int *width, int *lines) {
+ initscr();
+ curs_set(0);
+ timeout(0);
+ noecho();
+ start_color();
+ use_default_colors();
+
+ getmaxyx(stdscr, *lines, *width);
+ clear();
+
+ NCURSES_COLOR_T color_pair_number = 16;
+
+ NCURSES_COLOR_T bg_color_number;
+ bg_color_number = change_color_definition(0, bg_color_string, predef_bg_color);
+
+ if (!gradient) {
+
+ NCURSES_COLOR_T fg_color_number;
+ fg_color_number = change_color_definition(1, fg_color_string, predef_fg_color);
+
+ init_pair(color_pair_number, fg_color_number, bg_color_number);
+
+ } else if (gradient) {
+
+ // 0 -> col1, 1-> col1<=>col2, 2 -> col2 and so on
+ short unsigned int rgb[2 * gradient_count - 1][3];
+ char next_color[14];
+
+ gradient_size = *lines;
+
+ if (gradient_size > COLORS)
+ gradient_size = COLORS - 1;
+
+ if (gradient_size > COLOR_PAIRS)
+ gradient_size = COLOR_PAIRS - 1;
+
+ if (gradient_size > MAX_COLOR_REDEFINITION)
+ gradient_size = MAX_COLOR_REDEFINITION - 1;
+
+ for (int i = 0; i < gradient_count; i++) {
+ int col = (i + 1) * 2 - 2;
+ sscanf(gradient_colors[i] + 1, "%02hx%02hx%02hx", &rgb[col][0], &rgb[col][1],
+ &rgb[col][2]);
+ }
+
+ // sscanf(gradient_color_1 + 1, "%02hx%02hx%02hx", &rgb[0][0], &rgb[0][1], &rgb[0][2]);
+ // sscanf(gradient_color_2 + 1, "%02hx%02hx%02hx", &rgb[1][0], &rgb[1][1], &rgb[1][2]);
+
+ int individual_size = gradient_size / (gradient_count - 1);
+
+ for (int i = 0; i < gradient_count - 1; i++) {
+
+ int col = (i + 1) * 2 - 2;
+ if (i == gradient_count - 1)
+ col = 2 * (gradient_count - 1) - 2;
+
+ for (int j = 0; j < individual_size; j++) {
+
+ for (int k = 0; k < 3; k++) {
+ rgb[col + 1][k] = rgb[col][k] + (rgb[col + 2][k] - rgb[col][k]) *
+ (j / (individual_size * 0.85));
+ if (rgb[col + 1][k] > 255)
+ rgb[col][k] = 0;
+ if (j > individual_size * 0.85)
+ rgb[col + 1][k] = rgb[col + 2][k];
+ }
+
+ sprintf(next_color, "#%02x%02x%02x", rgb[col + 1][0], rgb[col + 1][1],
+ rgb[col + 1][2]);
+
+ change_color_definition(color_pair_number, next_color, color_pair_number);
+ init_pair(color_pair_number, color_pair_number, bg_color_number);
+ color_pair_number++;
+ }
+ }
+
+ int left = individual_size * (gradient_count - 1);
+ int col = 2 * (gradient_count)-2;
+ while (left < gradient_size) {
+ sprintf(next_color, "#%02x%02x%02x", rgb[col][0], rgb[col][1], rgb[col][2]);
+ change_color_definition(color_pair_number, next_color, color_pair_number);
+ init_pair(color_pair_number, color_pair_number, bg_color_number);
+ color_pair_number++;
+ left++;
+ }
+ color_pair_number--;
+ }
+
+ attron(COLOR_PAIR(color_pair_number));
+
+ if (bg_color_number != -1)
+ bkgd(COLOR_PAIR(color_pair_number));
+
+ for (int y = 0; y < *lines; y++) {
+ for (int x = 0; x < *width; x++) {
+ mvaddch(y, x, ' ');
+ }
+ }
+ refresh();
+}
+
+void change_colors(int cur_height, int tot_height) {
+ tot_height /= gradient_size;
+ if (tot_height < 1)
+ tot_height = 1;
+ cur_height /= tot_height;
+ if (cur_height > gradient_size - 1)
+ cur_height = gradient_size - 1;
+ attron(COLOR_PAIR(cur_height + 16));
+}
+
+void get_terminal_dim_ncurses(int *width, int *height) {
+ getmaxyx(stdscr, *height, *width);
+ gradient_size = *height;
+ clear(); // clearing in case of resieze
+}
+
+#define TERMINAL_RESIZED -1
+
+int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width, int bars_count,
+ int bar_width, int bar_spacing, int rest, const int f[200],
+ int flastd[200], int gradient) {
+ const int height = terminal_height - 1;
+ const wchar_t *bar_heights[] = {L"\u2581", L"\u2582", L"\u2583", L"\u2584",
+ L"\u2585", L"\u2586", L"\u2587", L"\u2588"};
+ int num_bar_heights = (sizeof(bar_heights) / sizeof(bar_heights[0]));
+
+ // output: check if terminal has been resized
+ if (!is_tty) {
+ if (LINES != terminal_height || COLS != terminal_width) {
+ return TERMINAL_RESIZED;
+ }
+ }
+
+ // Compute how much of the screen we possibly need to update ahead-of-time.
+ int max_update_y = 0;
+ for (int bar = 0; bar < bars_count; bar++) {
+ max_update_y = max(max_update_y, max(f[bar], flastd[bar]));
+ }
+
+ max_update_y = (max_update_y + num_bar_heights) / num_bar_heights;
+
+ for (int y = 0; y < max_update_y; y++) {
+ if (gradient) {
+ change_colors(y, height);
+ }
+
+ for (int bar = 0; bar < bars_count; bar++) {
+ if (f[bar] == flastd[bar]) {
+ continue;
+ }
+
+ int cur_col = bar * bar_width + bar * bar_spacing + rest;
+ int f_cell = (f[bar] - 1) / num_bar_heights;
+ int f_last_cell = (flastd[bar] - 1) / num_bar_heights;
+
+ if (f_cell >= y) {
+ int bar_step;
+
+ if (f_cell == y) {
+ // The "cap" of the bar occurs at this [y].
+ bar_step = (f[bar] - 1) % num_bar_heights;
+ } else if (f_last_cell <= y) {
+ // The bar is full at this [y].
+ bar_step = num_bar_heights - 1;
+ } else {
+ // No update necessary since last frame.
+ continue;
+ }
+
+ for (int col = cur_col, i = 0; i < bar_width; i++, col++) {
+ if (is_tty) {
+ mvaddch(height - y, col, '1' + bar_step);
+ } else {
+ mvaddwstr(height - y, col, bar_heights[bar_step]);
+ }
+ }
+ } else if (f_last_cell >= y) {
+ // This bar was taller during the last frame than during this frame, so
+ // clear the excess characters.
+ for (int col = cur_col, i = 0; i < bar_width; i++, col++) {
+ mvaddch(height - y, col, ' ');
+ }
+ }
+ }
+ }
+
+ refresh();
+ return 0;
+}
+
+// general: cleanup
+void cleanup_terminal_ncurses(void) {
+ echo();
+ system("setfont >/dev/null 2>&1");
+ system("setfont /usr/share/consolefonts/Lat2-Fixed16.psf.gz >/dev/null 2>&1");
+ system("setterm -blank 10 >/dev/null 2>&1");
+ /*for(int i = 0; i < gradient_size; ++i) {
+ if(the_color_redefinitions[i].color) {
+ init_color(the_color_redefinitions[i].color,
+ the_color_redefinitions[i].R,
+ the_color_redefinitions[i].G,
+ the_color_redefinitions[i].B);
+ }
+ }
+*/
+ standend();
+ endwin();
+ system("clear");
+}
diff --git a/output/terminal_ncurses.h b/output/terminal_ncurses.h
new file mode 100644
index 0000000..5c36fb2
--- /dev/null
+++ b/output/terminal_ncurses.h
@@ -0,0 +1,8 @@
+void init_terminal_ncurses(char *const fg_color_string, char *const bg_color_string,
+ int predef_fg_color, int predef_bg_color, int gradient,
+ int gradient_count, char **gradient_colors, int *width, int *height);
+void get_terminal_dim_ncurses(int *width, int *height);
+int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width, int bars_count,
+ int bar_width, int bar_spacing, int rest, const int f[200],
+ int flastd[200], int gradient);
+void cleanup_terminal_ncurses(void);
diff --git a/output/terminal_noncurses.c b/output/terminal_noncurses.c
new file mode 100644
index 0000000..6789f30
--- /dev/null
+++ b/output/terminal_noncurses.c
@@ -0,0 +1,287 @@
+#include <locale.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <unistd.h>
+#include <wchar.h>
+
+wchar_t *frame_buffer;
+wchar_t *barstring[8];
+wchar_t *spacestring;
+int buf_length;
+char *ttyframe_buffer;
+char *ttybarstring[8];
+char *ttyspacestring;
+int ttybuf_length;
+
+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 tty, int col, int bgcol, int width, int lines, int bar_width) {
+
+ if (tty) {
+
+ ttybuf_length = sizeof(char) * width * lines * 10;
+ ttyframe_buffer = (char *)malloc(ttybuf_length);
+ ttyspacestring = (char *)malloc(sizeof(char) * bar_width);
+
+ // clearing barstrings
+ for (int n = 0; n < 8; n++) {
+ ttybarstring[n] = (char *)malloc(sizeof(char) * bar_width);
+ ttybarstring[n][0] = '\0';
+ }
+ ttyspacestring[0] = '\0';
+ ttyframe_buffer[0] = '\0';
+
+ // creating barstrings for drawing
+ for (int n = 0; n < bar_width; n++) {
+ strcat(ttybarstring[0], "8");
+ strcat(ttybarstring[1], "1");
+ strcat(ttybarstring[2], "2");
+ strcat(ttybarstring[3], "3");
+ strcat(ttybarstring[4], "4");
+ strcat(ttybarstring[5], "5");
+ strcat(ttybarstring[6], "6");
+ strcat(ttybarstring[7], "7");
+ strcat(ttyspacestring, " ");
+ }
+ } else if (!tty) {
+
+ buf_length = sizeof(wchar_t) * width * lines * 10;
+ frame_buffer = (wchar_t *)malloc(buf_length);
+ spacestring = (wchar_t *)malloc(sizeof(wchar_t) * bar_width);
+
+ // clearing barstrings
+ for (int n = 0; n < 8; n++) {
+ barstring[n] = (wchar_t *)malloc(sizeof(wchar_t) * bar_width);
+ barstring[n][0] = '\0';
+ }
+ spacestring[0] = '\0';
+ frame_buffer[0] = '\0';
+
+ // creating barstrings for drawing
+ for (int n = 0; n < bar_width; n++) {
+ wcscat(barstring[0], L"\u2588");
+ wcscat(barstring[1], L"\u2581");
+ wcscat(barstring[2], L"\u2582");
+ wcscat(barstring[3], L"\u2583");
+ wcscat(barstring[4], L"\u2584");
+ wcscat(barstring[5], L"\u2585");
+ wcscat(barstring[6], L"\u2586");
+ wcscat(barstring[7], L"\u2587");
+ wcscat(spacestring, L" ");
+ }
+ }
+
+ col += 30;
+
+ system("setterm -cursor off");
+ system("setterm -blank 0");
+
+ // output: reset console
+ printf("\033[0m\n");
+ system("clear");
+
+ if (col)
+ printf("\033[%dm", col); // setting color
+
+ // printf("\033[1m"); // setting "bright" color mode, looks cooler... I think
+
+ if (bgcol != 0) {
+
+ bgcol += 40;
+ printf("\033[%dm", bgcol);
+
+ for (int n = (lines); n >= 0; n--) {
+ for (int i = 0; i < width; i++) {
+
+ printf(" "); // setting backround color
+ }
+ printf("\n");
+ }
+ printf("\033[%dA", lines); // moving cursor back up
+ }
+
+ setecho(STDIN_FILENO, 0);
+
+ return 0;
+}
+
+void get_terminal_dim_noncurses(int *width, int *lines) {
+
+ struct winsize dim;
+
+ ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim);
+
+ *lines = (int)dim.ws_row;
+ *width = (int)dim.ws_col;
+
+ system("clear"); // clearing in case of resieze
+}
+
+int draw_terminal_noncurses(int tty, int lines, int width, int number_of_bars, int bar_width,
+ int bar_spacing, int rest, int bars[200], int previous_frame[200]) {
+
+ int current_cell, prev_cell, same_line, new_line, cx;
+
+ struct winsize dim;
+
+ same_line = 0;
+ new_line = 0;
+ cx = 0;
+ if (!tty) {
+
+ // output: check if terminal has been resized
+ ioctl(STDOUT_FILENO, TIOCGWINSZ, &dim);
+
+ if ((int)dim.ws_row != lines || (int)dim.ws_col != width) {
+ free(frame_buffer);
+ free(spacestring);
+ for (int i = 0; i < 8; i++)
+ free(barstring[i]);
+
+ return -1;
+ }
+ }
+ if (tty)
+ ttyframe_buffer[0] = '\0';
+ else if (!tty)
+ frame_buffer[0] = '\0';
+
+ for (int current_line = lines - 1; current_line >= 0; current_line--) {
+
+ int same_bar = 0;
+ int center_adjusted = 0;
+
+ for (int i = 0; i < number_of_bars; i++) {
+
+ current_cell = bars[i] - current_line * 8;
+ prev_cell = previous_frame[i] - current_line * 8;
+
+ // same as last frame
+ if ((current_cell < 1 && prev_cell < 1) || (current_cell > 7 && prev_cell > 7) ||
+ (current_cell == prev_cell)) {
+ same_bar++;
+ } else {
+ if (tty) {
+ if (same_line > 0) {
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "\033[%dB",
+ same_line); // move down
+ new_line += same_line;
+ same_line = 0;
+ }
+
+ if (same_bar > 0) {
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "\033[%dC",
+ (bar_width + bar_spacing) * same_bar); // move forward
+ same_bar = 0;
+ }
+
+ if (!center_adjusted) {
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "\033[%dC", rest);
+ center_adjusted = 1;
+ }
+
+ if (current_cell < 1)
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "%s",
+ ttyspacestring);
+ else if (current_cell > 7)
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "%s",
+ ttybarstring[0]);
+ else
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "%s",
+ ttybarstring[current_cell]);
+
+ cx +=
+ snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "\033[%dC", bar_spacing);
+ } else if (!tty) {
+ if (same_line > 0) {
+ cx += swprintf(frame_buffer + cx, buf_length - cx, L"\033[%dB",
+ same_line); // move down
+ new_line += same_line;
+ same_line = 0;
+ }
+
+ if (same_bar > 0) {
+ cx += swprintf(frame_buffer + cx, buf_length - cx, L"\033[%dC",
+ (bar_width + bar_spacing) * same_bar); // move forward
+ same_bar = 0;
+ }
+
+ if (!center_adjusted && rest) {
+ cx += swprintf(frame_buffer + cx, buf_length - cx, L"\033[%dC", rest);
+ center_adjusted = 1;
+ }
+
+ if (current_cell < 1)
+ cx += swprintf(frame_buffer + cx, buf_length - cx, spacestring);
+ else if (current_cell > 7)
+ cx += swprintf(frame_buffer + cx, buf_length - cx, barstring[0]);
+ else
+ cx += swprintf(frame_buffer + cx, buf_length - cx, barstring[current_cell]);
+
+ cx += swprintf(frame_buffer + cx, buf_length - cx, L"\033[%dC", bar_spacing);
+ }
+ }
+ }
+
+ if (same_bar != number_of_bars) {
+ if (current_line != 0) {
+ if (tty)
+ cx += snprintf(ttyframe_buffer + cx, ttybuf_length - cx, "\n");
+ else if (!tty)
+ cx += swprintf(frame_buffer + cx, buf_length - cx, L"\n");
+
+ new_line++;
+ }
+ } else {
+ same_line++;
+ }
+ }
+ if (same_line != lines) {
+ if (tty)
+ printf("%s\r\033[%dA", ttyframe_buffer, new_line);
+ else if (!tty)
+ printf("%ls\r\033[%dA", frame_buffer, new_line);
+
+ fflush(stdout);
+ }
+ return 0;
+}
+
+// general: cleanup
+void cleanup_terminal_noncurses(void) {
+ free(frame_buffer);
+ free(ttyframe_buffer);
+ free(spacestring);
+ free(ttyspacestring);
+ for (int i = 0; i < 8; i++) {
+ free(barstring[i]);
+ free(ttybarstring[i]);
+ }
+ setecho(STDIN_FILENO, 1);
+ printf("\033[0m\n");
+ system("setfont >/dev/null 2>&1");
+ system("setfont /usr/share/consolefonts/Lat2-Fixed16.psf.gz >/dev/null 2>&1");
+ system("setterm -cursor on");
+ system("setterm -blank 10");
+ system("clear");
+}
diff --git a/output/terminal_noncurses.h b/output/terminal_noncurses.h
new file mode 100644
index 0000000..542774d
--- /dev/null
+++ b/output/terminal_noncurses.h
@@ -0,0 +1,5 @@
+int init_terminal_noncurses(int tty, int col, int bgcol, int w, int h, int bar_width);
+void get_terminal_dim_noncurses(int *w, int *h);
+int draw_terminal_noncurses(int virt, int height, int width, int bars, int bar_width, int bs,
+ int rest, int f[200], int flastd[200]);
+void cleanup_terminal_noncurses(void);