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
126
127
128
129
130
131
132
133
|
#include "internal.h"
#include "screen.h"
_Thread_local char term_thread_anchor;
const char *term_unicode_version(void)
{
return UNICODE_DATA_VERSION;
}
unsigned term_version(void)
{
return TERM_VERSION_CODE;
}
void term_lock(struct term *t)
{
term_write_begin(t);
}
void term_unlock(struct term *t)
{
term_write_end(t);
}
struct term_vector2i term_size(const struct term *t)
{
if (!t)
return (struct term_vector2i){ 0 };
term_write_begin((struct term *)t);
struct term_vector2i size = { .x = t->cols, .y = t->rows };
term_write_end((struct term *)t);
return size;
}
struct term_modes term_modes(const struct term *t)
{
if (!t)
return (struct term_modes){ 0 };
term_write_begin((struct term *)t);
struct term_modes m = {
.keyboard = t->keyboard[t->alternate].flags,
.mouse = (enum term_mouse)t->mouse_mode,
.mouse_encoding = (enum term_mouse_encoding)t->mouse_encoding,
.grid = { .x = t->cols, .y = t->rows },
.app_cursor = t->application_cursor,
.app_keypad = t->application_keypad,
.backarrow_bs = t->backarrow_sends_bs,
.bracketed_paste = t->bracketed_paste,
.focus_events = t->focus_events,
.alternate = t->alternate,
.reverse_video = t->reverse_video,
.synchronized = t->synchronized_output,
};
term_write_end((struct term *)t);
return m;
}
struct term_cursor term_cursor(const struct term *t)
{
if (!t)
return (struct term_cursor){ .visible = true };
term_write_begin((struct term *)t);
struct term_cursor c = {
.pos = { .x = t->cursor_x, .y = t->cursor_y },
.style = t->cursor_style,
.visible = t->cursor_visible,
.blink = t->cursor_blink,
};
term_write_end((struct term *)t);
return c;
}
void term_set_cursor_default(struct term *t, enum term_cursor_style style, bool steady)
{
if (!t)
return;
term_write_begin(t);
if (style > TERM_CURSOR_BAR)
style = TERM_CURSOR_BLOCK;
if (t->cursor_style != style || t->cursor_blink == steady) {
struct srow *cur = term_row(t, t->cursor_y);
if (cur) cur->version++;
}
t->default_cursor_style = t->cursor_style = style;
t->default_cursor_blink = t->cursor_blink = !steady;
term_write_end(t);
}
void term_set_theme(struct term *t, const struct term_theme *theme)
{
if (!t)
return;
term_write_begin(t);
struct palette next = { .version = t->palette.version };
term_palette_init(&next, theme);
if (memcmp(&next.theme, &t->palette.theme, sizeof(next.theme)))
t->palette = next;
term_write_end(t);
}
void term_focus(struct term *t, bool focused)
{
if (!t)
return;
term_write_begin(t);
if (t->focus_events)
send_response(t, focused ? "\033[I" : "\033[O");
term_write_end(t);
}
char *term_cwd(const struct term *t)
{
if (!t) return NULL;
term_write_begin((struct term *)t);
char *text = t->cwd ? term_strdup(t->cwd) : NULL;
term_write_end((struct term *)t);
return text;
}
char *term_pointer_shape(const struct term *t)
{
if (!t) return NULL;
term_write_begin((struct term *)t);
char *text = t->pointer_shape ? term_strdup(t->pointer_shape) : NULL;
term_write_end((struct term *)t);
return text;
}
void term_text_free(char *text)
{
free(text);
}
|