Home | History | Annotate | Download | only in src

Lines Matching refs:state

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