Support any encoding available here, mostly.
[apps/madtty.git] / madtty / madtty.h
1 /*
2     LICENSE INFORMATION:
3     This program is free software; you can redistribute it and/or
4     modify it under the terms of the GNU Lesser General Public
5     License (LGPL) as published by the Free Software Foundation.
6
7     Please refer to the COPYING file for more information.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     General Public License for more details.
13
14     You should have received a copy of the GNU Lesser General Public
15     License along with this program; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17
18     Copyright © 2004 Bruno T. C. de Oliveira
19     Copyright © 2006 Pierre Habouzit
20  */
21
22 #ifndef MADTTY_MADTTY_H
23 #define MADTTY_MADTTY_H
24
25 #include <ncurses.h>
26 #include <stdbool.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #include <unistd.h>
31 #include <wchar.h>
32
33 #define MAX_CSI_ES_PARAMS 32
34 #define ESEQ_BUF_SIZE     128  /* size of escape sequence buffer */
35
36 typedef struct mtty_row_t {
37     wchar_t  *text;
38     uint16_t *attr;
39 } mtty_row_t;
40
41 /* Represents each of the text cells in the terminal screen */
42 typedef struct {
43     char s[4];
44     char len;
45     int16_t attrs;
46 } RoteCell;
47
48 typedef struct {
49     int   pty;
50     pid_t childpid;
51
52     /* flags */
53     unsigned insert    : 1;
54     unsigned escaped   : 1;
55     unsigned graphmode : 1;
56
57     /* geometry */
58     int rows, cols;
59
60     mtty_row_t *lines;
61     mtty_row_t *scroll_top;
62     mtty_row_t *scroll_bot;
63
64     /* cursor */
65     unsigned curattrs;
66     mtty_row_t *curs_row;
67     int curs_col;
68     int curs_srow, curs_scol;
69
70     /* buffers and parsing state */
71     mbstate_t ps;
72     char rbuf[BUFSIZ];
73     char esbuf[ESEQ_BUF_SIZE];
74     int  rbuf_len, esbuf_len;
75 } madtty_t;
76
77 void madtty_initialize(void);
78
79 madtty_t *madtty_create(int rows, int cols);
80 void madtty_destroy(madtty_t *rt);
81 pid_t madtty_forkpty(madtty_t *rt, const char *path, const char *argv[]);
82
83 int madtty_process(madtty_t *rt);
84 void madtty_keypress(madtty_t *rt, int keycode);
85 void madtty_draw(madtty_t *rt, WINDOW *win, int startrow, int startcol);
86
87
88 #endif /* MADTTY_MADTTY_H */