aboutsummaryrefslogtreecommitdiff
path: root/terminal.h
blob: 7a033330c7f28512246d28be5858503925ce2d29 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once

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

#include <threads.h>

#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-keysyms.h>

#include "tllist.h"

struct attributes {
    bool bold;
    bool italic;
    bool underline;
    bool strikethrough;
    bool blink;
    bool conceal;
    bool reverse;
    uint32_t foreground;
    uint32_t background;
};

struct cell {
    char c[5];
    struct attributes attrs;
};

enum damage_type {DAMAGE_UPDATE, DAMAGE_ERASE, DAMAGE_SCROLL};
struct damage {
    enum damage_type type;
    union {
        /* DAMAGE_UPDATE, DAMAGE_ERASE */
        struct {
            int start;
            int length;
        } range;

        /* DAMAGE_SCROLL */
        struct {
            int top_margin;
            int bottom_margin;
            int lines;
        } scroll;
    };
};

struct grid {
    int cols;
    int rows;
    int cell_width;
    int cell_height;

    int linear_cursor;
    struct {
        int row;
        int col;
    } cursor;
    bool print_needs_wrap;

    struct cell *cells;

    uint32_t foreground;
    uint32_t background;

    tll(struct damage) damage;
};

struct vt {
    int state;  /* enum state */
    struct {
        struct {
            unsigned value;
            struct {
                unsigned value[16];
                size_t idx;
            } sub;
        } v[16];
        size_t idx;
    } params;
    struct {
        uint8_t data[2];
        size_t idx;
    } intermediates;
    struct {
        uint8_t data[1024];
        size_t idx;
    } osc;
    struct {
        uint8_t data[4];
        size_t idx;
        size_t left;
    } utf8;
    struct attributes attrs;
    bool dim;
};

struct kbd {
    struct xkb_context *xkb;
    struct xkb_keymap *xkb_keymap;
    struct xkb_state *xkb_state;
    struct {
        mtx_t mutex;
        cnd_t cond;
        int trigger;
        int pipe_read_fd;
        int pipe_write_fd;
        enum {REPEAT_STOP, REPEAT_START, REPEAT_EXIT} cmd;

        bool dont_re_repeat;
        int32_t delay;
        int32_t rate;
        uint32_t key;
    } repeat;
};

struct terminal {
    pid_t slave;
    int ptmx;
    struct vt vt;
    struct grid grid;
    struct kbd kbd;
};