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;
214 state->gsingle_set ? &state->encoding[state->gsingle_set] :
215 !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] :
216 state->vt->mode.utf8 ? &state->encoding_utf8 :
217 &state->encoding[state->gr_set];
220 codepoints, &npoints, state->gsingle_set ? 1 : len,
223 if(state->gsingle_set && npoints)
224 state->gsingle_set = 0;
230 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]);
241 while(state->combine_chars[saved_i])
246 if(saved_i >= state->combine_chars_size)
247 grow_combine_buffer(state);
248 state->combine_chars[saved_i++] = codepoints[i++];
250 if(saved_i >= state->combine_chars_size)
251 grow_combine_buffer(state);
252 state->combine_chars[saved_i] = 0;
255 for(; state->combine_chars[printpos]; printpos++)
256 printf("U+%04x ", state->combine_chars[printpos]);
261 putglyph(state, state->combine_chars, state->combine_width, state->combine_pos);
299 if(state->at_phantom || state->pos.col + width > THISROWWIDTH(state)) {
300 linefeed(state);
301 state->pos.col = 0;
302 state->at_phantom = 0;
305 if(state->mode.insert) {
311 .start_row = state->pos.row,
312 .end_row = state->pos.row + 1,
313 .start_col = state->pos.col,
314 .end_col = THISROWWIDTH(state),
316 scroll(state, rect, 0, -1);
319 putglyph(state, chars, width, state->pos);
326 if(save_i >= state->combine_chars_size)
327 grow_combine_buffer(state);
328 state->combine_chars[save_i] = chars[save_i];
330 if(save_i >= state->combine_chars_size)
331 grow_combine_buffer(state);
332 state->combine_chars[save_i] = 0;
333 state->combine_width = width;
334 state->combine_pos = state->pos;
337 if(state->pos.col + width >= THISROWWIDTH(state)) {
338 if(state->mode.autowrap)
339 state->at_phantom = 1;
342 state->pos.col += width;
346 updatecursor(state, &oldpos, 0);
353 VTermState *state = user;
355 VTermPos oldpos = state->pos;
359 if(state->callbacks && state->callbacks->bell)
360 (*state->callbacks->bell)(state->cbdata);
364 if(state->pos.col > 0)
365 state->pos.col--;
369 tab(state, 1, +1);
375 linefeed(state);
376 if(state->mode.newline)
377 state->pos.col = 0;
381 state->pos.col = 0;
385 state->gl_set = 1;
389 state->gl_set = 0;
393 linefeed(state);
397 linefeed(state);
398 state->pos.col = 0;
402 set_col_tabstop(state, state->pos.col);
406 if(state->pos.row == state->scrollregion_top) {
408 .start_row = state->scrollregion_top,
409 .end_row = SCROLLREGION_BOTTOM(state),
410 .start_col = SCROLLREGION_LEFT(state),
411 .end_col = SCROLLREGION_RIGHT(state),
414 scroll(state, rect, -1, 0);
416 else if(state->pos.row > 0)
417 state->pos.row--;
421 state->gsingle_set = 2;
425 state->gsingle_set = 3;
432 updatecursor(state, &oldpos, 1);
437 static void output_mouse(VTermState *state, int code, int pressed, int modifiers, int col, int row)
441 switch(state->mouse_protocol) {
451 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "M%c%c%c",
467 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "M%s", utf8);
472 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "<%d;%d;%d%c",
480 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "%d;%d;%dM",
488 VTermState *state = data;
490 int old_col = state->mouse_col;
491 int old_row = state->mouse_row;
492 int old_buttons = state->mouse_buttons;
494 state->mouse_col = col;
495 state->mouse_row = row;
499 state->mouse_buttons |= (1 << (button-1));
501 state->mouse_buttons &= ~(1 << (button-1));
508 if(state->mouse_buttons != old_buttons || button >= 4) {
510 output_mouse(state, button-1, pressed, modifiers, col, row);
513 output_mouse(state, button-4 + 0x40, pressed, modifiers, col, row);
517 if((state->mouse_flags & MOUSE_WANT_DRAG && state->mouse_buttons) ||
518 (state->mouse_flags & MOUSE_WANT_MOVE)) {
519 int button = state->mouse_buttons & 0x01 ? 1 :
520 state->mouse_buttons & 0x02 ? 2 :
521 state->mouse_buttons & 0x04 ? 3 : 4;
522 output_mouse(state, button-1 + 0x20, 1, modifiers, col, row);
527 static int settermprop_bool(VTermState *state, VTermProp prop, int v)
530 return vterm_state_set_termprop(state, prop, &val);
533 static int settermprop_int(VTermState *state, VTermProp prop, int v)
536 return vterm_state_set_termprop(state, prop, &val);
539 static int settermprop_string(VTermState *state, VTermProp prop, const char *str, size_t len)
547 return vterm_state_set_termprop(state, prop, &val);
550 static void savecursor(VTermState *state, int save)
553 state->saved.pos = state->pos;
554 state->saved.mode.cursor_visible = state->mode.cursor_visible;
555 state->saved.mode.cursor_blink = state->mode.cursor_blink;
556 state->saved.mode.cursor_shape = state->mode.cursor_shape;
558 vterm_state_savepen(state, 1);
561 VTermPos oldpos = state->pos;
563 state->pos = state->saved.pos;
565 settermprop_bool(state, VTERM_PROP_CURSORVISIBLE, state->saved.mode.cursor_visible);
566 settermprop_bool(state, VTERM_PROP_CURSORBLINK, state->saved.mode.cursor_blink);
567 settermprop_int (state, VTERM_PROP_CURSORSHAPE, state->saved.mode.cursor_shape);
569 vterm_state_savepen(state, 0);
571 updatecursor(state, &oldpos, 1);
577 VTermState *state = user;
589 state->vt->mode.ctrl8bit = 0;
593 state->vt->mode.ctrl8bit = 1;
607 if(state->mode.leftrightmargin)
609 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_TOP);
613 if(state->mode.leftrightmargin)
615 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_BOTTOM);
619 if(state->mode.leftrightmargin)
621 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_OFF, DHL_OFF);
625 if(state->mode.leftrightmargin)
627 set_lineinfo(state, state->pos.row, NO_FORCE, DWL_ON, DHL_OFF);
634 for(pos.row = 0; pos.row < state->rows; pos.row++)
635 for(pos.col = 0; pos.col < ROWWIDTH(state, pos.row); pos.col++)
636 putglyph(state, E, 1, pos);
654 state->encoding[setnum].enc = newenc;
657 (*newenc->init)(newenc, state->encoding[setnum].data);
664 savecursor(state, 1);
668 savecursor(state, 0);
675 state->mode.keypad = 1;
679 state->mode.keypad = 0;
684 VTermPos oldpos = state->pos;
685 vterm_state_reset(state, 1);
686 if(state->callbacks && state->callbacks->movecursor)
687 (*state->callbacks->movecursor)(state->pos, oldpos, state->mode.cursor_visible, state->cbdata);
692 state->gl_set = 2;
696 state->gl_set = 3;
700 state->gr_set = 1;
704 state->gr_set = 2;
708 state->gr_set = 3;
716 static void set_mode(VTermState *state, int num, int val)
720 state->mode.insert = val;
724 state->mode.newline = val;
733 static void set_dec_mode(VTermState *state, int num, int val)
737 state->mode.cursor = val;
741 settermprop_bool(state, VTERM_PROP_REVERSE, val);
746 VTermPos oldpos = state->pos;
747 state->mode.origin = val;
748 state->pos.row = state->mode.origin ? state->scrollregion_top : 0;
749 state->pos.col = state->mode.origin ? SCROLLREGION_LEFT(state) : 0;
750 updatecursor(state, &oldpos, 1);
755 state->mode.autowrap = val;
759 settermprop_bool(state, VTERM_PROP_CURSORBLINK, val);
763 settermprop_bool(state, VTERM_PROP_CURSORVISIBLE, val);
768 state->mode.leftrightmargin = val;
771 // Setting DECVSSM must clear doublewidth/doubleheight state of every line
772 for(row = 0; row < state->rows; row++)
773 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF);
782 state->mouse_col = 0;
783 state->mouse_row = 0;
784 state->mouse_buttons = 0;
786 state->mouse_flags = MOUSE_WANT_CLICK;
787 state->mouse_protocol = MOUSE_X10;
790 state->mouse_flags |= MOUSE_WANT_DRAG;
792 state->mouse_flags |= MOUSE_WANT_MOVE;
795 state->mouse_flags = 0;
798 if(state->callbacks && state->callbacks->setmousefunc)
799 (*state->callbacks->setmousefunc)(val ? mousefunc : NULL, state, state->cbdata);
804 state->mouse_protocol = val ? MOUSE_UTF8 : MOUSE_X10;
808 state->mouse_protocol = val ? MOUSE_SGR : MOUSE_X10;
812 state->mouse_protocol = val ? MOUSE_RXVT : MOUSE_X10;
816 settermprop_bool(state, VTERM_PROP_ALTSCREEN, val);
820 savecursor(state, val);
824 settermprop_bool(state, VTERM_PROP_ALTSCREEN, val);
825 savecursor(state, val);
834 static void request_dec_mode(VTermState *state, int num)
840 reply = state->mode.cursor;
844 reply = state->mode.screen;
848 reply = state->mode.origin;
852 reply = state->mode.autowrap;
856 reply = state->mode.cursor_blink;
860 reply = state->mode.cursor_visible;
864 reply = state->mode.leftrightmargin;
868 reply = state->mouse_flags == MOUSE_WANT_CLICK;
872 reply = state->mouse_flags == (MOUSE_WANT_CLICK|MOUSE_WANT_DRAG);
876 reply = state->mouse_flags == (MOUSE_WANT_CLICK|MOUSE_WANT_MOVE);
880 reply = state->mouse_protocol == MOUSE_UTF8;
884 reply = state->mouse_protocol == MOUSE_SGR;
888 reply = state->mouse_protocol == MOUSE_RXVT;
892 reply = state->mode.alt_screen;
896 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, 0);
900 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, reply ? 1 : 2);
905 VTermState *state = user;
946 oldpos = state->pos;
958 rect.start_row = state->pos.row;
959 rect.end_row = state->pos.row + 1;
960 rect.start_col = state->pos.col;
961 if(state->mode.leftrightmargin)
962 rect.end_col = SCROLLREGION_RIGHT(state);
964 rect.end_col = THISROWWIDTH(state);
966 scroll(state, rect, 0, -count);
972 state->pos.row -= count;
973 state->at_phantom = 0;
978 state->pos.row += count;
979 state->at_phantom = 0;
984 state->pos.col += count;
985 state->at_phantom = 0;
990 state->pos.col -= count;
991 state->at_phantom = 0;
996 state->pos.col = 0;
997 state->pos.row += count;
998 state->at_phantom = 0;
1003 state->pos.col = 0;
1004 state->pos.row -= count;
1005 state->at_phantom = 0;
1010 state->pos.col = val-1;
1011 state->at_phantom = 0;
1018 state->pos.row = row-1;
1019 state->pos.col = col-1;
1020 if(state->mode.origin) {
1021 state->pos.row += state->scrollregion_top;
1022 state->pos.col += SCROLLREGION_LEFT(state);
1024 state->at_phantom = 0;
1029 tab(state, count, +1);
1038 rect.start_row = state->pos.row; rect.end_row = state->pos.row + 1;
1039 rect.start_col = state->pos.col; rect.end_col = state->cols;
1041 erase(state, rect, selective);
1043 rect.start_row = state->pos.row + 1; rect.end_row = state->rows;
1046 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF);
1048 erase(state, rect, selective);
1052 rect.start_row = 0; rect.end_row = state->pos.row;
1053 rect.start_col = 0; rect.end_col = state->cols;
1055 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF);
1057 erase(state, rect, selective);
1059 rect.start_row = state->pos.row; rect.end_row = state->pos.row + 1;
1060 rect.end_col = state->pos.col + 1;
1062 erase(state, rect, selective);
1066 rect.start_row = 0; rect.end_row = state->rows;
1067 rect.start_col = 0; rect.end_col = state->cols;
1069 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF);
1070 erase(state, rect, selective);
1078 rect.start_row = state->pos.row;
1079 rect.end_row = state->pos.row + 1;
1084 rect.start_col = state->pos.col; rect.end_col = THISROWWIDTH(state); break;
1086 rect.start_col = 0; rect.end_col = state->pos.col + 1; break;
1088 rect.start_col = 0; rect.end_col = THISROWWIDTH(state); break;
1094 erase(state, rect, selective);
1101 rect.start_row = state->pos.row;
1102 rect.end_row = SCROLLREGION_BOTTOM(state);
1103 rect.start_col = SCROLLREGION_LEFT(state);
1104 rect.end_col = SCROLLREGION_RIGHT(state);
1106 scroll(state, rect, -count, 0);
1113 rect.start_row = state->pos.row;
1114 rect.end_row = SCROLLREGION_BOTTOM(state);
1115 rect.start_col = SCROLLREGION_LEFT(state);
1116 rect.end_col = SCROLLREGION_RIGHT(state);
1118 scroll(state, rect, count, 0);
1125 rect.start_row = state->pos.row;
1126 rect.end_row = state->pos.row + 1;
1127 rect.start_col = state->pos.col;
1128 if(state->mode.leftrightmargin)
1129 rect.end_col = SCROLLREGION_RIGHT(state);
1131 rect.end_col = THISROWWIDTH(state);
1133 scroll(state, rect, 0, count);
1140 rect.start_row = state->scrollregion_top;
1141 rect.end_row = SCROLLREGION_BOTTOM(state);
1142 rect.start_col = SCROLLREGION_LEFT(state);
1143 rect.end_col = SCROLLREGION_RIGHT(state);
1145 scroll(state, rect, count, 0);
1152 rect.start_row = state->scrollregion_top;
1153 rect.end_row = SCROLLREGION_BOTTOM(state);
1154 rect.start_col = SCROLLREGION_LEFT(state);
1155 rect.end_col = SCROLLREGION_RIGHT(state);
1157 scroll(state, rect, -count, 0);
1164 rect.start_row = state->pos.row;
1165 rect.end_row = state->pos.row + 1;
1166 rect.start_col = state->pos.col;
1167 rect.end_col = state->pos.col + count;
1168 UBOUND(rect.end_col, THISROWWIDTH(state));
1170 erase(state, rect, 0);
1175 tab(state, count, -1);
1180 state->pos.col = col-1;
1181 state->at_phantom = 0;
1186 state->pos.col += count;
1187 state->at_phantom = 0;
1194 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?1;2c");
1198 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, ">%d;%d;%dc", 0, 100, 0);
1203 state->pos.row = row-1;
1204 if(state->mode.origin)
1205 state->pos.row += state->scrollregion_top;
1206 state->at_phantom = 0;
1211 state->pos.row += count;
1212 state->at_phantom = 0;
1219 state->pos.row = row-1;
1220 state->pos.col = col-1;
1221 if(state->mode.origin) {
1222 state->pos.row += state->scrollregion_top;
1223 state->pos.col += SCROLLREGION_LEFT(state);
1225 state->at_phantom = 0;
1233 clear_col_tabstop(state, state->pos.col);
1237 for(col = 0; col < state->cols; col++)
1238 clear_col_tabstop(state, col);
1252 set_mode(state, CSI_ARG(args[0]), 1);
1257 set_dec_mode(state, CSI_ARG(args[0]), 1);
1262 state->pos.col -= count;
1263 state->at_phantom = 0;
1268 state->pos.row -= count;
1269 state->at_phantom = 0;
1274 set_mode(state, CSI_ARG(args[0]), 0);
1279 set_dec_mode(state, CSI_ARG(args[0]), 0);
1283 vterm_state_setpen(state, args, argcount);
1298 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "%s0n", qmark);
1301 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "%s%d;%dR", qmark, state->pos.row + 1, state->pos.col + 1);
1309 vterm_state_reset(state, 0);
1313 request_dec_mode(state, CSI_ARG(args[0]));
1321 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1);
1322 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BLOCK);
1325 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 0);
1326 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BLOCK);
1329 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1);
1330 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_UNDERLINE);
1333 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 0);
1334 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_UNDERLINE);
1337 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1);
1338 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BAR_LEFT);
1341 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 0);
1342 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BAR_LEFT);
1353 state->protected_cell = 0;
1356 state->protected_cell = 1;
1363 state->scrollregion_top = CSI_ARG_OR(args[0], 1) - 1;
1364 state->scrollregion_bottom = argcount < 2 || CSI_ARG_IS_MISSING(args[1]) ? -1 : CSI_ARG(args[1]);
1365 LBOUND(state->scrollregion_top, -1);
1366 UBOUND(state->scrollregion_top, state->rows);
1367 LBOUND(state->scrollregion_bottom, -1);
1368 if(state->scrollregion_top == 0 && state->scrollregion_bottom == state->rows)
1369 state->scrollregion_bottom = -1;
1371 UBOUND(state->scrollregion_bottom, state->rows);
1377 state->scrollregion_left = CSI_ARG_OR(args[0], 1) - 1;
1378 state->scrollregion_right = argcount < 2 || CSI_ARG_IS_MISSING(args[1]) ? -1 : CSI_ARG(args[1]);
1379 LBOUND(state->scrollregion_left, -1);
1380 UBOUND(state->scrollregion_left, state->cols);
1381 LBOUND(state->scrollregion_right, -1);
1382 if(state->scrollregion_left == 0 && state->scrollregion_right == state->cols)
1383 state->scrollregion_right = -1;
1385 UBOUND(state->scrollregion_right, state->cols);
1392 rect.start_row = state->scrollregion_top;
1393 rect.end_row = SCROLLREGION_BOTTOM(state);
1394 rect.start_col = state->pos.col;
1395 rect.end_col = SCROLLREGION_RIGHT(state);
1397 scroll(state, rect, 0, -count);
1404 rect.start_row = state->scrollregion_top;
1405 rect.end_row = SCROLLREGION_BOTTOM(state);
1406 rect.start_col = state->pos.col;
1407 rect.end_col = SCROLLREGION_RIGHT(state);
1409 scroll(state, rect, 0, count);
1417 if(state->mode.origin) {
1418 LBOUND(state->pos.row, state->scrollregion_top);
1419 UBOUND(state->pos.row, state->scrollregion_bottom-1);
1420 LBOUND(state->pos.col, SCROLLREGION_LEFT(state));
1421 UBOUND(state->pos.col, SCROLLREGION_RIGHT(state)-1);
1424 LBOUND(state->pos.row, 0);
1425 UBOUND(state->pos.row, state->rows-1);
1426 LBOUND(state->pos.col, 0);
1427 UBOUND(state->pos.col, THISROWWIDTH(state)-1);
1430 updatecursor(state, &oldpos, 1);
1437 VTermState *state = user;
1443 settermprop_string(state, VTERM_PROP_ICONNAME, command + 2, cmdlen - 2);
1444 settermprop_string(state, VTERM_PROP_TITLE, command + 2, cmdlen - 2);
1448 settermprop_string(state, VTERM_PROP_ICONNAME, command + 2, cmdlen - 2);
1452 settermprop_string(state, VTERM_PROP_TITLE, command + 2, cmdlen - 2);
1459 static void request_status_string(VTermState *state, const char *command, size_t cmdlen)
1466 int argc = vterm_state_getpen(state, args, sizeof(args)/sizeof(args[0]));
1468 vterm_push_output_sprintf_ctrl(state->vt, C1_DCS, "1$r");
1470 vterm_push_output_sprintf(state->vt,
1475 vterm_push_output_sprintf(state->vt, "m");
1476 vterm_push_output_sprintf_ctrl(state->vt, C1_ST, "");
1480 vterm_push_output_sprintf_dcs(state->vt, "1$r%d;%dr", state->scrollregion_top+1, SCROLLREGION_BOTTOM(state));
1483 vterm_push_output_sprintf_dcs(state->vt, "1$r%d;%ds", SCROLLREGION_LEFT(state)+1, SCROLLREGION_RIGHT(state));
1490 switch(state->mode.cursor_shape) {
1495 if(state->mode.cursor_blink)
1497 vterm_push_output_sprintf_dcs(state->vt, "1$r%d q", reply);
1501 vterm_push_output_sprintf_dcs(state->vt, "1$r%d\"q", state->protected_cell ? 1 : 2);
1506 vterm_push_output_sprintf_dcs(state->vt, "0$r%.s", (int)cmdlen, command);
1511 VTermState *state = user;
1514 request_status_string(state, command+2, cmdlen-2);
1523 VTermState *state = user;
1524 VTermPos oldpos = state->pos;
1527 if(cols != state->cols) {
1528 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8);
1532 for(col = 0; col < state->cols && col < cols; col++) {
1534 if(state->tabstops[col >> 3] & mask)
1548 vterm_allocator_free(state->vt, state->tabstops);
1549 state->tabstops = newtabstops;
1552 if(rows != state->rows) {
1553 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo));
1556 for(row = 0; row < state->rows && row < rows; row++) {
1557 newlineinfo[row] = state->lineinfo[row];
1566 vterm_allocator_free(state->vt, state->lineinfo);
1567 state->lineinfo = newlineinfo;
1570 state->rows = rows;
1571 state->cols = cols;
1573 if(state->callbacks && state->callbacks->resize)
1574 (*state->callbacks->resize)(rows, cols, &delta, state->cbdata);
1576 if(state->at_phantom && state->pos.col < cols-1) {
1577 state->at_phantom = 0;
1578 state->pos.col++;
1581 state->pos.row += delta.row;
1582 state->pos.col += delta.col;
1584 if(state->pos.row >= rows)
1585 state->pos.row = rows - 1;
1586 if(state->pos.col >= cols)
1587 state->pos.col = cols - 1;
1589 updatecursor(state, &oldpos, 1);
1606 VTermState *state;
1607 if(vt->state)
1608 return vt->state;
1610 state = vterm_state_new(vt);
1611 vt->state = state;
1613 state->combine_chars_size = 16;
1614 state->combine_chars = vterm_allocator_malloc(state->vt, state->combine_chars_size * sizeof(state->combine_chars[0]));
1616 state->tabstops = vterm_allocator_malloc(state->vt, (state->cols + 7) / 8);
1618 state->lineinfo = vterm_allocator_malloc(state->vt, state->rows * sizeof(VTermLineInfo));
1620 state->encoding_utf8.enc = vterm_lookup_encoding(ENC_UTF8, 'u');
1621 if(*state->encoding_utf8.enc->init)
1622 (*state->encoding_utf8.enc->init)(state->encoding_utf8.enc, state->encoding_utf8.data);
1624 vterm_set_parser_callbacks(vt, &parser_callbacks, state);
1626 return state;
1629 void vterm_state_reset(VTermState *state, int hard)
1634 state->scrollregion_top = 0;
1635 state->scrollregion_bottom = -1;
1636 state->scrollregion_left = 0;
1637 state->scrollregion_right = -1;
1639 state->mode.keypad = 0;
1640 state->mode.cursor = 0;
1641 state->mode.autowrap = 1;
1642 state->mode.insert = 0;
1643 state->mode.newline = 0;
1644 state->mode.alt_screen = 0;
1645 state->mode.origin = 0;
1646 state->mode.leftrightmargin = 0;
1648 state->vt->mode.ctrl8bit = 0;
1650 for(col = 0; col < state->cols; col++)
1652 set_col_tabstop(state, col);
1654 clear_col_tabstop(state, col);
1656 for(row = 0; row < state->rows; row++)
1657 set_lineinfo(state, row, FORCE, DWL_OFF, DHL_OFF);
1659 if(state->callbacks && state->callbacks->initpen)
1660 (*state->callbacks->initpen)(state->cbdata);
1662 vterm_state_resetpen(state);
1664 default_enc = state->vt->mode.utf8 ?
1669 state->encoding[i].enc = default_enc;
1671 (*default_enc->init)(default_enc, state->encoding[i].data);
1674 state->gl_set = 0;
1675 state->gr_set = 1;
1676 state->gsingle_set = 0;
1678 state->protected_cell = 0;
1681 settermprop_bool(state, VTERM_PROP_CURSORVISIBLE, 1);
1682 settermprop_bool(state, VTERM_PROP_CURSORBLINK, 1);
1683 settermprop_int (state, VTERM_PROP_CURSORSHAPE, VTERM_PROP_CURSORSHAPE_BLOCK);
1686 VTermRect rect = { 0, state->rows, 0, state->cols };
1687 state->pos.row = 0;
1688 state->pos.col = 0;
1689 state->at_phantom = 0;
1691 erase(state, rect, 0);
1695 void vterm_state_get_cursorpos(const VTermState *state, VTermPos *cursorpos)
1697 *cursorpos = state->pos;
1700 void vterm_state_set_callbacks(VTermState *state, const VTermStateCallbacks *callbacks, void *user)
1703 state->callbacks = callbacks;
1704 state->cbdata = user;
1706 if(state->callbacks && state->callbacks->initpen)
1707 (*state->callbacks->initpen)(state->cbdata);
1710 state->callbacks = NULL;
1711 state->cbdata = NULL;
1715 int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val)
1719 if(state->callbacks && state->callbacks->settermprop)
1720 if(!(*state->callbacks->settermprop)(prop, val, state->cbdata))
1729 state->mode.cursor_visible = val->boolean;
1732 state->mode.cursor_blink = val->boolean;
1735 state->mode.cursor_shape = val->number;
1738 state->mode.screen = val->boolean;
1741 state->mode.alt_screen = val->boolean;
1742 if(state->mode.alt_screen) {
1746 .end_row = state->rows,
1747 .end_col = state->cols,
1749 erase(state, rect, 0);
1757 const VTermLineInfo *vterm_state_get_lineinfo(const VTermState *state, int row)
1759 return state->lineinfo + row;