flanterm/term.h

106 lines
3.1 KiB
C
Raw Normal View History

2022-10-04 01:49:47 +03:00
#ifndef _TERM_H
#define _TERM_H
2022-10-30 00:59:02 +03:00
#ifdef __cplusplus
extern "C" {
#endif
2022-10-04 01:49:47 +03:00
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#define TERM_MAX_ESC_VALUES 16
#define TERM_CB_DEC 10
#define TERM_CB_BELL 20
#define TERM_CB_PRIVATE_ID 30
#define TERM_CB_STATUS_REPORT 40
#define TERM_CB_POS_REPORT 50
#define TERM_CB_KBD_LEDS 60
#define TERM_CB_MODE 70
#define TERM_CB_LINUX 80
struct term_context {
2022-10-04 04:31:39 +03:00
/* internal use */
2022-10-04 01:49:47 +03:00
size_t tab_size;
bool autoflush;
bool scroll_enabled;
bool control_sequence;
bool csi;
bool escape;
2022-11-01 05:55:14 +03:00
bool osc;
bool osc_escape;
2022-10-04 01:49:47 +03:00
bool rrr;
bool discard_next;
bool bold;
2022-11-01 05:55:14 +03:00
bool bg_bold;
2022-10-04 01:49:47 +03:00
bool reverse_video;
bool dec_private;
bool insert_mode;
2022-12-01 19:20:30 +03:00
uint64_t code_point;
size_t unicode_remaining;
2022-10-04 01:49:47 +03:00
uint8_t g_select;
uint8_t charsets[2];
size_t current_charset;
size_t escape_offset;
size_t esc_values_i;
size_t saved_cursor_x;
size_t saved_cursor_y;
size_t current_primary;
2022-11-01 05:55:14 +03:00
size_t current_bg;
2022-10-04 01:49:47 +03:00
size_t scroll_top_margin;
size_t scroll_bottom_margin;
uint32_t esc_values[TERM_MAX_ESC_VALUES];
bool saved_state_bold;
2022-11-01 05:55:14 +03:00
bool saved_state_bg_bold;
2022-10-04 01:49:47 +03:00
bool saved_state_reverse_video;
size_t saved_state_current_charset;
size_t saved_state_current_primary;
2022-11-01 05:55:14 +03:00
size_t saved_state_current_bg;
2022-10-04 01:49:47 +03:00
2022-10-04 04:31:39 +03:00
/* to be set by backend */
size_t rows, cols;
bool in_bootloader;
2022-10-04 01:49:47 +03:00
void (*raw_putchar)(struct term_context *, uint8_t c);
void (*clear)(struct term_context *, bool move);
void (*enable_cursor)(struct term_context *);
bool (*disable_cursor)(struct term_context *);
void (*set_cursor_pos)(struct term_context *, size_t x, size_t y);
void (*get_cursor_pos)(struct term_context *, size_t *x, size_t *y);
void (*set_text_fg)(struct term_context *, size_t fg);
void (*set_text_bg)(struct term_context *, size_t bg);
void (*set_text_fg_bright)(struct term_context *, size_t fg);
void (*set_text_bg_bright)(struct term_context *, size_t bg);
void (*set_text_fg_rgb)(struct term_context *, uint32_t fg);
void (*set_text_bg_rgb)(struct term_context *, uint32_t bg);
void (*set_text_fg_default)(struct term_context *);
void (*set_text_bg_default)(struct term_context *);
2022-12-14 17:05:46 +03:00
void (*set_text_fg_default_bright)(struct term_context *);
void (*set_text_bg_default_bright)(struct term_context *);
2022-10-04 01:49:47 +03:00
void (*move_character)(struct term_context *, size_t new_x, size_t new_y, size_t old_x, size_t old_y);
void (*scroll)(struct term_context *);
void (*revscroll)(struct term_context *);
void (*swap_palette)(struct term_context *);
void (*save_state)(struct term_context *);
void (*restore_state)(struct term_context *);
void (*double_buffer_flush)(struct term_context *);
void (*full_refresh)(struct term_context *);
void (*deinit)(struct term_context *, void (*)(void *, size_t));
2022-10-04 04:31:39 +03:00
/* to be set by client */
2022-10-04 01:49:47 +03:00
void (*callback)(struct term_context *, uint64_t, uint64_t, uint64_t, uint64_t);
};
void term_context_reinit(struct term_context *ctx);
void term_write(struct term_context *ctx, const char *buf, size_t count);
2022-10-30 00:59:02 +03:00
#ifdef __cplusplus
}
#endif
2022-10-04 01:49:47 +03:00
#endif