lt/term.h -rw-r--r-- 2.5 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef TERM_H
#define TERM_H

#include <stdint.h>
#include <stdbool.h>

typedef struct {
    uint_least32_t      u;      /*!< Character code (UTF-8) */
    unsigned short      mode;   /*!< Attribute flags */
    uint32_t            fg;     /*!< Foreground color */
    uint32_t            bg;     /*!< Background color */
} char_t;

typedef struct {
    char_t      attr;   /*!< Current char attributes */
    int         x;      /*!< X position */
    int         y;      /*!< Y position */
    uint8_t     state;  /*!< Cursor state */
} cursor_t;

enum cursor_state {
    CURSOR_DEFAULT      = 0,
    CURSOR_WRAPNEXT     = 1,
    CURSOR_ORIGIN       = 2
};

enum cursor_mouvement {
    CURSOR_SAVE,
    CURSOR_LOAD
};

enum escape_state {
    ESC_START      = 1,
    ESC_CSI        = 2,
    ESC_STR        = 4,
    ESC_ALTCHARSET = 8,
    ESC_STR_END    = 16,
    ESC_TEST       = 32,
    ESC_UTF8       = 64,
    ESC_DCS        = 128,
};

typedef struct {
    int         row;            /*!< Number of rows */
    int         col;            /*!< Number of columns */
    char_t      **line;         /*!< Screen buffer */
    char_t      **alt;          /*!< Alternate Screen buffer */
    int         *dirty;         /*!< Dirtyness of lines */
    cursor_t    c;              /*!< Cursor */
    int         ocx;            /*!< Old cursor column */
    int         ocy;            /*!< Old cursor row */
    int         top;            /*!< Top scroll limit */
    int         bot;            /*!< Bottom scroll limit */
    int         mode;           /*!< Terminal mode flags */
    int         esc;            /*!< Escape state flags */
    char        trant_bl[4];    /*!< Charset table translation */
    int         charset;        /*!< Current charset */
    int         icharset;       /*!< Selected charset for sequence */
    int         *tabs;
} term_t;

enum term_mode {
    MODE_WRAP           = 1 << 0,
    MODE_INSERT         = 1 << 1,
    MODE_ALTSCREEN      = 1 << 2,
    MODE_CRLF           = 1 << 3,
    MODE_ECHO           = 1 << 4,
    MODE_PRINT          = 1 << 5,
    MODE_UTF8           = 1 << 6,
    MODE_SIXEL          = 1 << 7,
};

void term_init(term_t *t, int col, int row);
void term_dtr(term_t *t);
void term_set_scroll(term_t *t, int a, int b);
void term_move_to(term_t *t, int x, int y);
void term_clear_region(term_t *t, int x1, int y1, int x2, int y2);
void term_swap_screen(term_t *t);
void term_cursor(term_t *t, int mode);
int term_write(term_t *term, const char *buf, int len, bool show_ctrl);
void term_putc(term_t *t, uint_least32_t u);

#endif /* TERM_H */