#ifndef _SYS_TEM_H
#define _SYS_TEM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <sys/visual_io.h>
#include <sys/font.h>
#include <sys/list.h>
#include <sys/tem.h>
#include <sys/rgb.h>
#include <bootstrap.h>
#include <stdbool.h>
#define TEM_ATTR_MASK 0x7FF
#define TEM_CHAR(c) ((c) & 0x1fffff)
#define TEM_CHAR_ATTR(c) (((c) >> 21) & TEM_ATTR_MASK)
#define TEM_ATTR(c) (((c) & TEM_ATTR_MASK) << 21)
#define TEM_ATTR_ISSET(c, a) ((TEM_CHAR_ATTR(c) & (a)) == (a))
#define TEM_MAXPARAMS 32
#define TEM_MAXFKEY 30
#define MAX_TEM 2
#define TEM_SCROLL_UP 0
#define TEM_SCROLL_DOWN 1
#define TEM_SHIFT_LEFT 0
#define TEM_SHIFT_RIGHT 1
#define TEM_ATTR_NORMAL 0x0000
#define TEM_ATTR_REVERSE 0x0001
#define TEM_ATTR_BOLD 0x0002
#define TEM_ATTR_BLINK 0x0004
#define TEM_ATTR_UNDERLINE 0x0008
#define TEM_ATTR_SCREEN_REVERSE 0x0010
#define TEM_ATTR_BRIGHT_FG 0x0020
#define TEM_ATTR_BRIGHT_BG 0x0040
#define TEM_ATTR_TRANSPARENT 0x0080
#define TEM_ATTR_IMAGE 0x0100
#define TEM_ATTR_RGB_FG 0x0200
#define TEM_ATTR_RGB_BG 0x0400
#define ANSI_COLOR_BLACK 0
#define ANSI_COLOR_RED 1
#define ANSI_COLOR_GREEN 2
#define ANSI_COLOR_YELLOW 3
#define ANSI_COLOR_BLUE 4
#define ANSI_COLOR_MAGENTA 5
#define ANSI_COLOR_CYAN 6
#define ANSI_COLOR_WHITE 7
#define TEM_TEXT_WHITE 0
#define TEM_TEXT_BLACK 1
#define TEM_TEXT_BLACK24_RED 0x00
#define TEM_TEXT_BLACK24_GREEN 0x00
#define TEM_TEXT_BLACK24_BLUE 0x00
#define TEM_TEXT_WHITE24_RED 0xff
#define TEM_TEXT_WHITE24_GREEN 0xff
#define TEM_TEXT_WHITE24_BLUE 0xff
#define A_STATE_START 0
#define A_STATE_ESC 1
#define A_STATE_CSI 2
#define A_STATE_CSI_QMARK 3
#define A_STATE_CSI_EQUAL 4
#define TEM_DEFAULT_ROWS 25
#define TEM_DEFAULT_COLS 80
#if !defined(DEFAULT_ANSI_FOREGROUND) && !defined(DEFAULT_ANSI_BACKGROUND)
#define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_BLACK
#define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_WHITE
#endif
#define BUF_LEN 160
typedef uint32_t tem_char_t;
typedef union {
uint32_t n;
struct bgra {
uint8_t b;
uint8_t g;
uint8_t r;
uint8_t a;
} rgb;
} text_color_t;
typedef uint16_t text_attr_t;
typedef struct tem_color {
text_color_t fg_color;
text_color_t bg_color;
text_attr_t a_flags;
} tem_color_t;
struct tem_pix_pos {
screen_pos_t x;
screen_pos_t y;
};
struct tem_char_pos {
screen_pos_t col;
screen_pos_t row;
};
struct tem_size {
screen_size_t width;
screen_size_t height;
};
typedef struct term_char {
text_color_t tc_fg_color;
text_color_t tc_bg_color;
tem_char_t tc_char;
} term_char_t;
#define TVS_AUTOWRAP 0x00000001
#define TVS_WRAPPED 0x00000002
struct tem_vt_state {
uint8_t tvs_fbmode;
uint8_t tvs_alpha;
text_attr_t tvs_flags;
int tvs_state;
uint_t tvs_stateflags;
bool tvs_gotparam;
int tvs_curparam;
int tvs_paramval;
int tvs_params[TEM_MAXPARAMS];
screen_pos_t *tvs_tabs;
size_t tvs_maxtab;
size_t tvs_ntabs;
int tvs_nscroll;
struct tem_char_pos tvs_s_cursor;
struct tem_char_pos tvs_c_cursor;
struct tem_char_pos tvs_r_cursor;
term_char_t *tvs_outbuf;
int tvs_outindex;
void *tvs_pix_data;
unsigned tvs_pix_data_size;
text_color_t tvs_fg_color;
text_color_t tvs_bg_color;
int tvs_first_line;
term_char_t *tvs_screen_buf;
unsigned tvs_utf8_left;
tem_char_t tvs_utf8_partial;
bool tvs_isactive;
bool tvs_initialized;
bool tvs_cursor_hidden;
list_node_t tvs_list_node;
};
typedef struct tem_callbacks {
void (*tsc_display)(struct tem_vt_state *, term_char_t *, int,
screen_pos_t, screen_pos_t);
void (*tsc_copy)(struct tem_vt_state *,
screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
screen_pos_t, screen_pos_t);
void (*tsc_cursor)(struct tem_vt_state *, short);
void (*tsc_bit2pix)(struct tem_vt_state *, term_char_t *);
void (*tsc_cls)(struct tem_vt_state *, int, screen_pos_t, screen_pos_t);
} tem_callbacks_t;
typedef struct __tem_modechg_cb_arg *tem_modechg_cb_arg_t;
typedef void (*tem_modechg_cb_t) (tem_modechg_cb_arg_t arg);
typedef struct __tem_vt_state *tem_vt_state_t;
typedef struct tem_state {
struct console *ts_hdl;
screen_size_t ts_linebytes;
int ts_display_mode;
struct tem_size ts_c_dimension;
struct tem_size ts_p_dimension;
struct tem_pix_pos ts_p_offset;
unsigned ts_pix_data_size;
int ts_pdepth;
struct font ts_font;
bool update_font;
tem_callbacks_t *ts_callbacks;
int ts_initialized;
tem_modechg_cb_t ts_modechg_cb;
tem_modechg_cb_arg_t ts_modechg_arg;
color_map_fn_t ts_color_map;
tem_color_t ts_init_color;
struct tem_vt_state *ts_active;
list_t ts_list;
} tem_state_t;
extern tem_state_t tems;
int tems_cls(struct vis_consclear *);
void tems_display(struct vis_consdisplay *);
void tems_copy(struct vis_conscopy *);
void tems_cursor(struct vis_conscursor *);
int tem_initialized(tem_vt_state_t);
tem_vt_state_t tem_init(void);
int tem_info_init(struct console *);
void tem_write(tem_vt_state_t, uint8_t *, ssize_t);
void tem_get_size(uint16_t *, uint16_t *, uint16_t *, uint16_t *);
void tem_save_state(void);
void tem_register_modechg_cb(tem_modechg_cb_t, tem_modechg_cb_arg_t);
void tem_activate(tem_vt_state_t, bool);
void tem_get_colors(tem_vt_state_t, text_color_t *, text_color_t *);
void tem_image_display(struct tem_vt_state *, screen_pos_t, screen_pos_t,
screen_pos_t, screen_pos_t);
#ifdef __cplusplus
}
#endif
#endif