Mercurial > vim
annotate src/libvterm/src/parser.c @ 20488:1d595fada804 v8.2.0798
patch 8.2.0798: libvterm code lags behind the upstream version
Commit: https://github.com/vim/vim/commit/be593bf135f6967335b14ba188bd5f8f32175c75
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 19 21:20:04 2020 +0200
patch 8.2.0798: libvterm code lags behind the upstream version
Problem: Libvterm code lags behind the upstream version.
Solution: Include revisions 755 - 758.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 19 May 2020 21:30:07 +0200 |
parents | 1c75e1974313 |
children | 55a373a243c0 |
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)( |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
37 vt->parser.v.csi.leaderlen ? vt->parser.v.csi.leader : NULL, |
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 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
122 for( ; pos < len; pos++) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
123 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
|
124 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
|
125 size_t string_len; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
126 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
127 if(c == 0x00 || c == 0x7f) { // NUL, DEL |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
128 if(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
|
129 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
|
130 string_start = bytes + pos + 1; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
131 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
132 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
133 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
134 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
|
135 vt->parser.in_esc = FALSE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
136 ENTER_NORMAL_STATE(); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
137 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
139 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
|
140 vt->parser.intermedlen = 0; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
141 if(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
|
142 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
|
143 vt->parser.in_esc = TRUE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
145 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
146 else if(c == 0x07 && // BEL, can stand for ST in OSC or DCS state |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
147 vt->parser.state >= OSC) { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
148 // fallthrough |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
150 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
|
151 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
|
152 if(c == 0x08) // BS |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
153 // 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
|
154 // activation |
8b4f9be5db73
patch 8.1.2027: MS-Windows: problem with ambiwidth characters
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
155 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
|
156 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
|
157 } |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
158 if(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
|
159 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
|
160 do_control(vt, c); |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
161 if(vt->parser.state >= OSC) |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 string_start = bytes + pos + 1; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
163 continue; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 } |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
165 // else fallthrough |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
167 string_len = bytes + pos - string_start; |
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 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
|
170 // 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
|
171 // 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
|
172 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
|
173 c >= 0x40 && c < 0x60 && |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
174 ((vt->parser.state < OSC || c == 0x5c))) { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
175 c += 0x40; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
176 c1_allowed = TRUE; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
177 string_len -= 1; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
178 vt->parser.in_esc = FALSE; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 } |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
180 else { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
181 string_start = NULL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
182 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
|
183 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
184 } |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
185 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
186 switch(vt->parser.state) { |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
187 case CSI_LEADER: |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
188 // 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
|
189 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
|
190 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
|
191 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
|
192 break; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
193 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
194 |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
195 // else fallthrough |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
196 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
|
197 |
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.argi = 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
199 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
|
200 vt->parser.state = CSI_ARGS; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
201 |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
202 // fallthrough |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
203 case CSI_ARGS: |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
204 // Numerical value of argument |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 break; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
211 } |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
212 if(c == ':') { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
213 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
|
214 c = ';'; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
215 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
216 if(c == ';') { |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
217 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
|
218 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
|
219 break; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
220 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
221 |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
222 // else fallthrough |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
223 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
|
224 vt->parser.intermedlen = 0; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
225 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
|
226 // fallthrough |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
227 case CSI_INTERMED: |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
228 if(is_intermed(c)) { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
229 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
|
230 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
|
231 break; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
232 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
233 else if(c == 0x1b) { |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
234 // ESC in CSI cancels |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
235 } |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
236 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
|
237 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
|
238 do_csi(vt, c); |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
239 } |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
240 // else was invalid CSI |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
241 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
242 ENTER_NORMAL_STATE(); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
243 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
244 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
245 case OSC_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
246 /* 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
|
247 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
|
248 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
|
249 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
|
250 else |
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 *= 10; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
252 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
|
253 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
254 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
255 if(c == ';') { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
256 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
|
257 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
|
258 break; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
259 } |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
260 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
261 /* else fallthrough */ |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
262 string_start = bytes + pos; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
263 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
|
264 goto string_state; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
265 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
266 case DCS_COMMAND: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
267 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
|
268 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
|
269 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
274 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
275 |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
276 string_state: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
277 case OSC: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
278 case DCS: |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 } |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
283 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
284 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
285 case NORMAL: |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 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
|
290 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 ENTER_NORMAL_STATE(); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
295 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
296 else { |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
297 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
|
298 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
299 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
300 } |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
301 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
|
302 switch(c) { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 ENTER_STATE(DCS_COMMAND); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
307 break; |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
308 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
|
309 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
|
310 ENTER_STATE(CSI_LEADER); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
311 break; |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 ENTER_STATE(OSC_COMMAND); |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
316 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
317 default: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
318 do_control(vt, c); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
319 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
320 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
321 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
322 else { |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
323 size_t eaten = 0; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
324 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
|
325 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
|
326 |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
327 if(!eaten) { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
328 DEBUG_LOG("libvterm: Text callback did not consume any input\n"); |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
329 // 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
|
330 eaten = 1; |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
331 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
332 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
13606
diff
changeset
|
333 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
|
334 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
335 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
336 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
337 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
338 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
339 if(string_start) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
19091
diff
changeset
|
340 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
|
341 |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
342 return len; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
343 } |
13531
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
344 |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
345 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
|
346 { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
347 vt->parser.callbacks = callbacks; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
348 vt->parser.cbdata = user; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
349 } |
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 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
|
352 { |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
353 return vt->parser.cbdata; |
9f857e6310b6
patch 8.0.1639: libvterm code lags behind master
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
354 } |