summaryrefslogtreecommitdiff
path: root/uuterm.h
blob: defe16f63e1516f88f6160d404d5d2091af1db8c (plain) (blame)
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
/* uuterm, Copyright (C) 2006 Rich Felker; licensed under GNU GPL v2 only */

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

struct uucell
{
	uint32_t x[3];
};

struct uurow
{
	int idx;
	int x1, x2; /* dirty region */
	struct uucell cells[1];
};

/* Cell-preserved attributes must lie in 0xC000FC01, see cell.c */

#define UU_ATTR_UL      0x00000001
#define UU_ATTR_BOLD    0x00000002
#define UU_ATTR_BLINK   0x00000004
#define UU_ATTR_DIM     0x00000008
#define UU_ATTR_REV     0x00000010

struct uuterm
{
	struct uurow **rows;
	int w, h;

	// all members past this point are zero-filled on reset!
	int reset;

	// output state
	int x, y;
	int attr;
	int color;
	int sr_y1, sr_y2;
	int ins  :1;
	int am   :1;
	int noam :1;

	// input state
	int ckp  :1;
	int kp   :1;
	char reslen;
	char res[16];

	// saved state
	int save_x, save_y;
	int save_attr, save_fg, save_bg;

	// escape sequence processing
	int esc;
	unsigned param[16];
	int nparam;

	// multibyte parsing
	mbstate_t mbs;
};

struct uudisp
{
	int cell_w, cell_h;
	int w, h;
	int inlen;
	unsigned char *intext;
	unsigned char inbuf[16];
	int blink;
	void *font;
	long priv[64];
};

#define UU_FULLWIDTH 0xfffe

#define UU_ROW_SIZE(w) (sizeof(struct uurow) + (w)*sizeof(struct uucell))
#define UU_BUF_SIZE(w, h) ( (h) * (sizeof(struct uurow *) * UU_ROW_SIZE((w))) )

void uuterm_reset(struct uuterm *);
void uuterm_replace_buffer(struct uuterm *, int, int, void *);
void uuterm_stuff_byte(struct uuterm *, unsigned char);

void uuterm_refresh_row(struct uudisp *, struct uurow *, int, int);

void uucell_set(struct uucell *, wchar_t, int, int);
void uucell_append(struct uucell *, wchar_t);
int uucell_get_attr(struct uucell *);
int uucell_get_color(struct uucell *);
int uucell_get_wcs(struct uucell *, wchar_t *, size_t);

int uu_decompose_char(unsigned, unsigned *, unsigned);

int uudisp_open(struct uudisp *);
int uudisp_fd_set(struct uudisp *, int, void *);
void uudisp_next_event(struct uudisp *, void *);
void uudisp_close(struct uudisp *);
void uudisp_refresh(struct uudisp *, struct uuterm *);
void uudisp_predraw_cell(struct uudisp *, int, int, int);
void uudisp_draw_glyph(struct uudisp *, int, int, const void *);

void *uuterm_alloc(size_t);
void uuterm_free(void *);
void *uuterm_buf_alloc(int, int);

void uutty_resize(int, int, int);
int uutty_open(char **, int, int);