rulimine/common/lib/term.h

60 lines
1.3 KiB
C
Raw Normal View History

2020-09-02 10:55:56 +03:00
#ifndef __LIB__TERM_H__
#define __LIB__TERM_H__
#include <stddef.h>
#include <stdint.h>
#include <lib/print.h>
2023-03-29 23:43:06 +03:00
#include <flanterm/flanterm.h>
enum {
_NOT_READY,
2022-10-04 02:37:19 +03:00
GTERM,
TEXTMODE,
FALLBACK
};
#if defined (BIOS)
extern int current_video_mode;
#endif
2020-09-02 10:55:56 +03:00
2023-03-29 23:43:06 +03:00
extern struct flanterm_context **terms;
extern size_t terms_i;
extern int term_backend;
#define TERM_CTX_SIZE ((uint64_t)(-1))
#define TERM_CTX_SAVE ((uint64_t)(-2))
#define TERM_CTX_RESTORE ((uint64_t)(-3))
2021-08-16 21:56:39 +03:00
#define TERM_FULL_REFRESH ((uint64_t)(-4))
#define TERM_OOB_OUTPUT_GET ((uint64_t)(-10))
#define TERM_OOB_OUTPUT_SET ((uint64_t)(-11))
2020-10-27 10:09:27 +03:00
#define FOR_TERM(...) do { \
for (size_t FOR_TERM_i = 0; FOR_TERM_i < terms_i; FOR_TERM_i++) { \
2023-03-29 23:43:06 +03:00
struct flanterm_context *TERM = terms[FOR_TERM_i]; \
__VA_ARGS__ \
; \
} \
} while (0)
2021-10-09 14:32:57 +03:00
inline void reset_term(void) {
for (size_t i = 0; i < terms_i; i++) {
2023-03-29 23:43:06 +03:00
struct flanterm_context *term = terms[i];
print("\e[2J\e[H");
2023-03-29 23:43:06 +03:00
flanterm_context_reinit(term);
term->cursor_enabled = true;
term->double_buffer_flush(term);
}
2021-10-09 14:32:57 +03:00
}
inline void set_cursor_pos_helper(size_t x, size_t y) {
print("\e[%u;%uH", (int)y + 1, (int)x + 1);
}
void term_notready(void);
void term_fallback(void);
2023-03-29 23:43:06 +03:00
void _term_write(struct flanterm_context *term, uint64_t buf, uint64_t count);
2020-09-02 10:55:56 +03:00
#endif