edecde95de7b78bfb267dce3ca93f81189f0b38f
[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
35 typedef struct mtty_row_t mtty_row_t;
36
37 typedef struct {
38     int   pty;
39     pid_t childpid;
40
41     /* flags */
42     unsigned seen_input : 1;
43     unsigned insert     : 1;
44     unsigned escaped    : 1;
45     unsigned graphmode  : 1;
46     unsigned curshid    : 1;
47
48     /* geometry */
49     int rows, cols;
50
51     mtty_row_t *lines;
52     mtty_row_t *scroll_top;
53     mtty_row_t *scroll_bot;
54
55     /* cursor */
56     unsigned curattrs;
57     mtty_row_t *curs_row;
58     int curs_col;
59     int curs_srow, curs_scol;
60
61     /* buffers and parsing state */
62     mbstate_t ps;
63     char rbuf[BUFSIZ];
64     char ebuf[BUFSIZ];
65     int  rlen, elen;
66 } madtty_t;
67
68 void madtty_initialize(void);
69
70 madtty_t *madtty_create(int rows, int cols);
71 void madtty_resize(madtty_t *rt, int rows, int cols);
72 void madtty_destroy(madtty_t *rt);
73 pid_t madtty_forkpty(madtty_t *rt, const char *path, const char *argv[]);
74
75 int madtty_process(madtty_t *rt);
76 void madtty_keypress(madtty_t *rt, int keycode);
77 void madtty_draw(madtty_t *rt, WINDOW *win, int startrow, int startcol);
78
79
80 #endif /* MADTTY_MADTTY_H */