4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
27 * Based on the description by Paul Williams at:
29 * http://vt100.net/emu/dec_ansi_parser
31 * With the following changes:
35 * - Support for UTF-8.
37 * - OSC (but not APC) may be terminated by \007 as well as ST.
39 * - A state for APC similar to OSC. Some terminals appear to use this to set
42 * - A state for the screen \033k...\033\\ sequence to rename a window. This is
43 * pretty stupid but not supporting it is more trouble than it is worth.
45 * - Special handling for ESC inside a DCS to allow arbitrary byte sequences to
46 * be passed to the underlying teminal(s).
49 /* Helper functions. */
50 struct input_transition
;
51 int input_split(struct input_ctx
*);
52 int input_get(struct input_ctx
*, u_int
, int, int);
53 void input_reply(struct input_ctx
*, const char *, ...);
54 void input_set_state(struct window_pane
*, const struct input_transition
*);
56 /* Transition entry/exit handlers. */
57 void input_clear(struct input_ctx
*);
58 void input_enter_osc(struct input_ctx
*);
59 void input_exit_osc(struct input_ctx
*);
60 void input_enter_apc(struct input_ctx
*);
61 void input_exit_apc(struct input_ctx
*);
62 void input_enter_rename(struct input_ctx
*);
63 void input_exit_rename(struct input_ctx
*);
65 /* Input state handlers. */
66 int input_print(struct input_ctx
*);
67 int input_intermediate(struct input_ctx
*);
68 int input_parameter(struct input_ctx
*);
69 int input_input(struct input_ctx
*);
70 int input_c0_dispatch(struct input_ctx
*);
71 int input_esc_dispatch(struct input_ctx
*);
72 int input_csi_dispatch(struct input_ctx
*);
73 void input_csi_dispatch_rm(struct input_ctx
*);
74 void input_csi_dispatch_rm_private(struct input_ctx
*);
75 void input_csi_dispatch_sm(struct input_ctx
*);
76 void input_csi_dispatch_sm_private(struct input_ctx
*);
77 void input_csi_dispatch_sgr(struct input_ctx
*);
78 int input_dcs_dispatch(struct input_ctx
*);
79 int input_utf8_open(struct input_ctx
*);
80 int input_utf8_add(struct input_ctx
*);
81 int input_utf8_close(struct input_ctx
*);
83 /* Command table comparison function. */
84 int input_table_compare(const void *, const void *);
86 /* Command table entry. */
87 struct input_table_entry
{
93 /* Escape commands. */
109 /* Escape command table. */
110 const struct input_table_entry input_esc_table
[] = {
111 { '0', "(", INPUT_ESC_SCSOFF_G0
},
112 { '7', "", INPUT_ESC_DECSC
},
113 { '8', "", INPUT_ESC_DECRC
},
114 { '8', "#", INPUT_ESC_DECALN
},
115 { '=', "", INPUT_ESC_DECKPAM
},
116 { '>', "", INPUT_ESC_DECKPNM
},
117 { 'B', "(", INPUT_ESC_SCSON_G0
},
118 { 'D', "", INPUT_ESC_IND
},
119 { 'E', "", INPUT_ESC_NEL
},
120 { 'H', "", INPUT_ESC_HTS
},
121 { 'M', "", INPUT_ESC_RI
},
122 { 'c', "", INPUT_ESC_RIS
},
125 /* Control (CSI) commands. */
126 enum input_csi_type
{
150 INPUT_CSI_RM_PRIVATE
,
154 INPUT_CSI_SM_PRIVATE
,
159 /* Control (CSI) command table. */
160 const struct input_table_entry input_csi_table
[] = {
161 { '@', "", INPUT_CSI_ICH
},
162 { 'A', "", INPUT_CSI_CUU
},
163 { 'B', "", INPUT_CSI_CUD
},
164 { 'C', "", INPUT_CSI_CUF
},
165 { 'D', "", INPUT_CSI_CUB
},
166 { 'E', "", INPUT_CSI_CNL
},
167 { 'F', "", INPUT_CSI_CPL
},
168 { 'G', "", INPUT_CSI_HPA
},
169 { 'H', "", INPUT_CSI_CUP
},
170 { 'J', "", INPUT_CSI_ED
},
171 { 'K', "", INPUT_CSI_EL
},
172 { 'L', "", INPUT_CSI_IL
},
173 { 'M', "", INPUT_CSI_DL
},
174 { 'P', "", INPUT_CSI_DCH
},
175 { 'X', "", INPUT_CSI_ECH
},
176 { 'Z', "", INPUT_CSI_CBT
},
177 { 'c', "", INPUT_CSI_DA
},
178 { 'c', ">", INPUT_CSI_DA_TWO
},
179 { 'd', "", INPUT_CSI_VPA
},
180 { 'f', "", INPUT_CSI_CUP
},
181 { 'g', "", INPUT_CSI_TBC
},
182 { 'h', "", INPUT_CSI_SM
},
183 { 'h', "?", INPUT_CSI_SM_PRIVATE
},
184 { 'l', "", INPUT_CSI_RM
},
185 { 'l', "?", INPUT_CSI_RM_PRIVATE
},
186 { 'm', "", INPUT_CSI_SGR
},
187 { 'n', "", INPUT_CSI_DSR
},
188 { 'q', " ", INPUT_CSI_DECSCUSR
},
189 { 'r', "", INPUT_CSI_DECSTBM
},
190 { 's', "", INPUT_CSI_SCP
},
191 { 'u', "", INPUT_CSI_RCP
},
194 /* Input transition. */
195 struct input_transition
{
199 int (*handler
)(struct input_ctx
*);
200 const struct input_state
*state
;
206 void (*enter
)(struct input_ctx
*);
207 void (*exit
)(struct input_ctx
*);
208 const struct input_transition
*transitions
;
211 /* State transitions available from all states. */
212 #define INPUT_STATE_ANYWHERE \
213 { 0x18, 0x18, input_c0_dispatch, &input_state_ground }, \
214 { 0x1a, 0x1a, input_c0_dispatch, &input_state_ground }, \
215 { 0x1b, 0x1b, NULL, &input_state_esc_enter }
217 /* Forward declarations of state tables. */
218 const struct input_transition input_state_ground_table
[];
219 const struct input_transition input_state_esc_enter_table
[];
220 const struct input_transition input_state_esc_intermediate_table
[];
221 const struct input_transition input_state_csi_enter_table
[];
222 const struct input_transition input_state_csi_parameter_table
[];
223 const struct input_transition input_state_csi_intermediate_table
[];
224 const struct input_transition input_state_csi_ignore_table
[];
225 const struct input_transition input_state_dcs_enter_table
[];
226 const struct input_transition input_state_dcs_parameter_table
[];
227 const struct input_transition input_state_dcs_intermediate_table
[];
228 const struct input_transition input_state_dcs_handler_table
[];
229 const struct input_transition input_state_dcs_escape_table
[];
230 const struct input_transition input_state_dcs_ignore_table
[];
231 const struct input_transition input_state_osc_string_table
[];
232 const struct input_transition input_state_apc_string_table
[];
233 const struct input_transition input_state_rename_string_table
[];
234 const struct input_transition input_state_consume_st_table
[];
235 const struct input_transition input_state_utf8_three_table
[];
236 const struct input_transition input_state_utf8_two_table
[];
237 const struct input_transition input_state_utf8_one_table
[];
239 /* ground state definition. */
240 const struct input_state input_state_ground
= {
243 input_state_ground_table
246 /* esc_enter state definition. */
247 const struct input_state input_state_esc_enter
= {
250 input_state_esc_enter_table
253 /* esc_intermediate state definition. */
254 const struct input_state input_state_esc_intermediate
= {
257 input_state_esc_intermediate_table
260 /* csi_enter state definition. */
261 const struct input_state input_state_csi_enter
= {
264 input_state_csi_enter_table
267 /* csi_parameter state definition. */
268 const struct input_state input_state_csi_parameter
= {
271 input_state_csi_parameter_table
274 /* csi_intermediate state definition. */
275 const struct input_state input_state_csi_intermediate
= {
278 input_state_csi_intermediate_table
281 /* csi_ignore state definition. */
282 const struct input_state input_state_csi_ignore
= {
285 input_state_csi_ignore_table
288 /* dcs_enter state definition. */
289 const struct input_state input_state_dcs_enter
= {
292 input_state_dcs_enter_table
295 /* dcs_parameter state definition. */
296 const struct input_state input_state_dcs_parameter
= {
299 input_state_dcs_parameter_table
302 /* dcs_intermediate state definition. */
303 const struct input_state input_state_dcs_intermediate
= {
306 input_state_dcs_intermediate_table
309 /* dcs_handler state definition. */
310 const struct input_state input_state_dcs_handler
= {
313 input_state_dcs_handler_table
316 /* dcs_escape state definition. */
317 const struct input_state input_state_dcs_escape
= {
320 input_state_dcs_escape_table
323 /* dcs_ignore state definition. */
324 const struct input_state input_state_dcs_ignore
= {
327 input_state_dcs_ignore_table
330 /* osc_string state definition. */
331 const struct input_state input_state_osc_string
= {
333 input_enter_osc
, input_exit_osc
,
334 input_state_osc_string_table
337 /* apc_string state definition. */
338 const struct input_state input_state_apc_string
= {
340 input_enter_apc
, input_exit_apc
,
341 input_state_apc_string_table
344 /* rename_string state definition. */
345 const struct input_state input_state_rename_string
= {
347 input_enter_rename
, input_exit_rename
,
348 input_state_rename_string_table
351 /* consume_st state definition. */
352 const struct input_state input_state_consume_st
= {
355 input_state_consume_st_table
358 /* utf8_three state definition. */
359 const struct input_state input_state_utf8_three
= {
362 input_state_utf8_three_table
365 /* utf8_two state definition. */
366 const struct input_state input_state_utf8_two
= {
369 input_state_utf8_two_table
372 /* utf8_one state definition. */
373 const struct input_state input_state_utf8_one
= {
376 input_state_utf8_one_table
379 /* ground state table. */
380 const struct input_transition input_state_ground_table
[] = {
381 INPUT_STATE_ANYWHERE
,
383 { 0x00, 0x17, input_c0_dispatch
, NULL
},
384 { 0x19, 0x19, input_c0_dispatch
, NULL
},
385 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
386 { 0x20, 0x7e, input_print
, NULL
},
387 { 0x7f, 0x7f, NULL
, NULL
},
388 { 0x80, 0xc1, input_print
, NULL
},
389 { 0xc2, 0xdf, input_utf8_open
, &input_state_utf8_one
},
390 { 0xe0, 0xef, input_utf8_open
, &input_state_utf8_two
},
391 { 0xf0, 0xf4, input_utf8_open
, &input_state_utf8_three
},
392 { 0xf5, 0xff, input_print
, NULL
},
394 { -1, -1, NULL
, NULL
}
397 /* esc_enter state table. */
398 const struct input_transition input_state_esc_enter_table
[] = {
399 INPUT_STATE_ANYWHERE
,
401 { 0x00, 0x17, input_c0_dispatch
, NULL
},
402 { 0x19, 0x19, input_c0_dispatch
, NULL
},
403 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
404 { 0x20, 0x2f, input_intermediate
, &input_state_esc_intermediate
},
405 { 0x30, 0x4f, input_esc_dispatch
, &input_state_ground
},
406 { 0x50, 0x50, NULL
, &input_state_dcs_enter
},
407 { 0x51, 0x57, input_esc_dispatch
, &input_state_ground
},
408 { 0x58, 0x58, NULL
, &input_state_consume_st
},
409 { 0x59, 0x59, input_esc_dispatch
, &input_state_ground
},
410 { 0x5a, 0x5a, input_esc_dispatch
, &input_state_ground
},
411 { 0x5b, 0x5b, NULL
, &input_state_csi_enter
},
412 { 0x5c, 0x5c, input_esc_dispatch
, &input_state_ground
},
413 { 0x5d, 0x5d, NULL
, &input_state_osc_string
},
414 { 0x5e, 0x5e, NULL
, &input_state_consume_st
},
415 { 0x5f, 0x5f, NULL
, &input_state_apc_string
},
416 { 0x60, 0x6a, input_esc_dispatch
, &input_state_ground
},
417 { 0x6b, 0x6b, NULL
, &input_state_rename_string
},
418 { 0x6c, 0x7e, input_esc_dispatch
, &input_state_ground
},
419 { 0x7f, 0xff, NULL
, NULL
},
421 { -1, -1, NULL
, NULL
}
424 /* esc_interm state table. */
425 const struct input_transition input_state_esc_intermediate_table
[] = {
426 INPUT_STATE_ANYWHERE
,
428 { 0x00, 0x17, input_c0_dispatch
, NULL
},
429 { 0x19, 0x19, input_c0_dispatch
, NULL
},
430 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
431 { 0x20, 0x2f, input_intermediate
, NULL
},
432 { 0x30, 0x7e, input_esc_dispatch
, &input_state_ground
},
433 { 0x7f, 0xff, NULL
, NULL
},
435 { -1, -1, NULL
, NULL
}
438 /* csi_enter state table. */
439 const struct input_transition input_state_csi_enter_table
[] = {
440 INPUT_STATE_ANYWHERE
,
442 { 0x00, 0x17, input_c0_dispatch
, NULL
},
443 { 0x19, 0x19, input_c0_dispatch
, NULL
},
444 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
445 { 0x20, 0x2f, input_intermediate
, &input_state_csi_intermediate
},
446 { 0x30, 0x39, input_parameter
, &input_state_csi_parameter
},
447 { 0x3a, 0x3a, NULL
, &input_state_csi_ignore
},
448 { 0x3b, 0x3b, input_parameter
, &input_state_csi_parameter
},
449 { 0x3c, 0x3f, input_intermediate
, &input_state_csi_parameter
},
450 { 0x40, 0x7e, input_csi_dispatch
, &input_state_ground
},
451 { 0x7f, 0xff, NULL
, NULL
},
453 { -1, -1, NULL
, NULL
}
456 /* csi_parameter state table. */
457 const struct input_transition input_state_csi_parameter_table
[] = {
458 INPUT_STATE_ANYWHERE
,
460 { 0x00, 0x17, input_c0_dispatch
, NULL
},
461 { 0x19, 0x19, input_c0_dispatch
, NULL
},
462 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
463 { 0x20, 0x2f, input_intermediate
, &input_state_csi_intermediate
},
464 { 0x30, 0x39, input_parameter
, NULL
},
465 { 0x3a, 0x3a, NULL
, &input_state_csi_ignore
},
466 { 0x3b, 0x3b, input_parameter
, NULL
},
467 { 0x3c, 0x3f, NULL
, &input_state_csi_ignore
},
468 { 0x40, 0x7e, input_csi_dispatch
, &input_state_ground
},
469 { 0x7f, 0xff, NULL
, NULL
},
471 { -1, -1, NULL
, NULL
}
474 /* csi_intermediate state table. */
475 const struct input_transition input_state_csi_intermediate_table
[] = {
476 INPUT_STATE_ANYWHERE
,
478 { 0x00, 0x17, input_c0_dispatch
, NULL
},
479 { 0x19, 0x19, input_c0_dispatch
, NULL
},
480 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
481 { 0x20, 0x2f, input_intermediate
, NULL
},
482 { 0x30, 0x3f, NULL
, &input_state_csi_ignore
},
483 { 0x40, 0x7e, input_csi_dispatch
, &input_state_ground
},
484 { 0x7f, 0xff, NULL
, NULL
},
486 { -1, -1, NULL
, NULL
}
489 /* csi_ignore state table. */
490 const struct input_transition input_state_csi_ignore_table
[] = {
491 INPUT_STATE_ANYWHERE
,
493 { 0x00, 0x17, input_c0_dispatch
, NULL
},
494 { 0x19, 0x19, input_c0_dispatch
, NULL
},
495 { 0x1c, 0x1f, input_c0_dispatch
, NULL
},
496 { 0x20, 0x3f, NULL
, NULL
},
497 { 0x40, 0x7e, NULL
, &input_state_ground
},
498 { 0x7f, 0xff, NULL
, NULL
},
500 { -1, -1, NULL
, NULL
}
503 /* dcs_enter state table. */
504 const struct input_transition input_state_dcs_enter_table
[] = {
505 INPUT_STATE_ANYWHERE
,
507 { 0x00, 0x17, NULL
, NULL
},
508 { 0x19, 0x19, NULL
, NULL
},
509 { 0x1c, 0x1f, NULL
, NULL
},
510 { 0x20, 0x2f, input_intermediate
, &input_state_dcs_intermediate
},
511 { 0x30, 0x39, input_parameter
, &input_state_dcs_parameter
},
512 { 0x3a, 0x3a, NULL
, &input_state_dcs_ignore
},
513 { 0x3b, 0x3b, input_parameter
, &input_state_dcs_parameter
},
514 { 0x3c, 0x3f, input_intermediate
, &input_state_dcs_parameter
},
515 { 0x40, 0x7e, input_input
, &input_state_dcs_handler
},
516 { 0x7f, 0xff, NULL
, NULL
},
518 { -1, -1, NULL
, NULL
}
521 /* dcs_parameter state table. */
522 const struct input_transition input_state_dcs_parameter_table
[] = {
523 INPUT_STATE_ANYWHERE
,
525 { 0x00, 0x17, NULL
, NULL
},
526 { 0x19, 0x19, NULL
, NULL
},
527 { 0x1c, 0x1f, NULL
, NULL
},
528 { 0x20, 0x2f, input_intermediate
, &input_state_dcs_intermediate
},
529 { 0x30, 0x39, input_parameter
, NULL
},
530 { 0x3a, 0x3a, NULL
, &input_state_dcs_ignore
},
531 { 0x3b, 0x3b, input_parameter
, NULL
},
532 { 0x3c, 0x3f, NULL
, &input_state_dcs_ignore
},
533 { 0x40, 0x7e, input_input
, &input_state_dcs_handler
},
534 { 0x7f, 0xff, NULL
, NULL
},
536 { -1, -1, NULL
, NULL
}
539 /* dcs_interm state table. */
540 const struct input_transition input_state_dcs_intermediate_table
[] = {
541 INPUT_STATE_ANYWHERE
,
543 { 0x00, 0x17, NULL
, NULL
},
544 { 0x19, 0x19, NULL
, NULL
},
545 { 0x1c, 0x1f, NULL
, NULL
},
546 { 0x20, 0x2f, input_intermediate
, NULL
},
547 { 0x30, 0x3f, NULL
, &input_state_dcs_ignore
},
548 { 0x40, 0x7e, input_input
, &input_state_dcs_handler
},
549 { 0x7f, 0xff, NULL
, NULL
},
551 { -1, -1, NULL
, NULL
}
554 /* dcs_handler state table. */
555 const struct input_transition input_state_dcs_handler_table
[] = {
556 /* No INPUT_STATE_ANYWHERE */
558 { 0x00, 0x1a, input_input
, NULL
},
559 { 0x1b, 0x1b, NULL
, &input_state_dcs_escape
},
560 { 0x1c, 0xff, input_input
, NULL
},
562 { -1, -1, NULL
, NULL
}
565 /* dcs_escape state table. */
566 const struct input_transition input_state_dcs_escape_table
[] = {
567 /* No INPUT_STATE_ANYWHERE */
569 { 0x00, 0x5b, input_input
, &input_state_dcs_handler
},
570 { 0x5c, 0x5c, input_dcs_dispatch
, &input_state_ground
},
571 { 0x5d, 0xff, input_input
, &input_state_dcs_handler
},
573 { -1, -1, NULL
, NULL
}
576 /* dcs_ignore state table. */
577 const struct input_transition input_state_dcs_ignore_table
[] = {
578 INPUT_STATE_ANYWHERE
,
580 { 0x00, 0x17, NULL
, NULL
},
581 { 0x19, 0x19, NULL
, NULL
},
582 { 0x1c, 0x1f, NULL
, NULL
},
583 { 0x20, 0xff, NULL
, NULL
},
585 { -1, -1, NULL
, NULL
}
588 /* osc_string state table. */
589 const struct input_transition input_state_osc_string_table
[] = {
590 INPUT_STATE_ANYWHERE
,
592 { 0x00, 0x06, NULL
, NULL
},
593 { 0x07, 0x07, NULL
, &input_state_ground
},
594 { 0x08, 0x17, NULL
, NULL
},
595 { 0x19, 0x19, NULL
, NULL
},
596 { 0x1c, 0x1f, NULL
, NULL
},
597 { 0x20, 0xff, input_input
, NULL
},
599 { -1, -1, NULL
, NULL
}
602 /* apc_string state table. */
603 const struct input_transition input_state_apc_string_table
[] = {
604 INPUT_STATE_ANYWHERE
,
606 { 0x00, 0x17, NULL
, NULL
},
607 { 0x19, 0x19, NULL
, NULL
},
608 { 0x1c, 0x1f, NULL
, NULL
},
609 { 0x20, 0xff, input_input
, NULL
},
611 { -1, -1, NULL
, NULL
}
614 /* rename_string state table. */
615 const struct input_transition input_state_rename_string_table
[] = {
616 INPUT_STATE_ANYWHERE
,
618 { 0x00, 0x17, NULL
, NULL
},
619 { 0x19, 0x19, NULL
, NULL
},
620 { 0x1c, 0x1f, NULL
, NULL
},
621 { 0x20, 0xff, input_input
, NULL
},
623 { -1, -1, NULL
, NULL
}
626 /* consume_st state table. */
627 const struct input_transition input_state_consume_st_table
[] = {
628 INPUT_STATE_ANYWHERE
,
630 { 0x00, 0x17, NULL
, NULL
},
631 { 0x19, 0x19, NULL
, NULL
},
632 { 0x1c, 0x1f, NULL
, NULL
},
633 { 0x20, 0xff, NULL
, NULL
},
635 { -1, -1, NULL
, NULL
}
638 /* utf8_three state table. */
639 const struct input_transition input_state_utf8_three_table
[] = {
640 /* No INPUT_STATE_ANYWHERE */
642 { 0x00, 0x7f, NULL
, &input_state_ground
},
643 { 0x80, 0xbf, input_utf8_add
, &input_state_utf8_two
},
644 { 0xc0, 0xff, NULL
, &input_state_ground
},
646 { -1, -1, NULL
, NULL
}
649 /* utf8_two state table. */
650 const struct input_transition input_state_utf8_two_table
[] = {
651 /* No INPUT_STATE_ANYWHERE */
653 { 0x00, 0x7f, NULL
, &input_state_ground
},
654 { 0x80, 0xbf, input_utf8_add
, &input_state_utf8_one
},
655 { 0xc0, 0xff, NULL
, &input_state_ground
},
657 { -1, -1, NULL
, NULL
}
660 /* utf8_one state table. */
661 const struct input_transition input_state_utf8_one_table
[] = {
662 /* No INPUT_STATE_ANYWHERE */
664 { 0x00, 0x7f, NULL
, &input_state_ground
},
665 { 0x80, 0xbf, input_utf8_close
, &input_state_ground
},
666 { 0xc0, 0xff, NULL
, &input_state_ground
},
668 { -1, -1, NULL
, NULL
}
671 /* Input table compare. */
673 input_table_compare(const void *key
, const void *value
)
675 const struct input_ctx
*ictx
= key
;
676 const struct input_table_entry
*entry
= value
;
678 if (ictx
->ch
!= entry
->ch
)
679 return (ictx
->ch
- entry
->ch
);
680 return (strcmp(ictx
->interm_buf
, entry
->interm
));
683 /* Initialise input parser. */
685 input_init(struct window_pane
*wp
)
687 struct input_ctx
*ictx
= &wp
->ictx
;
689 memcpy(&ictx
->cell
, &grid_default_cell
, sizeof ictx
->cell
);
691 memcpy(&ictx
->old_cell
, &grid_default_cell
, sizeof ictx
->old_cell
);
695 *ictx
->interm_buf
= '\0';
696 ictx
->interm_len
= 0;
698 *ictx
->param_buf
= '\0';
701 ictx
->state
= &input_state_ground
;
704 ictx
->since_ground
= evbuffer_new();
707 /* Destroy input parser. */
709 input_free(struct window_pane
*wp
)
712 evbuffer_free(wp
->ictx
.since_ground
);
715 /* Change input state. */
717 input_set_state(struct window_pane
*wp
, const struct input_transition
*itr
)
719 struct input_ctx
*ictx
= &wp
->ictx
;
720 struct evbuffer
*ground_evb
= ictx
->since_ground
;
722 if (ictx
->state
->exit
!= NULL
)
723 ictx
->state
->exit(ictx
);
725 if (itr
->state
== &input_state_ground
)
726 evbuffer_drain(ground_evb
, EVBUFFER_LENGTH(ground_evb
));
728 ictx
->state
= itr
->state
;
729 if (ictx
->state
->enter
!= NULL
)
730 ictx
->state
->enter(ictx
);
735 input_parse(struct window_pane
*wp
)
737 struct input_ctx
*ictx
= &wp
->ictx
;
738 const struct input_transition
*itr
;
739 struct evbuffer
*evb
= wp
->event
->input
;
743 if (EVBUFFER_LENGTH(evb
) == 0)
746 wp
->window
->flags
|= WINDOW_ACTIVITY
;
747 wp
->window
->flags
&= ~WINDOW_SILENCE
;
750 * Open the screen. Use NULL wp if there is a mode set as don't want to
753 if (wp
->mode
== NULL
)
754 screen_write_start(&ictx
->ctx
, wp
, &wp
->base
);
756 screen_write_start(&ictx
->ctx
, NULL
, &wp
->base
);
759 buf
= EVBUFFER_DATA(evb
);
760 len
= EVBUFFER_LENGTH(evb
);
761 notify_input(wp
, evb
);
764 /* Parse the input. */
766 ictx
->ch
= buf
[off
++];
767 log_debug("%s: '%c' %s", __func__
, ictx
->ch
, ictx
->state
->name
);
769 /* Find the transition. */
770 itr
= ictx
->state
->transitions
;
771 while (itr
->first
!= -1 && itr
->last
!= -1) {
772 if (ictx
->ch
>= itr
->first
&& ictx
->ch
<= itr
->last
)
776 if (itr
->first
== -1 || itr
->last
== -1) {
777 /* No transition? Eh? */
778 fatalx("No transition from state!");
782 * Execute the handler, if any. Don't switch state if it
785 if (itr
->handler
!= NULL
&& itr
->handler(ictx
) != 0)
788 /* And switch state, if necessary. */
789 if (itr
->state
!= NULL
)
790 input_set_state(wp
, itr
);
792 /* If not in ground state, save input. */
793 if (ictx
->state
!= &input_state_ground
)
794 evbuffer_add(ictx
->since_ground
, &ictx
->ch
, 1);
797 /* Close the screen. */
798 screen_write_stop(&ictx
->ctx
);
800 evbuffer_drain(evb
, len
);
803 /* Split the parameter list (if any). */
805 input_split(struct input_ctx
*ictx
)
812 ictx
->param_list_len
= 0;
813 if (ictx
->param_len
== 0)
816 ptr
= ictx
->param_buf
;
817 while ((out
= strsep(&ptr
, ";")) != NULL
) {
821 n
= strtonum(out
, 0, INT_MAX
, &errstr
);
826 ictx
->param_list
[ictx
->param_list_len
++] = n
;
827 if (ictx
->param_list_len
== nitems(ictx
->param_list
))
834 /* Get an argument or return default value. */
836 input_get(struct input_ctx
*ictx
, u_int validx
, int minval
, int defval
)
840 if (validx
>= ictx
->param_list_len
)
843 retval
= ictx
->param_list
[validx
];
851 /* Reply to terminal query. */
853 input_reply(struct input_ctx
*ictx
, const char *fmt
, ...)
859 vasprintf(&reply
, fmt
, ap
);
862 bufferevent_write(ictx
->wp
->event
, reply
, strlen(reply
));
866 /* Clear saved state. */
868 input_clear(struct input_ctx
*ictx
)
870 *ictx
->interm_buf
= '\0';
871 ictx
->interm_len
= 0;
873 *ictx
->param_buf
= '\0';
876 *ictx
->input_buf
= '\0';
879 ictx
->flags
&= ~INPUT_DISCARD
;
882 /* Output this character to the screen. */
884 input_print(struct input_ctx
*ictx
)
886 grid_cell_one(&ictx
->cell
, ictx
->ch
);
887 screen_write_cell(&ictx
->ctx
, &ictx
->cell
);
892 /* Collect intermediate string. */
894 input_intermediate(struct input_ctx
*ictx
)
896 if (ictx
->interm_len
== (sizeof ictx
->interm_buf
) - 1)
897 ictx
->flags
|= INPUT_DISCARD
;
899 ictx
->interm_buf
[ictx
->interm_len
++] = ictx
->ch
;
900 ictx
->interm_buf
[ictx
->interm_len
] = '\0';
906 /* Collect parameter string. */
908 input_parameter(struct input_ctx
*ictx
)
910 if (ictx
->param_len
== (sizeof ictx
->param_buf
) - 1)
911 ictx
->flags
|= INPUT_DISCARD
;
913 ictx
->param_buf
[ictx
->param_len
++] = ictx
->ch
;
914 ictx
->param_buf
[ictx
->param_len
] = '\0';
920 /* Collect input string. */
922 input_input(struct input_ctx
*ictx
)
924 if (ictx
->input_len
== (sizeof ictx
->input_buf
) - 1)
925 ictx
->flags
|= INPUT_DISCARD
;
927 ictx
->input_buf
[ictx
->input_len
++] = ictx
->ch
;
928 ictx
->input_buf
[ictx
->input_len
] = '\0';
934 /* Execute C0 control sequence. */
936 input_c0_dispatch(struct input_ctx
*ictx
)
938 struct screen_write_ctx
*sctx
= &ictx
->ctx
;
939 struct window_pane
*wp
= ictx
->wp
;
940 struct screen
*s
= sctx
->s
;
943 log_debug("%s: '%c", __func__
, ictx
->ch
);
946 case '\000': /* NUL */
948 case '\007': /* BEL */
949 wp
->window
->flags
|= WINDOW_BELL
;
951 case '\010': /* BS */
952 screen_write_backspace(sctx
);
954 case '\011': /* HT */
955 /* Don't tab beyond the end of the line. */
956 if (s
->cx
>= screen_size_x(s
) - 1)
959 /* Find the next tab point, or use the last column if none. */
962 if (bit_test(s
->tabs
, s
->cx
))
964 } while (s
->cx
< screen_size_x(s
) - 1);
966 case '\012': /* LF */
967 case '\013': /* VT */
968 case '\014': /* FF */
969 screen_write_linefeed(sctx
, 0);
971 case '\015': /* CR */
972 screen_write_carriagereturn(sctx
);
974 case '\016': /* SO */
975 ictx
->cell
.attr
|= GRID_ATTR_CHARSET
;
977 case '\017': /* SI */
978 ictx
->cell
.attr
&= ~GRID_ATTR_CHARSET
;
981 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
988 trigger
= options_get_number(&wp
->window
->options
, "c0-change-trigger");
989 if (++wp
->changes
== trigger
) {
990 wp
->flags
|= PANE_DROP
;
991 window_pane_timer_start(wp
);
997 /* Execute escape sequence. */
999 input_esc_dispatch(struct input_ctx
*ictx
)
1001 struct screen_write_ctx
*sctx
= &ictx
->ctx
;
1002 struct screen
*s
= sctx
->s
;
1003 struct input_table_entry
*entry
;
1005 if (ictx
->flags
& INPUT_DISCARD
)
1007 log_debug("%s: '%c', %s", __func__
, ictx
->ch
, ictx
->interm_buf
);
1009 entry
= bsearch(ictx
, input_esc_table
, nitems(input_esc_table
),
1010 sizeof input_esc_table
[0], input_table_compare
);
1011 if (entry
== NULL
) {
1012 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1016 switch (entry
->type
) {
1018 memcpy(&ictx
->cell
, &grid_default_cell
, sizeof ictx
->cell
);
1019 memcpy(&ictx
->old_cell
, &ictx
->cell
, sizeof ictx
->old_cell
);
1023 screen_write_reset(sctx
);
1026 screen_write_linefeed(sctx
, 0);
1029 screen_write_carriagereturn(sctx
);
1030 screen_write_linefeed(sctx
, 0);
1033 if (s
->cx
< screen_size_x(s
))
1034 bit_set(s
->tabs
, s
->cx
);
1037 screen_write_reverseindex(sctx
);
1039 case INPUT_ESC_DECKPAM
:
1040 screen_write_mode_set(sctx
, MODE_KKEYPAD
);
1042 case INPUT_ESC_DECKPNM
:
1043 screen_write_mode_clear(sctx
, MODE_KKEYPAD
);
1045 case INPUT_ESC_DECSC
:
1046 memcpy(&ictx
->old_cell
, &ictx
->cell
, sizeof ictx
->old_cell
);
1047 ictx
->old_cx
= s
->cx
;
1048 ictx
->old_cy
= s
->cy
;
1050 case INPUT_ESC_DECRC
:
1051 memcpy(&ictx
->cell
, &ictx
->old_cell
, sizeof ictx
->cell
);
1052 screen_write_cursormove(sctx
, ictx
->old_cx
, ictx
->old_cy
);
1054 case INPUT_ESC_DECALN
:
1055 screen_write_alignmenttest(sctx
);
1057 case INPUT_ESC_SCSON_G0
:
1059 * Not really supported, but fake it up enough for those that
1060 * use it to switch character sets (by redefining G0 to
1061 * graphics set, rather than switching to G1).
1063 ictx
->cell
.attr
&= ~GRID_ATTR_CHARSET
;
1065 case INPUT_ESC_SCSOFF_G0
:
1066 ictx
->cell
.attr
|= GRID_ATTR_CHARSET
;
1073 /* Execute control sequence. */
1075 input_csi_dispatch(struct input_ctx
*ictx
)
1077 struct screen_write_ctx
*sctx
= &ictx
->ctx
;
1078 struct screen
*s
= sctx
->s
;
1079 struct input_table_entry
*entry
;
1082 if (ictx
->flags
& INPUT_DISCARD
)
1084 if (input_split(ictx
) != 0)
1086 log_debug("%s: '%c' \"%s\" \"%s\"",
1087 __func__
, ictx
->ch
, ictx
->interm_buf
, ictx
->param_buf
);
1089 entry
= bsearch(ictx
, input_csi_table
, nitems(input_csi_table
),
1090 sizeof input_csi_table
[0], input_table_compare
);
1091 if (entry
== NULL
) {
1092 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1096 switch (entry
->type
) {
1098 /* Find the previous tab point, n times. */
1099 n
= input_get(ictx
, 0, 1, 1);
1100 while (s
->cx
> 0 && n
-- > 0) {
1103 while (s
->cx
> 0 && !bit_test(s
->tabs
, s
->cx
));
1107 screen_write_cursorleft(sctx
, input_get(ictx
, 0, 1, 1));
1110 screen_write_cursordown(sctx
, input_get(ictx
, 0, 1, 1));
1113 screen_write_cursorright(sctx
, input_get(ictx
, 0, 1, 1));
1116 n
= input_get(ictx
, 0, 1, 1);
1117 m
= input_get(ictx
, 1, 1, 1);
1118 screen_write_cursormove(sctx
, m
- 1, n
- 1);
1121 screen_write_cursorup(sctx
, input_get(ictx
, 0, 1, 1));
1124 screen_write_carriagereturn(sctx
);
1125 screen_write_cursordown(sctx
, input_get(ictx
, 0, 1, 1));
1128 screen_write_carriagereturn(sctx
);
1129 screen_write_cursorup(sctx
, input_get(ictx
, 0, 1, 1));
1132 switch (input_get(ictx
, 0, 0, 0)) {
1134 input_reply(ictx
, "\033[?1;2c");
1137 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1141 case INPUT_CSI_DA_TWO
:
1142 switch (input_get(ictx
, 0, 0, 0)) {
1144 input_reply(ictx
, "\033[>0;95;0c");
1147 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1152 screen_write_clearcharacter(sctx
, input_get(ictx
, 0, 1, 1));
1155 screen_write_deletecharacter(sctx
, input_get(ictx
, 0, 1, 1));
1157 case INPUT_CSI_DECSTBM
:
1158 n
= input_get(ictx
, 0, 1, 1);
1159 m
= input_get(ictx
, 1, 1, screen_size_y(s
));
1160 screen_write_scrollregion(sctx
, n
- 1, m
- 1);
1163 screen_write_deleteline(sctx
, input_get(ictx
, 0, 1, 1));
1166 switch (input_get(ictx
, 0, 0, 0)) {
1168 input_reply(ictx
, "\033[0n");
1171 input_reply(ictx
, "\033[%u;%uR", s
->cy
+ 1, s
->cx
+ 1);
1174 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1179 switch (input_get(ictx
, 0, 0, 0)) {
1181 screen_write_clearendofscreen(sctx
);
1184 screen_write_clearstartofscreen(sctx
);
1187 screen_write_clearscreen(sctx
);
1190 switch (input_get(ictx
, 1, 0, 0)) {
1193 * Linux console extension to clear history
1194 * (for example before locking the screen).
1196 screen_write_clearhistory(sctx
);
1201 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1206 switch (input_get(ictx
, 0, 0, 0)) {
1208 screen_write_clearendofline(sctx
);
1211 screen_write_clearstartofline(sctx
);
1214 screen_write_clearline(sctx
);
1217 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1222 n
= input_get(ictx
, 0, 1, 1);
1223 screen_write_cursormove(sctx
, n
- 1, s
->cy
);
1226 screen_write_insertcharacter(sctx
, input_get(ictx
, 0, 1, 1));
1229 screen_write_insertline(sctx
, input_get(ictx
, 0, 1, 1));
1232 memcpy(&ictx
->cell
, &ictx
->old_cell
, sizeof ictx
->cell
);
1233 screen_write_cursormove(sctx
, ictx
->old_cx
, ictx
->old_cy
);
1236 input_csi_dispatch_rm(ictx
);
1238 case INPUT_CSI_RM_PRIVATE
:
1239 input_csi_dispatch_rm_private(ictx
);
1242 memcpy(&ictx
->old_cell
, &ictx
->cell
, sizeof ictx
->old_cell
);
1243 ictx
->old_cx
= s
->cx
;
1244 ictx
->old_cy
= s
->cy
;
1247 input_csi_dispatch_sgr(ictx
);
1250 input_csi_dispatch_sm(ictx
);
1252 case INPUT_CSI_SM_PRIVATE
:
1253 input_csi_dispatch_sm_private(ictx
);
1256 switch (input_get(ictx
, 0, 0, 0)) {
1258 if (s
->cx
< screen_size_x(s
))
1259 bit_clear(s
->tabs
, s
->cx
);
1262 bit_nclear(s
->tabs
, 0, screen_size_x(s
) - 1);
1265 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1270 n
= input_get(ictx
, 0, 1, 1);
1271 screen_write_cursormove(sctx
, s
->cx
, n
- 1);
1273 case INPUT_CSI_DECSCUSR
:
1274 n
= input_get(ictx
, 0, 0, 0);
1275 screen_set_cursor_style(s
, n
);
1282 /* Handle CSI RM. */
1284 input_csi_dispatch_rm(struct input_ctx
*ictx
)
1288 for (i
= 0; i
< ictx
->param_list_len
; i
++) {
1289 switch (input_get(ictx
, i
, 0, -1)) {
1291 screen_write_mode_clear(&ictx
->ctx
, MODE_INSERT
);
1294 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1300 /* Handle CSI private RM. */
1302 input_csi_dispatch_rm_private(struct input_ctx
*ictx
)
1306 for (i
= 0; i
< ictx
->param_list_len
; i
++) {
1307 switch (input_get(ictx
, i
, 0, -1)) {
1308 case 1: /* DECCKM */
1309 screen_write_mode_clear(&ictx
->ctx
, MODE_KCURSOR
);
1311 case 3: /* DECCOLM */
1312 screen_write_cursormove(&ictx
->ctx
, 0, 0);
1313 screen_write_clearscreen(&ictx
->ctx
);
1315 case 7: /* DECAWM */
1316 screen_write_mode_clear(&ictx
->ctx
, MODE_WRAP
);
1319 screen_write_mode_clear(&ictx
->ctx
, MODE_CURSOR
);
1325 screen_write_mode_clear(&ictx
->ctx
, ALL_MOUSE_MODES
);
1328 screen_write_mode_clear(&ictx
->ctx
, MODE_FOCUSON
);
1331 screen_write_mode_clear(&ictx
->ctx
, MODE_MOUSE_UTF8
);
1334 screen_write_mode_clear(&ictx
->ctx
, MODE_MOUSE_SGR
);
1338 window_pane_alternate_off(ictx
->wp
, &ictx
->cell
, 0);
1341 window_pane_alternate_off(ictx
->wp
, &ictx
->cell
, 1);
1344 screen_write_mode_clear(&ictx
->ctx
, MODE_BRACKETPASTE
);
1347 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1353 /* Handle CSI SM. */
1355 input_csi_dispatch_sm(struct input_ctx
*ictx
)
1359 for (i
= 0; i
< ictx
->param_list_len
; i
++) {
1360 switch (input_get(ictx
, i
, 0, -1)) {
1362 screen_write_mode_set(&ictx
->ctx
, MODE_INSERT
);
1365 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1371 /* Handle CSI private SM. */
1373 input_csi_dispatch_sm_private(struct input_ctx
*ictx
)
1377 for (i
= 0; i
< ictx
->param_list_len
; i
++) {
1378 switch (input_get(ictx
, i
, 0, -1)) {
1379 case 1: /* DECCKM */
1380 screen_write_mode_set(&ictx
->ctx
, MODE_KCURSOR
);
1382 case 3: /* DECCOLM */
1383 screen_write_cursormove(&ictx
->ctx
, 0, 0);
1384 screen_write_clearscreen(&ictx
->ctx
);
1386 case 7: /* DECAWM */
1387 screen_write_mode_set(&ictx
->ctx
, MODE_WRAP
);
1390 screen_write_mode_set(&ictx
->ctx
, MODE_CURSOR
);
1393 screen_write_mode_clear(&ictx
->ctx
, ALL_MOUSE_MODES
);
1394 screen_write_mode_set(&ictx
->ctx
, MODE_MOUSE_STANDARD
);
1397 screen_write_mode_clear(&ictx
->ctx
, ALL_MOUSE_MODES
);
1398 screen_write_mode_set(&ictx
->ctx
, MODE_MOUSE_BUTTON
);
1401 screen_write_mode_clear(&ictx
->ctx
, ALL_MOUSE_MODES
);
1402 screen_write_mode_set(&ictx
->ctx
, MODE_MOUSE_ANY
);
1405 if (ictx
->ctx
.s
->mode
& MODE_FOCUSON
)
1407 screen_write_mode_set(&ictx
->ctx
, MODE_FOCUSON
);
1408 ictx
->wp
->flags
|= PANE_FOCUSPUSH
; /* force update */
1411 screen_write_mode_set(&ictx
->ctx
, MODE_MOUSE_UTF8
);
1414 screen_write_mode_set(&ictx
->ctx
, MODE_MOUSE_SGR
);
1418 window_pane_alternate_on(ictx
->wp
, &ictx
->cell
, 0);
1421 window_pane_alternate_on(ictx
->wp
, &ictx
->cell
, 1);
1424 screen_write_mode_set(&ictx
->ctx
, MODE_BRACKETPASTE
);
1427 log_debug("%s: unknown '%c'", __func__
, ictx
->ch
);
1433 /* Handle CSI SGR. */
1435 input_csi_dispatch_sgr(struct input_ctx
*ictx
)
1437 struct grid_cell
*gc
= &ictx
->cell
;
1442 if (ictx
->param_list_len
== 0) {
1444 memcpy(gc
, &grid_default_cell
, sizeof *gc
);
1445 gc
->attr
|= (attr
& GRID_ATTR_CHARSET
);
1449 for (i
= 0; i
< ictx
->param_list_len
; i
++) {
1450 n
= input_get(ictx
, i
, 0, 0);
1452 if (n
== 38 || n
== 48) {
1454 if (input_get(ictx
, i
, 0, -1) != 5)
1458 m
= input_get(ictx
, i
, 0, -1);
1461 gc
->flags
&= ~GRID_FLAG_FG256
;
1463 } else if (n
== 48) {
1464 gc
->flags
&= ~GRID_FLAG_BG256
;
1470 gc
->flags
|= GRID_FLAG_FG256
;
1472 } else if (n
== 48) {
1473 gc
->flags
|= GRID_FLAG_BG256
;
1484 memcpy(gc
, &grid_default_cell
, sizeof *gc
);
1485 gc
->attr
|= (attr
& GRID_ATTR_CHARSET
);
1488 gc
->attr
|= GRID_ATTR_BRIGHT
;
1491 gc
->attr
|= GRID_ATTR_DIM
;
1494 gc
->attr
|= GRID_ATTR_ITALICS
;
1497 gc
->attr
|= GRID_ATTR_UNDERSCORE
;
1500 gc
->attr
|= GRID_ATTR_BLINK
;
1503 gc
->attr
|= GRID_ATTR_REVERSE
;
1506 gc
->attr
|= GRID_ATTR_HIDDEN
;
1509 gc
->attr
&= ~(GRID_ATTR_BRIGHT
|GRID_ATTR_DIM
);
1512 gc
->attr
&= ~GRID_ATTR_ITALICS
;
1515 gc
->attr
&= ~GRID_ATTR_UNDERSCORE
;
1518 gc
->attr
&= ~GRID_ATTR_BLINK
;
1521 gc
->attr
&= ~GRID_ATTR_REVERSE
;
1531 gc
->flags
&= ~GRID_FLAG_FG256
;
1535 gc
->flags
&= ~GRID_FLAG_FG256
;
1546 gc
->flags
&= ~GRID_FLAG_BG256
;
1550 gc
->flags
&= ~GRID_FLAG_BG256
;
1561 gc
->flags
&= ~GRID_FLAG_FG256
;
1572 gc
->flags
&= ~GRID_FLAG_BG256
;
1579 /* DCS terminator (ST) received. */
1581 input_dcs_dispatch(struct input_ctx
*ictx
)
1583 const char prefix
[] = "tmux;";
1584 const u_int prefix_len
= (sizeof prefix
) - 1;
1586 if (ictx
->flags
& INPUT_DISCARD
)
1589 log_debug("%s: \"%s\"", __func__
, ictx
->input_buf
);
1591 /* Check for tmux prefix. */
1592 if (ictx
->input_len
>= prefix_len
&&
1593 strncmp(ictx
->input_buf
, prefix
, prefix_len
) == 0) {
1594 screen_write_rawstring(&ictx
->ctx
,
1595 ictx
->input_buf
+ prefix_len
, ictx
->input_len
- prefix_len
);
1601 /* OSC string started. */
1603 input_enter_osc(struct input_ctx
*ictx
)
1605 log_debug("%s", __func__
);
1610 /* OSC terminator (ST) received. */
1612 input_exit_osc(struct input_ctx
*ictx
)
1614 u_char
*p
= ictx
->input_buf
;
1617 if (ictx
->flags
& INPUT_DISCARD
)
1619 if (ictx
->input_len
< 1 || *p
< '0' || *p
> '9')
1622 log_debug("%s: \"%s\"", __func__
, p
);
1625 while (*p
>= '0' && *p
<= '9')
1626 option
= option
* 10 + *p
++ - '0';
1633 screen_set_title(ictx
->ctx
.s
, p
);
1634 server_status_window(ictx
->wp
->window
);
1637 if (*p
!= '?') /* ? is colour request */
1638 screen_set_cursor_colour(ictx
->ctx
.s
, p
);
1641 if (*p
== '\0') /* no arguments allowed */
1642 screen_set_cursor_colour(ictx
->ctx
.s
, "");
1645 log_debug("%s: unknown '%u'", __func__
, option
);
1650 /* APC string started. */
1652 input_enter_apc(struct input_ctx
*ictx
)
1654 log_debug("%s", __func__
);
1659 /* APC terminator (ST) received. */
1661 input_exit_apc(struct input_ctx
*ictx
)
1663 if (ictx
->flags
& INPUT_DISCARD
)
1665 log_debug("%s: \"%s\"", __func__
, ictx
->input_buf
);
1667 screen_set_title(ictx
->ctx
.s
, ictx
->input_buf
);
1668 server_status_window(ictx
->wp
->window
);
1671 /* Rename string started. */
1673 input_enter_rename(struct input_ctx
*ictx
)
1675 log_debug("%s", __func__
);
1680 /* Rename terminator (ST) received. */
1682 input_exit_rename(struct input_ctx
*ictx
)
1684 if (ictx
->flags
& INPUT_DISCARD
)
1686 if (!options_get_number(&ictx
->wp
->window
->options
, "allow-rename"))
1688 log_debug("%s: \"%s\"", __func__
, ictx
->input_buf
);
1690 window_set_name(ictx
->wp
->window
, ictx
->input_buf
);
1691 options_set_number(&ictx
->wp
->window
->options
, "automatic-rename", 0);
1693 server_status_window(ictx
->wp
->window
);
1696 /* Open UTF-8 character. */
1698 input_utf8_open(struct input_ctx
*ictx
)
1700 if (!options_get_number(&ictx
->wp
->window
->options
, "utf8")) {
1701 /* Print, and do not switch state. */
1705 log_debug("%s", __func__
);
1707 utf8_open(&ictx
->utf8data
, ictx
->ch
);
1711 /* Append to UTF-8 character. */
1713 input_utf8_add(struct input_ctx
*ictx
)
1715 log_debug("%s", __func__
);
1717 utf8_append(&ictx
->utf8data
, ictx
->ch
);
1721 /* Close UTF-8 string. */
1723 input_utf8_close(struct input_ctx
*ictx
)
1725 log_debug("%s", __func__
);
1727 utf8_append(&ictx
->utf8data
, ictx
->ch
);
1729 grid_cell_set(&ictx
->cell
, &ictx
->utf8data
);
1730 screen_write_cell(&ictx
->ctx
, &ictx
->cell
);