@@ -20,9 +20,17 @@ struct colors {
20
20
21
21
#define MAX_COLOR_REDEFINITION 256
22
22
23
- const wchar_t * bar_heights [] = {L"\u2581" , L"\u2582" , L"\u2583" , L"\u2584" ,
24
- L"\u2585" , L"\u2586" , L"\u2587" , L"\u2588" };
25
- int num_bar_heights = (sizeof (bar_heights ) / sizeof (bar_heights [0 ]));
23
+ const int num_bar_heights = 8 ;
24
+ const wchar_t * bar_heights_bottom [] = {L"\u2581" , L"\u2582" , L"\u2583" , L"\u2584" ,
25
+ L"\u2585" , L"\u2586" , L"\u2587" , L"\u2588" };
26
+ const wchar_t * bar_heights_top [] = {L"\u2594" , L"\U0001FB82" , L"\U0001FB83" , L"\u2580" ,
27
+ L"\U0001FB84" , L"\U0001FB85" , L"\U0001FB86" , L"\u2588" };
28
+ const wchar_t * bar_heights_left [] = {L"\u258F" , L"\u258E" , L"\u258D" , L"\u258C" ,
29
+ L"\u258B" , L"\u258A" , L"\u2589" , L"\u2588" };
30
+ const wchar_t * bar_heights_right [] = {L"\u2595" , L"\U0001FB87" , L"\U0001FB88" , L"\u2590" ,
31
+ L"\U0001FB89" , L"\U0001FB8A" , L"\U0001FB8B" , L"\u2588" };
32
+ const wchar_t * * bar_heights [] = {bar_heights_bottom , bar_heights_top , bar_heights_left ,
33
+ bar_heights_right };
26
34
27
35
// static struct colors the_color_redefinitions[MAX_COLOR_REDEFINITION];
28
36
@@ -69,6 +77,28 @@ static NCURSES_COLOR_T change_color_definition(NCURSES_COLOR_T color_number,
69
77
return return_color_number ;
70
78
}
71
79
80
+ static void get_screen_coords (int val , int col , int max_value , enum orientation orientation , int * x ,
81
+ int * y ) {
82
+ switch (orientation ) {
83
+ case ORIENT_LEFT :
84
+ * x = val ;
85
+ * y = col ;
86
+ break ;
87
+ case ORIENT_RIGHT :
88
+ * x = max_value - val ;
89
+ * y = col ;
90
+ break ;
91
+ case ORIENT_TOP :
92
+ * x = col ;
93
+ * y = val ;
94
+ break ;
95
+ default :
96
+ * x = col ;
97
+ * y = max_value - val ;
98
+ break ;
99
+ }
100
+ }
101
+
72
102
void init_terminal_ncurses (char * const fg_color_string , char * const bg_color_string ,
73
103
int predef_fg_color , int predef_bg_color , int gradient ,
74
104
int gradient_count , char * * gradient_colors , int * width , int * lines ) {
@@ -191,33 +221,42 @@ void get_terminal_dim_ncurses(int *width, int *height) {
191
221
192
222
#define TERMINAL_RESIZED -1
193
223
194
- int draw_terminal_ncurses (int is_tty , int terminal_height , int terminal_width , int bars_count ,
224
+ int draw_terminal_ncurses (int is_tty , int dimension_value , int dimension_bar , int bars_count ,
195
225
int bar_width , int bar_spacing , int rest , const int bars [],
196
- int previous_frame [], int gradient , int x_axis_info ) {
197
- const int height = terminal_height - 1 ;
226
+ int previous_frame [], int gradient , int x_axis_info ,
227
+ enum orientation orientation ) {
228
+ const int max_value = dimension_value - 1 ;
198
229
199
230
// output: check if terminal has been resized
200
231
if (!is_tty ) {
201
232
if (x_axis_info )
202
- terminal_height ++ ;
233
+ dimension_value ++ ;
234
+ int terminal_width , terminal_height ;
235
+ if (orientation == ORIENT_LEFT || orientation == ORIENT_RIGHT ) {
236
+ terminal_width = dimension_value ;
237
+ terminal_height = dimension_bar ;
238
+ } else {
239
+ terminal_width = dimension_bar ;
240
+ terminal_height = dimension_value ;
241
+ }
203
242
if (LINES != terminal_height || COLS != terminal_width ) {
204
243
return TERMINAL_RESIZED ;
205
244
if (x_axis_info )
206
- terminal_height -- ;
245
+ dimension_value -- ;
207
246
}
208
247
}
209
248
210
249
// Compute how much of the screen we possibly need to update ahead-of-time.
211
- int max_update_y = 0 ;
250
+ int max_update_value = 0 ;
212
251
for (int bar = 0 ; bar < bars_count ; bar ++ ) {
213
- max_update_y = max (max_update_y , max (bars [bar ], previous_frame [bar ]));
252
+ max_update_value = max (max_update_value , max (bars [bar ], previous_frame [bar ]));
214
253
}
215
254
216
- max_update_y = (max_update_y + num_bar_heights ) / num_bar_heights ;
255
+ max_update_value = (max_update_value + num_bar_heights ) / num_bar_heights ;
217
256
218
- for (int y = 0 ; y < max_update_y ; y ++ ) {
257
+ for (int val = 0 ; val < max_update_value ; val ++ ) {
219
258
if (gradient ) {
220
- change_colors (y , height );
259
+ change_colors (val , max_value );
221
260
}
222
261
223
262
for (int bar = 0 ; bar < bars_count ; bar ++ ) {
@@ -229,32 +268,37 @@ int draw_terminal_ncurses(int is_tty, int terminal_height, int terminal_width, i
229
268
int f_cell = (bars [bar ] - 1 ) / num_bar_heights ;
230
269
int f_last_cell = (previous_frame [bar ] - 1 ) / num_bar_heights ;
231
270
232
- if (f_cell >= y ) {
271
+ if (f_cell >= val ) {
233
272
int bar_step ;
234
273
235
- if (f_cell == y ) {
236
- // The "cap" of the bar occurs at this [y ].
274
+ if (f_cell == val ) {
275
+ // The "cap" of the bar occurs at this [val ].
237
276
bar_step = (bars [bar ] - 1 ) % num_bar_heights ;
238
- } else if (f_last_cell <= y ) {
239
- // The bar is full at this [y ].
277
+ } else if (f_last_cell <= val ) {
278
+ // The bar is full at this [val ].
240
279
bar_step = num_bar_heights - 1 ;
241
280
} else {
242
281
// No update necessary since last frame.
243
282
continue ;
244
283
}
245
284
246
285
for (int col = cur_col , i = 0 ; i < bar_width ; i ++ , col ++ ) {
286
+ int x , y ;
287
+ get_screen_coords (val , col , max_value , orientation , & x , & y );
288
+
247
289
if (is_tty ) {
248
- mvaddch (height - y , col , 0x41 + bar_step );
290
+ mvaddch (y , x , 0x41 + bar_step );
249
291
} else {
250
- mvaddwstr (height - y , col , bar_heights [bar_step ]);
292
+ mvaddwstr (y , x , bar_heights [ orientation ] [bar_step ]);
251
293
}
252
294
}
253
- } else if (f_last_cell >= y ) {
295
+ } else if (f_last_cell >= val ) {
254
296
// This bar was taller during the last frame than during this frame, so
255
297
// clear the excess characters.
256
298
for (int col = cur_col , i = 0 ; i < bar_width ; i ++ , col ++ ) {
257
- mvaddch (height - y , col , ' ' );
299
+ int x , y ;
300
+ get_screen_coords (val , col , max_value , orientation , & x , & y );
301
+ mvaddch (y , x , ' ' );
258
302
}
259
303
}
260
304
}
0 commit comments