more refactoring
[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 <ncursesw/curses.h>
26 #include <stdbool.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #include <unistd.h>
31
32 #define MAX_CSI_ES_PARAMS 32
33 #define ESEQ_BUF_SIZE     128  /* size of escape sequence buffer */
34
35 /* Represents each of the text cells in the terminal screen */
36 typedef struct {
37     char s[4];
38     char len;
39     attr_t attrs;
40 } RoteCell;
41
42 typedef struct {
43     int   pty;
44     pid_t childpid;
45
46     /* flags */
47     unsigned insert    : 1;
48     unsigned escaped   : 1;
49     unsigned graphmode : 1;
50
51     /* geometry */
52     int rows, cols;
53     int scrolltop, scrollbottom;
54     RoteCell **cells;
55
56     /* cursor */
57     attr_t curattrs;
58     int curs_row, curs_col;
59     int curs_srow, curs_scol;
60
61     char esbuf[ESEQ_BUF_SIZE];
62     int  esbuf_len;
63 } madtty_t;
64
65 void madtty_initialize(void);
66
67 madtty_t *madtty_create(int rows, int cols);
68 void madtty_destroy(madtty_t *rt);
69 pid_t madtty_forkpty(madtty_t *rt, const char *path, const char *argv[]);
70
71 int madtty_read(madtty_t *rt, char *buf, int buflen);
72 int madtty_write(madtty_t *rt, const char *data, int length);
73
74 int madtty_inject(madtty_t *rt, const char *data, int length);
75 void madtty_draw(madtty_t *rt, WINDOW *win, int startrow, int startcol);
76
77 void madtty_keypress(madtty_t *rt, int keycode);
78
79 #endif /* MADTTY_MADTTY_H */