Lines Matching refs:state

20 static void putglyph(VTermState *state, const uint32_t chars[], int width, VTermPos pos)  in putglyph()  argument
25 .protected_cell = state->protected_cell, in putglyph()
26 .dwl = state->lineinfo[pos.row].doublewidth, in putglyph()
27 .dhl = state->lineinfo[pos.row].doubleheight, in putglyph()
30 if(state->callbacks && state->callbacks->putglyph) in putglyph()
31 if((*state->callbacks->putglyph)(&info, pos, state->cbdata)) in putglyph()
37 static void updatecursor(VTermState *state, VTermPos *oldpos, int cancel_phantom) in updatecursor() argument
39 if(state->pos.col == oldpos->col && state->pos.row == oldpos->row) in updatecursor()
43 state->at_phantom = 0; in updatecursor()
45 if(state->callbacks && state->callbacks->movecursor) in updatecursor()
46 …if((*state->callbacks->movecursor)(state->pos, *oldpos, state->mode.cursor_visible, state->cbdata)) in updatecursor()
50 static void erase(VTermState *state, VTermRect rect, int selective) in erase() argument
52 if(state->callbacks && state->callbacks->erase) in erase()
53 if((*state->callbacks->erase)(rect, selective, state->cbdata)) in erase()
59 VTermState *state = vterm_allocator_malloc(vt, sizeof(VTermState)); in vterm_state_new() local
61 state->vt = vt; in vterm_state_new()
63 state->rows = vt->rows; in vterm_state_new()
64 state->cols = vt->cols; in vterm_state_new()
66 vterm_state_newpen(state); in vterm_state_new()
68 state->bold_is_highbright = 0; in vterm_state_new()
70 return state; in vterm_state_new()
73 INTERNAL void vterm_state_free(VTermState *state) in vterm_state_free() argument
75 vterm_allocator_free(state->vt, state->tabstops); in vterm_state_free()
76 vterm_allocator_free(state->vt, state->lineinfo); in vterm_state_free()
77 vterm_allocator_free(state->vt, state->combine_chars); in vterm_state_free()
78 vterm_allocator_free(state->vt, state); in vterm_state_free()
81 static void scroll(VTermState *state, VTermRect rect, int downward, int rightward) in scroll() argument
87 if(rect.start_col == 0 && rect.end_col == state->cols && rightward == 0) { in scroll()
91 memmove(state->lineinfo + rect.start_row, in scroll()
92 state->lineinfo + rect.start_row + downward, in scroll()
93 height * sizeof(state->lineinfo[0])); in scroll()
95 memmove(state->lineinfo + rect.start_row - downward, in scroll()
96 state->lineinfo + rect.start_row, in scroll()
97 height * sizeof(state->lineinfo[0])); in scroll()
100 if(state->callbacks && state->callbacks->scrollrect) in scroll()
101 if((*state->callbacks->scrollrect)(rect, downward, rightward, state->cbdata)) in scroll()
104 if(state->callbacks) in scroll()
106 state->callbacks->moverect, state->callbacks->erase, state->cbdata); in scroll()
109 static void linefeed(VTermState *state) in linefeed() argument
111 if(state->pos.row == SCROLLREGION_BOTTOM(state) - 1) { in linefeed()
113 .start_row = state->scrollregion_top, in linefeed()
114 .end_row = SCROLLREGION_BOTTOM(state), in linefeed()
115 .start_col = SCROLLREGION_LEFT(state), in linefeed()
116 .end_col = SCROLLREGION_RIGHT(state), in linefeed()
119 scroll(state, rect, 1, 0); in linefeed()
121 else if(state->pos.row < state->rows-1) in linefeed()
122 state->pos.row++; in linefeed()
125 static void grow_combine_buffer(VTermState *state) in grow_combine_buffer() argument
127 size_t new_size = state->combine_chars_size * 2; in grow_combine_buffer()
128 uint32_t *new_chars = vterm_allocator_malloc(state->vt, new_size * sizeof(new_chars[0])); in grow_combine_buffer()
130 memcpy(new_chars, state->combine_chars, state->combine_chars_size * sizeof(new_chars[0])); in grow_combine_buffer()
132 vterm_allocator_free(state->vt, state->combine_chars); in grow_combine_buffer()
134 state->combine_chars = new_chars; in grow_combine_buffer()
135 state->combine_chars_size = new_size; in grow_combine_buffer()
138 static void set_col_tabstop(VTermState *state, int col) in set_col_tabstop() argument
141 state->tabstops[col >> 3] |= mask; in set_col_tabstop()
144 static void clear_col_tabstop(VTermState *state, int col) in clear_col_tabstop() argument
147 state->tabstops[col >> 3] &= ~mask; in clear_col_tabstop()
150 static int is_col_tabstop(VTermState *state, int col) in is_col_tabstop() argument
153 return state->tabstops[col >> 3] & mask; in is_col_tabstop()
156 static void tab(VTermState *state, int count, int direction) in tab() argument
159 while(state->pos.col >= 0 && state->pos.col < THISROWWIDTH(state)-1) { in tab()
160 state->pos.col += direction; in tab()
162 if(is_col_tabstop(state, state->pos.col)) in tab()
177 static void set_lineinfo(VTermState *state, int row, int force, int dwl, int dhl) in set_lineinfo() argument
179 VTermLineInfo info = state->lineinfo[row]; in set_lineinfo()
194 if((state->callbacks && in set_lineinfo()
195 state->callbacks->setlineinfo && in set_lineinfo()
196 (*state->callbacks->setlineinfo)(row, &info, state->lineinfo + row, state->cbdata)) in set_lineinfo()
198 state->lineinfo[row] = info; in set_lineinfo()
203 VTermState *state = user; in on_text() local
205 VTermPos oldpos = state->pos; in on_text()
213 state->gsingle_set ? &state->encoding[state->gsingle_set] : in on_text()
214 !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] : in on_text()
215 state->vt->mode.utf8 ? &state->encoding_utf8 : in on_text()
216 &state->encoding[state->gr_set]; in on_text()
219 codepoints, &npoints, state->gsingle_set ? 1 : len, in on_text()
222 if(state->gsingle_set && npoints) in on_text()
223 state->gsingle_set = 0; in on_text()
231 …if(state->pos.row == state->combine_pos.row && state->pos.col == state->combine_pos.col + state->c… in on_text()
235 for(printpos = 0; state->combine_chars[printpos]; printpos++) in on_text()
236 printf("U+%04x ", state->combine_chars[printpos]); in on_text()
242 while(state->combine_chars[saved_i]) in on_text()
247 if(saved_i >= state->combine_chars_size) in on_text()
248 grow_combine_buffer(state); in on_text()
249 state->combine_chars[saved_i++] = codepoints[i++]; in on_text()
251 if(saved_i >= state->combine_chars_size) in on_text()
252 grow_combine_buffer(state); in on_text()
253 state->combine_chars[saved_i] = 0; in on_text()
256 for(; state->combine_chars[printpos]; printpos++) in on_text()
257 printf("U+%04x ", state->combine_chars[printpos]); in on_text()
262 putglyph(state, state->combine_chars, state->combine_width, state->combine_pos); in on_text()
297 if(state->at_phantom || state->pos.col + width > THISROWWIDTH(state)) { in on_text()
298 linefeed(state); in on_text()
299 state->pos.col = 0; in on_text()
300 state->at_phantom = 0; in on_text()
303 if(state->mode.insert) { in on_text()
309 .start_row = state->pos.row, in on_text()
310 .end_row = state->pos.row + 1, in on_text()
311 .start_col = state->pos.col, in on_text()
312 .end_col = THISROWWIDTH(state), in on_text()
314 scroll(state, rect, 0, -1); in on_text()
317 putglyph(state, chars, width, state->pos); in on_text()
324 if(save_i >= state->combine_chars_size) in on_text()
325 grow_combine_buffer(state); in on_text()
326 state->combine_chars[save_i] = chars[save_i]; in on_text()
328 if(save_i >= state->combine_chars_size) in on_text()
329 grow_combine_buffer(state); in on_text()
330 state->combine_chars[save_i] = 0; in on_text()
331 state->combine_width = width; in on_text()
332 state->combine_pos = state->pos; in on_text()
335 if(state->pos.col + width >= THISROWWIDTH(state)) { in on_text()
336 if(state->mode.autowrap) in on_text()
337 state->at_phantom = 1; in on_text()
340 state->pos.col += width; in on_text()
344 updatecursor(state, &oldpos, 0); in on_text()
351 VTermState *state = user; in on_control() local
353 VTermPos oldpos = state->pos; in on_control()
357 if(state->callbacks && state->callbacks->bell) in on_control()
358 (*state->callbacks->bell)(state->cbdata); in on_control()
362 if(state->pos.col > 0) in on_control()
363 state->pos.col--; in on_control()
367 tab(state, 1, +1); in on_control()
373 linefeed(state); in on_control()
374 if(state->mode.newline) in on_control()
375 state->pos.col = 0; in on_control()
379 state->pos.col = 0; in on_control()
383 state->gl_set = 1; in on_control()
387 state->gl_set = 0; in on_control()
391 linefeed(state); in on_control()
395 linefeed(state); in on_control()
396 state->pos.col = 0; in on_control()
400 set_col_tabstop(state, state->pos.col); in on_control()
404 if(state->pos.row == state->scrollregion_top) { in on_control()
406 .start_row = state->scrollregion_top, in on_control()
407 .end_row = SCROLLREGION_BOTTOM(state), in on_control()
408 .start_col = SCROLLREGION_LEFT(state), in on_control()
409 .end_col = SCROLLREGION_RIGHT(state), in on_control()
412 scroll(state, rect, -1, 0); in on_control()
414 else if(state->pos.row > 0) in on_control()
415 state->pos.row--; in on_control()
419 state->gsingle_set = 2; in on_control()
423 state->gsingle_set = 3; in on_control()
430 updatecursor(state, &oldpos, 1); in on_control()
435 static void output_mouse(VTermState *state, int code, int pressed, int modifiers, int col, int row) in output_mouse() argument
439 switch(state->mouse_protocol) { in output_mouse()
449 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "M%c%c%c", in output_mouse()
465 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "M%s", utf8); in output_mouse()
470 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "<%d;%d;%d%c", in output_mouse()
478 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "%d;%d;%dM", in output_mouse()
486 VTermState *state = data; in mousefunc() local
488 int old_col = state->mouse_col; in mousefunc()
489 int old_row = state->mouse_row; in mousefunc()
490 int old_buttons = state->mouse_buttons; in mousefunc()
492 state->mouse_col = col; in mousefunc()
493 state->mouse_row = row; in mousefunc()
497 state->mouse_buttons |= (1 << (button-1)); in mousefunc()
499 state->mouse_buttons &= ~(1 << (button-1)); in mousefunc()
506 if(state->mouse_buttons != old_buttons || button >= 4) { in mousefunc()
508 output_mouse(state, button-1, pressed, modifiers, col, row); in mousefunc()
511 output_mouse(state, button-4 + 0x40, pressed, modifiers, col, row); in mousefunc()
515 if((state->mouse_flags & MOUSE_WANT_DRAG && state->mouse_buttons) || in mousefunc()
516 (state->mouse_flags & MOUSE_WANT_MOVE)) { in mousefunc()
517 int button = state->mouse_buttons & 0x01 ? 1 : in mousefunc()
518 state->mouse_buttons & 0x02 ? 2 : in mousefunc()
519 state->mouse_buttons & 0x04 ? 3 : 4; in mousefunc()
520 output_mouse(state, button-1 + 0x20, 1, modifiers, col, row); in mousefunc()
525 static int settermprop_bool(VTermState *state, VTermProp prop, int v) in settermprop_bool() argument
528 return vterm_state_set_termprop(state, prop, &val); in settermprop_bool()
531 static int settermprop_int(VTermState *state, VTermProp prop, int v) in settermprop_int() argument
534 return vterm_state_set_termprop(state, prop, &val); in settermprop_int()
537 static int settermprop_string(VTermState *state, VTermProp prop, const char *str, size_t len) in settermprop_string() argument
544 return vterm_state_set_termprop(state, prop, &val); in settermprop_string()
547 static void savecursor(VTermState *state, int save) in savecursor() argument
550 state->saved.pos = state->pos; in savecursor()
551 state->saved.mode.cursor_visible = state->mode.cursor_visible; in savecursor()
552 state->saved.mode.cursor_blink = state->mode.cursor_blink; in savecursor()
553 state->saved.mode.cursor_shape = state->mode.cursor_shape; in savecursor()
555 vterm_state_savepen(state, 1); in savecursor()
558 VTermPos oldpos = state->pos; in savecursor()
560 state->pos = state->saved.pos; in savecursor()
562 settermprop_bool(state, VTERM_PROP_CURSORVISIBLE, state->saved.mode.cursor_visible); in savecursor()
563 settermprop_bool(state, VTERM_PROP_CURSORBLINK, state->saved.mode.cursor_blink); in savecursor()
564 settermprop_int (state, VTERM_PROP_CURSORSHAPE, state->saved.mode.cursor_shape); in savecursor()
566 vterm_state_savepen(state, 0); in savecursor()
568 updatecursor(state, &oldpos, 1); in savecursor()
574 VTermState *state = user; in on_escape() local
586 state->vt->mode.ctrl8bit = 0; in on_escape()
590 state->vt->mode.ctrl8bit = 1; in on_escape()
604 if(state->mode.leftrightmargin) in on_escape()
606 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_TOP); in on_escape()
610 if(state->mode.leftrightmargin) in on_escape()
612 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_BOTTOM); in on_escape()
616 if(state->mode.leftrightmargin) in on_escape()
618 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_OFF, DHL_OFF); in on_escape()
622 if(state->mode.leftrightmargin) in on_escape()
624 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_OFF); in on_escape()
631 for(pos.row = 0; pos.row < state->rows; pos.row++) in on_escape()
632 for(pos.col = 0; pos.col < ROWWIDTH(state, pos.row); pos.col++) in on_escape()
633 putglyph(state, E, 1, pos); in on_escape()
651 state->encoding[setnum].enc = newenc; in on_escape()
654 (*newenc->init)(newenc, state->encoding[setnum].data); in on_escape()
661 savecursor(state, 1); in on_escape()
665 savecursor(state, 0); in on_escape()
672 state->mode.keypad = 1; in on_escape()
676 state->mode.keypad = 0; in on_escape()
681 VTermPos oldpos = state->pos; in on_escape()
682 vterm_state_reset(state, 1); in on_escape()
683 if(state->callbacks && state->callbacks->movecursor) in on_escape()
684 … (*state->callbacks->movecursor)(state->pos, oldpos, state->mode.cursor_visible, state->cbdata); in on_escape()
689 state->gl_set = 2; in on_escape()
693 state->gl_set = 3; in on_escape()
697 state->gr_set = 1; in on_escape()
701 state->gr_set = 2; in on_escape()
705 state->gr_set = 3; in on_escape()
713 static void set_mode(VTermState *state, int num, int val) in set_mode() argument
717 state->mode.insert = val; in set_mode()
721 state->mode.newline = val; in set_mode()
730 static void set_dec_mode(VTermState *state, int num, int val) in set_dec_mode() argument
734 state->mode.cursor = val; in set_dec_mode()
738 settermprop_bool(state, VTERM_PROP_REVERSE, val); in set_dec_mode()
743 VTermPos oldpos = state->pos; in set_dec_mode()
744 state->mode.origin = val; in set_dec_mode()
745 state->pos.row = state->mode.origin ? state->scrollregion_top : 0; in set_dec_mode()
746 state->pos.col = state->mode.origin ? SCROLLREGION_LEFT(state) : 0; in set_dec_mode()
747 updatecursor(state, &oldpos, 1); in set_dec_mode()
752 state->mode.autowrap = val; in set_dec_mode()
756 settermprop_bool(state, VTERM_PROP_CURSORBLINK, val); in set_dec_mode()
760 settermprop_bool(state, VTERM_PROP_CURSORVISIBLE, val); in set_dec_mode()
765 state->mode.leftrightmargin = val; in set_dec_mode()
768 for(int row = 0; row < state->rows; row++) in set_dec_mode()
769 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF); in set_dec_mode()
778 state->mouse_col = 0; in set_dec_mode()
779 state->mouse_row = 0; in set_dec_mode()
780 state->mouse_buttons = 0; in set_dec_mode()
782 state->mouse_flags = MOUSE_WANT_CLICK; in set_dec_mode()
783 state->mouse_protocol = MOUSE_X10; in set_dec_mode()
786 state->mouse_flags |= MOUSE_WANT_DRAG; in set_dec_mode()
788 state->mouse_flags |= MOUSE_WANT_MOVE; in set_dec_mode()
791 state->mouse_flags = 0; in set_dec_mode()
794 if(state->callbacks && state->callbacks->setmousefunc) in set_dec_mode()
795 (*state->callbacks->setmousefunc)(val ? mousefunc : NULL, state, state->cbdata); in set_dec_mode()
800 state->mouse_protocol = val ? MOUSE_UTF8 : MOUSE_X10; in set_dec_mode()
804 state->mouse_protocol = val ? MOUSE_SGR : MOUSE_X10; in set_dec_mode()
808 state->mouse_protocol = val ? MOUSE_RXVT : MOUSE_X10; in set_dec_mode()
812 settermprop_bool(state, VTERM_PROP_ALTSCREEN, val); in set_dec_mode()
816 savecursor(state, val); in set_dec_mode()
820 settermprop_bool(state, VTERM_PROP_ALTSCREEN, val); in set_dec_mode()
821 savecursor(state, val); in set_dec_mode()
830 static void request_dec_mode(VTermState *state, int num) in request_dec_mode() argument
836 reply = state->mode.cursor; in request_dec_mode()
840 reply = state->mode.screen; in request_dec_mode()
844 reply = state->mode.origin; in request_dec_mode()
848 reply = state->mode.autowrap; in request_dec_mode()
852 reply = state->mode.cursor_blink; in request_dec_mode()
856 reply = state->mode.cursor_visible; in request_dec_mode()
860 reply = state->mode.leftrightmargin; in request_dec_mode()
864 reply = state->mouse_flags == MOUSE_WANT_CLICK; in request_dec_mode()
868 reply = state->mouse_flags == (MOUSE_WANT_CLICK|MOUSE_WANT_DRAG); in request_dec_mode()
872 reply = state->mouse_flags == (MOUSE_WANT_CLICK|MOUSE_WANT_MOVE); in request_dec_mode()
876 reply = state->mouse_protocol == MOUSE_UTF8; in request_dec_mode()
880 reply = state->mouse_protocol == MOUSE_SGR; in request_dec_mode()
884 reply = state->mouse_protocol == MOUSE_RXVT; in request_dec_mode()
888 reply = state->mode.alt_screen; in request_dec_mode()
892 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, 0); in request_dec_mode()
896 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, reply ? 1 : 2); in request_dec_mode()
901 VTermState *state = user; in on_csi() local
935 VTermPos oldpos = state->pos; in on_csi()
953 rect.start_row = state->pos.row; in on_csi()
954 rect.end_row = state->pos.row + 1; in on_csi()
955 rect.start_col = state->pos.col; in on_csi()
956 if(state->mode.leftrightmargin) in on_csi()
957 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
959 rect.end_col = THISROWWIDTH(state); in on_csi()
961 scroll(state, rect, 0, -count); in on_csi()
967 state->pos.row -= count; in on_csi()
968 state->at_phantom = 0; in on_csi()
973 state->pos.row += count; in on_csi()
974 state->at_phantom = 0; in on_csi()
979 state->pos.col += count; in on_csi()
980 state->at_phantom = 0; in on_csi()
985 state->pos.col -= count; in on_csi()
986 state->at_phantom = 0; in on_csi()
991 state->pos.col = 0; in on_csi()
992 state->pos.row += count; in on_csi()
993 state->at_phantom = 0; in on_csi()
998 state->pos.col = 0; in on_csi()
999 state->pos.row -= count; in on_csi()
1000 state->at_phantom = 0; in on_csi()
1005 state->pos.col = val-1; in on_csi()
1006 state->at_phantom = 0; in on_csi()
1013 state->pos.row = row-1; in on_csi()
1014 state->pos.col = col-1; in on_csi()
1015 if(state->mode.origin) { in on_csi()
1016 state->pos.row += state->scrollregion_top; in on_csi()
1017 state->pos.col += SCROLLREGION_LEFT(state); in on_csi()
1019 state->at_phantom = 0; in on_csi()
1024 tab(state, count, +1); in on_csi()
1033 rect.start_row = state->pos.row; rect.end_row = state->pos.row + 1; in on_csi()
1034 rect.start_col = state->pos.col; rect.end_col = state->cols; in on_csi()
1036 erase(state, rect, selective); in on_csi()
1038 rect.start_row = state->pos.row + 1; rect.end_row = state->rows; in on_csi()
1041 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF); in on_csi()
1043 erase(state, rect, selective); in on_csi()
1047 rect.start_row = 0; rect.end_row = state->pos.row; in on_csi()
1048 rect.start_col = 0; rect.end_col = state->cols; in on_csi()
1050 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF); in on_csi()
1052 erase(state, rect, selective); in on_csi()
1054 rect.start_row = state->pos.row; rect.end_row = state->pos.row + 1; in on_csi()
1055 rect.end_col = state->pos.col + 1; in on_csi()
1057 erase(state, rect, selective); in on_csi()
1061 rect.start_row = 0; rect.end_row = state->rows; in on_csi()
1062 rect.start_col = 0; rect.end_col = state->cols; in on_csi()
1064 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF); in on_csi()
1065 erase(state, rect, selective); in on_csi()
1073 rect.start_row = state->pos.row; in on_csi()
1074 rect.end_row = state->pos.row + 1; in on_csi()
1079 rect.start_col = state->pos.col; rect.end_col = THISROWWIDTH(state); break; in on_csi()
1081 rect.start_col = 0; rect.end_col = state->pos.col + 1; break; in on_csi()
1083 rect.start_col = 0; rect.end_col = THISROWWIDTH(state); break; in on_csi()
1089 erase(state, rect, selective); in on_csi()
1096 rect.start_row = state->pos.row; in on_csi()
1097 rect.end_row = SCROLLREGION_BOTTOM(state); in on_csi()
1098 rect.start_col = SCROLLREGION_LEFT(state); in on_csi()
1099 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1101 scroll(state, rect, -count, 0); in on_csi()
1108 rect.start_row = state->pos.row; in on_csi()
1109 rect.end_row = SCROLLREGION_BOTTOM(state); in on_csi()
1110 rect.start_col = SCROLLREGION_LEFT(state); in on_csi()
1111 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1113 scroll(state, rect, count, 0); in on_csi()
1120 rect.start_row = state->pos.row; in on_csi()
1121 rect.end_row = state->pos.row + 1; in on_csi()
1122 rect.start_col = state->pos.col; in on_csi()
1123 if(state->mode.leftrightmargin) in on_csi()
1124 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1126 rect.end_col = THISROWWIDTH(state); in on_csi()
1128 scroll(state, rect, 0, count); in on_csi()
1135 rect.start_row = state->scrollregion_top; in on_csi()
1136 rect.end_row = SCROLLREGION_BOTTOM(state); in on_csi()
1137 rect.start_col = SCROLLREGION_LEFT(state); in on_csi()
1138 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1140 scroll(state, rect, count, 0); in on_csi()
1147 rect.start_row = state->scrollregion_top; in on_csi()
1148 rect.end_row = SCROLLREGION_BOTTOM(state); in on_csi()
1149 rect.start_col = SCROLLREGION_LEFT(state); in on_csi()
1150 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1152 scroll(state, rect, -count, 0); in on_csi()
1159 rect.start_row = state->pos.row; in on_csi()
1160 rect.end_row = state->pos.row + 1; in on_csi()
1161 rect.start_col = state->pos.col; in on_csi()
1162 rect.end_col = state->pos.col + count; in on_csi()
1163 UBOUND(rect.end_col, THISROWWIDTH(state)); in on_csi()
1165 erase(state, rect, 0); in on_csi()
1170 tab(state, count, -1); in on_csi()
1175 state->pos.col = col-1; in on_csi()
1176 state->at_phantom = 0; in on_csi()
1181 state->pos.col += count; in on_csi()
1182 state->at_phantom = 0; in on_csi()
1189 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?1;2c"); in on_csi()
1193 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, ">%d;%d;%dc", 0, 100, 0); in on_csi()
1198 state->pos.row = row-1; in on_csi()
1199 if(state->mode.origin) in on_csi()
1200 state->pos.row += state->scrollregion_top; in on_csi()
1201 state->at_phantom = 0; in on_csi()
1206 state->pos.row += count; in on_csi()
1207 state->at_phantom = 0; in on_csi()
1214 state->pos.row = row-1; in on_csi()
1215 state->pos.col = col-1; in on_csi()
1216 if(state->mode.origin) { in on_csi()
1217 state->pos.row += state->scrollregion_top; in on_csi()
1218 state->pos.col += SCROLLREGION_LEFT(state); in on_csi()
1220 state->at_phantom = 0; in on_csi()
1228 clear_col_tabstop(state, state->pos.col); in on_csi()
1232 for(col = 0; col < state->cols; col++) in on_csi()
1233 clear_col_tabstop(state, col); in on_csi()
1247 set_mode(state, CSI_ARG(args[0]), 1); in on_csi()
1252 set_dec_mode(state, CSI_ARG(args[0]), 1); in on_csi()
1257 state->pos.col -= count; in on_csi()
1258 state->at_phantom = 0; in on_csi()
1263 state->pos.row -= count; in on_csi()
1264 state->at_phantom = 0; in on_csi()
1269 set_mode(state, CSI_ARG(args[0]), 0); in on_csi()
1274 set_dec_mode(state, CSI_ARG(args[0]), 0); in on_csi()
1278 vterm_state_setpen(state, args, argcount); in on_csi()
1293 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "%s0n", qmark); in on_csi()
1296 …vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "%s%d;%dR", qmark, state->pos.row + 1, state->po… in on_csi()
1304 vterm_state_reset(state, 0); in on_csi()
1308 request_dec_mode(state, CSI_ARG(args[0])); in on_csi()
1316 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1); in on_csi()
1317 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BLOCK); in on_csi()
1320 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 0); in on_csi()
1321 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BLOCK); in on_csi()
1324 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1); in on_csi()
1325 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_UNDERLINE); in on_csi()
1328 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 0); in on_csi()
1329 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_UNDERLINE); in on_csi()
1332 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1); in on_csi()
1333 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BAR_LEFT); in on_csi()
1336 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 0); in on_csi()
1337 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BAR_LEFT); in on_csi()
1348 state->protected_cell = 0; in on_csi()
1351 state->protected_cell = 1; in on_csi()
1358 state->scrollregion_top = CSI_ARG_OR(args[0], 1) - 1; in on_csi()
1359state->scrollregion_bottom = argcount < 2 || CSI_ARG_IS_MISSING(args[1]) ? -1 : CSI_ARG(args[1]); in on_csi()
1360 LBOUND(state->scrollregion_top, -1); in on_csi()
1361 UBOUND(state->scrollregion_top, state->rows); in on_csi()
1362 LBOUND(state->scrollregion_bottom, -1); in on_csi()
1363 if(state->scrollregion_top == 0 && state->scrollregion_bottom == state->rows) in on_csi()
1364 state->scrollregion_bottom = -1; in on_csi()
1366 UBOUND(state->scrollregion_bottom, state->rows); in on_csi()
1372 state->scrollregion_left = CSI_ARG_OR(args[0], 1) - 1; in on_csi()
1373 state->scrollregion_right = argcount < 2 || CSI_ARG_IS_MISSING(args[1]) ? -1 : CSI_ARG(args[1]); in on_csi()
1374 LBOUND(state->scrollregion_left, -1); in on_csi()
1375 UBOUND(state->scrollregion_left, state->cols); in on_csi()
1376 LBOUND(state->scrollregion_right, -1); in on_csi()
1377 if(state->scrollregion_left == 0 && state->scrollregion_right == state->cols) in on_csi()
1378 state->scrollregion_right = -1; in on_csi()
1380 UBOUND(state->scrollregion_right, state->cols); in on_csi()
1387 rect.start_row = state->scrollregion_top; in on_csi()
1388 rect.end_row = SCROLLREGION_BOTTOM(state); in on_csi()
1389 rect.start_col = state->pos.col; in on_csi()
1390 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1392 scroll(state, rect, 0, -count); in on_csi()
1399 rect.start_row = state->scrollregion_top; in on_csi()
1400 rect.end_row = SCROLLREGION_BOTTOM(state); in on_csi()
1401 rect.start_col = state->pos.col; in on_csi()
1402 rect.end_col = SCROLLREGION_RIGHT(state); in on_csi()
1404 scroll(state, rect, 0, count); in on_csi()
1412 if(state->mode.origin) { in on_csi()
1413 LBOUND(state->pos.row, state->scrollregion_top); in on_csi()
1414 UBOUND(state->pos.row, state->scrollregion_bottom-1); in on_csi()
1415 LBOUND(state->pos.col, SCROLLREGION_LEFT(state)); in on_csi()
1416 UBOUND(state->pos.col, SCROLLREGION_RIGHT(state)-1); in on_csi()
1419 LBOUND(state->pos.row, 0); in on_csi()
1420 UBOUND(state->pos.row, state->rows-1); in on_csi()
1421 LBOUND(state->pos.col, 0); in on_csi()
1422 UBOUND(state->pos.col, THISROWWIDTH(state)-1); in on_csi()
1425 updatecursor(state, &oldpos, 1); in on_csi()
1432 VTermState *state = user; in on_osc() local
1438 settermprop_string(state, VTERM_PROP_ICONNAME, command + 2, cmdlen - 2); in on_osc()
1439 settermprop_string(state, VTERM_PROP_TITLE, command + 2, cmdlen - 2); in on_osc()
1443 settermprop_string(state, VTERM_PROP_ICONNAME, command + 2, cmdlen - 2); in on_osc()
1447 settermprop_string(state, VTERM_PROP_TITLE, command + 2, cmdlen - 2); in on_osc()
1454 static void request_status_string(VTermState *state, const char *command, size_t cmdlen) in request_status_string() argument
1461 int argc = vterm_state_getpen(state, args, sizeof(args)/sizeof(args[0])); in request_status_string()
1462 vterm_push_output_sprintf_ctrl(state->vt, C1_DCS, "1$r"); in request_status_string()
1464 vterm_push_output_sprintf(state->vt, in request_status_string()
1469 vterm_push_output_sprintf(state->vt, "m"); in request_status_string()
1470 vterm_push_output_sprintf_ctrl(state->vt, C1_ST, ""); in request_status_string()
1474 …vterm_push_output_sprintf_dcs(state->vt, "1$r%d;%dr", state->scrollregion_top+1, SCROLLREGION_BOTT… in request_status_string()
1477 …vterm_push_output_sprintf_dcs(state->vt, "1$r%d;%ds", SCROLLREGION_LEFT(state)+1, SCROLLREGION_RIG… in request_status_string()
1484 switch(state->mode.cursor_shape) { in request_status_string()
1489 if(state->mode.cursor_blink) in request_status_string()
1491 vterm_push_output_sprintf_dcs(state->vt, "1$r%d q", reply); in request_status_string()
1495 vterm_push_output_sprintf_dcs(state->vt, "1$r%d\"q", state->protected_cell ? 1 : 2); in request_status_string()
1500 vterm_push_output_sprintf_dcs(state->vt, "0$r%.s", (int)cmdlen, command); in request_status_string()
1505 VTermState *state = user; in on_dcs() local
1508 request_status_string(state, command+2, cmdlen-2); in on_dcs()
1517 VTermState *state = user; in on_resize() local
1518 VTermPos oldpos = state->pos; in on_resize()
1520 if(cols != state->cols) { in on_resize()
1521 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8); in on_resize()
1525 for(col = 0; col < state->cols && col < cols; col++) { in on_resize()
1527 if(state->tabstops[col >> 3] & mask) in on_resize()
1541 vterm_allocator_free(state->vt, state->tabstops); in on_resize()
1542 state->tabstops = newtabstops; in on_resize()
1545 if(rows != state->rows) { in on_resize()
1546 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); in on_resize()
1549 for(row = 0; row < state->rows && row < rows; row++) { in on_resize()
1550 newlineinfo[row] = state->lineinfo[row]; in on_resize()
1559 vterm_allocator_free(state->vt, state->lineinfo); in on_resize()
1560 state->lineinfo = newlineinfo; in on_resize()
1563 state->rows = rows; in on_resize()
1564 state->cols = cols; in on_resize()
1568 if(state->callbacks && state->callbacks->resize) in on_resize()
1569 (*state->callbacks->resize)(rows, cols, &delta, state->cbdata); in on_resize()
1571 if(state->at_phantom && state->pos.col < cols-1) { in on_resize()
1572 state->at_phantom = 0; in on_resize()
1573 state->pos.col++; in on_resize()
1576 state->pos.row += delta.row; in on_resize()
1577 state->pos.col += delta.col; in on_resize()
1579 if(state->pos.row >= rows) in on_resize()
1580 state->pos.row = rows - 1; in on_resize()
1581 if(state->pos.col >= cols) in on_resize()
1582 state->pos.col = cols - 1; in on_resize()
1584 updatecursor(state, &oldpos, 1); in on_resize()
1601 if(vt->state) in vterm_obtain_state()
1602 return vt->state; in vterm_obtain_state()
1604 VTermState *state = vterm_state_new(vt); in vterm_obtain_state() local
1605 vt->state = state; in vterm_obtain_state()
1607 state->combine_chars_size = 16; in vterm_obtain_state()
1608state->combine_chars = vterm_allocator_malloc(state->vt, state->combine_chars_size * sizeof(state-… in vterm_obtain_state()
1610 state->tabstops = vterm_allocator_malloc(state->vt, (state->cols + 7) / 8); in vterm_obtain_state()
1612 state->lineinfo = vterm_allocator_malloc(state->vt, state->rows * sizeof(VTermLineInfo)); in vterm_obtain_state()
1614 state->encoding_utf8.enc = vterm_lookup_encoding(ENC_UTF8, 'u'); in vterm_obtain_state()
1615 if(*state->encoding_utf8.enc->init) in vterm_obtain_state()
1616 (*state->encoding_utf8.enc->init)(state->encoding_utf8.enc, state->encoding_utf8.data); in vterm_obtain_state()
1618 vterm_set_parser_callbacks(vt, &parser_callbacks, state); in vterm_obtain_state()
1620 return state; in vterm_obtain_state()
1623 void vterm_state_reset(VTermState *state, int hard) in vterm_state_reset() argument
1625 state->scrollregion_top = 0; in vterm_state_reset()
1626 state->scrollregion_bottom = -1; in vterm_state_reset()
1627 state->scrollregion_left = 0; in vterm_state_reset()
1628 state->scrollregion_right = -1; in vterm_state_reset()
1630 state->mode.keypad = 0; in vterm_state_reset()
1631 state->mode.cursor = 0; in vterm_state_reset()
1632 state->mode.autowrap = 1; in vterm_state_reset()
1633 state->mode.insert = 0; in vterm_state_reset()
1634 state->mode.newline = 0; in vterm_state_reset()
1635 state->mode.alt_screen = 0; in vterm_state_reset()
1636 state->mode.origin = 0; in vterm_state_reset()
1637 state->mode.leftrightmargin = 0; in vterm_state_reset()
1639 state->vt->mode.ctrl8bit = 0; in vterm_state_reset()
1641 for(int col = 0; col < state->cols; col++) in vterm_state_reset()
1643 set_col_tabstop(state, col); in vterm_state_reset()
1645 clear_col_tabstop(state, col); in vterm_state_reset()
1647 for(int row = 0; row < state->rows; row++) in vterm_state_reset()
1648 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF); in vterm_state_reset()
1650 if(state->callbacks && state->callbacks->initpen) in vterm_state_reset()
1651 (*state->callbacks->initpen)(state->cbdata); in vterm_state_reset()
1653 vterm_state_resetpen(state); in vterm_state_reset()
1655 VTermEncoding *default_enc = state->vt->mode.utf8 ? in vterm_state_reset()
1660 state->encoding[i].enc = default_enc; in vterm_state_reset()
1662 (*default_enc->init)(default_enc, state->encoding[i].data); in vterm_state_reset()
1665 state->gl_set = 0; in vterm_state_reset()
1666 state->gr_set = 1; in vterm_state_reset()
1667 state->gsingle_set = 0; in vterm_state_reset()
1669 state->protected_cell = 0; in vterm_state_reset()
1672 settermprop_bool(state, VTERM_PROP_CURSORVISIBLE, 1); in vterm_state_reset()
1673 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1); in vterm_state_reset()
1674 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BLOCK); in vterm_state_reset()
1677 state->pos.row = 0; in vterm_state_reset()
1678 state->pos.col = 0; in vterm_state_reset()
1679 state->at_phantom = 0; in vterm_state_reset()
1681 VTermRect rect = { 0, state->rows, 0, state->cols }; in vterm_state_reset()
1682 erase(state, rect, 0); in vterm_state_reset()
1686 void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos) in vterm_state_get_cursorpos() argument
1688 *cursorpos = state->pos; in vterm_state_get_cursorpos()
1691 void vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user) in vterm_state_set_callbacks() argument
1694 state->callbacks = callbacks; in vterm_state_set_callbacks()
1695 state->cbdata = user; in vterm_state_set_callbacks()
1697 if(state->callbacks && state->callbacks->initpen) in vterm_state_set_callbacks()
1698 (*state->callbacks->initpen)(state->cbdata); in vterm_state_set_callbacks()
1701 state->callbacks = NULL; in vterm_state_set_callbacks()
1702 state->cbdata = NULL; in vterm_state_set_callbacks()
1706 int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val) in vterm_state_set_termprop() argument
1710 if(state->callbacks && state->callbacks->settermprop) in vterm_state_set_termprop()
1711 if(!(*state->callbacks->settermprop)(prop, val, state->cbdata)) in vterm_state_set_termprop()
1720 state->mode.cursor_visible = val->boolean; in vterm_state_set_termprop()
1723 state->mode.cursor_blink = val->boolean; in vterm_state_set_termprop()
1726 state->mode.cursor_shape = val->number; in vterm_state_set_termprop()
1729 state->mode.screen = val->boolean; in vterm_state_set_termprop()
1732 state->mode.alt_screen = val->boolean; in vterm_state_set_termprop()
1733 if(state->mode.alt_screen) { in vterm_state_set_termprop()
1737 .end_row = state->rows, in vterm_state_set_termprop()
1738 .end_col = state->cols, in vterm_state_set_termprop()
1740 erase(state, rect, 0); in vterm_state_set_termprop()
1748 const VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row) in vterm_state_get_lineinfo() argument
1750 return state->lineinfo + row; in vterm_state_get_lineinfo()