Forward CSI "Media Copy" printer control sequences ESC[5i & ESC[4i and the data they bracket to client for output on a local printer. Once started, data is passed as unaltered binary bytes. All control sequences other than Printer-Controller-Off, are ignored.
While not comprehensive, this facility is sufficient to support the print-to-clipboard feature of some terminal emulators. --- input.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/input.c b/input.c index b95101c..e3fa38e 100644 --- a/input.c +++ b/input.c @@ -62,6 +62,8 @@ void input_enter_apc(struct input_ctx *); void input_exit_apc(struct input_ctx *); void input_enter_rename(struct input_ctx *); void input_exit_rename(struct input_ctx *); +void input_enter_media_copy(struct input_ctx *); +void input_exit_media_copy(struct input_ctx *); /* Input state handlers. */ int input_print(struct input_ctx *); @@ -76,6 +78,7 @@ int input_dcs_dispatch(struct input_ctx *); int input_utf8_open(struct input_ctx *); int input_utf8_add(struct input_ctx *); int input_utf8_close(struct input_ctx *); +int input_media_copy(struct input_ctx *ictx); /* Command table comparison function. */ int input_table_compare(const void *, const void *); @@ -230,6 +233,8 @@ const struct input_transition input_state_consume_st_table[]; const struct input_transition input_state_utf8_three_table[]; const struct input_transition input_state_utf8_two_table[]; const struct input_transition input_state_utf8_one_table[]; +const struct input_transition input_state_media_copy_table[]; +const struct input_transition input_state_csi_maybe_mc_table[]; /* ground state definition. */ const struct input_state input_state_ground = { @@ -371,6 +376,19 @@ const struct input_state input_state_utf8_one = { input_state_utf8_one_table }; +const struct input_state input_state_media_copy = { + "media_copy", + input_enter_media_copy, input_exit_media_copy, + input_state_media_copy_table +}; + +/* csi_maybe_me state definition. */ +const struct input_state input_state_csi_maybe_mc = { + "csi_maybe_mc", + NULL, NULL, + input_state_csi_maybe_mc_table +}; + /* ground state table. */ const struct input_transition input_state_ground_table[] = { INPUT_STATE_ANYWHERE, @@ -438,13 +456,40 @@ const struct input_transition input_state_csi_enter_table[] = { { 0x19, 0x19, input_c0_dispatch, NULL }, { 0x1c, 0x1f, input_c0_dispatch, NULL }, { 0x20, 0x2f, input_intermediate, &input_state_csi_intermediate }, - { 0x30, 0x39, input_parameter, &input_state_csi_parameter }, + { 0x30, 0x34, input_parameter, &input_state_csi_parameter }, + { 0x35, 0x35, input_parameter, &input_state_csi_maybe_mc }, + { 0x36, 0x39, input_parameter, &input_state_csi_parameter }, { 0x3a, 0x3a, NULL, &input_state_csi_ignore }, { 0x3b, 0x3b, input_parameter, &input_state_csi_parameter }, { 0x3c, 0x3f, input_intermediate, &input_state_csi_parameter }, { 0x40, 0x7e, input_csi_dispatch, &input_state_ground }, { 0x7f, 0xff, NULL, NULL }, +}; + +/* media_copy_table - ignore all control sequences */ +const struct input_transition input_state_media_copy_table[] = { + { 0x00, 0xff, input_media_copy, &input_state_ground }, + { -1, -1, NULL, NULL } +}; + +/* csi_maybe_mc - handle ESC[5i specially */ +const struct input_transition input_state_csi_maybe_mc_table[] = { + INPUT_STATE_ANYWHERE, + + { 0x00, 0x17, input_c0_dispatch, &input_state_csi_parameter }, + { 0x19, 0x19, input_c0_dispatch, &input_state_csi_parameter }, + { 0x1c, 0x1f, input_c0_dispatch, &input_state_csi_parameter }, + { 0x20, 0x2f, input_intermediate, &input_state_csi_intermediate }, + { 0x30, 0x39, input_parameter, &input_state_csi_parameter }, + { 0x3a, 0x3a, NULL, &input_state_csi_ignore }, + { 0x3b, 0x3b, input_parameter, &input_state_csi_parameter }, + { 0x3c, 0x3f, NULL, &input_state_csi_ignore }, + { 0x40, 0x68, input_csi_dispatch, &input_state_ground }, + { 0x69, 0x69, NULL, &input_state_media_copy }, + { 0x6a, 0x7e, input_csi_dispatch, &input_state_ground }, + { 0x7f, 0xff, NULL, &input_state_csi_parameter }, + { -1, -1, NULL, NULL } }; @@ -1611,6 +1656,28 @@ input_exit_rename(struct input_ctx *ictx) server_status_window(ictx->wp->window); } +int +input_media_copy(struct input_ctx *ictx) +{ + static const char* end_media_copy = "\x1b[4i"; + if (ictx->ch == end_media_copy[ictx->param_len]) + return ictx->param_len++ < 3; + ictx->param_len = 0; + return 1; +} + +void +input_enter_media_copy(struct input_ctx *ictx) +{ + ictx->param_len = 0; +} + +void +input_exit_media_copy(struct input_ctx *ictx) +{ + screen_write_verbatim(&ictx->ctx, ictx->since_ground); +} + /* Open UTF-8 character. */ int input_utf8_open(struct input_ctx *ictx) -- 1.7.10.4 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users