| 1 | /* @title: Console terminal state */ |
| 2 | #pragma once |
| 3 | #include <compiler.h> |
| 4 | #include <stdbool.h> |
| 5 | #include <stdint.h> |
| 6 | |
| 7 | #define TERM_PROBE_TIMEOUT_MS 250 |
| 8 | |
| 9 | #define TERM_FALLBACK_ROWS 25 |
| 10 | #define TERM_FALLBACK_COLS 80 |
| 11 | |
| 12 | struct term_geometry { |
| 13 | uint16_t rows; |
| 14 | uint16_t cols; |
| 15 | }; |
| 16 | |
| 17 | /* Ask terminal about size */ |
| 18 | bool term_probe(void); |
| 19 | bool term_available(void); |
| 20 | |
| 21 | /* falls back to FALLBACK */ |
| 22 | struct term_geometry term_size(void); |
| 23 | |
| 24 | /* Pin the geometry */ |
| 25 | void term_geometry_set(uint16_t rows, uint16_t cols); |
| 26 | |
| 27 | /* Plain mode strips escapes, swapping box drawing for ASCII */ |
| 28 | void term_set_plain(bool plain); |
| 29 | bool term_plain(void); |
| 30 | |
| 31 | void term_set_unicode(bool unicode); |
| 32 | bool term_unicode(void); |
| 33 | |
| 34 | enum term_sev { |
| 35 | TERM_SEV_NORMAL, |
| 36 | TERM_SEV_DIM, |
| 37 | TERM_SEV_LABEL, |
| 38 | TERM_SEV_OK, |
| 39 | TERM_SEV_WARN, |
| 40 | TERM_SEV_CRIT, |
| 41 | TERM_SEV_HEAD, |
| 42 | }; |
| 43 | |
| 44 | /* Severities instead of raw ANSI so plain mode just removes color here */ |
| 45 | const char *term_style(enum term_sev sev); |
| 46 | const char *term_style_reset(void); |
| 47 | |
| 48 | /* Mark console broken, drops scroll region, and locks don't get taken */ |
| 49 | void term_enter_panic(void); |
| 50 | bool term_in_panic(void); |
| 51 | |