:: limine / common / lib / term.h 1.3 KB raw

1
#ifndef LIB__TERM_H__
2
#define LIB__TERM_H__
3
4
#include <stddef.h>
5
#include <stdint.h>
6
#include <stdbool.h>
7
#include <lib/print.h>
8
#include <flanterm.h>
9
10
enum {
11
    _NOT_READY,
12
    GTERM,
13
    TEXTMODE,
14
    FALLBACK
15
};
16
17
#if defined (BIOS)
18
extern int current_video_mode;
19
#endif
20
21
extern struct flanterm_context **terms;
22
extern size_t terms_i;
23
24
extern int term_backend;
25
26
#define TERM_CTX_SIZE ((uint64_t)(-1))
27
#define TERM_CTX_SAVE ((uint64_t)(-2))
28
#define TERM_CTX_RESTORE ((uint64_t)(-3))
29
#define TERM_FULL_REFRESH ((uint64_t)(-4))
30
#define TERM_OOB_OUTPUT_GET ((uint64_t)(-10))
31
#define TERM_OOB_OUTPUT_SET ((uint64_t)(-11))
32
33
#define FOR_TERM(...) do { \
34
    for (size_t FOR_TERM_i = 0; FOR_TERM_i < terms_i; FOR_TERM_i++) { \
35
        struct flanterm_context *TERM = terms[FOR_TERM_i]; \
36
        __VA_ARGS__ \
37
        ; \
38
    } \
39
} while (0)
40
41
static inline void reset_term(void) {
42
    for (size_t i = 0; i < terms_i; i++) {
43
        struct flanterm_context *term = terms[i];
44
45
        print("\e[2J\e[H");
46
        flanterm_context_reinit(term);
47
        term->cursor_enabled = true;
48
        term->double_buffer_flush(term);
49
    }
50
}
51
52
static inline void set_cursor_pos_helper(size_t x, size_t y) {
53
    print("\e[%u;%uH", (int)y + 1, (int)x + 1);
54
}
55
56
void term_notready(void);
57
void term_fallback(void);
58
void _term_write(struct flanterm_context *term, uint64_t buf, uint64_t count);
59
60
#endif
tab: 248 wrap: offon