1
+ #include "output/terminal_noncurses.h"
2
+
1
3
#include <locale.h>
2
4
#include <math.h>
3
5
#include <stdio.h>
18
20
19
21
wchar_t * frame_buffer ;
20
22
wchar_t * barstring [8 ];
23
+ wchar_t * top_barstring [8 ];
21
24
wchar_t * spacestring ;
22
25
int buf_length ;
23
26
char * ttyframe_buffer ;
@@ -78,6 +81,7 @@ void free_terminal_noncurses(void) {
78
81
free (ttyspacestring );
79
82
for (int i = 0 ; i < 8 ; i ++ ) {
80
83
free (barstring [i ]);
84
+ free (top_barstring [i ]);
81
85
free (ttybarstring [i ]);
82
86
}
83
87
free (gradient_colors );
@@ -125,6 +129,8 @@ int init_terminal_noncurses(int tty, char *const fg_color_string, char *const bg
125
129
for (int n = 0 ; n < 8 ; n ++ ) {
126
130
barstring [n ] = (wchar_t * )malloc (sizeof (wchar_t ) * (bar_width + 1 ));
127
131
barstring [n ][0 ] = '\0' ;
132
+ top_barstring [n ] = (wchar_t * )malloc (sizeof (wchar_t ) * (bar_width + 1 ));
133
+ top_barstring [n ][0 ] = '\0' ;
128
134
}
129
135
spacestring [0 ] = '\0' ;
130
136
frame_buffer [0 ] = '\0' ;
@@ -139,6 +145,14 @@ int init_terminal_noncurses(int tty, char *const fg_color_string, char *const bg
139
145
wcscat (barstring [5 ], L"\u2585" );
140
146
wcscat (barstring [6 ], L"\u2586" );
141
147
wcscat (barstring [7 ], L"\u2587" );
148
+ wcscat (top_barstring [0 ], L"\u2588" );
149
+ wcscat (top_barstring [1 ], L"\u2594" );
150
+ wcscat (top_barstring [2 ], L"\U0001FB82" );
151
+ wcscat (top_barstring [3 ], L"\U0001FB83" );
152
+ wcscat (top_barstring [4 ], L"\u2580" );
153
+ wcscat (top_barstring [5 ], L"\U0001FB84" );
154
+ wcscat (top_barstring [6 ], L"\U0001FB85" );
155
+ wcscat (top_barstring [7 ], L"\U0001FB86" );
142
156
wcscat (spacestring , L" " );
143
157
}
144
158
}
@@ -260,7 +274,7 @@ void get_terminal_dim_noncurses(int *width, int *lines) {
260
274
261
275
int draw_terminal_noncurses (int tty , int lines , int width , int number_of_bars , int bar_width ,
262
276
int bar_spacing , int rest , int bars [], int previous_frame [],
263
- int gradient , int x_axis_info ) {
277
+ int gradient , int x_axis_info , enum orientation orientation ) {
264
278
265
279
int current_cell , prev_cell , same_line , new_line , cx ;
266
280
@@ -291,17 +305,33 @@ int draw_terminal_noncurses(int tty, int lines, int width, int number_of_bars, i
291
305
292
306
for (int current_line = lines - 1 ; current_line >= 0 ; current_line -- ) {
293
307
294
- if (gradient ) {
295
- if (tty ) {
296
- cx += snprintf (ttyframe_buffer + cx , ttybuf_length - cx , "\033[38;2;%d;%d;%dm" ,
297
- gradient_colors [current_line ].rgb [0 ],
298
- gradient_colors [current_line ].rgb [1 ],
299
- gradient_colors [current_line ].rgb [2 ]);
300
- } else if (!tty ) {
301
- cx += swprintf (frame_buffer + cx , buf_length - cx , L"\033[38;2;%d;%d;%dm" ,
302
- gradient_colors [current_line ].rgb [0 ],
303
- gradient_colors [current_line ].rgb [1 ],
304
- gradient_colors [current_line ].rgb [2 ]);
308
+ if (orientation == ORIENT_BOTTOM ) {
309
+ if (gradient ) {
310
+ if (tty ) {
311
+ cx += snprintf (ttyframe_buffer + cx , ttybuf_length - cx , "\033[38;2;%d;%d;%dm" ,
312
+ gradient_colors [current_line ].rgb [0 ],
313
+ gradient_colors [current_line ].rgb [1 ],
314
+ gradient_colors [current_line ].rgb [2 ]);
315
+ } else if (!tty ) {
316
+ cx += swprintf (frame_buffer + cx , buf_length - cx , L"\033[38;2;%d;%d;%dm" ,
317
+ gradient_colors [current_line ].rgb [0 ],
318
+ gradient_colors [current_line ].rgb [1 ],
319
+ gradient_colors [current_line ].rgb [2 ]);
320
+ }
321
+ }
322
+ } else if (orientation == ORIENT_TOP ) {
323
+ if (gradient ) {
324
+ if (tty ) {
325
+ cx += snprintf (ttyframe_buffer + cx , ttybuf_length - cx , "\033[38;2;%d;%d;%dm" ,
326
+ gradient_colors [lines - current_line - 1 ].rgb [0 ],
327
+ gradient_colors [lines - current_line - 1 ].rgb [1 ],
328
+ gradient_colors [lines - current_line - 1 ].rgb [2 ]);
329
+ } else if (!tty ) {
330
+ cx += swprintf (frame_buffer + cx , buf_length - cx , L"\033[38;2;%d;%d;%dm" ,
331
+ gradient_colors [lines - current_line - 1 ].rgb [0 ],
332
+ gradient_colors [lines - current_line - 1 ].rgb [1 ],
333
+ gradient_colors [lines - current_line - 1 ].rgb [2 ]);
334
+ }
305
335
}
306
336
}
307
337
@@ -310,8 +340,13 @@ int draw_terminal_noncurses(int tty, int lines, int width, int number_of_bars, i
310
340
311
341
for (int i = 0 ; i < number_of_bars ; i ++ ) {
312
342
313
- current_cell = bars [i ] - current_line * 8 ;
314
- prev_cell = previous_frame [i ] - current_line * 8 ;
343
+ if (orientation == ORIENT_BOTTOM ) {
344
+ current_cell = bars [i ] - current_line * 8 ;
345
+ prev_cell = previous_frame [i ] - current_line * 8 ;
346
+ } else if (orientation == ORIENT_TOP ) {
347
+ current_cell = bars [i ] - (lines - current_line - 1 ) * 8 ;
348
+ prev_cell = previous_frame [i ] - (lines - current_line - 1 ) * 8 ;
349
+ }
315
350
316
351
// same as last frame
317
352
if ((current_cell < 1 && prev_cell < 1 ) || (current_cell > 7 && prev_cell > 7 ) ||
@@ -369,12 +404,21 @@ int draw_terminal_noncurses(int tty, int lines, int width, int number_of_bars, i
369
404
center_adjusted = 1 ;
370
405
}
371
406
372
- if (current_cell < 1 )
407
+ if (current_cell < 1 ) {
373
408
cx += swprintf (frame_buffer + cx , buf_length - cx , spacestring );
374
- else if (current_cell > 7 )
375
- cx += swprintf (frame_buffer + cx , buf_length - cx , barstring [0 ]);
376
- else
377
- cx += swprintf (frame_buffer + cx , buf_length - cx , barstring [current_cell ]);
409
+ } else if (current_cell > 7 ) {
410
+ if (orientation == ORIENT_BOTTOM )
411
+ cx += swprintf (frame_buffer + cx , buf_length - cx , barstring [0 ]);
412
+ else if (orientation == ORIENT_TOP )
413
+ cx += swprintf (frame_buffer + cx , buf_length - cx , top_barstring [0 ]);
414
+ } else {
415
+ if (orientation == ORIENT_BOTTOM )
416
+ cx += swprintf (frame_buffer + cx , buf_length - cx ,
417
+ barstring [current_cell ]);
418
+ else if (orientation == ORIENT_TOP )
419
+ cx += swprintf (frame_buffer + cx , buf_length - cx ,
420
+ top_barstring [current_cell ]);
421
+ }
378
422
379
423
if (bar_spacing )
380
424
cx +=
0 commit comments