X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=madtty%2Fmadtty.h;h=69d7288a3079a0521d7e741d39745d2816ebb60a;hb=d0e48d929c19d39c4a13e57e0f8a8dd6194d6dde;hp=cd51378200079458af6c19e907ae7d13accbf90f;hpb=fcbd5f6835f65055d0ac14d3a2da3afb39634fd3;p=apps%2Fmadtty.git diff --git a/madtty/madtty.h b/madtty/madtty.h index cd51378..69d7288 100644 --- a/madtty/madtty.h +++ b/madtty/madtty.h @@ -74,9 +74,9 @@ #define ROTE_ATTR_MOD_XBG(attr, newxbg) attr &= 0xF0, attr |= (newxbg) #define ROTE_ATTR_MOD_XFG(attr, newxfg) attr &= 0x0F, attr |= ((newxfg) << 4) #define ROTE_ATTR_MOD_BOLD(attr, boldbit) \ - attr &= 0x7F, attr |= (boldbit)?0x80:0x00 + attr &= 0x7F, attr |= (boldbit)?0x80:0x00 #define ROTE_ATTR_MOD_BLINK(attr, blinkbit) \ - attr &= 0xF7, attr |= (blinkbit)?0x08:0x00 + attr &= 0xF7, attr |= (blinkbit)?0x08:0x00 /* these return non-zero for 'yes', zero for 'no'. Don't rely on them being * any more specific than that (e.g. being exactly 1 for 'yes' or whatever). */ @@ -85,10 +85,10 @@ /* Represents each of the text cells in the terminal screen */ typedef struct RoteCell_ { - unsigned char ch; /* >= 32, that is, control characters are not - * allowed to be on the virtual screen */ + unsigned char ch; /* >= 32, that is, control characters are not + * allowed to be on the virtual screen */ - unsigned char attr; /* a color attribute, as described previously */ + unsigned char attr; /* a color attribute, as described previously */ } RoteCell; /* Declaration of opaque rote_Term_Private structure */ @@ -98,38 +98,39 @@ typedef struct RoteTermPrivate_ RoteTermPrivate; * of this structure, but please pay close attention to the fields * marked read-only or with special usage notes. */ typedef struct RoteTerm_ { - int rows, cols; /* terminal dimensions, READ-ONLY. You - * can't resize the terminal by changing - * this (a segfault is about all you will - * accomplish). */ - - RoteCell **cells; /* matrix of cells. This - * matrix is indexed as cell[row][column] - * where 0 <= row < rows and - * 0 <= col < cols - * - * You may freely modify the contents of - * the cells. - */ - - int crow, ccol; /* cursor coordinates. READ-ONLY. */ - - unsigned char curattr; /* current attribute, that is the attribute - * that will be used for newly inserted - * characters */ - - pid_t childpid; /* pid of the child process running in the - * terminal; 0 for none. This is READ-ONLY. */ - - RoteTermPrivate *pd; /* private state data */ - - bool insert; /* insert or replace mode */ - /* --- dirtiness flags: the following flags will be raised when the - * corresponding items are modified. They can only be unset by YOU - * (when, for example, you redraw the term or something) --- */ - bool curpos_dirty; /* whether cursor location has changed */ - bool *line_dirty; /* whether each row is dirty */ - /* --- end dirtiness flags */ + int rows, cols; /* terminal dimensions, READ-ONLY. You + * can't resize the terminal by changing + * this (a segfault is about all you will + * accomplish). */ + + RoteCell **cells; /* matrix of cells. This + * matrix is indexed as cell[row][column] + * where 0 <= row < rows and + * 0 <= col < cols + * + * You may freely modify the contents of + * the cells. + */ + + int crow, ccol; /* cursor coordinates. READ-ONLY. */ + + unsigned char curattr; /* current attribute, that is the attribute + * that will be used for newly inserted + * characters */ + + int pty; /* pty of the process */ + pid_t childpid; /* pid of the child process running in the + * terminal; 0 for none. This is READ-ONLY. */ + + RoteTermPrivate *pd; /* private state data */ + + bool insert; /* insert or replace mode */ + /* --- dirtiness flags: the following flags will be raised when the + * corresponding items are modified. They can only be unset by YOU + * (when, for example, you redraw the term or something) --- */ + bool curpos_dirty; /* whether cursor location has changed */ + bool *line_dirty; /* whether each row is dirty */ + /* --- end dirtiness flags */ } RoteTerm; /* Creates a new virtual terminal with the given dimensions. You @@ -166,7 +167,7 @@ void rote_vt_destroy(RoteTerm *rt); * to execute the command and will exit with status 127. You can catch * that by installing a SIGCHLD handler if you want. */ -pid_t rote_vt_forkpty(RoteTerm *rt, const char *command); +pid_t rote_vt_forkpty(RoteTerm *rt, const char *path, const char *argv[]); /* Disconnects the RoteTerm from its forked child process. This function * should be called when the child process dies or something of the sort. @@ -183,6 +184,8 @@ void rote_vt_forsake_child(RoteTerm *rt); * read from the child process it will return immediately. */ void rote_vt_update(RoteTerm *rt); +int rote_vt_read(RoteTerm *rt, char *buf, int buflen); + /* Puts data into the terminal: if there is a forked process running, * the data will be sent to it. If there is no forked process, * the data will simply be injected into the terminal (as in @@ -240,64 +243,4 @@ void *rote_vt_take_snapshot(RoteTerm *rt); * This function does NOT free() the passed buffer */ void rote_vt_restore_snapshot(RoteTerm *rt, void *snapbuf); -/* Returns the pseudo tty descriptor associated with the given terminal. - * Please don't do weird things with it (like close it for instance), - * or things will break - * - * This function returns -1 if the given terminal does not yet have - * an associated pty. A pty is only associated to a terminal when - * needed, e.g. on a call to rote_vt_forkpty. */ -int rote_vt_get_pty_fd(RoteTerm *rt); - -/* Declaration of custom escape sequence callback type. See the - * rote_vt_add_es_handler function for more info */ -typedef int (*rote_es_handler_t)(RoteTerm *rt, const char *es); - -/* Installs a custom escape sequence handler for the given RoteTerm. - * The handler will be called by the library every time it tries to - * recognize an escape sequence; depending on the return value of the - * handler, it will proceed in a different manner. See the description - * of the possible return values (ROTE_HANDLERESULT_* constants) below - * for more info. - * - * This handler will be called EACH TIME THE ESCAPE SEQUENCE BUFFER - * RECEIVES A CHARACTER. Therefore, it must execute speedily in order - * not to create too heavy a performance penalty. In particular, the - * writer of the handler should take care to quickly test for invalid - * or incomplete escape sequences before trying to do more elaborate - * parsing. - * - * The handler will NOT be called with an empty escape sequence (i.e. - * one in which only the initial ESC was received). - * - * The custom handler receives the terminal it pertains to and the - * escape sequence as a string (without the initial escape character). - * - * The handler may of course modify the terminal as it sees fit, taking - * care not to corrupt it of course (in particular, it should appropriately - * raise the line_dirty[] and curpos_dirty flags to indicate what it has - * changed). - */ -void rote_vt_install_handler(RoteTerm *rt, rote_es_handler_t handler); - -/* Possible return values for the custom handler function and their - * meanings: */ -#define ROTE_HANDLERESULT_OK 0 /* means escape sequence was handled */ - -#define ROTE_HANDLERESULT_NOTYET 1 /* means the escape sequence was not - * recognized yet, but there is hope that - * it still will once more characters - * arrive (i.e. it is not yet complete). - * - * The library will thus continue collecting - * characters and calling the handler as - * each character arrives until - * either OK or NOWAY is returned. - */ - -#define ROTE_HANDLERESULT_NOWAY 2 /* means the escape sequence was not - * recognized, and there is no chance - * that it will even if more characters - * are added to it. */ - #endif /* MADTTY_MADTTY_H */