diff options
Diffstat (limited to 'escape.h')
-rw-r--r-- | escape.h | 67 |
1 files changed, 55 insertions, 12 deletions
@@ -12,6 +12,16 @@ //nF ESC[0x20-02F]*[0x30-0x7E] //Fp ESC[0x30-0x3F] save and clear + +//Clearing commands +//ESC c +//ESC [ [1-3] J + +//ESC [ [1-2] K +//ESC [ m @ +// note: these two can't clear im preview b/c of scroll locking + + //last read key enum esc_state { //C0 except BEL or ESC, \n ,\r and \f @@ -59,14 +69,22 @@ int safe_state(enum esc_state state) { enum esc_state in_state = NORMAL; //global pty -> stdout ESC state enum esc_state out_state = NORMAL; +//global output parity +int out_c_parity = 0; +//global output clear state, cleared by im_routine_update +int out_clr = 0; -//c0 c1 c2 osc, sf nF sequences +//updates the state, the return is the type of the last character read -//also ESC 7 and ESC 8 up down bit -//have a semaphore and above lock, IM will draw if available when input updates -//or if some time has passed since output has been written +//updates c parity depending on cursor store and restore + //if c parity is not NULL +//sets clr to 1 if it encounters a cursor clear escape sequence + // if clr is not NULL -enum esc_state update_esc_state(char * buff,unsigned int buff_len, enum esc_state state) { +enum esc_state update_esc_state(char * buff,unsigned int buff_len, + enum esc_state state, + int * c_parity, int * clr) +{ for (int i = 0; i < buff_len; i++) { char c = buff[i]; switch (state) { @@ -92,8 +110,13 @@ enum esc_state update_esc_state(char * buff,unsigned int buff_len, enum esc_stat } break; case ESC: + if (c == 'c') { + if (clr != NULL) { + *clr = 1; + } + } //fix length C1 - if (c == 'N' || c == 'O') { + else if (c == 'N' || c == 'O') { state = C1; } else if (c == '[') { @@ -103,18 +126,32 @@ enum esc_state update_esc_state(char * buff,unsigned int buff_len, enum esc_stat else if (c == ']' || c =='P' || c == '^' || c == 'X' || c == '_') { state = C1_START; } - //nF - else if (c >= 0x20 && c <= 0x2F) { - state = nF_START; - } else if (c == '\\') { state - ST; } else if (c == '7') { state = DECSC; + if ( c_parity != NULL) { + *c_parity++; + } } else if (c == '8') { - state = DECSC; + state = DECRC; + if ( c_parity != NULL) { + *c_parity--; + } + } + //nF + else if (c >= 0x20 && c <= 0x2F) { + state = nF_START; + } + //all other Fe/C1 Sequences, should be fixed len + else if (c >= 0x40 && c <= 0x5F) { + state = C1; + } + //Fs Sequences + else if (c >= 0x60 && c <= 0x7E) { + state = C1; } else if (c == 0x1B) { state = DOUBLE_ESC; @@ -134,7 +171,12 @@ enum esc_state update_esc_state(char * buff,unsigned int buff_len, enum esc_stat break; case CSI_START: case CSI_MID: - if (c >= 0x30 && c <= 0x3F) { + if (c == 'J') { + state = CSI_END; + if (clr != NULL) { + *clr = 1; + } + } else if (c >= 0x30 && c <= 0x3F) { state = CSI_MID; } else if (c >= 0x20 && c <= 0x2F) { state = CSI_MID; @@ -159,3 +201,4 @@ enum esc_state update_esc_state(char * buff,unsigned int buff_len, enum esc_stat } return state; } + |