forked from tigerkelly/fbcurses
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbcurses.h
More file actions
748 lines (637 loc) · 32.9 KB
/
Copy pathfbcurses.h
File metadata and controls
748 lines (637 loc) · 32.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
#ifndef FBCURSES_H
#define FBCURSES_H
/*
* fbcurses.h — Linux Framebuffer TUI Library
* A ncurses-style API for direct framebuffer rendering.
*
* Copyright (c) 2026 Richard Kelly Wiles (rkwiles@twc.com)
*/
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "fonts.h"
/* ─── Versioning ─────────────────────────────────────────────────── */
#define FBCURSES_VERSION_MAJOR 1
#define FBCURSES_VERSION_MINOR 0
#define FBCURSES_VERSION_PATCH 0
/* ─── Colour (32-bit ARGB) ───────────────────────────────────────── */
typedef uint32_t fbColor;
#define FB_RGB(r, g, b) ((fbColor)(0xFF000000u | ((r) << 16) | ((g) << 8) | (b)))
#define FB_RGBA(r, g, b, a) ((fbColor)(((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
#define FB_COLOR_R(c) (((c) >> 16) & 0xFF)
#define FB_COLOR_G(c) (((c) >> 8) & 0xFF)
#define FB_COLOR_B(c) (((c) ) & 0xFF)
#define FB_COLOR_A(c) (((c) >> 24) & 0xFF)
/* Named colours */
#define FB_BLACK FB_RGB( 0, 0, 0)
#define FB_WHITE FB_RGB(255, 255, 255)
#define FB_RED FB_RGB(205, 49, 49)
#define FB_GREEN FB_RGB( 13, 188, 121)
#define FB_YELLOW FB_RGB(229, 229, 16)
#define FB_BLUE FB_RGB( 36, 114, 200)
#define FB_MAGENTA FB_RGB(188, 63, 188)
#define FB_CYAN FB_RGB( 17, 168, 205)
#define FB_GRAY FB_RGB(118, 118, 118)
#define FB_BRIGHT_RED FB_RGB(241, 76, 76)
#define FB_BRIGHT_GREEN FB_RGB( 35, 209, 139)
#define FB_BRIGHT_YELLOW FB_RGB(245, 245, 67)
#define FB_BRIGHT_BLUE FB_RGB( 59, 142, 234)
#define FB_BRIGHT_MAGENTA FB_RGB(214, 112, 214)
#define FB_BRIGHT_CYAN FB_RGB( 41, 184, 219)
#define FB_TRANSPARENT ((fbColor)0x00000000u)
/* ─── Text attributes (bit flags) ───────────────────────────────── */
#define FB_ATTR_NONE 0x00u
#define FB_ATTR_BOLD 0x01u
#define FB_ATTR_UNDERLINE 0x02u
#define FB_ATTR_REVERSE 0x04u
#define FB_ATTR_BLINK 0x08u /* best-effort; flicker via timer */
#define FB_ATTR_DIM 0x10u
/* ─── Border styles ─────────────────────────────────────────────── */
typedef enum {
FB_BORDER_NONE = 0,
FB_BORDER_SINGLE, /* ┌─┐│└─┘ */
FB_BORDER_DOUBLE, /* ╔═╗║╚═╝ */
FB_BORDER_ROUNDED, /* ╭─╮│╰─╯ */
FB_BORDER_THICK, /* ┏━┓┃┗━┛ */
FB_BORDER_DASHED, /* ┌╌┐╎└╌┘ */
FB_BORDER_CUSTOM
} fbBorderStyle;
typedef struct {
fbBorderStyle style;
wchar_t tl, tr, bl, br; /* corners: top-left, top-right, … */
wchar_t horiz, vert; /* horizontal / vertical bar */
fbColor color;
} fbBorder;
/* ─── Key codes (returned by fbGetKey) ──────────────────────────── */
#define FB_KEY_NONE 0x0000
#define FB_KEY_UP 0x0100
#define FB_KEY_DOWN 0x0101
#define FB_KEY_LEFT 0x0102
#define FB_KEY_RIGHT 0x0103
#define FB_KEY_HOME 0x0104
#define FB_KEY_END 0x0105
#define FB_KEY_PAGE_UP 0x0106
#define FB_KEY_PAGE_DOWN 0x0107
#define FB_KEY_F1 0x0201
#define FB_KEY_F2 0x0202
#define FB_KEY_F3 0x0203
#define FB_KEY_F4 0x0204
#define FB_KEY_F5 0x0205
#define FB_KEY_F6 0x0206
#define FB_KEY_F7 0x0207
#define FB_KEY_F8 0x0208
#define FB_KEY_F9 0x0209
#define FB_KEY_F10 0x020A
#define FB_KEY_F11 0x020B
#define FB_KEY_F12 0x020C
#define FB_KEY_BACKSPACE 0x007F
#define FB_KEY_ENTER 0x000D
#define FB_KEY_ESC 0x001B
#define FB_KEY_TAB 0x0009
#define FB_KEY_DELETE 0x0300
#define FB_KEY_INSERT 0x0301
#define FB_KEY_RESIZE 0xFFFF /* terminal/fb size changed */
/* ─── Screen / window types ─────────────────────────────────────── */
typedef struct fbScreen fbScreen;
typedef struct fbWindow fbWindow;
/* ─── Alignment ─────────────────────────────────────────────────── */
typedef enum {
FB_ALIGN_LEFT = 0,
FB_ALIGN_CENTER = 1,
FB_ALIGN_RIGHT = 2
} fbAlign;
/* ═══════════════════════════════════════════════════════════════════
* Screen (global context, one per program)
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbInit — open the framebuffer and prepare the library.
*
* @param device framebuffer device path, e.g. "/dev/fb0" (NULL → auto)
* @return pointer to the screen context, or NULL on failure
*/
fbScreen *fbInit(const char *device);
/**
* fbShutdown — restore state and close the framebuffer.
*/
void fbShutdown(fbScreen *scr);
/** fbWidth / fbHeight — screen dimensions in *pixels*. */
int fbWidth(const fbScreen *scr);
int fbHeight(const fbScreen *scr);
/** fbColsRows — character columns/rows (using the built-in 8×16 font). */
int fbCols(const fbScreen *scr);
int fbRows(const fbScreen *scr);
/**
* fbClear — fill the entire screen with a colour.
*/
void fbClear(fbScreen *scr, fbColor color);
/**
* fbFlush — blit the back-buffer to the real framebuffer.
* Call once per frame after all drawing is done.
*/
void fbFlush(fbScreen *scr);
/**
* fbSetCursor — show/hide the hardware text cursor (if supported).
*/
void fbSetCursor(fbScreen *scr, bool visible);
/* ═══════════════════════════════════════════════════════════════════
* Window (a rectangular sub-region with its own coordinate space)
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbNewWindow — create a window in character-cell coordinates.
*
* @param scr parent screen
* @param col left edge (character columns from screen left)
* @param row top edge (character rows from screen top)
* @param cols width in character columns
* @param rows height in character rows
* @return new window, or NULL on failure
*/
fbWindow *fbNewWindow(fbScreen *scr, int col, int row, int cols, int rows);
/** fbDelWindow — destroy a window and free its resources. */
void fbDelWindow(fbWindow *win);
/** fbMoveWindow — reposition a window (character coordinates). */
void fbMoveWindow(fbWindow *win, int col, int row);
/** fbResizeWindow — resize a window (character coordinates). */
void fbResizeWindow(fbWindow *win, int cols, int rows);
/** fbWindowCols / fbWindowRows — window dimensions in character cells. */
int fbWindowCols(const fbWindow *win);
int fbWindowRows(const fbWindow *win);
/**
* fbClearWindow — fill the window background with a colour.
*/
void fbClearWindow(fbWindow *win, fbColor bg);
/**
* fbRefresh — render a window's content to the screen back-buffer.
* Does NOT call fbFlush; you control when to flip.
*/
void fbRefresh(fbWindow *win);
/* ═══════════════════════════════════════════════════════════════════
* Drawing primitives (pixel-level, relative to screen)
* ═══════════════════════════════════════════════════════════════════ */
void fbDrawPixel (fbScreen *scr, int x, int y, fbColor color);
void fbDrawLine (fbScreen *scr, int x0, int y0, int x1, int y1, fbColor color);
void fbDrawRect (fbScreen *scr, int x, int y, int w, int h, fbColor color);
void fbFillRect (fbScreen *scr, int x, int y, int w, int h, fbColor color);
void fbDrawCircle(fbScreen *scr, int cx, int cy, int r, fbColor color);
void fbFillCircle(fbScreen *scr, int cx, int cy, int r, fbColor color);
/* ═══════════════════════════════════════════════════════════════════
* Text rendering (character-cell, relative to window)
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbMoveCursor — move the window's internal text cursor.
*/
void fbMoveCursor(fbWindow *win, int col, int row);
/**
* fbSetColors — set the active fg/bg colour pair for the window.
*/
void fbSetColors(fbWindow *win, fbColor fg, fbColor bg);
/**
* fbSetAttr — set text attribute flags (FB_ATTR_*).
*/
void fbSetAttr(fbWindow *win, uint8_t attr);
/**
* fbAddChar — draw a single character at the cursor, then advance.
*/
void fbAddChar(fbWindow *win, char ch);
/**
* fbAddWchar — draw a single wide (Unicode) character at the cursor.
* Handles box-drawing, block elements, braille, and any wchar_t codepoint.
*/
void fbAddWchar(fbWindow *win, wchar_t ch);
/**
* fbAddStr — draw a NUL-terminated string at the cursor.
*/
void fbAddStr(fbWindow *win, const char *str);
/**
* fbPrint — printf-style formatted text at the cursor.
*/
void fbPrint(fbWindow *win, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
/**
* fbPrintAt — move then print (convenience wrapper).
*/
void fbPrintAt(fbWindow *win, int col, int row, const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
/**
* fbPrintAligned — print text aligned within the window's width.
*/
void fbPrintAligned(fbWindow *win, int row, fbAlign align, const char *str);
/* ═══════════════════════════════════════════════════════════════════
* Borders & boxes
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbDrawBorder — draw a border around the entire window using a preset style.
*/
void fbDrawBorder(fbWindow *win, fbBorderStyle style, fbColor color);
/**
* fbDrawCustomBorder — draw a border using a fully custom fbBorder descriptor.
*/
void fbDrawCustomBorder(fbWindow *win, const fbBorder *border);
/**
* fbDrawBox — draw a box at an arbitrary cell position within the window.
*/
void fbDrawBox(fbWindow *win, int col, int row, int cols, int rows,
fbBorderStyle style, fbColor color);
/**
* fbDrawTitleBar — draw the border *and* a centred title string.
*/
void fbDrawTitleBar(fbWindow *win, const char *title,
fbBorderStyle style, fbColor borderColor,
fbColor titleFg, fbColor titleBg);
/* ═══════════════════════════════════════════════════════════════════
* Progress & status widgets
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbDrawProgressBar — horizontal progress bar inside the window.
*
* @param col, row top-left character position within the window
* @param width bar width in character columns
* @param percent 0–100
* @param fg filled-section colour
* @param bg empty-section colour
* @param showPct if true, render "NN%" text in the bar
*/
void fbDrawProgressBar(fbWindow *win, int col, int row, int width,
int percent, fbColor fg, fbColor bg, bool showPct);
/**
* fbDrawSpinner — animated spinner at (col, row).
* Call repeatedly; the frame advances automatically each call.
*
* @param tick monotonically increasing counter driving the animation
*/
void fbDrawSpinner(fbWindow *win, int col, int row, int tick,
fbColor fg, fbColor bg);
/* ═══════════════════════════════════════════════════════════════════
* Scrolling & panning
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbScrollUp / fbScrollDown — scroll the window content by n rows.
* Vacated rows are filled with bg.
*/
void fbScrollUp (fbWindow *win, int n, fbColor bg);
void fbScrollDown(fbWindow *win, int n, fbColor bg);
/* ═══════════════════════════════════════════════════════════════════
* Input
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbGetKey — blocking read of one keypress.
* Returns an FB_KEY_* constant or a plain ASCII value.
*/
int fbGetKey(fbScreen *scr);
/**
* fbGetKeyTimeout — like fbGetKey but returns FB_KEY_NONE after ms milliseconds.
*/
int fbGetKeyTimeout(fbScreen *scr, int ms);
/**
* fbGetStr — read a line of text into buf (max len-1 chars + NUL).
* Displays input at the current window cursor with basic editing.
* Returns the number of characters read.
*/
int fbGetStr(fbWindow *win, char *buf, int len);
/* ═══════════════════════════════════════════════════════════════════
* Colour utilities
* ═══════════════════════════════════════════════════════════════════ */
/** fbBlend — alpha-composite src over dst. */
fbColor fbBlend(fbColor dst, fbColor src);
/** fbDarken / fbLighten — adjust brightness by factor (0.0–1.0). */
fbColor fbDarken (fbColor c, float factor);
fbColor fbLighten(fbColor c, float factor);
/** fbGrayscale — convert colour to grayscale. */
fbColor fbGrayscale(fbColor c);
/** fbLerp — linear interpolate between two colours (t = 0.0–1.0). */
fbColor fbLerp(fbColor a, fbColor b, float t);
/* ═══════════════════════════════════════════════════════════════════
* Pixel-level text blitting (font-aware, bypasses cell grid)
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbDrawTextPx — render a string directly at pixel coordinates (x, y)
* using any font, without involving a window or cell grid.
*
* This is the correct way to display text in multiple different fonts
* on the same screen — each call can use a different font and the
* glyphs are placed at exact pixel positions.
*
* After drawing, call fbFlush() to push to hardware.
*
* @param scr target screen
* @param x, y top-left pixel position
* @param str NUL-terminated ASCII string
* @param fg foreground colour
* @param bg background colour (use FB_TRANSPARENT to skip bg fill)
* @param attr FB_ATTR_* flags (bold, underline, etc.)
* @param font which font to use (NULL → fbVga)
* @returns pixel x coordinate immediately after the last glyph
*/
int fbDrawTextPx(fbScreen *scr, int x, int y, const char *str,
fbColor fg, fbColor bg, uint8_t attr,
const fbFont *font);
/**
* fbDrawWTextPx — same as fbDrawTextPx but accepts a wide string,
* rendering Unicode / box-drawing characters correctly.
*/
int fbDrawWTextPx(fbScreen *scr, int x, int y, const wchar_t *str,
fbColor fg, fbColor bg, uint8_t attr,
const fbFont *font);
/* ═══════════════════════════════════════════════════════════════════
* Font selection
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbSetFont — change the active bitmap font for a window.
*
* The window's character-cell grid (cols, rows) is recalculated based on
* the new font's pixel dimensions. All existing cells are preserved and
* re-marked dirty so the next fbRefresh() redraws everything correctly.
*
* Pass NULL to reset to the default VGA 8×16 font.
*
* @param win target window
* @param font pointer to an fbFont (e.g. &fbBold8, &fbThin5, …)
*/
void fbSetFont(fbWindow *win, const fbFont *font);
/**
* fbGetFont — return the font currently active on a window.
*/
const fbFont *fbGetFont(const fbWindow *win);
/* ═══════════════════════════════════════════════════════════════════
* Error handling
* ═══════════════════════════════════════════════════════════════════ */
/** fbGetError — return a human-readable description of the last error. */
const char *fbGetError(void);
/** fbErrorCode — numeric error code (0 = no error). */
int fbErrorCode(void);
/* ═══════════════════════════════════════════════════════════════════
* Mouse input
* ═══════════════════════════════════════════════════════════════════ */
typedef struct {
int x, y; /* pixel position */
int col, row; /* character-cell position (VGA font grid) */
bool left, middle, right;
bool moved; /* position changed since last event */
int wheelDelta; /* +1 scroll up, -1 scroll down */
} fbMouseEvent;
/**
* fbMouseInit — enable mouse tracking on the active terminal.
* Call once after fbInit(). Disable with fbMouseShutdown().
*/
void fbMouseInit (fbScreen *scr);
void fbMouseShutdown(fbScreen *scr);
/**
* fbMousePoll — non-blocking read of one mouse event.
* Returns true if an event was available; sets *ev.
*/
bool fbMousePoll(fbScreen *scr, fbMouseEvent *ev);
/* ═══════════════════════════════════════════════════════════════════
* Menu widget
* ═══════════════════════════════════════════════════════════════════ */
typedef struct {
const char *label; /* menu item text (NULL = separator line) */
int id; /* value returned when item is selected */
bool disabled;
} fbMenuItem;
/**
* fbMenu — display a pop-up menu anchored at (col, row) in screen
* character coordinates and run a blocking event loop until the user
* selects an item or presses Escape.
*
* Returns the selected item's id, or -1 if cancelled.
*
* @param items array of fbMenuItem, terminated by {NULL, 0, false}
* @param fgSel foreground colour for the highlighted item
* @param bgSel background colour for the highlighted item
* @param fg foreground colour for normal items
* @param bg background colour for normal items
* @param border border style for the menu box
*/
int fbMenu(fbScreen *scr, int col, int row,
const fbMenuItem *items,
fbColor fg, fbColor bg,
fbColor fgSel, fbColor bgSel,
fbBorderStyle border);
/* ═══════════════════════════════════════════════════════════════════
* Text-input widget (single-line editor with cursor)
* ═══════════════════════════════════════════════════════════════════ */
typedef struct fbTextInput fbTextInput;
/**
* fbTextInputNew — create a single-line editor.
*
* @param win host window
* @param col,row position within window (character cells)
* @param width visible width in character cells
* @param maxLen maximum string length (not counting NUL)
* @param initial initial content (may be NULL)
*/
fbTextInput *fbTextInputNew (fbWindow *win, int col, int row,
int width, int maxLen,
const char *initial);
void fbTextInputFree(fbTextInput *ti);
/** fbTextInputDraw — render the widget into the parent window. */
void fbTextInputDraw(fbTextInput *ti,
fbColor fg, fbColor bg, fbColor cursorFg);
/**
* fbTextInputKey — feed a key (from fbGetKey) into the editor.
* Returns true if the key was consumed; false if it should propagate
* (e.g. Tab, Enter, Escape — the caller decides what these mean).
*/
bool fbTextInputKey(fbTextInput *ti, int key);
/** fbTextInputGet — return the current text (pointer into internal buf). */
const char *fbTextInputGet(const fbTextInput *ti);
/** fbTextInputSet — replace the content programmatically. */
void fbTextInputSet(fbTextInput *ti, const char *text);
/* ═══════════════════════════════════════════════════════════════════
* Toast / notification popup
* ═══════════════════════════════════════════════════════════════════ */
typedef enum {
FB_TOAST_INFO = 0,
FB_TOAST_SUCCESS = 1,
FB_TOAST_WARNING = 2,
FB_TOAST_ERROR = 3,
} fbToastKind;
/**
* fbToast — display a floating notification for durationMs milliseconds,
* then erase it and restore what was underneath.
*
* @param kind visual style (info/success/warning/error)
* @param msg message text (one line)
* @param durationMs display time; ≤0 = wait for any keypress
*/
void fbToast(fbScreen *scr, fbToastKind kind,
const char *msg, int durationMs);
/* ═══════════════════════════════════════════════════════════════════
* Table / data-grid widget
* ═══════════════════════════════════════════════════════════════════ */
typedef struct {
const char *header; /* column header text */
int width; /* column width in chars (0 = auto-size) */
fbAlign align;
} fbTableCol;
/**
* fbDrawTable — render a data table inside a window.
*
* @param win target window
* @param startCol left edge (character column within window)
* @param startRow top edge
* @param cols column descriptors array, terminated by {NULL,0,0}
* @param rows 2-D array of strings: rows[r][c]
* @param nRows number of data rows
* @param selRow highlighted row index (-1 = none)
* @param headerFg/Bg header colours
* @param cellFg/Bg cell colours
* @param selFg/Bg selected-row colours
*/
void fbDrawTable(fbWindow *win, int startCol, int startRow,
const fbTableCol *cols,
const char * const * const *rows, int nRows,
int selRow,
fbColor headerFg, fbColor headerBg,
fbColor cellFg, fbColor cellBg,
fbColor selFg, fbColor selBg);
/* ═══════════════════════════════════════════════════════════════════
* Gauge / sparkline widgets
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbDrawGauge — vertical bar gauge (like a VU meter) at (col,row).
*
* @param height gauge height in rows
* @param value current value (0–maxVal)
* @param maxVal maximum value
* @param fg filled bar colour
* @param bg empty background colour
*/
void fbDrawGauge(fbWindow *win, int col, int row,
int height, int value, int maxVal,
fbColor fg, fbColor bg);
/**
* fbDrawSparkline — mini line chart using ▁▂▃▄▅▆▇█ block chars.
*
* @param values array of nValues floats (0.0–1.0 normalised)
* @param nValues number of data points (should equal width)
* @param width width in character cells
* @param fg bar colour
* @param bg background colour
*/
void fbDrawSparkline(fbWindow *win, int col, int row,
const float *values, int nValues, int width,
fbColor fg, fbColor bg);
/* ═══════════════════════════════════════════════════════════════════
* Wide-string text output
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbAddWStr — draw a NUL-terminated wide string at the cursor.
* Handles any Unicode codepoint including box-drawing characters.
*/
void fbAddWStr(fbWindow *win, const wchar_t *str);
/**
* fbAddUtf8 — draw a UTF-8 encoded string at the cursor.
* Decodes multi-byte sequences and renders each codepoint correctly.
*/
void fbAddUtf8(fbWindow *win, const char *utf8);
/* ═══════════════════════════════════════════════════════════════════
* File picker widget
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbFilePicker — interactive file browser dialog.
*
* Displays a scrollable file listing rooted at startDir.
* The user can navigate with arrow keys, Enter to descend into
* directories or select a file, Backspace/Left to go up, Esc to cancel.
*
* @param startDir initial directory (NULL = current working dir)
* @param outPath buffer to receive the selected path
* @param outLen size of outPath buffer
* @returns true if a file was selected, false if cancelled
*/
bool fbFilePicker(fbScreen *scr, const char *startDir,
char *outPath, int outLen);
/* ═══════════════════════════════════════════════════════════════════
* Colour picker widget
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbColorPicker — interactive 256-colour swatch picker.
*
* Displays a palette grid; user navigates with arrow keys.
* Enter selects, Esc cancels.
*
* @param initial initially highlighted colour (or FB_BLACK)
* @returns selected fbColor, or FB_TRANSPARENT on cancel
*/
fbColor fbColorPicker(fbScreen *scr, fbColor initial);
/* ═══════════════════════════════════════════════════════════════════
* Message box
* ═══════════════════════════════════════════════════════════════════ */
typedef enum {
FB_MSGBOX_OK = 0x01,
FB_MSGBOX_OK_CANCEL = 0x03,
FB_MSGBOX_YES_NO = 0x06,
FB_MSGBOX_YES_NO_CANCEL = 0x07,
} fbMsgBoxButtons;
#define FB_MSGBOX_RESULT_OK 1
#define FB_MSGBOX_RESULT_CANCEL 2
#define FB_MSGBOX_RESULT_YES 4
#define FB_MSGBOX_RESULT_NO 8
/**
* fbMsgBox — display a modal message box with configurable buttons.
*
* @param title title bar text
* @param msg message body (may contain newlines)
* @param buttons which buttons to show (FB_MSGBOX_* flags)
* @param kind visual style (FB_TOAST_INFO / WARNING / ERROR / SUCCESS)
* @returns FB_MSGBOX_RESULT_* for the button the user pressed
*/
int fbMsgBox(fbScreen *scr, const char *title, const char *msg,
fbMsgBoxButtons buttons, fbToastKind kind);
/* ═══════════════════════════════════════════════════════════════════
* Virtual Console (VT) switching
*
* Linux supports up to 63 virtual consoles (VT1–VT63). These
* functions let your program switch VTs programmatically rather than
* requiring the user to press Alt-Fn or Ctrl-Alt-Fn.
*
* Typical use:
* int myVt = fbVtCurrent(scr); // which VT am I on?
* fbVtSwitch(scr, myVt + 1); // move to next VT
* fbVtSwitch(scr, myVt); // come back
*
* int free = fbVtOpenFree(scr); // allocate a fresh VT
* fbVtSwitch(scr, free); // switch to it
* // ... draw something ...
* fbVtSwitch(scr, myVt); // return home
* fbVtClose(scr, free); // release the VT
*
* Notes:
* - You normally need to be root or in the 'tty' group.
* - VT numbers are 1-based (VT1 = tty1, VT2 = tty2, …).
* - fbVtSwitch() calls fbFlush() first so the screen is clean on
* the new VT.
* ═══════════════════════════════════════════════════════════════════ */
/**
* fbVtCurrent — return the VT number this process is running on.
* Returns 0 if the VT number could not be determined.
*/
int fbVtCurrent(const fbScreen *scr);
/**
* fbVtSwitch — switch the active display to VT number @vt.
*
* Immediately changes the visible console; your program continues
* running on the new VT. Pass @waitActive=true to block until the
* VT is actually foregrounded (useful before drawing).
*
* Returns true on success.
*/
bool fbVtSwitch(fbScreen *scr, int vt, bool waitActive);
/**
* fbVtOpenFree — allocate the next unused VT and return its number.
* Returns -1 if no free VT is available or the ioctl fails.
*/
int fbVtOpenFree(fbScreen *scr);
/**
* fbVtClose — deallocate a VT that was previously opened with
* fbVtOpenFree(). Do not close the VT you are currently on.
* Returns true on success.
*/
bool fbVtClose(fbScreen *scr, int vt);
/**
* fbVtCount — return the total number of VTs configured in the kernel
* (NR_CONSOLES, typically 63). Returns -1 on error.
*/
int fbVtCount(fbScreen *scr);
#endif /* FBCURSES_H */