Mercurial > vim
annotate src/libvterm/src/parser.c @ 23810:8152b7daebad v8.2.2446
patch 8.2.2446: setting 'term' empty has different error if compiled with GUI
Commit: https://github.com/vim/vim/commit/5daa91162699e4f8b54f9d1caaaab2715038941c
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Feb 1 18:39:47 2021 +0100
patch 8.2.2446: setting 'term' empty has different error if compiled with GUI
Problem: Setting 'term' empty has different error if compiled with GUI.
Solution: Insert "else". (closes https://github.com/vim/vim/issues/7766)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 01 Feb 2021 18:45:06 +0100 |
parents | a4652d7ec99f |
children | f93337ae0612 |
rev | line source |
---|---|
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 #include "vterm_internal.h" |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 #include <stdio.h> |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 #include <string.h> |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
6 #undef DEBUG_PARSER |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
7 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
8 static int is_intermed(unsigned char c) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
9 { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
10 return c >= 0x20 && c <= 0x2f; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
11 } |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 static void do_control(VTerm *vt, unsigned char control) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 { |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
15 if(vt->parser.callbacks && vt->parser.callbacks->control) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
16 if((*vt->parser.callbacks->control)(control, vt->parser.cbdata)) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 DEBUG_LOG1("libvterm: Unhandled control 0x%02x\n", control); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
22 static void do_csi(VTerm *vt, char command) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 { |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
24 #ifdef DEBUG_PARSER |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
25 printf("Parsed CSI args as:\n", arglen, args); |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
26 printf(" leader: %s\n", vt->parser.v.csi.leader); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
27 for(int argi = 0; argi < vt->parser.v.csi.argi; argi++) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
28 printf(" %lu", CSI_ARG(vt->parser.v.csi.args[argi])); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
29 if(!CSI_ARG_HAS_MORE(vt->parser.v.csi.args[argi])) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 printf("\n"); |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
31 printf(" intermed: %s\n", vt->parser.intermed); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 #endif |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
35 if(vt->parser.callbacks && vt->parser.callbacks->csi) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
36 if((*vt->parser.callbacks->csi)( |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
37 vt->parser.v.csi.leaderlen ? vt->parser.v.csi.leader : NULL, |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
38 vt->parser.v.csi.args, |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
39 vt->parser.v.csi.argi, |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
40 vt->parser.intermedlen ? vt->parser.intermed : NULL, |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
41 command, |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
42 vt->parser.cbdata)) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
45 DEBUG_LOG1("libvterm: Unhandled CSI %c\n", command); |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
46 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
47 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
48 static void do_escape(VTerm *vt, char command) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
49 { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
50 char seq[INTERMED_MAX+1]; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
51 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
52 size_t len = vt->parser.intermedlen; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
53 strncpy(seq, vt->parser.intermed, len); |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
54 seq[len++] = command; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
55 seq[len] = 0; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
56 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
57 if(vt->parser.callbacks && vt->parser.callbacks->escape) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
58 if((*vt->parser.callbacks->escape)(seq, len, vt->parser.cbdata)) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
59 return; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
60 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
61 DEBUG_LOG1("libvterm: Unhandled escape ESC 0x%02x\n", command); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
64 static void string_fragment(VTerm *vt, const char *str, size_t len, int final) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
66 VTermStringFragment frag; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
67 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
68 frag.str = str; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
69 frag.len = len; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
70 frag.initial = vt->parser.string_initial; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
71 frag.final = final; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
72 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
73 switch(vt->parser.state) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
74 case OSC: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
75 if(vt->parser.callbacks && vt->parser.callbacks->osc) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
76 (*vt->parser.callbacks->osc)(vt->parser.v.osc.command, frag, vt->parser.cbdata); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
77 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
78 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
79 case DCS: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
80 if(len && vt->parser.callbacks && vt->parser.callbacks->dcs) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
81 (*vt->parser.callbacks->dcs)(vt->parser.v.dcs.command, vt->parser.v.dcs.commandlen, frag, vt->parser.cbdata); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
82 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
83 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
84 case NORMAL: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
85 case CSI_LEADER: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
86 case CSI_ARGS: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
87 case CSI_INTERMED: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
88 case OSC_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
89 case DCS_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
90 break; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
91 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
92 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
93 vt->parser.string_initial = FALSE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
94 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
95 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
96 size_t vterm_input_write(VTerm *vt, const char *bytes, size_t len) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
97 { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
98 size_t pos = 0; |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
99 const char *string_start = NULL; // init to avoid gcc warning |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
100 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
101 vt->in_backspace = 0; // Count down with BS key and activate when |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
102 // it reaches 1 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
103 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
104 switch(vt->parser.state) { |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
105 case NORMAL: |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
106 case CSI_LEADER: |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
107 case CSI_ARGS: |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
108 case CSI_INTERMED: |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
109 case OSC_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
110 case DCS_COMMAND: |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
111 string_start = NULL; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
112 break; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
113 case OSC: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
114 case DCS: |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
115 string_start = bytes; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
116 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
117 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
118 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
119 #define ENTER_STATE(st) do { vt->parser.state = st; string_start = NULL; } while(0) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
120 #define ENTER_NORMAL_STATE() ENTER_STATE(NORMAL) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
121 |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
122 #define IS_STRING_STATE() (vt->parser.state >= OSC_COMMAND) |
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
123 |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
124 for( ; pos < len; pos++) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
125 unsigned char c = bytes[pos]; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
126 int c1_allowed = !vt->mode.utf8; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
127 size_t string_len; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
128 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
129 if(c == 0x00 || c == 0x7f) { // NUL, DEL |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
130 if(IS_STRING_STATE()) { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
131 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
132 string_start = bytes + pos + 1; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
133 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
134 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
135 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
136 if(c == 0x18 || c == 0x1a) { // CAN, SUB |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
137 vt->parser.in_esc = FALSE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 ENTER_NORMAL_STATE(); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
139 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
140 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
141 else if(c == 0x1b) { // ESC |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
142 vt->parser.intermedlen = 0; |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
143 if(!IS_STRING_STATE()) |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
144 vt->parser.state = NORMAL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
145 vt->parser.in_esc = TRUE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
146 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
148 else if(c == 0x07 && // BEL, can stand for ST in OSC or DCS state |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
149 IS_STRING_STATE()) { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
150 // fallthrough |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
152 else if(c < 0x20) { // other C0 |
18064
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
153 if(vterm_get_special_pty_type() == 2) { |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
154 if(c == 0x08) // BS |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
155 // Set the trick for BS output after a sequence, to delay backspace |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
156 // activation |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
157 if(pos + 2 < len && bytes[pos + 1] == 0x20 && bytes[pos + 2] == 0x08) |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
158 vt->in_backspace = 2; // Trigger when count down to 1 |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
159 } |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
160 if(IS_STRING_STATE()) |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
161 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 do_control(vt, c); |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
163 if(IS_STRING_STATE()) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 string_start = bytes + pos + 1; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
167 // else fallthrough |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
169 string_len = bytes + pos - string_start; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
171 if(vt->parser.in_esc) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
172 // Hoist an ESC letter into a C1 if we're not in a string mode |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
173 // Always accept ESC \ == ST even in string mode |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
174 if(!vt->parser.intermedlen && |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
175 c >= 0x40 && c < 0x60 && |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
176 ((!IS_STRING_STATE() || c == 0x5c))) { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
177 c += 0x40; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
178 c1_allowed = TRUE; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
179 string_len -= 1; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
180 vt->parser.in_esc = FALSE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
181 } |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
182 else { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
183 string_start = NULL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
184 vt->parser.state = NORMAL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
185 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
186 } |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
187 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
188 switch(vt->parser.state) { |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
189 case CSI_LEADER: |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
190 /* Extract leader bytes 0x3c to 0x3f */ |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
191 if(c >= 0x3c && c <= 0x3f) { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
192 if(vt->parser.v.csi.leaderlen < CSI_LEADER_MAX-1) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
193 vt->parser.v.csi.leader[vt->parser.v.csi.leaderlen++] = c; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
194 break; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
195 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
196 |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
197 /* else fallthrough */ |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
198 vt->parser.v.csi.leader[vt->parser.v.csi.leaderlen] = 0; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
199 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
200 vt->parser.v.csi.argi = 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
201 vt->parser.v.csi.args[0] = CSI_ARG_MISSING; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
202 vt->parser.state = CSI_ARGS; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
203 |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
204 /* fallthrough */ |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
205 case CSI_ARGS: |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
206 /* Numerical value of argument */ |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
207 if(c >= '0' && c <= '9') { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
208 if(vt->parser.v.csi.args[vt->parser.v.csi.argi] == CSI_ARG_MISSING) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
209 vt->parser.v.csi.args[vt->parser.v.csi.argi] = 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
210 vt->parser.v.csi.args[vt->parser.v.csi.argi] *= 10; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
211 vt->parser.v.csi.args[vt->parser.v.csi.argi] += c - '0'; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
212 break; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 } |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
214 if(c == ':') { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
215 vt->parser.v.csi.args[vt->parser.v.csi.argi] |= CSI_ARG_FLAG_MORE; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
216 c = ';'; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
217 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
218 if(c == ';') { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
219 vt->parser.v.csi.argi++; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
220 vt->parser.v.csi.args[vt->parser.v.csi.argi] = CSI_ARG_MISSING; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
221 break; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
222 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
223 |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
224 /* else fallthrough */ |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
225 vt->parser.v.csi.argi++; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
226 vt->parser.intermedlen = 0; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
227 vt->parser.state = CSI_INTERMED; |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
228 // fallthrough |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
229 case CSI_INTERMED: |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
230 if(is_intermed(c)) { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
231 if(vt->parser.intermedlen < INTERMED_MAX-1) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
232 vt->parser.intermed[vt->parser.intermedlen++] = c; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
233 break; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
234 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
235 else if(c == 0x1b) { |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
236 /* ESC in CSI cancels */ |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
237 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
238 else if(c >= 0x40 && c <= 0x7e) { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
239 vt->parser.intermed[vt->parser.intermedlen] = 0; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
240 do_csi(vt, c); |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
241 } |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
242 /* else was invalid CSI */ |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
243 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
244 ENTER_NORMAL_STATE(); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
245 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
246 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
247 case OSC_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
248 /* Numerical value of command */ |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
249 if(c >= '0' && c <= '9') { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
250 if(vt->parser.v.osc.command == -1) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
251 vt->parser.v.osc.command = 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
252 else |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
253 vt->parser.v.osc.command *= 10; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
254 vt->parser.v.osc.command += c - '0'; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
255 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
256 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
257 if(c == ';') { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
258 vt->parser.state = OSC; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
259 string_start = bytes + pos + 1; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
260 break; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
261 } |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
262 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
263 /* else fallthrough */ |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
264 string_start = bytes + pos; |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
265 string_len = 0; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
266 vt->parser.state = OSC; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
267 goto string_state; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
268 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
269 case DCS_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
270 if(vt->parser.v.dcs.commandlen < CSI_LEADER_MAX) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
271 vt->parser.v.dcs.command[vt->parser.v.dcs.commandlen++] = c; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
272 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
273 if(c >= 0x40 && c<= 0x7e) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
274 string_start = bytes + pos + 1; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
275 vt->parser.state = DCS; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
276 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
277 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
278 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
279 string_state: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
280 case OSC: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
281 case DCS: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
282 if(c == 0x07 || (c1_allowed && c == 0x9c)) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
283 string_fragment(vt, string_start, string_len, TRUE); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
284 ENTER_NORMAL_STATE(); |
13604
caa9825b04cd
patch 8.0.1674: libvterm can't handle an OSC string split
Christian Brabandt <cb@256bit.org>
parents:
13531
diff
changeset
|
285 } |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
286 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
287 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
288 case NORMAL: |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
289 if(vt->parser.in_esc) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
290 if(is_intermed(c)) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
291 if(vt->parser.intermedlen < INTERMED_MAX-1) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
292 vt->parser.intermed[vt->parser.intermedlen++] = c; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
293 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
294 else if(c >= 0x30 && c < 0x7f) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
295 do_escape(vt, c); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
296 vt->parser.in_esc = 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
297 ENTER_NORMAL_STATE(); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
298 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
299 else { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
300 DEBUG_LOG1("TODO: Unhandled byte %02x in Escape\n", c); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
301 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
302 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
303 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
304 if(c1_allowed && c >= 0x80 && c < 0xa0) { |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
305 switch(c) { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
306 case 0x90: // DCS |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
307 vt->parser.string_initial = TRUE; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
308 vt->parser.v.dcs.commandlen = 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
309 ENTER_STATE(DCS_COMMAND); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
310 break; |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
311 case 0x9b: // CSI |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
312 vt->parser.v.csi.leaderlen = 0; |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
313 ENTER_STATE(CSI_LEADER); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
314 break; |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
315 case 0x9d: // OSC |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
316 vt->parser.v.osc.command = -1; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
317 vt->parser.string_initial = TRUE; |
20498
55a373a243c0
patch 8.2.0803: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
318 string_start = bytes + pos + 1; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
319 ENTER_STATE(OSC_COMMAND); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
320 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
321 default: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
322 do_control(vt, c); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
323 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
324 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
325 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
326 else { |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
327 size_t eaten = 0; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
328 if(vt->parser.callbacks && vt->parser.callbacks->text) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
329 eaten = (*vt->parser.callbacks->text)(bytes + pos, len - pos, vt->parser.cbdata); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
330 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
331 if(!eaten) { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
332 DEBUG_LOG("libvterm: Text callback did not consume any input\n"); |
20518
a4652d7ec99f
patch 8.2.0813: libvterm code is slightly different from upstream
Bram Moolenaar <Bram@vim.org>
parents:
20498
diff
changeset
|
333 /* force it to make progress */ |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
334 eaten = 1; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
335 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
337 pos += (eaten - 1); // we'll ++ it again in a moment |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
339 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
340 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
341 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
342 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
343 if(string_start) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
344 string_fragment(vt, string_start, bytes + pos - string_start, FALSE); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
345 |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
346 return len; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
347 } |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
348 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
349 void vterm_parser_set_callbacks(VTerm *vt, const VTermParserCallbacks *callbacks, void *user) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
350 { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
351 vt->parser.callbacks = callbacks; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
352 vt->parser.cbdata = user; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
353 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
354 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
355 void *vterm_parser_get_cbdata(VTerm *vt) |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
356 { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
357 return vt->parser.cbdata; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
358 } |