Mercurial > vim
annotate src/terminal.c @ 20981:6e0166b4443d
Added tag v8.2.1041 for changeset a51ce93f3e6cbd3ada4fc8fb6e12f52467380028
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 22 Jun 2020 22:15:04 +0200 |
parents | 9064044fd4f6 |
children | d0265fdadec9 |
rev | line source |
---|---|
12502 | 1 /* vi:set ts=8 sts=4 sw=4 noet: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Terminal window support, see ":help :terminal". | |
12 * | |
13 * There are three parts: | |
14 * 1. Generic code for all systems. | |
15 * Uses libvterm for the terminal emulator. | |
16 * 2. The MS-Windows implementation. | |
17 * Uses winpty. | |
18 * 3. The Unix-like implementation. | |
19 * Uses pseudo-tty's (pty's). | |
20 * | |
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of | |
22 * this library is in the libvterm directory. | |
23 * | |
24 * When a terminal window is opened, a job is started that will be connected to | |
25 * the terminal emulator. | |
26 * | |
27 * If the terminal window has keyboard focus, typed keys are converted to the | |
28 * terminal encoding and writing to the job over a channel. | |
29 * | |
30 * If the job produces output, it is written to the terminal emulator. The | |
31 * terminal emulator invokes callbacks when its screen content changes. The | |
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a | |
33 * while, if the terminal window is visible, the screen contents is drawn. | |
34 * | |
35 * When the job ends the text is put in a buffer. Redrawing then happens from | |
36 * that buffer, attributes come from the scrollback buffer tl_scrollback. | |
37 * When the buffer is changed it is turned into a normal buffer, the attributes | |
38 * in tl_scrollback are no longer used. | |
39 */ | |
40 | |
41 #include "vim.h" | |
42 | |
43 #if defined(FEAT_TERMINAL) || defined(PROTO) | |
44 | |
45 #ifndef MIN | |
46 # define MIN(x,y) ((x) < (y) ? (x) : (y)) | |
47 #endif | |
48 #ifndef MAX | |
49 # define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
50 #endif | |
51 | |
52 #include "libvterm/include/vterm.h" | |
53 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
54 // This is VTermScreenCell without the characters, thus much smaller. |
12502 | 55 typedef struct { |
56 VTermScreenCellAttrs attrs; | |
57 char width; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
58 VTermColor fg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
59 VTermColor bg; |
12502 | 60 } cellattr_T; |
61 | |
62 typedef struct sb_line_S { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
63 int sb_cols; // can differ per line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
64 cellattr_T *sb_cells; // allocated |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
65 cellattr_T sb_fill_attr; // for short line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
66 char_u *sb_text; // for tl_scrollback_postponed |
12502 | 67 } sb_line_T; |
68 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
69 #ifdef MSWIN |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
70 # ifndef HPCON |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
71 # define HPCON VOID* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
72 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
73 # ifndef EXTENDED_STARTUPINFO_PRESENT |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
74 # define EXTENDED_STARTUPINFO_PRESENT 0x00080000 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
75 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
76 # ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
77 # define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
78 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
79 typedef struct _DYN_STARTUPINFOEXW |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
80 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
81 STARTUPINFOW StartupInfo; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
82 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
83 } DYN_STARTUPINFOEXW, *PDYN_STARTUPINFOEXW; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
84 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
85 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
86 // typedef term_T in structs.h |
12502 | 87 struct terminal_S { |
88 term_T *tl_next; | |
89 | |
90 VTerm *tl_vterm; | |
91 job_T *tl_job; | |
92 buf_T *tl_buffer; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
93 #if defined(FEAT_GUI) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
94 int tl_system; // when non-zero used for :!cmd output |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
95 int tl_toprow; // row with first line of system terminal |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
96 #endif |
12502 | 97 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
98 // Set when setting the size of a vterm, reset after redrawing. |
12502 | 99 int tl_vterm_size_changed; |
100 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
101 int tl_normal_mode; // TRUE: Terminal-Normal mode |
12502 | 102 int tl_channel_closed; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
103 int tl_channel_recently_closed; // still need to handle tl_finish |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
104 |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
105 int tl_finish; |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
106 #define TL_FINISH_UNSET NUL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
107 #define TL_FINISH_CLOSE 'c' // ++close or :terminal without argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
108 #define TL_FINISH_NOCLOSE 'n' // ++noclose |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
109 #define TL_FINISH_OPEN 'o' // ++open |
12502 | 110 char_u *tl_opencmd; |
111 char_u *tl_eof_chars; | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
112 char_u *tl_api; // prefix for terminal API function |
12502 | 113 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
114 char_u *tl_arg0_cmd; // To format the status bar |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
115 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
116 #ifdef MSWIN |
12502 | 117 void *tl_winpty_config; |
118 void *tl_winpty; | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
119 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
120 HPCON tl_conpty; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
121 DYN_STARTUPINFOEXW tl_siex; // Structure that always needs to be hold |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
122 |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
123 FILE *tl_out_fd; |
12502 | 124 #endif |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
125 #if defined(FEAT_SESSION) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
126 char_u *tl_command; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
127 #endif |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
128 char_u *tl_kill; |
12502 | 129 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
130 // last known vterm size |
12502 | 131 int tl_rows; |
132 int tl_cols; | |
133 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
134 char_u *tl_title; // NULL or allocated |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
135 char_u *tl_status_text; // NULL or allocated |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
136 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
137 // Range of screen rows to update. Zero based. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
138 int tl_dirty_row_start; // MAX_ROW if nothing dirty |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
139 int tl_dirty_row_end; // row below last one to update |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
140 int tl_dirty_snapshot; // text updated after making snapshot |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
141 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
142 int tl_timer_set; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
143 proftime_T tl_timer_due; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
144 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
145 int tl_postponed_scroll; // to be scrolled up |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
146 |
12502 | 147 garray_T tl_scrollback; |
148 int tl_scrollback_scrolled; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
149 garray_T tl_scrollback_postponed; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
150 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
151 char_u *tl_highlight_name; // replaces "Terminal"; allocated |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
152 |
12502 | 153 cellattr_T tl_default_color; |
154 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
155 linenr_T tl_top_diff_rows; // rows of top diff file or zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
156 linenr_T tl_bot_diff_rows; // rows of bottom diff file |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
157 |
12502 | 158 VTermPos tl_cursor_pos; |
159 int tl_cursor_visible; | |
160 int tl_cursor_blink; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
161 int tl_cursor_shape; // 1: block, 2: underline, 3: bar |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
162 char_u *tl_cursor_color; // NULL or allocated |
12502 | 163 |
164 int tl_using_altscreen; | |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
165 garray_T tl_osc_buf; // incomplete OSC string |
12502 | 166 }; |
167 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
168 #define TMODE_ONCE 1 // CTRL-\ CTRL-N used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
169 #define TMODE_LOOP 2 // CTRL-W N used |
12502 | 170 |
171 /* | |
172 * List of all active terminals. | |
173 */ | |
174 static term_T *first_term = NULL; | |
175 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
176 // Terminal active in terminal_loop(). |
12502 | 177 static term_T *in_terminal_loop = NULL; |
178 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
179 #ifdef MSWIN |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
180 static BOOL has_winpty = FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
181 static BOOL has_conpty = FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
182 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
183 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
184 #define MAX_ROW 999999 // used for tl_dirty_row_end to update all rows |
12502 | 185 #define KEY_BUF_LEN 200 |
186 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
187 #define FOR_ALL_TERMS(term) \ |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
188 for ((term) = first_term; (term) != NULL; (term) = (term)->tl_next) |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
189 |
12502 | 190 /* |
191 * Functions with separate implementation for MS-Windows and Unix-like systems. | |
192 */ | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
193 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt); |
12502 | 194 static int create_pty_only(term_T *term, jobopt_T *opt); |
195 static void term_report_winsize(term_T *term, int rows, int cols); | |
196 static void term_free_vterm(term_T *term); | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
197 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
198 static void update_system_term(term_T *term); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
199 #endif |
12502 | 200 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
201 static void handle_postponed_scrollback(term_T *term); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
202 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
203 // The character that we know (or assume) that the terminal expects for the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
204 // backspace key. |
12502 | 205 static int term_backspace_char = BS; |
206 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
207 // "Terminal" highlight group colors. |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
208 static int term_default_cterm_fg = -1; |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
209 static int term_default_cterm_bg = -1; |
12502 | 210 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
211 // Store the last set and the desired cursor properties, so that we only update |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
212 // them when needed. Doing it unnecessary may result in flicker. |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
213 static char_u *last_set_cursor_color = NULL; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
214 static char_u *desired_cursor_color = NULL; |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
215 static int last_set_cursor_shape = -1; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
216 static int desired_cursor_shape = -1; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
217 static int last_set_cursor_blink = -1; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
218 static int desired_cursor_blink = -1; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
219 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
220 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
221 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
222 // 1. Generic code for all systems. |
12502 | 223 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
224 static int |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
225 cursor_color_equal(char_u *lhs_color, char_u *rhs_color) |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
226 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
227 if (lhs_color != NULL && rhs_color != NULL) |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
228 return STRCMP(lhs_color, rhs_color) == 0; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
229 return lhs_color == NULL && rhs_color == NULL; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
230 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
231 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
232 static void |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
233 cursor_color_copy(char_u **to_color, char_u *from_color) |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
234 { |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
235 // Avoid a free & alloc if the value is already right. |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
236 if (cursor_color_equal(*to_color, from_color)) |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
237 return; |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
238 vim_free(*to_color); |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
239 *to_color = (from_color == NULL) ? NULL : vim_strsave(from_color); |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
240 } |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
241 |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
242 static char_u * |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
243 cursor_color_get(char_u *color) |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
244 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
245 return (color == NULL) ? (char_u *)"" : color; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
246 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
247 |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
248 |
12502 | 249 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
250 * Parse 'termwinsize' and set "rows" and "cols" for the terminal size in the |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
251 * current window. |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
252 * Sets "rows" and/or "cols" to zero when it should follow the window size. |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
253 * Return TRUE if the size is the minimum size: "24*80". |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
254 */ |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
255 static int |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
256 parse_termwinsize(win_T *wp, int *rows, int *cols) |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
257 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
258 int minsize = FALSE; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
259 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
260 *rows = 0; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
261 *cols = 0; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
262 |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
263 if (*wp->w_p_tws != NUL) |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
264 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
265 char_u *p = vim_strchr(wp->w_p_tws, 'x'); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
266 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
267 // Syntax of value was already checked when it's set. |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
268 if (p == NULL) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
269 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
270 minsize = TRUE; |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
271 p = vim_strchr(wp->w_p_tws, '*'); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
272 } |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
273 *rows = atoi((char *)wp->w_p_tws); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
274 *cols = atoi((char *)p + 1); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
275 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
276 return minsize; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
277 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
278 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
279 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
280 * Determine the terminal size from 'termwinsize' and the current window. |
12502 | 281 */ |
282 static void | |
283 set_term_and_win_size(term_T *term) | |
284 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
285 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
286 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
287 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
288 // Use the whole screen for the system command. However, it will start |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
289 // at the command line and scroll up as needed, using tl_toprow. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
290 term->tl_rows = Rows; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
291 term->tl_cols = Columns; |
13624
429f0eb87d6f
patch 8.0.1684: ml_get errors when using terminal window for shell command
Christian Brabandt <cb@256bit.org>
parents:
13616
diff
changeset
|
292 return; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
293 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
294 #endif |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
295 if (parse_termwinsize(curwin, &term->tl_rows, &term->tl_cols)) |
12502 | 296 { |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
297 if (term->tl_rows != 0) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
298 term->tl_rows = MAX(term->tl_rows, curwin->w_height); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
299 if (term->tl_cols != 0) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
300 term->tl_cols = MAX(term->tl_cols, curwin->w_width); |
12502 | 301 } |
302 if (term->tl_rows == 0) | |
303 term->tl_rows = curwin->w_height; | |
304 else | |
305 win_setheight_win(term->tl_rows, curwin); | |
306 if (term->tl_cols == 0) | |
307 term->tl_cols = curwin->w_width; | |
308 else | |
309 win_setwidth_win(term->tl_cols, curwin); | |
310 } | |
311 | |
312 /* | |
313 * Initialize job options for a terminal job. | |
314 * Caller may overrule some of them. | |
315 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
316 void |
12502 | 317 init_job_options(jobopt_T *opt) |
318 { | |
319 clear_job_options(opt); | |
320 | |
321 opt->jo_mode = MODE_RAW; | |
322 opt->jo_out_mode = MODE_RAW; | |
323 opt->jo_err_mode = MODE_RAW; | |
324 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; | |
325 } | |
326 | |
327 /* | |
328 * Set job options mandatory for a terminal job. | |
329 */ | |
330 static void | |
331 setup_job_options(jobopt_T *opt, int rows, int cols) | |
332 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
333 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
334 // Win32: Redirecting the job output won't work, thus always connect stdout |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
335 // here. |
12502 | 336 if (!(opt->jo_set & JO_OUT_IO)) |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
337 #endif |
12502 | 338 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
339 // Connect stdout to the terminal. |
12502 | 340 opt->jo_io[PART_OUT] = JIO_BUFFER; |
341 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; | |
342 opt->jo_modifiable[PART_OUT] = 0; | |
343 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE; | |
344 } | |
345 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
346 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
347 // Win32: Redirecting the job output won't work, thus always connect stderr |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
348 // here. |
12502 | 349 if (!(opt->jo_set & JO_ERR_IO)) |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
350 #endif |
12502 | 351 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
352 // Connect stderr to the terminal. |
12502 | 353 opt->jo_io[PART_ERR] = JIO_BUFFER; |
354 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; | |
355 opt->jo_modifiable[PART_ERR] = 0; | |
356 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE; | |
357 } | |
358 | |
359 opt->jo_pty = TRUE; | |
360 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0) | |
361 opt->jo_term_rows = rows; | |
362 if ((opt->jo_set2 & JO2_TERM_COLS) == 0) | |
363 opt->jo_term_cols = cols; | |
364 } | |
365 | |
366 /* | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
367 * Flush messages on channels. |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
368 */ |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
369 static void |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
370 term_flush_messages() |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
371 { |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
372 mch_check_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
373 parse_queued_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
374 } |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
375 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
376 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
377 * Close a terminal buffer (and its window). Used when creating the terminal |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
378 * fails. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
379 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
380 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
381 term_close_buffer(buf_T *buf, buf_T *old_curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
382 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
383 free_terminal(buf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
384 if (old_curbuf != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
385 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
386 --curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
387 curbuf = old_curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
388 curwin->w_buffer = curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
389 ++curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
390 } |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19542
diff
changeset
|
391 CHECK_CURBUF; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
392 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
393 // Wiping out the buffer will also close the window and call |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
394 // free_terminal(). |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
395 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
396 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
397 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
398 /* |
12502 | 399 * Start a terminal window and return its buffer. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
400 * Use either "argvar" or "argv", the other must be NULL. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
401 * When "flags" has TERM_START_NOJOB only create the buffer, b_term and open |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
402 * the window. |
12502 | 403 * Returns NULL when failed. |
404 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
405 buf_T * |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
406 term_start( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
407 typval_T *argvar, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
408 char **argv, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
409 jobopt_T *opt, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
410 int flags) |
12502 | 411 { |
412 exarg_T split_ea; | |
413 win_T *old_curwin = curwin; | |
414 term_T *term; | |
415 buf_T *old_curbuf = NULL; | |
416 int res; | |
417 buf_T *newbuf; | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
418 int vertical = opt->jo_vertical || (cmdmod.split & WSP_VERT); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
419 jobopt_T orig_opt; // only partly filled |
12502 | 420 |
421 if (check_restricted() || check_secure()) | |
422 return NULL; | |
423 | |
424 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)) | |
425 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO) | |
426 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF)) | |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
427 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF)) |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
428 || (argvar != NULL |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
429 && argvar->v_type == VAR_LIST |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
430 && argvar->vval.v_list != NULL |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
431 && argvar->vval.v_list->lv_first == &range_list_item)) |
12502 | 432 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
433 emsg(_(e_invarg)); |
12502 | 434 return NULL; |
435 } | |
436 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
437 term = ALLOC_CLEAR_ONE(term_T); |
12502 | 438 if (term == NULL) |
439 return NULL; | |
440 term->tl_dirty_row_end = MAX_ROW; | |
441 term->tl_cursor_visible = TRUE; | |
442 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | |
443 term->tl_finish = opt->jo_term_finish; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
444 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
445 term->tl_system = (flags & TERM_START_SYSTEM); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
446 #endif |
12502 | 447 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300); |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
448 ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300); |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
449 ga_init2(&term->tl_osc_buf, sizeof(char), 300); |
12502 | 450 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
451 CLEAR_FIELD(split_ea); |
12502 | 452 if (opt->jo_curwin) |
453 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
454 // Create a new buffer in the current window. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
455 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT)) |
12502 | 456 { |
457 no_write_message(); | |
458 vim_free(term); | |
459 return NULL; | |
460 } | |
461 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE, | |
20617
c81f61e3b508
patch 8.2.0862: ":term ++curwin" makes the current buffer hidden
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
462 (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0) |
c81f61e3b508
patch 8.2.0862: ":term ++curwin" makes the current buffer hidden
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
463 + ((flags & TERM_START_FORCEIT) ? ECMD_FORCEIT : 0), |
c81f61e3b508
patch 8.2.0862: ":term ++curwin" makes the current buffer hidden
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
464 curwin) == FAIL) |
12502 | 465 { |
466 vim_free(term); | |
467 return NULL; | |
468 } | |
469 } | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
470 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM)) |
12502 | 471 { |
472 buf_T *buf; | |
473 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
474 // Create a new buffer without a window. Make it the current buffer for |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
475 // a moment to be able to do the initializations. |
12502 | 476 buf = buflist_new((char_u *)"", NULL, (linenr_T)0, |
477 BLN_NEW | BLN_LISTED); | |
478 if (buf == NULL || ml_open(buf) == FAIL) | |
479 { | |
480 vim_free(term); | |
481 return NULL; | |
482 } | |
483 old_curbuf = curbuf; | |
484 --curbuf->b_nwindows; | |
485 curbuf = buf; | |
486 curwin->w_buffer = buf; | |
487 ++curbuf->b_nwindows; | |
488 } | |
489 else | |
490 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
491 // Open a new window or tab. |
12502 | 492 split_ea.cmdidx = CMD_new; |
493 split_ea.cmd = (char_u *)"new"; | |
494 split_ea.arg = (char_u *)""; | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
495 if (opt->jo_term_rows > 0 && !vertical) |
12502 | 496 { |
497 split_ea.line2 = opt->jo_term_rows; | |
498 split_ea.addr_count = 1; | |
499 } | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
500 if (opt->jo_term_cols > 0 && vertical) |
12502 | 501 { |
502 split_ea.line2 = opt->jo_term_cols; | |
503 split_ea.addr_count = 1; | |
504 } | |
505 | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
506 if (vertical) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
507 cmdmod.split |= WSP_VERT; |
12502 | 508 ex_splitview(&split_ea); |
509 if (curwin == old_curwin) | |
510 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
511 // split failed |
12502 | 512 vim_free(term); |
513 return NULL; | |
514 } | |
515 } | |
516 term->tl_buffer = curbuf; | |
517 curbuf->b_term = term; | |
518 | |
519 if (!opt->jo_hidden) | |
520 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
521 // Only one size was taken care of with :new, do the other one. With |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
522 // "curwin" both need to be done. |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
523 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical)) |
12502 | 524 win_setheight(opt->jo_term_rows); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
525 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical)) |
12502 | 526 win_setwidth(opt->jo_term_cols); |
527 } | |
528 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
529 // Link the new terminal in the list of active terminals. |
12502 | 530 term->tl_next = first_term; |
531 first_term = term; | |
532 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
533 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); |
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
534 |
12502 | 535 if (opt->jo_term_name != NULL) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
536 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
537 vim_free(curbuf->b_ffname); |
12502 | 538 curbuf->b_ffname = vim_strsave(opt->jo_term_name); |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
539 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
540 else if (argv != NULL) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
541 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
542 vim_free(curbuf->b_ffname); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
543 curbuf->b_ffname = vim_strsave((char_u *)"!system"); |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
544 } |
12502 | 545 else |
546 { | |
547 int i; | |
548 size_t len; | |
549 char_u *cmd, *p; | |
550 | |
551 if (argvar->v_type == VAR_STRING) | |
552 { | |
553 cmd = argvar->vval.v_string; | |
554 if (cmd == NULL) | |
555 cmd = (char_u *)""; | |
556 else if (STRCMP(cmd, "NONE") == 0) | |
557 cmd = (char_u *)"pty"; | |
558 } | |
559 else if (argvar->v_type != VAR_LIST | |
560 || argvar->vval.v_list == NULL | |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
561 || argvar->vval.v_list->lv_len == 0 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
562 || (cmd = tv_get_string_chk( |
12502 | 563 &argvar->vval.v_list->lv_first->li_tv)) == NULL) |
564 cmd = (char_u*)""; | |
565 | |
566 len = STRLEN(cmd) + 10; | |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
567 p = alloc(len); |
12502 | 568 |
569 for (i = 0; p != NULL; ++i) | |
570 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
571 // Prepend a ! to the command name to avoid the buffer name equals |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
572 // the executable, otherwise ":w!" would overwrite it. |
12502 | 573 if (i == 0) |
574 vim_snprintf((char *)p, len, "!%s", cmd); | |
575 else | |
576 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i); | |
577 if (buflist_findname(p) == NULL) | |
578 { | |
579 vim_free(curbuf->b_ffname); | |
580 curbuf->b_ffname = p; | |
581 break; | |
582 } | |
583 } | |
584 } | |
19513
274052873790
patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
19358
diff
changeset
|
585 vim_free(curbuf->b_sfname); |
274052873790
patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
19358
diff
changeset
|
586 curbuf->b_sfname = vim_strsave(curbuf->b_ffname); |
12502 | 587 curbuf->b_fname = curbuf->b_ffname; |
588 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
589 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
590 |
12502 | 591 if (opt->jo_term_opencmd != NULL) |
592 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); | |
593 | |
594 if (opt->jo_eof_chars != NULL) | |
595 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); | |
596 | |
597 set_string_option_direct((char_u *)"buftype", -1, | |
598 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0); | |
14449
5faab0545f3c
patch 8.1.0238: 'buftype' is cleared when using ":term ++hidden cat"
Christian Brabandt <cb@256bit.org>
parents:
14311
diff
changeset
|
599 // Avoid that 'buftype' is reset when this buffer is entered. |
5faab0545f3c
patch 8.1.0238: 'buftype' is cleared when using ":term ++hidden cat"
Christian Brabandt <cb@256bit.org>
parents:
14311
diff
changeset
|
600 curbuf->b_p_initialized = TRUE; |
12502 | 601 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
602 // Mark the buffer as not modifiable. It can only be made modifiable after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
603 // the job finished. |
12502 | 604 curbuf->b_p_ma = FALSE; |
605 | |
606 set_term_and_win_size(term); | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
607 #ifdef MSWIN |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
608 mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io)); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
609 #endif |
12502 | 610 setup_job_options(opt, term->tl_rows, term->tl_cols); |
611 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
612 if (flags & TERM_START_NOJOB) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
613 return curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
614 |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
615 #if defined(FEAT_SESSION) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
616 // Remember the command for the session file. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
617 if (opt->jo_term_norestore || argv != NULL) |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
618 term->tl_command = vim_strsave((char_u *)"NONE"); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
619 else if (argvar->v_type == VAR_STRING) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
620 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
621 char_u *cmd = argvar->vval.v_string; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
622 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
623 if (cmd != NULL && STRCMP(cmd, p_sh) != 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
624 term->tl_command = vim_strsave(cmd); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
625 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
626 else if (argvar->v_type == VAR_LIST |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
627 && argvar->vval.v_list != NULL |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
628 && argvar->vval.v_list->lv_len > 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
629 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
630 garray_T ga; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
631 listitem_T *item; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
632 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
633 ga_init2(&ga, 1, 100); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
634 FOR_ALL_LIST_ITEMS(argvar->vval.v_list, item) |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
635 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
636 char_u *s = tv_get_string_chk(&item->li_tv); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
637 char_u *p; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
638 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
639 if (s == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
640 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
641 p = vim_strsave_fnameescape(s, FALSE); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
642 if (p == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
643 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
644 ga_concat(&ga, p); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
645 vim_free(p); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
646 ga_append(&ga, ' '); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
647 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
648 if (item == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
649 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
650 ga_append(&ga, NUL); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
651 term->tl_command = ga.ga_data; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
652 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
653 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
654 ga_clear(&ga); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
655 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
656 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
657 |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
658 if (opt->jo_term_kill != NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
659 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
660 char_u *p = skiptowhite(opt->jo_term_kill); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
661 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
662 term->tl_kill = vim_strnsave(opt->jo_term_kill, p - opt->jo_term_kill); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
663 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
664 |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
665 if (opt->jo_term_api != NULL) |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
666 { |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
667 char_u *p = skiptowhite(opt->jo_term_api); |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
668 |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
669 term->tl_api = vim_strnsave(opt->jo_term_api, p - opt->jo_term_api); |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
670 } |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
671 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
672 term->tl_api = vim_strsave((char_u *)"Tapi_"); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
673 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
674 if (opt->jo_set2 & JO2_TERM_HIGHLIGHT) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
675 term->tl_highlight_name = vim_strsave(opt->jo_term_highlight); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
676 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
677 // System dependent: setup the vterm and maybe start the job in it. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
678 if (argv == NULL |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
679 && argvar->v_type == VAR_STRING |
12502 | 680 && argvar->vval.v_string != NULL |
681 && STRCMP(argvar->vval.v_string, "NONE") == 0) | |
682 res = create_pty_only(term, opt); | |
683 else | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
684 res = term_and_job_init(term, argvar, argv, opt, &orig_opt); |
12502 | 685 |
686 newbuf = curbuf; | |
687 if (res == OK) | |
688 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
689 // Get and remember the size we ended up with. Update the pty. |
12502 | 690 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); |
691 term_report_winsize(term, term->tl_rows, term->tl_cols); | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
692 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
693 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
694 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
695 // display first line below typed command |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
696 term->tl_toprow = msg_row + 1; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
697 term->tl_dirty_row_end = 0; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
698 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
699 #endif |
12502 | 700 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
701 // Make sure we don't get stuck on sending keys to the job, it leads to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
702 // a deadlock if the job is waiting for Vim to read. |
12502 | 703 channel_set_nonblock(term->tl_job->jv_channel, PART_IN); |
704 | |
13835
8e583c52eb44
patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13829
diff
changeset
|
705 if (old_curbuf != NULL) |
12502 | 706 { |
707 --curbuf->b_nwindows; | |
708 curbuf = old_curbuf; | |
709 curwin->w_buffer = curbuf; | |
710 ++curbuf->b_nwindows; | |
711 } | |
712 } | |
713 else | |
714 { | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
715 term_close_buffer(curbuf, old_curbuf); |
12502 | 716 return NULL; |
717 } | |
13444
9f06f7aca74c
patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
718 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
719 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf); |
18450
507348b211b4
patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents:
18420
diff
changeset
|
720 if (!opt->jo_hidden && !(flags & TERM_START_SYSTEM)) |
507348b211b4
patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents:
18420
diff
changeset
|
721 apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf); |
12502 | 722 return newbuf; |
723 } | |
724 | |
725 /* | |
726 * ":terminal": open a terminal window and execute a job in it. | |
727 */ | |
728 void | |
729 ex_terminal(exarg_T *eap) | |
730 { | |
731 typval_T argvar[2]; | |
732 jobopt_T opt; | |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
733 int opt_shell = FALSE; |
12502 | 734 char_u *cmd; |
735 char_u *tofree = NULL; | |
736 | |
737 init_job_options(&opt); | |
738 | |
739 cmd = eap->arg; | |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
740 while (*cmd == '+' && *(cmd + 1) == '+') |
12502 | 741 { |
742 char_u *p, *ep; | |
743 | |
744 cmd += 2; | |
745 p = skiptowhite(cmd); | |
746 ep = vim_strchr(cmd, '='); | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
747 if (ep != NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
748 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
749 if (ep < p) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
750 p = ep; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
751 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
752 ep = NULL; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
753 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
754 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
755 # define OPTARG_HAS(name) ((int)(p - cmd) == sizeof(name) - 1 \ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
756 && STRNICMP(cmd, name, sizeof(name) - 1) == 0) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
757 if (OPTARG_HAS("close")) |
12502 | 758 opt.jo_term_finish = 'c'; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
759 else if (OPTARG_HAS("noclose")) |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
760 opt.jo_term_finish = 'n'; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
761 else if (OPTARG_HAS("open")) |
12502 | 762 opt.jo_term_finish = 'o'; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
763 else if (OPTARG_HAS("curwin")) |
12502 | 764 opt.jo_curwin = 1; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
765 else if (OPTARG_HAS("hidden")) |
12502 | 766 opt.jo_hidden = 1; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
767 else if (OPTARG_HAS("norestore")) |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
768 opt.jo_term_norestore = 1; |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
769 else if (OPTARG_HAS("shell")) |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
770 opt_shell = TRUE; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
771 else if (OPTARG_HAS("kill") && ep != NULL) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
772 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
773 opt.jo_set2 |= JO2_TERM_KILL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
774 opt.jo_term_kill = ep + 1; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
775 p = skiptowhite(cmd); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
776 } |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
777 else if (OPTARG_HAS("api")) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
778 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
779 opt.jo_set2 |= JO2_TERM_API; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
780 if (ep != NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
781 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
782 opt.jo_term_api = ep + 1; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
783 p = skiptowhite(cmd); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
784 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
785 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
786 opt.jo_term_api = NULL; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
787 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
788 else if (OPTARG_HAS("rows") && ep != NULL && isdigit(ep[1])) |
12502 | 789 { |
790 opt.jo_set2 |= JO2_TERM_ROWS; | |
791 opt.jo_term_rows = atoi((char *)ep + 1); | |
792 p = skiptowhite(cmd); | |
793 } | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
794 else if (OPTARG_HAS("cols") && ep != NULL && isdigit(ep[1])) |
12502 | 795 { |
796 opt.jo_set2 |= JO2_TERM_COLS; | |
797 opt.jo_term_cols = atoi((char *)ep + 1); | |
798 p = skiptowhite(cmd); | |
799 } | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
800 else if (OPTARG_HAS("eof") && ep != NULL) |
12502 | 801 { |
802 char_u *buf = NULL; | |
803 char_u *keys; | |
804 | |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
805 vim_free(opt.jo_eof_chars); |
12502 | 806 p = skiptowhite(cmd); |
807 *p = NUL; | |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
808 keys = replace_termcodes(ep + 1, &buf, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
809 REPTERM_FROM_PART | REPTERM_DO_LT | REPTERM_SPECIAL, NULL); |
12502 | 810 opt.jo_set2 |= JO2_EOF_CHARS; |
811 opt.jo_eof_chars = vim_strsave(keys); | |
812 vim_free(buf); | |
813 *p = ' '; | |
814 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
815 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
816 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "type", 4) == 0 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
817 && ep != NULL) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
818 { |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
819 int tty_type = NUL; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
820 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
821 p = skiptowhite(cmd); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
822 if (STRNICMP(ep + 1, "winpty", p - (ep + 1)) == 0) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
823 tty_type = 'w'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
824 else if (STRNICMP(ep + 1, "conpty", p - (ep + 1)) == 0) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
825 tty_type = 'c'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
826 else |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
827 { |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
828 semsg(e_invargval, "type"); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
829 goto theend; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
830 } |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
831 opt.jo_set2 |= JO2_TTY_TYPE; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
832 opt.jo_tty_type = tty_type; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
833 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
834 #endif |
12502 | 835 else |
836 { | |
837 if (*p) | |
838 *p = NUL; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
839 semsg(_("E181: Invalid attribute: %s"), cmd); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
840 goto theend; |
12502 | 841 } |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
842 # undef OPTARG_HAS |
12502 | 843 cmd = skipwhite(p); |
844 } | |
845 if (*cmd == NUL) | |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
846 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
847 // Make a copy of 'shell', an autocommand may change the option. |
12502 | 848 tofree = cmd = vim_strsave(p_sh); |
849 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
850 // default to close when the shell exits |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
851 if (opt.jo_term_finish == NUL) |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
852 opt.jo_term_finish = TL_FINISH_CLOSE; |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
853 } |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
854 |
12502 | 855 if (eap->addr_count > 0) |
856 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
857 // Write lines from current buffer to the job. |
12502 | 858 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; |
859 opt.jo_io[PART_IN] = JIO_BUFFER; | |
860 opt.jo_io_buf[PART_IN] = curbuf->b_fnum; | |
861 opt.jo_in_top = eap->line1; | |
862 opt.jo_in_bot = eap->line2; | |
863 } | |
864 | |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
865 if (opt_shell && tofree == NULL) |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
866 { |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
867 #ifdef UNIX |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
868 char **argv = NULL; |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
869 char_u *tofree1 = NULL; |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
870 char_u *tofree2 = NULL; |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
871 |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
872 // :term ++shell command |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
873 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == OK) |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
874 term_start(NULL, argv, &opt, eap->forceit ? TERM_START_FORCEIT : 0); |
18595
517bfb2998aa
patch 8.1.2291: memory leak when executing command in a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18522
diff
changeset
|
875 vim_free(argv); |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
876 vim_free(tofree1); |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
877 vim_free(tofree2); |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
878 goto theend; |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
879 #else |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
880 # ifdef MSWIN |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
881 long_u cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
882 char_u *newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
883 |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
884 newcmd = alloc(cmdlen); |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
885 if (newcmd == NULL) |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
886 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
887 tofree = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
888 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd); |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
889 cmd = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
890 # else |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
891 emsg(_("E279: Sorry, ++shell is not supported on this system")); |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
892 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
893 # endif |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
894 #endif |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
895 } |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
896 argvar[0].v_type = VAR_STRING; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
897 argvar[0].vval.v_string = cmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
898 argvar[1].v_type = VAR_UNKNOWN; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
899 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
900 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
901 theend: |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
902 vim_free(tofree); |
12502 | 903 vim_free(opt.jo_eof_chars); |
904 } | |
905 | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
906 #if defined(FEAT_SESSION) || defined(PROTO) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
907 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
908 * Write a :terminal command to the session file to restore the terminal in |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
909 * window "wp". |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
910 * Return FAIL if writing fails. |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
911 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
912 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
913 term_write_session(FILE *fd, win_T *wp) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
914 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
915 term_T *term = wp->w_buffer->b_term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
916 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
917 // Create the terminal and run the command. This is not without |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
918 // risk, but let's assume the user only creates a session when this |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
919 // will be OK. |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
920 if (fprintf(fd, "terminal ++curwin ++cols=%d ++rows=%d ", |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
921 term->tl_cols, term->tl_rows) < 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
922 return FAIL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
923 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
924 if (fprintf(fd, "++type=%s ", term->tl_job->jv_tty_type) < 0) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
925 return FAIL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
926 #endif |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
927 if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
928 return FAIL; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
929 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
930 return put_eol(fd); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
931 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
932 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
933 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
934 * Return TRUE if "buf" has a terminal that should be restored. |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
935 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
936 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
937 term_should_restore(buf_T *buf) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
938 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
939 term_T *term = buf->b_term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
940 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
941 return term != NULL && (term->tl_command == NULL |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
942 || STRCMP(term->tl_command, "NONE") != 0); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
943 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
944 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
945 |
12502 | 946 /* |
947 * Free the scrollback buffer for "term". | |
948 */ | |
949 static void | |
950 free_scrollback(term_T *term) | |
951 { | |
952 int i; | |
953 | |
954 for (i = 0; i < term->tl_scrollback.ga_len; ++i) | |
955 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); | |
956 ga_clear(&term->tl_scrollback); | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
957 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
958 vim_free(((sb_line_T *)term->tl_scrollback_postponed.ga_data + i)->sb_cells); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
959 ga_clear(&term->tl_scrollback_postponed); |
12502 | 960 } |
961 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
962 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
963 // Terminals that need to be freed soon. |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
18033
diff
changeset
|
964 static term_T *terminals_to_free = NULL; |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
965 |
12502 | 966 /* |
967 * Free a terminal and everything it refers to. | |
968 * Kills the job if there is one. | |
969 * Called when wiping out a buffer. | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
970 * The actual terminal structure is freed later in free_unused_terminals(), |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
971 * because callbacks may wipe out a buffer while the terminal is still |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
972 * referenced. |
12502 | 973 */ |
974 void | |
975 free_terminal(buf_T *buf) | |
976 { | |
977 term_T *term = buf->b_term; | |
978 term_T *tp; | |
979 | |
980 if (term == NULL) | |
981 return; | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
982 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
983 // Unlink the terminal form the list of terminals. |
12502 | 984 if (first_term == term) |
985 first_term = term->tl_next; | |
986 else | |
987 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next) | |
988 if (tp->tl_next == term) | |
989 { | |
990 tp->tl_next = term->tl_next; | |
991 break; | |
992 } | |
993 | |
994 if (term->tl_job != NULL) | |
995 { | |
996 if (term->tl_job->jv_status != JOB_ENDED | |
997 && term->tl_job->jv_status != JOB_FINISHED | |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
998 && term->tl_job->jv_status != JOB_FAILED) |
12502 | 999 job_stop(term->tl_job, NULL, "kill"); |
1000 job_unref(term->tl_job); | |
1001 } | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1002 term->tl_next = terminals_to_free; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1003 terminals_to_free = term; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1004 |
12502 | 1005 buf->b_term = NULL; |
1006 if (in_terminal_loop == term) | |
1007 in_terminal_loop = NULL; | |
1008 } | |
1009 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1010 void |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1011 free_unused_terminals() |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1012 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1013 while (terminals_to_free != NULL) |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1014 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1015 term_T *term = terminals_to_free; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1016 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1017 terminals_to_free = term->tl_next; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1018 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1019 free_scrollback(term); |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
1020 ga_clear(&term->tl_osc_buf); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1021 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1022 term_free_vterm(term); |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
1023 vim_free(term->tl_api); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1024 vim_free(term->tl_title); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1025 #ifdef FEAT_SESSION |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1026 vim_free(term->tl_command); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1027 #endif |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1028 vim_free(term->tl_kill); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1029 vim_free(term->tl_status_text); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1030 vim_free(term->tl_opencmd); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1031 vim_free(term->tl_eof_chars); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
1032 vim_free(term->tl_arg0_cmd); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1033 #ifdef MSWIN |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1034 if (term->tl_out_fd != NULL) |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1035 fclose(term->tl_out_fd); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1036 #endif |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
1037 vim_free(term->tl_highlight_name); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1038 vim_free(term->tl_cursor_color); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1039 vim_free(term); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1040 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1041 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1042 |
12502 | 1043 /* |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1044 * Get the part that is connected to the tty. Normally this is PART_IN, but |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1045 * when writing buffer lines to the job it can be another. This makes it |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1046 * possible to do "1,5term vim -". |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1047 */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1048 static ch_part_T |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1049 get_tty_part(term_T *term UNUSED) |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1050 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1051 #ifdef UNIX |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1052 ch_part_T parts[3] = {PART_IN, PART_OUT, PART_ERR}; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1053 int i; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1054 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1055 for (i = 0; i < 3; ++i) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1056 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1057 int fd = term->tl_job->jv_channel->ch_part[parts[i]].ch_fd; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1058 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1059 if (mch_isatty(fd)) |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1060 return parts[i]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1061 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1062 #endif |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1063 return PART_IN; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1064 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1065 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1066 /* |
12502 | 1067 * Write job output "msg[len]" to the vterm. |
1068 */ | |
1069 static void | |
1070 term_write_job_output(term_T *term, char_u *msg, size_t len) | |
1071 { | |
1072 VTerm *vterm = term->tl_vterm; | |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1073 size_t prevlen = vterm_output_get_buffer_current(vterm); |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1074 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1075 vterm_input_write(vterm, (char *)msg, len); |
12502 | 1076 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1077 // flush vterm buffer when vterm responded to control sequence |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1078 if (prevlen != vterm_output_get_buffer_current(vterm)) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1079 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1080 char buf[KEY_BUF_LEN]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1081 size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN); |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1082 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1083 if (curlen > 0) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1084 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1085 (char_u *)buf, (int)curlen, NULL); |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1086 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1087 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1088 // this invokes the damage callbacks |
12502 | 1089 vterm_screen_flush_damage(vterm_obtain_screen(vterm)); |
1090 } | |
1091 | |
1092 static void | |
1093 update_cursor(term_T *term, int redraw) | |
1094 { | |
1095 if (term->tl_normal_mode) | |
1096 return; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1097 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1098 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1099 windgoto(term->tl_cursor_pos.row + term->tl_toprow, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1100 term->tl_cursor_pos.col); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1101 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1102 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1103 setcursor(); |
12502 | 1104 if (redraw) |
1105 { | |
1106 if (term->tl_buffer == curbuf && term->tl_cursor_visible) | |
1107 cursor_on(); | |
1108 out_flush(); | |
1109 #ifdef FEAT_GUI | |
1110 if (gui.in_use) | |
13000
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1111 { |
12502 | 1112 gui_update_cursor(FALSE, FALSE); |
13000
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1113 gui_mch_flush(); |
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1114 } |
12502 | 1115 #endif |
1116 } | |
1117 } | |
1118 | |
1119 /* | |
1120 * Invoked when "msg" output from a job was received. Write it to the terminal | |
1121 * of "buffer". | |
1122 */ | |
1123 void | |
1124 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel) | |
1125 { | |
1126 size_t len = STRLEN(msg); | |
1127 term_T *term = buffer->b_term; | |
1128 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1129 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1130 // Win32: Cannot redirect output of the job, intercept it here and write to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1131 // the file. |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1132 if (term->tl_out_fd != NULL) |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1133 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1134 ch_log(channel, "Writing %d bytes to output file", (int)len); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1135 fwrite(msg, len, 1, term->tl_out_fd); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1136 return; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1137 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1138 #endif |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1139 |
12502 | 1140 if (term->tl_vterm == NULL) |
1141 { | |
1142 ch_log(channel, "NOT writing %d bytes to terminal", (int)len); | |
1143 return; | |
1144 } | |
1145 ch_log(channel, "writing %d bytes to terminal", (int)len); | |
1146 term_write_job_output(term, msg, len); | |
1147 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1148 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1149 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1150 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1151 // show system output, scrolling up the screen as needed |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1152 update_system_term(term); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1153 update_cursor(term, TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1154 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1155 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1156 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1157 // In Terminal-Normal mode we are displaying the buffer, not the terminal |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1158 // contents, thus no screen update is needed. |
12502 | 1159 if (!term->tl_normal_mode) |
1160 { | |
14117
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1161 // Don't use update_screen() when editing the command line, it gets |
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1162 // cleared. |
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1163 // TODO: only update once in a while. |
12502 | 1164 ch_log(term->tl_job->jv_channel, "updating screen"); |
14117
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1165 if (buffer == curbuf && (State & CMDLINE) == 0) |
12502 | 1166 { |
14117
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1167 update_screen(VALID_NO_UPDATE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1168 // update_screen() can be slow, check the terminal wasn't closed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1169 // already |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1170 if (buffer == curbuf && curbuf->b_term != NULL) |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1171 update_cursor(curbuf->b_term, TRUE); |
12502 | 1172 } |
1173 else | |
1174 redraw_after_callback(TRUE); | |
1175 } | |
1176 } | |
1177 | |
1178 /* | |
1179 * Send a mouse position and click to the vterm | |
1180 */ | |
1181 static int | |
1182 term_send_mouse(VTerm *vterm, int button, int pressed) | |
1183 { | |
1184 VTermModifier mod = VTERM_MOD_NONE; | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1185 int row = mouse_row - W_WINROW(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1186 int col = mouse_col - curwin->w_wincol; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1187 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1188 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1189 if (popup_is_popup(curwin)) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1190 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1191 row -= popup_top_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1192 col -= popup_left_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1193 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1194 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1195 vterm_mouse_move(vterm, row, col, mod); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1196 if (button != 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1197 vterm_mouse_button(vterm, button, pressed, mod); |
12502 | 1198 return TRUE; |
1199 } | |
1200 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1201 static int enter_mouse_col = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1202 static int enter_mouse_row = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1203 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1204 /* |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1205 * Handle a mouse click, drag or release. |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1206 * Return TRUE when a mouse event is sent to the terminal. |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1207 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1208 static int |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1209 term_mouse_click(VTerm *vterm, int key) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1210 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1211 #if defined(FEAT_CLIPBOARD) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1212 // For modeless selection mouse drag and release events are ignored, unless |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1213 // they are preceded with a mouse down event |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1214 static int ignore_drag_release = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1215 VTermMouseState mouse_state; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1216 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1217 vterm_state_get_mousestate(vterm_obtain_state(vterm), &mouse_state); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1218 if (mouse_state.flags == 0) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1219 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1220 // Terminal is not using the mouse, use modeless selection. |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1221 switch (key) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1222 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1223 case K_LEFTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1224 case K_LEFTRELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1225 case K_RIGHTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1226 case K_RIGHTRELEASE: |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1227 // Ignore drag and release events when the button-down wasn't |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1228 // seen before. |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1229 if (ignore_drag_release) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1230 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1231 int save_mouse_col, save_mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1232 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1233 if (enter_mouse_col < 0) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1234 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1235 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1236 // mouse click in the window gave us focus, handle that |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1237 // click now |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1238 save_mouse_col = mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1239 save_mouse_row = mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1240 mouse_col = enter_mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1241 mouse_row = enter_mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1242 clip_modeless(MOUSE_LEFT, TRUE, FALSE); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1243 mouse_col = save_mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1244 mouse_row = save_mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1245 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1246 // FALLTHROUGH |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1247 case K_LEFTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1248 case K_RIGHTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1249 if (key == K_LEFTRELEASE || key == K_RIGHTRELEASE) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1250 ignore_drag_release = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1251 else |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1252 ignore_drag_release = FALSE; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1253 // Should we call mouse_has() here? |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1254 if (clip_star.available) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1255 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1256 int button, is_click, is_drag; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1257 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1258 button = get_mouse_button(KEY2TERMCAP1(key), |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1259 &is_click, &is_drag); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1260 if (mouse_model_popup() && button == MOUSE_LEFT |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1261 && (mod_mask & MOD_MASK_SHIFT)) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1262 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1263 // Translate shift-left to right button. |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1264 button = MOUSE_RIGHT; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1265 mod_mask &= ~MOD_MASK_SHIFT; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1266 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1267 clip_modeless(button, is_click, is_drag); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1268 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1269 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1270 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1271 case K_MIDDLEMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1272 if (clip_star.available) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1273 insert_reg('*', TRUE); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1274 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1275 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1276 enter_mouse_col = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1277 return FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1278 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1279 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1280 enter_mouse_col = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1281 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1282 switch (key) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1283 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1284 case K_LEFTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1285 case K_LEFTMOUSE_NM: term_send_mouse(vterm, 1, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1286 case K_LEFTDRAG: term_send_mouse(vterm, 1, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1287 case K_LEFTRELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1288 case K_LEFTRELEASE_NM: term_send_mouse(vterm, 1, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1289 case K_MOUSEMOVE: term_send_mouse(vterm, 0, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1290 case K_MIDDLEMOUSE: term_send_mouse(vterm, 2, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1291 case K_MIDDLEDRAG: term_send_mouse(vterm, 2, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1292 case K_MIDDLERELEASE: term_send_mouse(vterm, 2, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1293 case K_RIGHTMOUSE: term_send_mouse(vterm, 3, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1294 case K_RIGHTDRAG: term_send_mouse(vterm, 3, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1295 case K_RIGHTRELEASE: term_send_mouse(vterm, 3, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1296 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1297 return TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1298 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1299 |
12502 | 1300 /* |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1301 * Convert typed key "c" with modifiers "modmask" into bytes to send to the |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1302 * job. |
12502 | 1303 * Return the number of bytes in "buf". |
1304 */ | |
1305 static int | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1306 term_convert_key(term_T *term, int c, int modmask, char *buf) |
12502 | 1307 { |
1308 VTerm *vterm = term->tl_vterm; | |
1309 VTermKey key = VTERM_KEY_NONE; | |
1310 VTermModifier mod = VTERM_MOD_NONE; | |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1311 int other = FALSE; |
12502 | 1312 |
1313 switch (c) | |
1314 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1315 // don't use VTERM_KEY_ENTER, it may do an unwanted conversion |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1316 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1317 // don't use VTERM_KEY_BACKSPACE, it always |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1318 // becomes 0x7f DEL |
12502 | 1319 case K_BS: c = term_backspace_char; break; |
1320 | |
1321 case ESC: key = VTERM_KEY_ESCAPE; break; | |
1322 case K_DEL: key = VTERM_KEY_DEL; break; | |
1323 case K_DOWN: key = VTERM_KEY_DOWN; break; | |
1324 case K_S_DOWN: mod = VTERM_MOD_SHIFT; | |
1325 key = VTERM_KEY_DOWN; break; | |
1326 case K_END: key = VTERM_KEY_END; break; | |
1327 case K_S_END: mod = VTERM_MOD_SHIFT; | |
1328 key = VTERM_KEY_END; break; | |
1329 case K_C_END: mod = VTERM_MOD_CTRL; | |
1330 key = VTERM_KEY_END; break; | |
1331 case K_F10: key = VTERM_KEY_FUNCTION(10); break; | |
1332 case K_F11: key = VTERM_KEY_FUNCTION(11); break; | |
1333 case K_F12: key = VTERM_KEY_FUNCTION(12); break; | |
1334 case K_F1: key = VTERM_KEY_FUNCTION(1); break; | |
1335 case K_F2: key = VTERM_KEY_FUNCTION(2); break; | |
1336 case K_F3: key = VTERM_KEY_FUNCTION(3); break; | |
1337 case K_F4: key = VTERM_KEY_FUNCTION(4); break; | |
1338 case K_F5: key = VTERM_KEY_FUNCTION(5); break; | |
1339 case K_F6: key = VTERM_KEY_FUNCTION(6); break; | |
1340 case K_F7: key = VTERM_KEY_FUNCTION(7); break; | |
1341 case K_F8: key = VTERM_KEY_FUNCTION(8); break; | |
1342 case K_F9: key = VTERM_KEY_FUNCTION(9); break; | |
1343 case K_HOME: key = VTERM_KEY_HOME; break; | |
1344 case K_S_HOME: mod = VTERM_MOD_SHIFT; | |
1345 key = VTERM_KEY_HOME; break; | |
1346 case K_C_HOME: mod = VTERM_MOD_CTRL; | |
1347 key = VTERM_KEY_HOME; break; | |
1348 case K_INS: key = VTERM_KEY_INS; break; | |
1349 case K_K0: key = VTERM_KEY_KP_0; break; | |
1350 case K_K1: key = VTERM_KEY_KP_1; break; | |
1351 case K_K2: key = VTERM_KEY_KP_2; break; | |
1352 case K_K3: key = VTERM_KEY_KP_3; break; | |
1353 case K_K4: key = VTERM_KEY_KP_4; break; | |
1354 case K_K5: key = VTERM_KEY_KP_5; break; | |
1355 case K_K6: key = VTERM_KEY_KP_6; break; | |
1356 case K_K7: key = VTERM_KEY_KP_7; break; | |
1357 case K_K8: key = VTERM_KEY_KP_8; break; | |
1358 case K_K9: key = VTERM_KEY_KP_9; break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1359 case K_KDEL: key = VTERM_KEY_DEL; break; // TODO |
12502 | 1360 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1361 case K_KEND: key = VTERM_KEY_KP_1; break; // TODO |
12502 | 1362 case K_KENTER: key = VTERM_KEY_KP_ENTER; break; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1363 case K_KHOME: key = VTERM_KEY_KP_7; break; // TODO |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1364 case K_KINS: key = VTERM_KEY_KP_0; break; // TODO |
12502 | 1365 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break; |
1366 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1367 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; // TODO |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1368 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; // TODO |
12502 | 1369 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break; |
1370 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break; | |
1371 case K_LEFT: key = VTERM_KEY_LEFT; break; | |
1372 case K_S_LEFT: mod = VTERM_MOD_SHIFT; | |
1373 key = VTERM_KEY_LEFT; break; | |
1374 case K_C_LEFT: mod = VTERM_MOD_CTRL; | |
1375 key = VTERM_KEY_LEFT; break; | |
1376 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break; | |
1377 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break; | |
1378 case K_RIGHT: key = VTERM_KEY_RIGHT; break; | |
1379 case K_S_RIGHT: mod = VTERM_MOD_SHIFT; | |
1380 key = VTERM_KEY_RIGHT; break; | |
1381 case K_C_RIGHT: mod = VTERM_MOD_CTRL; | |
1382 key = VTERM_KEY_RIGHT; break; | |
1383 case K_UP: key = VTERM_KEY_UP; break; | |
1384 case K_S_UP: mod = VTERM_MOD_SHIFT; | |
1385 key = VTERM_KEY_UP; break; | |
1386 case TAB: key = VTERM_KEY_TAB; break; | |
13294
5fc59833a748
patch 8.0.1521: Shift-Tab does not work in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13292
diff
changeset
|
1387 case K_S_TAB: mod = VTERM_MOD_SHIFT; |
5fc59833a748
patch 8.0.1521: Shift-Tab does not work in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13292
diff
changeset
|
1388 key = VTERM_KEY_TAB; break; |
12502 | 1389 |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1390 case K_MOUSEUP: other = term_send_mouse(vterm, 5, 1); break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1391 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break; |
12502 | 1392 case K_MOUSELEFT: /* TODO */ return 0; |
1393 case K_MOUSERIGHT: /* TODO */ return 0; | |
1394 | |
1395 case K_LEFTMOUSE: | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1396 case K_LEFTMOUSE_NM: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1397 case K_LEFTDRAG: |
12502 | 1398 case K_LEFTRELEASE: |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1399 case K_LEFTRELEASE_NM: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1400 case K_MOUSEMOVE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1401 case K_MIDDLEMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1402 case K_MIDDLEDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1403 case K_MIDDLERELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1404 case K_RIGHTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1405 case K_RIGHTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1406 case K_RIGHTRELEASE: if (!term_mouse_click(vterm, c)) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1407 return 0; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1408 other = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1409 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1410 |
12502 | 1411 case K_X1MOUSE: /* TODO */ return 0; |
1412 case K_X1DRAG: /* TODO */ return 0; | |
1413 case K_X1RELEASE: /* TODO */ return 0; | |
1414 case K_X2MOUSE: /* TODO */ return 0; | |
1415 case K_X2DRAG: /* TODO */ return 0; | |
1416 case K_X2RELEASE: /* TODO */ return 0; | |
1417 | |
1418 case K_IGNORE: return 0; | |
1419 case K_NOP: return 0; | |
1420 case K_UNDO: return 0; | |
1421 case K_HELP: return 0; | |
1422 case K_XF1: key = VTERM_KEY_FUNCTION(1); break; | |
1423 case K_XF2: key = VTERM_KEY_FUNCTION(2); break; | |
1424 case K_XF3: key = VTERM_KEY_FUNCTION(3); break; | |
1425 case K_XF4: key = VTERM_KEY_FUNCTION(4); break; | |
1426 case K_SELECT: return 0; | |
1427 #ifdef FEAT_GUI | |
1428 case K_VER_SCROLLBAR: return 0; | |
1429 case K_HOR_SCROLLBAR: return 0; | |
1430 #endif | |
1431 #ifdef FEAT_GUI_TABLINE | |
1432 case K_TABLINE: return 0; | |
1433 case K_TABMENU: return 0; | |
1434 #endif | |
1435 #ifdef FEAT_NETBEANS_INTG | |
1436 case K_F21: key = VTERM_KEY_FUNCTION(21); break; | |
1437 #endif | |
1438 #ifdef FEAT_DND | |
1439 case K_DROP: return 0; | |
1440 #endif | |
1441 case K_CURSORHOLD: return 0; | |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1442 case K_PS: vterm_keyboard_start_paste(vterm); |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1443 other = TRUE; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1444 break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1445 case K_PE: vterm_keyboard_end_paste(vterm); |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1446 other = TRUE; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1447 break; |
12502 | 1448 } |
1449 | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1450 // add modifiers for the typed key |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1451 if (modmask & MOD_MASK_SHIFT) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1452 mod |= VTERM_MOD_SHIFT; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1453 if (modmask & MOD_MASK_CTRL) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1454 mod |= VTERM_MOD_CTRL; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1455 if (modmask & (MOD_MASK_ALT | MOD_MASK_META)) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1456 mod |= VTERM_MOD_ALT; |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1457 |
12502 | 1458 /* |
1459 * Convert special keys to vterm keys: | |
1460 * - Write keys to vterm: vterm_keyboard_key() | |
1461 * - Write output to channel. | |
1462 */ | |
1463 if (key != VTERM_KEY_NONE) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1464 // Special key, let vterm convert it. |
12502 | 1465 vterm_keyboard_key(vterm, key, mod); |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1466 else if (!other) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1467 // Normal character, let vterm convert it. |
12502 | 1468 vterm_keyboard_unichar(vterm, c, mod); |
1469 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1470 // Read back the converted escape sequence. |
12502 | 1471 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); |
1472 } | |
1473 | |
1474 /* | |
1475 * Return TRUE if the job for "term" is still running. | |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1476 * If "check_job_status" is TRUE update the job status. |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1477 * NOTE: "term" may be freed by callbacks. |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1478 */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1479 static int |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1480 term_job_running_check(term_T *term, int check_job_status) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1481 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1482 // Also consider the job finished when the channel is closed, to avoid a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1483 // race condition when updating the title. |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1484 if (term != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1485 && term->tl_job != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1486 && channel_is_open(term->tl_job->jv_channel)) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1487 { |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1488 job_T *job = term->tl_job; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1489 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1490 // Careful: Checking the job status may invoked callbacks, which close |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1491 // the buffer and terminate "term". However, "job" will not be freed |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1492 // yet. |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1493 if (check_job_status) |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1494 job_status(job); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1495 return (job->jv_status == JOB_STARTED |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1496 || (job->jv_channel != NULL && job->jv_channel->ch_keep_open)); |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1497 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1498 return FALSE; |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1499 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1500 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1501 /* |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1502 * Return TRUE if the job for "term" is still running. |
12502 | 1503 */ |
1504 int | |
1505 term_job_running(term_T *term) | |
1506 { | |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1507 return term_job_running_check(term, FALSE); |
12502 | 1508 } |
1509 | |
1510 /* | |
1511 * Return TRUE if "term" has an active channel and used ":term NONE". | |
1512 */ | |
1513 int | |
1514 term_none_open(term_T *term) | |
1515 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1516 // Also consider the job finished when the channel is closed, to avoid a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1517 // race condition when updating the title. |
12502 | 1518 return term != NULL |
1519 && term->tl_job != NULL | |
1520 && channel_is_open(term->tl_job->jv_channel) | |
1521 && term->tl_job->jv_channel->ch_keep_open; | |
1522 } | |
1523 | |
1524 /* | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1525 * Used when exiting: kill the job in "buf" if so desired. |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1526 * Return OK when the job finished. |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1527 * Return FAIL when the job is still running. |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1528 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1529 int |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1530 term_try_stop_job(buf_T *buf) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1531 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1532 int count; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1533 char *how = (char *)buf->b_term->tl_kill; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1534 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1535 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1536 if ((how == NULL || *how == NUL) && (p_confirm || cmdmod.confirm)) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1537 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1538 char_u buff[DIALOG_MSG_SIZE]; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1539 int ret; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1540 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1541 dialog_msg(buff, _("Kill job in \"%s\"?"), buf->b_fname); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1542 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1543 if (ret == VIM_YES) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1544 how = "kill"; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1545 else if (ret == VIM_CANCEL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1546 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1547 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1548 #endif |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1549 if (how == NULL || *how == NUL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1550 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1551 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1552 job_stop(buf->b_term->tl_job, NULL, how); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1553 |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1554 // wait for up to a second for the job to die |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1555 for (count = 0; count < 100; ++count) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1556 { |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1557 job_T *job; |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1558 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1559 // buffer, terminal and job may be cleaned up while waiting |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1560 if (!buf_valid(buf) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1561 || buf->b_term == NULL |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1562 || buf->b_term->tl_job == NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1563 return OK; |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1564 job = buf->b_term->tl_job; |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1565 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1566 // Call job_status() to update jv_status. It may cause the job to be |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1567 // cleaned up but it won't be freed. |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1568 job_status(job); |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1569 if (job->jv_status >= JOB_ENDED) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1570 return OK; |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1571 |
18420
3a3efaaa05c5
patch 8.1.2204: crash on exit when closing terminals
Bram Moolenaar <Bram@vim.org>
parents:
18402
diff
changeset
|
1572 ui_delay(10L, TRUE); |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1573 term_flush_messages(); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1574 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1575 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1576 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1577 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1578 /* |
12502 | 1579 * Add the last line of the scrollback buffer to the buffer in the window. |
1580 */ | |
1581 static void | |
1582 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) | |
1583 { | |
1584 buf_T *buf = term->tl_buffer; | |
1585 int empty = (buf->b_ml.ml_flags & ML_EMPTY); | |
1586 linenr_T lnum = buf->b_ml.ml_line_count; | |
1587 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1588 #ifdef MSWIN |
12502 | 1589 if (!enc_utf8 && enc_codepage > 0) |
1590 { | |
1591 WCHAR *ret = NULL; | |
1592 int length = 0; | |
1593 | |
1594 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, | |
1595 &ret, &length); | |
1596 if (ret != NULL) | |
1597 { | |
1598 WideCharToMultiByte_alloc(enc_codepage, 0, | |
1599 ret, length, (char **)&text, &len, 0, 0); | |
1600 vim_free(ret); | |
1601 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); | |
1602 vim_free(text); | |
1603 } | |
1604 } | |
1605 else | |
1606 #endif | |
1607 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); | |
1608 if (empty) | |
1609 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1610 // Delete the empty line that was in the empty buffer. |
12502 | 1611 curbuf = buf; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1612 ml_delete(1); |
12502 | 1613 curbuf = curwin->w_buffer; |
1614 } | |
1615 } | |
1616 | |
1617 static void | |
1618 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr) | |
1619 { | |
1620 attr->width = cell->width; | |
1621 attr->attrs = cell->attrs; | |
1622 attr->fg = cell->fg; | |
1623 attr->bg = cell->bg; | |
1624 } | |
1625 | |
1626 static int | |
1627 equal_celattr(cellattr_T *a, cellattr_T *b) | |
1628 { | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
1629 // We only compare the RGB colors, ignoring the ANSI index and type. |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
1630 // Thus black set explicitly is equal the background black. |
12502 | 1631 return a->fg.red == b->fg.red |
1632 && a->fg.green == b->fg.green | |
1633 && a->fg.blue == b->fg.blue | |
1634 && a->bg.red == b->bg.red | |
1635 && a->bg.green == b->bg.green | |
1636 && a->bg.blue == b->bg.blue; | |
1637 } | |
1638 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1639 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1640 * Add an empty scrollback line to "term". When "lnum" is not zero, add the |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1641 * line at this position. Otherwise at the end. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1642 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1643 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1644 add_empty_scrollback(term_T *term, cellattr_T *fill_attr, int lnum) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1645 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1646 if (ga_grow(&term->tl_scrollback, 1) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1647 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1648 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1649 + term->tl_scrollback.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1650 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1651 if (lnum > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1652 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1653 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1654 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1655 for (i = 0; i < term->tl_scrollback.ga_len - lnum; ++i) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1656 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1657 *line = *(line - 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1658 --line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1659 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1660 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1661 line->sb_cols = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1662 line->sb_cells = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1663 line->sb_fill_attr = *fill_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1664 ++term->tl_scrollback.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1665 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1666 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1667 return FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1668 } |
12502 | 1669 |
1670 /* | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1671 * Remove the terminal contents from the scrollback and the buffer. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1672 * Used before adding a new scrollback line or updating the buffer for lines |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1673 * displayed in the terminal. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1674 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1675 static void |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1676 cleanup_scrollback(term_T *term) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1677 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1678 sb_line_T *line; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1679 garray_T *gap; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1680 |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1681 curbuf = term->tl_buffer; |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1682 gap = &term->tl_scrollback; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1683 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1684 && gap->ga_len > 0) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1685 { |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1686 ml_delete(curbuf->b_ml.ml_line_count); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1687 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1688 vim_free(line->sb_cells); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1689 --gap->ga_len; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1690 } |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1691 curbuf = curwin->w_buffer; |
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1692 if (curbuf == term->tl_buffer) |
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1693 check_cursor(); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1694 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1695 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1696 /* |
12502 | 1697 * Add the current lines of the terminal to scrollback and to the buffer. |
1698 */ | |
1699 static void | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1700 update_snapshot(term_T *term) |
12502 | 1701 { |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1702 VTermScreen *screen; |
12502 | 1703 int len; |
1704 int lines_skipped = 0; | |
1705 VTermPos pos; | |
1706 VTermScreenCell cell; | |
1707 cellattr_T fill_attr, new_fill_attr; | |
1708 cellattr_T *p; | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1709 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1710 ch_log(term->tl_job == NULL ? NULL : term->tl_job->jv_channel, |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1711 "Adding terminal window snapshot to buffer"); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1712 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1713 // First remove the lines that were appended before, they might be |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1714 // outdated. |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1715 cleanup_scrollback(term); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1716 |
12502 | 1717 screen = vterm_obtain_screen(term->tl_vterm); |
1718 fill_attr = new_fill_attr = term->tl_default_color; | |
1719 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row) | |
1720 { | |
1721 len = 0; | |
1722 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | |
1723 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | |
1724 && cell.chars[0] != NUL) | |
1725 { | |
1726 len = pos.col + 1; | |
1727 new_fill_attr = term->tl_default_color; | |
1728 } | |
1729 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1730 // Assume the last attr is the filler attr. |
12502 | 1731 cell2cellattr(&cell, &new_fill_attr); |
1732 | |
1733 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr)) | |
1734 ++lines_skipped; | |
1735 else | |
1736 { | |
1737 while (lines_skipped > 0) | |
1738 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1739 // Line was skipped, add an empty line. |
12502 | 1740 --lines_skipped; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1741 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
12502 | 1742 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
1743 } | |
1744 | |
1745 if (len == 0) | |
1746 p = NULL; | |
1747 else | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1748 p = ALLOC_MULT(cellattr_T, len); |
12502 | 1749 if ((p != NULL || len == 0) |
1750 && ga_grow(&term->tl_scrollback, 1) == OK) | |
1751 { | |
1752 garray_T ga; | |
1753 int width; | |
1754 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | |
1755 + term->tl_scrollback.ga_len; | |
1756 | |
1757 ga_init2(&ga, 1, 100); | |
1758 for (pos.col = 0; pos.col < len; pos.col += width) | |
1759 { | |
1760 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
1761 { | |
1762 width = 1; | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1763 CLEAR_POINTER(p + pos.col); |
12502 | 1764 if (ga_grow(&ga, 1) == OK) |
1765 ga.ga_len += utf_char2bytes(' ', | |
1766 (char_u *)ga.ga_data + ga.ga_len); | |
1767 } | |
1768 else | |
1769 { | |
1770 width = cell.width; | |
1771 | |
1772 cell2cellattr(&cell, &p[pos.col]); | |
1773 | |
15203
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1774 // Each character can be up to 6 bytes. |
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1775 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK) |
12502 | 1776 { |
1777 int i; | |
1778 int c; | |
1779 | |
1780 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) | |
1781 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
1782 (char_u *)ga.ga_data + ga.ga_len); | |
1783 } | |
1784 } | |
1785 } | |
1786 line->sb_cols = len; | |
1787 line->sb_cells = p; | |
1788 line->sb_fill_attr = new_fill_attr; | |
1789 fill_attr = new_fill_attr; | |
1790 ++term->tl_scrollback.ga_len; | |
1791 | |
1792 if (ga_grow(&ga, 1) == FAIL) | |
1793 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
1794 else | |
1795 { | |
1796 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
1797 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
1798 } | |
1799 ga_clear(&ga); | |
1800 } | |
1801 else | |
1802 vim_free(p); | |
1803 } | |
1804 } | |
1805 | |
15022
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1806 // Add trailing empty lines. |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1807 for (pos.row = term->tl_scrollback.ga_len; |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1808 pos.row < term->tl_scrollback_scrolled + term->tl_cursor_pos.row; |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1809 ++pos.row) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1810 { |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1811 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1812 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1813 } |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1814 |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1815 term->tl_dirty_snapshot = FALSE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1816 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1817 term->tl_timer_set = FALSE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1818 #endif |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1819 } |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1820 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1821 /* |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1822 * Loop over all windows in the current tab, and also curwin, which is not |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1823 * encountered when using a terminal in a popup window. |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1824 * Return TRUE if "*wp" was set to the next window. |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1825 */ |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1826 static int |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1827 for_all_windows_and_curwin(win_T **wp, int *did_curwin) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1828 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1829 if (*wp == NULL) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1830 *wp = firstwin; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1831 else if ((*wp)->w_next != NULL) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1832 *wp = (*wp)->w_next; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1833 else if (!*did_curwin) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1834 *wp = curwin; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1835 else |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1836 return FALSE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1837 if (*wp == curwin) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1838 *did_curwin = TRUE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1839 return TRUE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1840 } |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1841 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1842 /* |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1843 * If needed, add the current lines of the terminal to scrollback and to the |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1844 * buffer. Called after the job has ended and when switching to |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1845 * Terminal-Normal mode. |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1846 * When "redraw" is TRUE redraw the windows that show the terminal. |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1847 */ |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1848 static void |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1849 may_move_terminal_to_buffer(term_T *term, int redraw) |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1850 { |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1851 if (term->tl_vterm == NULL) |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1852 return; |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1853 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1854 // Update the snapshot only if something changes or the buffer does not |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1855 // have all the lines. |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1856 if (term->tl_dirty_snapshot || term->tl_buffer->b_ml.ml_line_count |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1857 <= term->tl_scrollback_scrolled) |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1858 update_snapshot(term); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1859 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1860 // Obtain the current background color. |
12502 | 1861 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
1862 &term->tl_default_color.fg, &term->tl_default_color.bg); | |
1863 | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1864 if (redraw) |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1865 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1866 win_T *wp = NULL; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1867 int did_curwin = FALSE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1868 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1869 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 1870 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1871 if (wp->w_buffer == term->tl_buffer) |
12502 | 1872 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1873 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1874 wp->w_cursor.col = 0; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1875 wp->w_valid = 0; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1876 if (wp->w_cursor.lnum >= wp->w_height) |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1877 { |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1878 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1879 |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1880 if (wp->w_topline < min_topline) |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1881 wp->w_topline = min_topline; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1882 } |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1883 redraw_win_later(wp, NOT_VALID); |
12502 | 1884 } |
1885 } | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1886 } |
12502 | 1887 } |
1888 | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1889 #if defined(FEAT_TIMERS) || defined(PROTO) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1890 /* |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1891 * Check if any terminal timer expired. If so, copy text from the terminal to |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1892 * the buffer. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1893 * Return the time until the next timer will expire. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1894 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1895 int |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1896 term_check_timers(int next_due_arg, proftime_T *now) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1897 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1898 term_T *term; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1899 int next_due = next_due_arg; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1900 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
1901 FOR_ALL_TERMS(term) |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1902 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1903 if (term->tl_timer_set && !term->tl_normal_mode) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1904 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1905 long this_due = proftime_time_left(&term->tl_timer_due, now); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1906 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1907 if (this_due <= 1) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1908 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1909 term->tl_timer_set = FALSE; |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1910 may_move_terminal_to_buffer(term, FALSE); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1911 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1912 else if (next_due == -1 || next_due > this_due) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1913 next_due = this_due; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1914 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1915 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1916 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1917 return next_due; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1918 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1919 #endif |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1920 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1921 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1922 * When "normal_mode" is TRUE set the terminal to Terminal-Normal mode, |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1923 * otherwise end it. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1924 */ |
12502 | 1925 static void |
1926 set_terminal_mode(term_T *term, int normal_mode) | |
1927 { | |
1928 term->tl_normal_mode = normal_mode; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1929 if (!normal_mode) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1930 handle_postponed_scrollback(term); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
1931 VIM_CLEAR(term->tl_status_text); |
12502 | 1932 if (term->tl_buffer == curbuf) |
1933 maketitle(); | |
1934 } | |
1935 | |
1936 /* | |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1937 * Called after the job is finished and Terminal mode is not active: |
12502 | 1938 * Move the vterm contents into the scrollback buffer and free the vterm. |
1939 */ | |
1940 static void | |
1941 cleanup_vterm(term_T *term) | |
1942 { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1943 set_terminal_mode(term, FALSE); |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
1944 if (term->tl_finish != TL_FINISH_CLOSE) |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1945 may_move_terminal_to_buffer(term, TRUE); |
12502 | 1946 term_free_vterm(term); |
1947 } | |
1948 | |
1949 /* | |
1950 * Switch from Terminal-Job mode to Terminal-Normal mode. | |
1951 * Suspends updating the terminal window. | |
1952 */ | |
1953 static void | |
1954 term_enter_normal_mode(void) | |
1955 { | |
1956 term_T *term = curbuf->b_term; | |
1957 | |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1958 set_terminal_mode(term, TRUE); |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1959 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1960 // Append the current terminal contents to the buffer. |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1961 may_move_terminal_to_buffer(term, TRUE); |
12502 | 1962 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1963 // Move the window cursor to the position of the cursor in the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1964 // terminal. |
12502 | 1965 curwin->w_cursor.lnum = term->tl_scrollback_scrolled |
1966 + term->tl_cursor_pos.row + 1; | |
1967 check_cursor(); | |
13935
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
1968 if (coladvance(term->tl_cursor_pos.col) == FAIL) |
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
1969 coladvance(MAXCOL); |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1970 curwin->w_set_curswant = TRUE; |
12502 | 1971 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1972 // Display the same lines as in the terminal. |
12502 | 1973 curwin->w_topline = term->tl_scrollback_scrolled + 1; |
1974 } | |
1975 | |
1976 /* | |
1977 * Returns TRUE if the current window contains a terminal and we are in | |
1978 * Terminal-Normal mode. | |
1979 */ | |
1980 int | |
1981 term_in_normal_mode(void) | |
1982 { | |
1983 term_T *term = curbuf->b_term; | |
1984 | |
1985 return term != NULL && term->tl_normal_mode; | |
1986 } | |
1987 | |
1988 /* | |
1989 * Switch from Terminal-Normal mode to Terminal-Job mode. | |
1990 * Restores updating the terminal window. | |
1991 */ | |
1992 void | |
1993 term_enter_job_mode() | |
1994 { | |
1995 term_T *term = curbuf->b_term; | |
1996 | |
1997 set_terminal_mode(term, FALSE); | |
1998 | |
1999 if (term->tl_channel_closed) | |
2000 cleanup_vterm(term); | |
2001 redraw_buf_and_status_later(curbuf, NOT_VALID); | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2002 #ifdef FEAT_PROP_POPUP |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2003 if (WIN_IS_POPUP(curwin)) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
2004 redraw_later(NOT_VALID); |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2005 #endif |
12502 | 2006 } |
2007 | |
2008 /* | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2009 * Get a key from the user with terminal mode mappings. |
12502 | 2010 * Note: while waiting a terminal may be closed and freed if the channel is |
2011 * closed and ++close was used. | |
2012 */ | |
2013 static int | |
2014 term_vgetc() | |
2015 { | |
2016 int c; | |
2017 int save_State = State; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2018 int modify_other_keys = |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2019 vterm_is_modify_other_keys(curbuf->b_term->tl_vterm); |
12502 | 2020 |
2021 State = TERMINAL; | |
2022 got_int = FALSE; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2023 #ifdef MSWIN |
12502 | 2024 ctrl_break_was_pressed = FALSE; |
2025 #endif | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2026 if (modify_other_keys) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2027 ++no_reduce_keys; |
12502 | 2028 c = vgetc(); |
2029 got_int = FALSE; | |
2030 State = save_State; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2031 if (modify_other_keys) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2032 --no_reduce_keys; |
12502 | 2033 return c; |
2034 } | |
2035 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2036 static int mouse_was_outside = FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2037 |
12502 | 2038 /* |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2039 * Send key "c" with modifiers "modmask" to terminal. |
12502 | 2040 * Return FAIL when the key needs to be handled in Normal mode. |
2041 * Return OK when the key was dropped or sent to the terminal. | |
2042 */ | |
2043 int | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2044 send_keys_to_term(term_T *term, int c, int modmask, int typed) |
12502 | 2045 { |
2046 char msg[KEY_BUF_LEN]; | |
2047 size_t len; | |
2048 int dragging_outside = FALSE; | |
2049 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2050 // Catch keys that need to be handled as in Normal mode. |
12502 | 2051 switch (c) |
2052 { | |
2053 case NUL: | |
2054 case K_ZERO: | |
2055 if (typed) | |
2056 stuffcharReadbuff(c); | |
2057 return FAIL; | |
2058 | |
13849
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
2059 case K_TABLINE: |
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
2060 stuffcharReadbuff(c); |
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
2061 return FAIL; |
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
2062 |
12502 | 2063 case K_IGNORE: |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2064 case K_CANCEL: // used for :normal when running out of chars |
12502 | 2065 return FAIL; |
2066 | |
2067 case K_LEFTDRAG: | |
2068 case K_MIDDLEDRAG: | |
2069 case K_RIGHTDRAG: | |
2070 case K_X1DRAG: | |
2071 case K_X2DRAG: | |
2072 dragging_outside = mouse_was_outside; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2073 // FALLTHROUGH |
12502 | 2074 case K_LEFTMOUSE: |
2075 case K_LEFTMOUSE_NM: | |
2076 case K_LEFTRELEASE: | |
2077 case K_LEFTRELEASE_NM: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
2078 case K_MOUSEMOVE: |
12502 | 2079 case K_MIDDLEMOUSE: |
2080 case K_MIDDLERELEASE: | |
2081 case K_RIGHTMOUSE: | |
2082 case K_RIGHTRELEASE: | |
2083 case K_X1MOUSE: | |
2084 case K_X1RELEASE: | |
2085 case K_X2MOUSE: | |
2086 case K_X2RELEASE: | |
2087 | |
2088 case K_MOUSEUP: | |
2089 case K_MOUSEDOWN: | |
2090 case K_MOUSELEFT: | |
2091 case K_MOUSERIGHT: | |
2092 { | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2093 int row = mouse_row; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2094 int col = mouse_col; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2095 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2096 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2097 if (popup_is_popup(curwin)) |
12502 | 2098 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2099 row -= popup_top_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2100 col -= popup_left_extra(curwin); |
12502 | 2101 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2102 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2103 if (row < W_WINROW(curwin) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2104 || row >= (W_WINROW(curwin) + curwin->w_height) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2105 || col < curwin->w_wincol |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2106 || col >= W_ENDCOL(curwin) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2107 || dragging_outside) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2108 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2109 // click or scroll outside the current window or on status |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2110 // line or vertical separator |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2111 if (typed) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2112 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2113 stuffcharReadbuff(c); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2114 mouse_was_outside = TRUE; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2115 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2116 return FAIL; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2117 } |
12502 | 2118 } |
2119 } | |
2120 if (typed) | |
2121 mouse_was_outside = FALSE; | |
2122 | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2123 // Convert the typed key to a sequence of bytes for the job. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2124 len = term_convert_key(term, c, modmask, msg); |
12502 | 2125 if (len > 0) |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2126 // TODO: if FAIL is returned, stop? |
12502 | 2127 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
2128 (char_u *)msg, (int)len, NULL); | |
2129 | |
2130 return OK; | |
2131 } | |
2132 | |
2133 static void | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2134 position_cursor(win_T *wp, VTermPos *pos, int add_off UNUSED) |
12502 | 2135 { |
2136 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); | |
2137 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1)); | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2138 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2139 if (add_off && popup_is_popup(curwin)) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2140 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2141 wp->w_wrow += popup_top_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2142 wp->w_wcol += popup_left_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2143 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2144 #endif |
12502 | 2145 wp->w_valid |= (VALID_WCOL|VALID_WROW); |
2146 } | |
2147 | |
2148 /* | |
2149 * Handle CTRL-W "": send register contents to the job. | |
2150 */ | |
2151 static void | |
2152 term_paste_register(int prev_c UNUSED) | |
2153 { | |
2154 int c; | |
2155 list_T *l; | |
2156 listitem_T *item; | |
2157 long reglen = 0; | |
2158 int type; | |
2159 | |
2160 #ifdef FEAT_CMDL_INFO | |
2161 if (add_to_showcmd(prev_c)) | |
2162 if (add_to_showcmd('"')) | |
2163 out_flush(); | |
2164 #endif | |
2165 c = term_vgetc(); | |
2166 #ifdef FEAT_CMDL_INFO | |
2167 clear_showcmd(); | |
2168 #endif | |
2169 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2170 // job finished while waiting for a character |
12502 | 2171 return; |
2172 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2173 // CTRL-W "= prompt for expression to evaluate. |
12502 | 2174 if (c == '=' && get_expr_register() != '=') |
2175 return; | |
2176 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2177 // job finished while waiting for a character |
12502 | 2178 return; |
2179 | |
2180 l = (list_T *)get_reg_contents(c, GREG_LIST); | |
2181 if (l != NULL) | |
2182 { | |
2183 type = get_reg_type(c, ®len); | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
2184 FOR_ALL_LIST_ITEMS(l, item) |
12502 | 2185 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
2186 char_u *s = tv_get_string(&item->li_tv); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2187 #ifdef MSWIN |
12502 | 2188 char_u *tmp = s; |
2189 | |
2190 if (!enc_utf8 && enc_codepage > 0) | |
2191 { | |
2192 WCHAR *ret = NULL; | |
2193 int length = 0; | |
2194 | |
2195 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s, | |
2196 (int)STRLEN(s), &ret, &length); | |
2197 if (ret != NULL) | |
2198 { | |
2199 WideCharToMultiByte_alloc(CP_UTF8, 0, | |
2200 ret, length, (char **)&s, &length, 0, 0); | |
2201 vim_free(ret); | |
2202 } | |
2203 } | |
2204 #endif | |
2205 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2206 s, (int)STRLEN(s), NULL); | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2207 #ifdef MSWIN |
12502 | 2208 if (tmp != s) |
2209 vim_free(s); | |
2210 #endif | |
2211 | |
2212 if (item->li_next != NULL || type == MLINE) | |
2213 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2214 (char_u *)"\r", 1, NULL); | |
2215 } | |
2216 list_free(l); | |
2217 } | |
2218 } | |
2219 | |
2220 /* | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2221 * Return TRUE when waiting for a character in the terminal, the cursor of the |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2222 * terminal should be displayed. |
12502 | 2223 */ |
2224 int | |
2225 terminal_is_active() | |
2226 { | |
2227 return in_terminal_loop != NULL; | |
2228 } | |
2229 | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2230 /* |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2231 * Return the highight group name for the terminal; "Terminal" if not set. |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2232 */ |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2233 static char_u * |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2234 term_get_highlight_name(term_T *term) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2235 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2236 if (term->tl_highlight_name == NULL) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2237 return (char_u *)"Terminal"; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2238 return term->tl_highlight_name; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2239 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2240 |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2241 #if defined(FEAT_GUI) || defined(PROTO) |
12502 | 2242 cursorentry_T * |
2243 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) | |
2244 { | |
2245 term_T *term = in_terminal_loop; | |
2246 static cursorentry_T entry; | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2247 int id; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2248 guicolor_T term_fg, term_bg; |
12502 | 2249 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2250 CLEAR_FIELD(entry); |
12502 | 2251 entry.shape = entry.mshape = |
2252 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : | |
2253 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : | |
2254 SHAPE_BLOCK; | |
2255 entry.percentage = 20; | |
2256 if (term->tl_cursor_blink) | |
2257 { | |
2258 entry.blinkwait = 700; | |
2259 entry.blinkon = 400; | |
2260 entry.blinkoff = 250; | |
2261 } | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2262 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2263 // The highlight group overrules the defaults. |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2264 id = syn_name2id(term_get_highlight_name(term)); |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2265 if (id != 0) |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2266 { |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2267 syn_id2colors(id, &term_fg, &term_bg); |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2268 *fg = term_bg; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2269 } |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2270 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2271 *fg = gui.back_pixel; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2272 |
12502 | 2273 if (term->tl_cursor_color == NULL) |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2274 { |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2275 if (id != 0) |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2276 *bg = term_fg; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2277 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2278 *bg = gui.norm_pixel; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2279 } |
12502 | 2280 else |
2281 *bg = color_name2handle(term->tl_cursor_color); | |
2282 entry.name = "n"; | |
2283 entry.used_for = SHAPE_CURSOR; | |
2284 | |
2285 return &entry; | |
2286 } | |
2287 #endif | |
2288 | |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2289 static void |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2290 may_output_cursor_props(void) |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2291 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2292 if (!cursor_color_equal(last_set_cursor_color, desired_cursor_color) |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2293 || last_set_cursor_shape != desired_cursor_shape |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2294 || last_set_cursor_blink != desired_cursor_blink) |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2295 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2296 cursor_color_copy(&last_set_cursor_color, desired_cursor_color); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2297 last_set_cursor_shape = desired_cursor_shape; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2298 last_set_cursor_blink = desired_cursor_blink; |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2299 term_cursor_color(cursor_color_get(desired_cursor_color)); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2300 if (desired_cursor_shape == -1 || desired_cursor_blink == -1) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2301 // this will restore the initial cursor style, if possible |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2302 ui_cursor_shape_forced(TRUE); |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2303 else |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2304 term_cursor_shape(desired_cursor_shape, desired_cursor_blink); |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2305 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2306 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2307 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2308 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2309 * Set the cursor color and shape, if not last set to these. |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2310 */ |
12502 | 2311 static void |
2312 may_set_cursor_props(term_T *term) | |
2313 { | |
2314 #ifdef FEAT_GUI | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2315 // For the GUI the cursor properties are obtained with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2316 // term_get_cursor_shape(). |
12502 | 2317 if (gui.in_use) |
2318 return; | |
2319 #endif | |
2320 if (in_terminal_loop == term) | |
2321 { | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2322 cursor_color_copy(&desired_cursor_color, term->tl_cursor_color); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2323 desired_cursor_shape = term->tl_cursor_shape; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2324 desired_cursor_blink = term->tl_cursor_blink; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2325 may_output_cursor_props(); |
12502 | 2326 } |
2327 } | |
2328 | |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2329 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2330 * Reset the desired cursor properties and restore them when needed. |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2331 */ |
12502 | 2332 static void |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2333 prepare_restore_cursor_props(void) |
12502 | 2334 { |
2335 #ifdef FEAT_GUI | |
2336 if (gui.in_use) | |
2337 return; | |
2338 #endif | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2339 cursor_color_copy(&desired_cursor_color, NULL); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2340 desired_cursor_shape = -1; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2341 desired_cursor_blink = -1; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2342 may_output_cursor_props(); |
12502 | 2343 } |
2344 | |
2345 /* | |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2346 * Returns TRUE if the current window contains a terminal and we are sending |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2347 * keys to the job. |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2348 * If "check_job_status" is TRUE update the job status. |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2349 */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2350 static int |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2351 term_use_loop_check(int check_job_status) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2352 { |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2353 term_T *term = curbuf->b_term; |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2354 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2355 return term != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2356 && !term->tl_normal_mode |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2357 && term->tl_vterm != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2358 && term_job_running_check(term, check_job_status); |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2359 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2360 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2361 /* |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2362 * Returns TRUE if the current window contains a terminal and we are sending |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2363 * keys to the job. |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2364 */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2365 int |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2366 term_use_loop(void) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2367 { |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2368 return term_use_loop_check(FALSE); |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2369 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2370 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2371 /* |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2372 * Called when entering a window with the mouse. If this is a terminal window |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2373 * we may want to change state. |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2374 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2375 void |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2376 term_win_entered() |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2377 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2378 term_T *term = curbuf->b_term; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2379 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2380 if (term != NULL) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2381 { |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2382 if (term_use_loop_check(TRUE)) |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2383 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2384 reset_VIsual_and_resel(); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2385 if (State & INSERT) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2386 stop_insert_mode = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2387 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2388 mouse_was_outside = FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2389 enter_mouse_col = mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2390 enter_mouse_row = mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2391 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2392 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2393 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2394 /* |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2395 * vgetc() may not include CTRL in the key when modify_other_keys is set. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2396 * Return the Ctrl-key value in that case. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2397 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2398 static int |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2399 raw_c_to_ctrl(int c) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2400 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2401 if ((mod_mask & MOD_MASK_CTRL) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2402 && ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_'))) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2403 return c & 0x1f; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2404 return c; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2405 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2406 |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2407 /* |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2408 * When modify_other_keys is set then do the reverse of raw_c_to_ctrl(). |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2409 * May set "mod_mask". |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2410 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2411 static int |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2412 ctrl_to_raw_c(int c) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2413 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2414 if (c < 0x20 && vterm_is_modify_other_keys(curbuf->b_term->tl_vterm)) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2415 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2416 mod_mask |= MOD_MASK_CTRL; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2417 return c + '@'; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2418 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2419 return c; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2420 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2421 |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2422 /* |
12502 | 2423 * Wait for input and send it to the job. |
2424 * When "blocking" is TRUE wait for a character to be typed. Otherwise return | |
2425 * when there is no more typahead. | |
2426 * Return when the start of a CTRL-W command is typed or anything else that | |
2427 * should be handled as a Normal mode command. | |
2428 * Returns OK if a typed character is to be handled in Normal mode, FAIL if | |
2429 * the terminal was closed. | |
2430 */ | |
2431 int | |
2432 terminal_loop(int blocking) | |
2433 { | |
2434 int c; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2435 int raw_c; |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2436 int termwinkey = 0; |
12502 | 2437 int ret; |
12767
4d9cdb1d8bea
patch 8.0.1261: program in terminal window gets NL instead of CR
Christian Brabandt <cb@256bit.org>
parents:
12724
diff
changeset
|
2438 #ifdef UNIX |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2439 int tty_fd = curbuf->b_term->tl_job->jv_channel |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2440 ->ch_part[get_tty_part(curbuf->b_term)].ch_fd; |
12767
4d9cdb1d8bea
patch 8.0.1261: program in terminal window gets NL instead of CR
Christian Brabandt <cb@256bit.org>
parents:
12724
diff
changeset
|
2441 #endif |
13906
0ae89b121c58
patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents:
13900
diff
changeset
|
2442 int restore_cursor = FALSE; |
12502 | 2443 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2444 // Remember the terminal we are sending keys to. However, the terminal |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2445 // might be closed while waiting for a character, e.g. typing "exit" in a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2446 // shell and ++close was used. Therefore use curbuf->b_term instead of a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2447 // stored reference. |
12502 | 2448 in_terminal_loop = curbuf->b_term; |
2449 | |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2450 if (*curwin->w_p_twk != NUL) |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2451 { |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2452 termwinkey = string_to_key(curwin->w_p_twk, TRUE); |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2453 if (termwinkey == Ctrl_W) |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2454 termwinkey = 0; |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2455 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2456 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos, TRUE); |
12502 | 2457 may_set_cursor_props(curbuf->b_term); |
2458 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2459 while (blocking || vpeekc_nomap() != NUL) |
12502 | 2460 { |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2461 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2462 if (!curbuf->b_term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2463 #endif |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2464 // TODO: skip screen update when handling a sequence of keys. |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2465 // Repeat redrawing in case a message is received while redrawing. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2466 while (must_redraw != 0) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2467 if (update_screen(0) == FAIL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2468 break; |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2469 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2470 // job finished while redrawing |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2471 break; |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2472 |
12502 | 2473 update_cursor(curbuf->b_term, FALSE); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2474 restore_cursor = TRUE; |
12502 | 2475 |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2476 raw_c = term_vgetc(); |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2477 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term) |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2478 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2479 // Job finished while waiting for a character. Push back the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2480 // received character. |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2481 if (raw_c != K_IGNORE) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2482 vungetc(raw_c); |
12502 | 2483 break; |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2484 } |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2485 if (raw_c == K_IGNORE) |
12502 | 2486 continue; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2487 c = raw_c_to_ctrl(raw_c); |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2488 |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2489 #ifdef UNIX |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2490 /* |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2491 * The shell or another program may change the tty settings. Getting |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2492 * them for every typed character is a bit of overhead, but it's needed |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2493 * for the first character typed, e.g. when Vim starts in a shell. |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2494 */ |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2495 if (mch_isatty(tty_fd)) |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2496 { |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2497 ttyinfo_T info; |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2498 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2499 // Get the current backspace character of the pty. |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2500 if (get_tty_info(tty_fd, &info) == OK) |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2501 term_backspace_char = info.backspace; |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2502 } |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2503 #endif |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2504 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2505 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2506 // On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2507 // Use CTRL-BREAK to kill the job. |
12502 | 2508 if (ctrl_break_was_pressed) |
2509 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
2510 #endif | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2511 // Was either CTRL-W (termwinkey) or CTRL-\ pressed? |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2512 // Not in a system terminal. |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2513 if ((c == (termwinkey == 0 ? Ctrl_W : termwinkey) || c == Ctrl_BSL) |
13474
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2514 #ifdef FEAT_GUI |
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2515 && !curbuf->b_term->tl_system |
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2516 #endif |
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2517 ) |
12502 | 2518 { |
2519 int prev_c = c; | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2520 int prev_raw_c = raw_c; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2521 int prev_mod_mask = mod_mask; |
12502 | 2522 |
2523 #ifdef FEAT_CMDL_INFO | |
2524 if (add_to_showcmd(c)) | |
2525 out_flush(); | |
2526 #endif | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2527 raw_c = term_vgetc(); |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2528 c = raw_c_to_ctrl(raw_c); |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2529 |
12502 | 2530 #ifdef FEAT_CMDL_INFO |
2531 clear_showcmd(); | |
2532 #endif | |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2533 if (!term_use_loop_check(TRUE) |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2534 || in_terminal_loop != curbuf->b_term) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2535 // job finished while waiting for a character |
12502 | 2536 break; |
2537 | |
2538 if (prev_c == Ctrl_BSL) | |
2539 { | |
2540 if (c == Ctrl_N) | |
2541 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2542 // CTRL-\ CTRL-N : go to Terminal-Normal mode. |
12502 | 2543 term_enter_normal_mode(); |
2544 ret = FAIL; | |
2545 goto theend; | |
2546 } | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2547 // Send both keys to the terminal, first one here, second one |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2548 // below. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2549 send_keys_to_term(curbuf->b_term, prev_raw_c, prev_mod_mask, |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2550 TRUE); |
12502 | 2551 } |
2552 else if (c == Ctrl_C) | |
2553 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2554 // "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job |
12502 | 2555 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); |
2556 } | |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2557 else if (c == '.') |
12502 | 2558 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2559 // "CTRL-W .": send CTRL-W to the job |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2560 // "'termwinkey' .": send 'termwinkey' to the job |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2561 raw_c = ctrl_to_raw_c(termwinkey == 0 ? Ctrl_W : termwinkey); |
12502 | 2562 } |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2563 else if (c == Ctrl_BSL) |
13668
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2564 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2565 // "CTRL-W CTRL-\": send CTRL-\ to the job |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2566 raw_c = ctrl_to_raw_c(Ctrl_BSL); |
13668
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2567 } |
12502 | 2568 else if (c == 'N') |
2569 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2570 // CTRL-W N : go to Terminal-Normal mode. |
12502 | 2571 term_enter_normal_mode(); |
2572 ret = FAIL; | |
2573 goto theend; | |
2574 } | |
2575 else if (c == '"') | |
2576 { | |
2577 term_paste_register(prev_c); | |
2578 continue; | |
2579 } | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2580 else if (termwinkey == 0 || c != termwinkey) |
12502 | 2581 { |
17702
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2582 char_u buf[MB_MAXBYTES + 2]; |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2583 |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2584 // Put the command into the typeahead buffer, when using the |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2585 // stuff buffer KeyStuffed is set and 'langmap' won't be used. |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2586 buf[0] = Ctrl_W; |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2587 buf[(*mb_char2bytes)(c, buf + 1) + 1] = NUL; |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2588 ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE); |
12502 | 2589 ret = OK; |
2590 goto theend; | |
2591 } | |
2592 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2593 # ifdef MSWIN |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2594 if (!enc_utf8 && has_mbyte && raw_c >= 0x80) |
12502 | 2595 { |
2596 WCHAR wc; | |
2597 char_u mb[3]; | |
2598 | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2599 mb[0] = (unsigned)raw_c >> 8; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2600 mb[1] = raw_c; |
12502 | 2601 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0) |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2602 raw_c = wc; |
12502 | 2603 } |
2604 # endif | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2605 if (send_keys_to_term(curbuf->b_term, raw_c, mod_mask, TRUE) != OK) |
12502 | 2606 { |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2607 if (raw_c == K_MOUSEMOVE) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2608 // We are sure to come back here, don't reset the cursor color |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2609 // and shape to avoid flickering. |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2610 restore_cursor = FALSE; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2611 |
12502 | 2612 ret = OK; |
2613 goto theend; | |
2614 } | |
2615 } | |
2616 ret = FAIL; | |
2617 | |
2618 theend: | |
2619 in_terminal_loop = NULL; | |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2620 if (restore_cursor) |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2621 prepare_restore_cursor_props(); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2622 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2623 // Move a snapshot of the screen contents to the buffer, so that completion |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2624 // works in other buffers. |
13935
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
2625 if (curbuf->b_term != NULL && !curbuf->b_term->tl_normal_mode) |
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
2626 may_move_terminal_to_buffer(curbuf->b_term, FALSE); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2627 |
12502 | 2628 return ret; |
2629 } | |
2630 | |
2631 static void | |
2632 may_toggle_cursor(term_T *term) | |
2633 { | |
2634 if (in_terminal_loop == term) | |
2635 { | |
2636 if (term->tl_cursor_visible) | |
2637 cursor_on(); | |
2638 else | |
2639 cursor_off(); | |
2640 } | |
2641 } | |
2642 | |
2643 /* | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2644 * Cache "Terminal" highlight group colors. |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2645 */ |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2646 void |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2647 set_terminal_default_colors(int cterm_fg, int cterm_bg) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2648 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2649 term_default_cterm_fg = cterm_fg - 1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2650 term_default_cterm_bg = cterm_bg - 1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2651 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2652 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2653 static int |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2654 get_default_cterm_fg(term_T *term) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2655 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2656 if (term->tl_highlight_name != NULL) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2657 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2658 int id = syn_name2id(term->tl_highlight_name); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2659 int fg = -1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2660 int bg = -1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2661 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2662 if (id > 0) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2663 syn_id2cterm_bg(id, &fg, &bg); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2664 return fg; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2665 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2666 return term_default_cterm_fg; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2667 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2668 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2669 static int |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2670 get_default_cterm_bg(term_T *term) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2671 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2672 if (term->tl_highlight_name != NULL) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2673 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2674 int id = syn_name2id(term->tl_highlight_name); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2675 int fg = -1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2676 int bg = -1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2677 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2678 if (id > 0) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2679 syn_id2cterm_bg(id, &fg, &bg); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2680 return bg; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2681 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2682 return term_default_cterm_bg; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2683 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2684 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2685 /* |
12502 | 2686 * Reverse engineer the RGB value into a cterm color index. |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2687 * First color is 1. Return 0 if no match found (default color). |
12502 | 2688 */ |
2689 static int | |
2690 color2index(VTermColor *color, int fg, int *boldp) | |
2691 { | |
2692 int red = color->red; | |
2693 int blue = color->blue; | |
2694 int green = color->green; | |
2695 | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2696 if (VTERM_COLOR_IS_DEFAULT_FG(color) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2697 || VTERM_COLOR_IS_DEFAULT_BG(color)) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2698 return 0; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2699 if (VTERM_COLOR_IS_INDEXED(color)) |
12502 | 2700 { |
16312
46e8430738fa
patch 8.1.1161: unreachable code
Bram Moolenaar <Bram@vim.org>
parents:
16283
diff
changeset
|
2701 // The first 16 colors and default: use the ANSI index. |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2702 switch (color->index + 1) |
12502 | 2703 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2704 case 0: return 0; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2705 case 1: return lookup_color( 0, fg, boldp) + 1; // black |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2706 case 2: return lookup_color( 4, fg, boldp) + 1; // dark red |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2707 case 3: return lookup_color( 2, fg, boldp) + 1; // dark green |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2708 case 4: return lookup_color( 7, fg, boldp) + 1; // dark yellow |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2709 case 5: return lookup_color( 1, fg, boldp) + 1; // dark blue |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2710 case 6: return lookup_color( 5, fg, boldp) + 1; // dark magenta |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2711 case 7: return lookup_color( 3, fg, boldp) + 1; // dark cyan |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2712 case 8: return lookup_color( 8, fg, boldp) + 1; // light grey |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2713 case 9: return lookup_color(12, fg, boldp) + 1; // dark grey |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2714 case 10: return lookup_color(20, fg, boldp) + 1; // red |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2715 case 11: return lookup_color(16, fg, boldp) + 1; // green |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2716 case 12: return lookup_color(24, fg, boldp) + 1; // yellow |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2717 case 13: return lookup_color(14, fg, boldp) + 1; // blue |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2718 case 14: return lookup_color(22, fg, boldp) + 1; // magenta |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2719 case 15: return lookup_color(18, fg, boldp) + 1; // cyan |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2720 case 16: return lookup_color(26, fg, boldp) + 1; // white |
12502 | 2721 } |
2722 } | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2723 |
12502 | 2724 if (t_colors >= 256) |
2725 { | |
2726 if (red == blue && red == green) | |
2727 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2728 // 24-color greyscale plus white and black |
12502 | 2729 static int cutoff[23] = { |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2730 0x0D, 0x17, 0x21, 0x2B, 0x35, 0x3F, 0x49, 0x53, 0x5D, 0x67, |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2731 0x71, 0x7B, 0x85, 0x8F, 0x99, 0xA3, 0xAD, 0xB7, 0xC1, 0xCB, |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2732 0xD5, 0xDF, 0xE9}; |
12502 | 2733 int i; |
2734 | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2735 if (red < 5) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2736 return 17; // 00/00/00 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2737 if (red > 245) // ff/ff/ff |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2738 return 232; |
12502 | 2739 for (i = 0; i < 23; ++i) |
2740 if (red < cutoff[i]) | |
2741 return i + 233; | |
2742 return 256; | |
2743 } | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2744 { |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2745 static int cutoff[5] = {0x2F, 0x73, 0x9B, 0xC3, 0xEB}; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2746 int ri, gi, bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2747 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2748 // 216-color cube |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2749 for (ri = 0; ri < 5; ++ri) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2750 if (red < cutoff[ri]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2751 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2752 for (gi = 0; gi < 5; ++gi) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2753 if (green < cutoff[gi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2754 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2755 for (bi = 0; bi < 5; ++bi) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2756 if (blue < cutoff[bi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2757 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2758 return 17 + ri * 36 + gi * 6 + bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2759 } |
12502 | 2760 } |
2761 return 0; | |
2762 } | |
2763 | |
2764 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2765 * Convert Vterm attributes to highlight flags. |
12502 | 2766 */ |
2767 static int | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2768 vtermAttr2hl(VTermScreenCellAttrs cellattrs) |
12502 | 2769 { |
2770 int attr = 0; | |
2771 | |
2772 if (cellattrs.bold) | |
2773 attr |= HL_BOLD; | |
2774 if (cellattrs.underline) | |
2775 attr |= HL_UNDERLINE; | |
2776 if (cellattrs.italic) | |
2777 attr |= HL_ITALIC; | |
2778 if (cellattrs.strike) | |
2779 attr |= HL_STRIKETHROUGH; | |
2780 if (cellattrs.reverse) | |
2781 attr |= HL_INVERSE; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2782 return attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2783 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2784 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2785 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2786 * Store Vterm attributes in "cell" from highlight flags. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2787 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2788 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2789 hl2vtermAttr(int attr, cellattr_T *cell) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2790 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2791 CLEAR_FIELD(cell->attrs); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2792 if (attr & HL_BOLD) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2793 cell->attrs.bold = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2794 if (attr & HL_UNDERLINE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2795 cell->attrs.underline = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2796 if (attr & HL_ITALIC) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2797 cell->attrs.italic = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2798 if (attr & HL_STRIKETHROUGH) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2799 cell->attrs.strike = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2800 if (attr & HL_INVERSE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2801 cell->attrs.reverse = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2802 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2803 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2804 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2805 * Convert the attributes of a vterm cell into an attribute index. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2806 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2807 static int |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2808 cell2attr( |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2809 term_T *term, |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2810 win_T *wp, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2811 VTermScreenCellAttrs cellattrs, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2812 VTermColor cellfg, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2813 VTermColor cellbg) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2814 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2815 int attr = vtermAttr2hl(cellattrs); |
12502 | 2816 |
2817 #ifdef FEAT_GUI | |
2818 if (gui.in_use) | |
2819 { | |
2820 guicolor_T fg, bg; | |
2821 | |
2822 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue); | |
2823 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue); | |
2824 return get_gui_attr_idx(attr, fg, bg); | |
2825 } | |
2826 else | |
2827 #endif | |
2828 #ifdef FEAT_TERMGUICOLORS | |
2829 if (p_tgc) | |
2830 { | |
2831 guicolor_T fg, bg; | |
2832 | |
2833 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue); | |
2834 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue); | |
2835 | |
2836 return get_tgc_attr_idx(attr, fg, bg); | |
2837 } | |
2838 else | |
2839 #endif | |
2840 { | |
2841 int bold = MAYBE; | |
2842 int fg = color2index(&cellfg, TRUE, &bold); | |
2843 int bg = color2index(&cellbg, FALSE, &bold); | |
2844 | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2845 // Use the 'wincolor' or "Terminal" highlighting for the default |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2846 // colors. |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2847 if ((fg == 0 || bg == 0) && t_colors >= 16) |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2848 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2849 int wincolor_fg = -1; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2850 int wincolor_bg = -1; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2851 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2852 if (wp != NULL && *wp->w_p_wcr != NUL) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2853 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2854 int id = syn_name2id(curwin->w_p_wcr); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2855 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2856 // Get the 'wincolor' group colors. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2857 if (id > 0) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2858 syn_id2cterm_bg(id, &wincolor_fg, &wincolor_bg); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2859 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2860 if (fg == 0) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2861 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2862 if (wincolor_fg >= 0) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2863 fg = wincolor_fg + 1; |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2864 else |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2865 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2866 int cterm_fg = get_default_cterm_fg(term); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2867 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2868 if (cterm_fg >= 0) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2869 fg = cterm_fg + 1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2870 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2871 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2872 if (bg == 0) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2873 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2874 if (wincolor_bg >= 0) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2875 bg = wincolor_bg + 1; |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2876 else |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2877 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2878 int cterm_bg = get_default_cterm_bg(term); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2879 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2880 if (cterm_bg >= 0) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2881 bg = cterm_bg + 1; |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2882 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2883 } |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2884 } |
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2885 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2886 // with 8 colors set the bold attribute to get a bright foreground |
12502 | 2887 if (bold == TRUE) |
2888 attr |= HL_BOLD; | |
2889 return get_cterm_attr_idx(attr, fg, bg); | |
2890 } | |
2891 return 0; | |
2892 } | |
2893 | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2894 static void |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2895 set_dirty_snapshot(term_T *term) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2896 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2897 term->tl_dirty_snapshot = TRUE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2898 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2899 if (!term->tl_normal_mode) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2900 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2901 // Update the snapshot after 100 msec of not getting updates. |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2902 profile_setlimit(100L, &term->tl_timer_due); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2903 term->tl_timer_set = TRUE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2904 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2905 #endif |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2906 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2907 |
12502 | 2908 static int |
2909 handle_damage(VTermRect rect, void *user) | |
2910 { | |
2911 term_T *term = (term_T *)user; | |
2912 | |
2913 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row); | |
2914 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row); | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2915 set_dirty_snapshot(term); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2916 redraw_buf_later(term->tl_buffer, SOME_VALID); |
12502 | 2917 return 1; |
2918 } | |
2919 | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2920 static void |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2921 term_scroll_up(term_T *term, int start_row, int count) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2922 { |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2923 win_T *wp = NULL; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2924 int did_curwin = FALSE; |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2925 VTermColor fg, bg; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2926 VTermScreenCellAttrs attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2927 int clear_attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2928 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2929 CLEAR_FIELD(attr); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2930 |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2931 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2932 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2933 if (wp->w_buffer == term->tl_buffer) |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2934 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2935 // Set the color to clear lines with. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2936 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2937 &fg, &bg); |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2938 clear_attr = cell2attr(term, wp, attr, fg, bg); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2939 win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2940 } |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2941 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2942 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2943 |
12502 | 2944 static int |
2945 handle_moverect(VTermRect dest, VTermRect src, void *user) | |
2946 { | |
2947 term_T *term = (term_T *)user; | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2948 int count = src.start_row - dest.start_row; |
12502 | 2949 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2950 // Scrolling up is done much more efficiently by deleting lines instead of |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2951 // redrawing the text. But avoid doing this multiple times, postpone until |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2952 // the redraw happens. |
12502 | 2953 if (dest.start_col == src.start_col |
2954 && dest.end_col == src.end_col | |
2955 && dest.start_row < src.start_row) | |
2956 { | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2957 if (dest.start_row == 0) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2958 term->tl_postponed_scroll += count; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2959 else |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2960 term_scroll_up(term, dest.start_row, count); |
12502 | 2961 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2962 |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2963 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, dest.start_row); |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2964 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2965 set_dirty_snapshot(term); |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2966 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2967 // Note sure if the scrolling will work correctly, let's do a complete |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2968 // redraw later. |
12502 | 2969 redraw_buf_later(term->tl_buffer, NOT_VALID); |
2970 return 1; | |
2971 } | |
2972 | |
2973 static int | |
2974 handle_movecursor( | |
2975 VTermPos pos, | |
2976 VTermPos oldpos UNUSED, | |
2977 int visible, | |
2978 void *user) | |
2979 { | |
2980 term_T *term = (term_T *)user; | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2981 win_T *wp = NULL; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2982 int did_curwin = FALSE; |
12502 | 2983 |
2984 term->tl_cursor_pos = pos; | |
2985 term->tl_cursor_visible = visible; | |
2986 | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2987 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 2988 { |
2989 if (wp->w_buffer == term->tl_buffer) | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2990 position_cursor(wp, &pos, FALSE); |
12502 | 2991 } |
2992 if (term->tl_buffer == curbuf && !term->tl_normal_mode) | |
2993 { | |
2994 may_toggle_cursor(term); | |
2995 update_cursor(term, term->tl_cursor_visible); | |
2996 } | |
2997 | |
2998 return 1; | |
2999 } | |
3000 | |
3001 static int | |
3002 handle_settermprop( | |
3003 VTermProp prop, | |
3004 VTermValue *value, | |
3005 void *user) | |
3006 { | |
3007 term_T *term = (term_T *)user; | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3008 char_u *strval = NULL; |
12502 | 3009 |
3010 switch (prop) | |
3011 { | |
3012 case VTERM_PROP_TITLE: | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3013 strval = vim_strnsave((char_u *)value->string.str, |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20617
diff
changeset
|
3014 value->string.len); |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3015 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3016 break; |
12502 | 3017 vim_free(term->tl_title); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3018 // a blank title isn't useful, make it empty, so that "running" is |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3019 // displayed |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3020 if (*skipwhite(strval) == NUL) |
12502 | 3021 term->tl_title = NULL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3022 // Same as blank |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3023 else if (term->tl_arg0_cmd != NULL |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3024 && STRNCMP(term->tl_arg0_cmd, strval, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3025 (int)STRLEN(term->tl_arg0_cmd)) == 0) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3026 term->tl_title = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3027 // Empty corrupted data of winpty |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3028 else if (STRNCMP(" - ", strval, 4) == 0) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3029 term->tl_title = NULL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3030 #ifdef MSWIN |
12502 | 3031 else if (!enc_utf8 && enc_codepage > 0) |
3032 { | |
3033 WCHAR *ret = NULL; | |
3034 int length = 0; | |
3035 | |
3036 MultiByteToWideChar_alloc(CP_UTF8, 0, | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3037 (char*)value->string.str, |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3038 (int)value->string.len, &ret, &length); |
12502 | 3039 if (ret != NULL) |
3040 { | |
3041 WideCharToMultiByte_alloc(enc_codepage, 0, | |
3042 ret, length, (char**)&term->tl_title, | |
3043 &length, 0, 0); | |
3044 vim_free(ret); | |
3045 } | |
3046 } | |
3047 #endif | |
3048 else | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3049 { |
20508
357dea6b9fde
patch 8.2.0808: not enough testing for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20500
diff
changeset
|
3050 term->tl_title = strval; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3051 strval = NULL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3052 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3053 VIM_CLEAR(term->tl_status_text); |
12502 | 3054 if (term == curbuf->b_term) |
3055 maketitle(); | |
3056 break; | |
3057 | |
3058 case VTERM_PROP_CURSORVISIBLE: | |
3059 term->tl_cursor_visible = value->boolean; | |
3060 may_toggle_cursor(term); | |
3061 out_flush(); | |
3062 break; | |
3063 | |
3064 case VTERM_PROP_CURSORBLINK: | |
3065 term->tl_cursor_blink = value->boolean; | |
3066 may_set_cursor_props(term); | |
3067 break; | |
3068 | |
3069 case VTERM_PROP_CURSORSHAPE: | |
3070 term->tl_cursor_shape = value->number; | |
3071 may_set_cursor_props(term); | |
3072 break; | |
3073 | |
3074 case VTERM_PROP_CURSORCOLOR: | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3075 strval = vim_strnsave((char_u *)value->string.str, |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20617
diff
changeset
|
3076 value->string.len); |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3077 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3078 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3079 cursor_color_copy(&term->tl_cursor_color, strval); |
12502 | 3080 may_set_cursor_props(term); |
3081 break; | |
3082 | |
3083 case VTERM_PROP_ALTSCREEN: | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3084 // TODO: do anything else? |
12502 | 3085 term->tl_using_altscreen = value->boolean; |
3086 break; | |
3087 | |
3088 default: | |
3089 break; | |
3090 } | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3091 vim_free(strval); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3092 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3093 // Always return 1, otherwise vterm doesn't store the value internally. |
12502 | 3094 return 1; |
3095 } | |
3096 | |
3097 /* | |
3098 * The job running in the terminal resized the terminal. | |
3099 */ | |
3100 static int | |
3101 handle_resize(int rows, int cols, void *user) | |
3102 { | |
3103 term_T *term = (term_T *)user; | |
3104 win_T *wp; | |
3105 | |
3106 term->tl_rows = rows; | |
3107 term->tl_cols = cols; | |
3108 if (term->tl_vterm_size_changed) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3109 // Size was set by vterm_set_size(), don't set the window size. |
12502 | 3110 term->tl_vterm_size_changed = FALSE; |
3111 else | |
3112 { | |
3113 FOR_ALL_WINDOWS(wp) | |
3114 { | |
3115 if (wp->w_buffer == term->tl_buffer) | |
3116 { | |
3117 win_setheight_win(rows, wp); | |
3118 win_setwidth_win(cols, wp); | |
3119 } | |
3120 } | |
3121 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3122 } | |
3123 return 1; | |
3124 } | |
3125 | |
3126 /* | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3127 * If the number of lines that are stored goes over 'termscrollback' then |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3128 * delete the first 10%. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3129 * "gap" points to tl_scrollback or tl_scrollback_postponed. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3130 * "update_buffer" is TRUE when the buffer should be updated. |
12502 | 3131 */ |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3132 static void |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3133 limit_scrollback(term_T *term, garray_T *gap, int update_buffer) |
12502 | 3134 { |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3135 if (gap->ga_len >= term->tl_buffer->b_p_twsl) |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3136 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
3137 int todo = term->tl_buffer->b_p_twsl / 10; |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3138 int i; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3139 |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3140 curbuf = term->tl_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3141 for (i = 0; i < todo; ++i) |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3142 { |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3143 vim_free(((sb_line_T *)gap->ga_data + i)->sb_cells); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3144 if (update_buffer) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
3145 ml_delete(1); |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3146 } |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3147 curbuf = curwin->w_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3148 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3149 gap->ga_len -= todo; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3150 mch_memmove(gap->ga_data, |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3151 (sb_line_T *)gap->ga_data + todo, |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3152 sizeof(sb_line_T) * gap->ga_len); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3153 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3154 term->tl_scrollback_scrolled -= todo; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3155 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3156 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3157 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3158 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3159 * Handle a line that is pushed off the top of the screen. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3160 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3161 static int |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3162 handle_pushline(int cols, const VTermScreenCell *cells, void *user) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3163 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3164 term_T *term = (term_T *)user; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3165 garray_T *gap; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3166 int update_buffer; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3167 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3168 if (term->tl_normal_mode) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3169 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3170 // In Terminal-Normal mode the user interacts with the buffer, thus we |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3171 // must not change it. Postpone adding the scrollback lines. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3172 gap = &term->tl_scrollback_postponed; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3173 update_buffer = FALSE; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3174 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3175 else |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3176 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3177 // First remove the lines that were appended before, the pushed line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3178 // goes above it. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3179 cleanup_scrollback(term); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3180 gap = &term->tl_scrollback; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3181 update_buffer = TRUE; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3182 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3183 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3184 limit_scrollback(term, gap, update_buffer); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3185 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3186 if (ga_grow(gap, 1) == OK) |
12502 | 3187 { |
3188 cellattr_T *p = NULL; | |
3189 int len = 0; | |
3190 int i; | |
3191 int c; | |
3192 int col; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3193 int text_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3194 char_u *text; |
12502 | 3195 sb_line_T *line; |
3196 garray_T ga; | |
3197 cellattr_T fill_attr = term->tl_default_color; | |
3198 | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3199 // do not store empty cells at the end |
12502 | 3200 for (i = 0; i < cols; ++i) |
3201 if (cells[i].chars[0] != 0) | |
3202 len = i + 1; | |
3203 else | |
3204 cell2cellattr(&cells[i], &fill_attr); | |
3205 | |
3206 ga_init2(&ga, 1, 100); | |
3207 if (len > 0) | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3208 p = ALLOC_MULT(cellattr_T, len); |
12502 | 3209 if (p != NULL) |
3210 { | |
3211 for (col = 0; col < len; col += cells[col].width) | |
3212 { | |
3213 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | |
3214 { | |
3215 ga.ga_len = 0; | |
3216 break; | |
3217 } | |
3218 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i) | |
3219 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
3220 (char_u *)ga.ga_data + ga.ga_len); | |
3221 cell2cellattr(&cells[col], &p[col]); | |
3222 } | |
3223 } | |
3224 if (ga_grow(&ga, 1) == FAIL) | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3225 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3226 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3227 text = (char_u *)""; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3228 else |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3229 text = vim_strsave((char_u *)""); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3230 text_len = 0; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3231 } |
12502 | 3232 else |
3233 { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3234 text = ga.ga_data; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3235 text_len = ga.ga_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3236 *(text + text_len) = NUL; |
12502 | 3237 } |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3238 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3239 add_scrollback_line_to_buffer(term, text, text_len); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3240 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3241 line = (sb_line_T *)gap->ga_data + gap->ga_len; |
12502 | 3242 line->sb_cols = len; |
3243 line->sb_cells = p; | |
3244 line->sb_fill_attr = fill_attr; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3245 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3246 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3247 line->sb_text = NULL; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3248 ++term->tl_scrollback_scrolled; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3249 ga_clear(&ga); // free the text |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3250 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3251 else |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3252 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3253 line->sb_text = text; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3254 ga_init(&ga); // text is kept in tl_scrollback_postponed |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3255 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3256 ++gap->ga_len; |
12502 | 3257 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3258 return 0; // ignored |
12502 | 3259 } |
3260 | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3261 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3262 * Called when leaving Terminal-Normal mode: deal with any scrollback that was |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3263 * received and stored in tl_scrollback_postponed. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3264 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3265 static void |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3266 handle_postponed_scrollback(term_T *term) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3267 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3268 int i; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3269 |
16026
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3270 if (term->tl_scrollback_postponed.ga_len == 0) |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3271 return; |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3272 ch_log(NULL, "Moving postponed scrollback to scrollback"); |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3273 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3274 // First remove the lines that were appended before, the pushed lines go |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3275 // above it. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3276 cleanup_scrollback(term); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3277 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3278 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3279 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3280 char_u *text; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3281 sb_line_T *pp_line; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3282 sb_line_T *line; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3283 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3284 if (ga_grow(&term->tl_scrollback, 1) == FAIL) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3285 break; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3286 pp_line = (sb_line_T *)term->tl_scrollback_postponed.ga_data + i; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3287 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3288 text = pp_line->sb_text; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3289 if (text == NULL) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3290 text = (char_u *)""; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3291 add_scrollback_line_to_buffer(term, text, (int)STRLEN(text)); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3292 vim_free(pp_line->sb_text); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3293 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3294 line = (sb_line_T *)term->tl_scrollback.ga_data |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3295 + term->tl_scrollback.ga_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3296 line->sb_cols = pp_line->sb_cols; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3297 line->sb_cells = pp_line->sb_cells; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3298 line->sb_fill_attr = pp_line->sb_fill_attr; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3299 line->sb_text = NULL; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3300 ++term->tl_scrollback_scrolled; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3301 ++term->tl_scrollback.ga_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3302 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3303 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3304 ga_clear(&term->tl_scrollback_postponed); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3305 limit_scrollback(term, &term->tl_scrollback, TRUE); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3306 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3307 |
12502 | 3308 static VTermScreenCallbacks screen_callbacks = { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3309 handle_damage, // damage |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3310 handle_moverect, // moverect |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3311 handle_movecursor, // movecursor |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3312 handle_settermprop, // settermprop |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3313 NULL, // bell |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3314 handle_resize, // resize |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3315 handle_pushline, // sb_pushline |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3316 NULL // sb_popline |
12502 | 3317 }; |
3318 | |
3319 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3320 * Do the work after the channel of a terminal was closed. |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3321 * Must be called only when updating_screen is FALSE. |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3322 * Returns TRUE when a buffer was closed (list of terminals may have changed). |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3323 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3324 static int |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3325 term_after_channel_closed(term_T *term) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3326 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3327 // Unless in Terminal-Normal mode: clear the vterm. |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3328 if (!term->tl_normal_mode) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3329 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3330 int fnum = term->tl_buffer->b_fnum; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3331 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3332 cleanup_vterm(term); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3333 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3334 if (term->tl_finish == TL_FINISH_CLOSE) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3335 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3336 aco_save_T aco; |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3337 int do_set_w_closing = term->tl_buffer->b_nwindows == 0; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3338 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3339 win_T *pwin = NULL; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3340 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3341 // If this was a terminal in a popup window, go back to the |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3342 // previous window. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3343 if (popup_is_popup(curwin) && curbuf == term->tl_buffer) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3344 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3345 pwin = curwin; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3346 if (win_valid(prevwin)) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3347 win_enter(prevwin, FALSE); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3348 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3349 else |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3350 #endif |
18402
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3351 // If this is the last normal window: exit Vim. |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3352 if (term->tl_buffer->b_nwindows > 0 && only_one_window()) |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3353 { |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3354 exarg_T ea; |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3355 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3356 CLEAR_FIELD(ea); |
18402
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3357 ex_quit(&ea); |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3358 return TRUE; |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3359 } |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3360 |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3361 // ++close or term_finish == "close" |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3362 ch_log(NULL, "terminal job finished, closing window"); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3363 aucmd_prepbuf(&aco, term->tl_buffer); |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3364 // Avoid closing the window if we temporarily use it. |
17133
2a9a5e69fb3e
patch 8.1.1566: error message when terminal closes in another tab
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
3365 if (curwin == aucmd_win) |
2a9a5e69fb3e
patch 8.1.1566: error message when terminal closes in another tab
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
3366 do_set_w_closing = TRUE; |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3367 if (do_set_w_closing) |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3368 curwin->w_closing = TRUE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3369 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE); |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3370 if (do_set_w_closing) |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3371 curwin->w_closing = FALSE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3372 aucmd_restbuf(&aco); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3373 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3374 if (pwin != NULL) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3375 popup_close_with_retval(pwin, 0); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3376 #endif |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3377 return TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3378 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3379 if (term->tl_finish == TL_FINISH_OPEN |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3380 && term->tl_buffer->b_nwindows == 0) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3381 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3382 char buf[50]; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3383 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3384 // TODO: use term_opencmd |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3385 ch_log(NULL, "terminal job finished, opening window"); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3386 vim_snprintf(buf, sizeof(buf), |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3387 term->tl_opencmd == NULL |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3388 ? "botright sbuf %d" |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3389 : (char *)term->tl_opencmd, fnum); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3390 do_cmdline_cmd((char_u *)buf); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3391 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3392 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3393 ch_log(NULL, "terminal job finished"); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3394 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3395 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3396 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3397 return FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3398 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3399 |
19275
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3400 #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3401 /* |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3402 * If the current window is a terminal in a popup window and the job has |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3403 * finished, close the popup window and to back to the previous window. |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3404 * Otherwise return FAIL. |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3405 */ |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3406 int |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3407 may_close_term_popup(void) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3408 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3409 if (popup_is_popup(curwin) && curbuf->b_term != NULL |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3410 && !term_job_running(curbuf->b_term)) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3411 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3412 win_T *pwin = curwin; |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3413 |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3414 if (win_valid(prevwin)) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3415 win_enter(prevwin, FALSE); |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3416 popup_close_with_retval(pwin, 0); |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3417 return OK; |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3418 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3419 return FAIL; |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3420 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3421 #endif |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3422 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3423 /* |
12502 | 3424 * Called when a channel has been closed. |
3425 * If this was a channel for a terminal window then finish it up. | |
3426 */ | |
3427 void | |
3428 term_channel_closed(channel_T *ch) | |
3429 { | |
3430 term_T *term; | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3431 term_T *next_term; |
12502 | 3432 int did_one = FALSE; |
3433 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3434 for (term = first_term; term != NULL; term = next_term) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3435 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3436 next_term = term->tl_next; |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3437 if (term->tl_job == ch->ch_job && !term->tl_channel_closed) |
12502 | 3438 { |
3439 term->tl_channel_closed = TRUE; | |
3440 did_one = TRUE; | |
3441 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3442 VIM_CLEAR(term->tl_title); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3443 VIM_CLEAR(term->tl_status_text); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3444 #ifdef MSWIN |
13862
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3445 if (term->tl_out_fd != NULL) |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3446 { |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3447 fclose(term->tl_out_fd); |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3448 term->tl_out_fd = NULL; |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3449 } |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3450 #endif |
12502 | 3451 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3452 if (updating_screen) |
12502 | 3453 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3454 // Cannot open or close windows now. Can happen when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3455 // 'lazyredraw' is set. |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3456 term->tl_channel_recently_closed = TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3457 continue; |
12502 | 3458 } |
3459 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3460 if (term_after_channel_closed(term)) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3461 next_term = first_term; |
12502 | 3462 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3463 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3464 |
12502 | 3465 if (did_one) |
3466 { | |
3467 redraw_statuslines(); | |
3468 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3469 // Need to break out of vgetc(). |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20555
diff
changeset
|
3470 ins_char_typebuf(K_IGNORE, 0); |
12502 | 3471 typebuf_was_filled = TRUE; |
3472 | |
3473 term = curbuf->b_term; | |
3474 if (term != NULL) | |
3475 { | |
3476 if (term->tl_job == ch->ch_job) | |
3477 maketitle(); | |
3478 update_cursor(term, term->tl_cursor_visible); | |
3479 } | |
3480 } | |
3481 } | |
3482 | |
3483 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3484 * To be called after resetting updating_screen: handle any terminal where the |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3485 * channel was closed. |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3486 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3487 void |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3488 term_check_channel_closed_recently() |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3489 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3490 term_T *term; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3491 term_T *next_term; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3492 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3493 for (term = first_term; term != NULL; term = next_term) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3494 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3495 next_term = term->tl_next; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3496 if (term->tl_channel_recently_closed) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3497 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3498 term->tl_channel_recently_closed = FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3499 if (term_after_channel_closed(term)) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3500 // start over, the list may have changed |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3501 next_term = first_term; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3502 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3503 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3504 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3505 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3506 /* |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3507 * Fill one screen line from a line of the terminal. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3508 * Advances "pos" to past the last column. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3509 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3510 static void |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3511 term_line2screenline( |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3512 term_T *term, |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3513 win_T *wp, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3514 VTermScreen *screen, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3515 VTermPos *pos, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3516 int max_col) |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3517 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3518 int off = screen_get_current_line_off(); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3519 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3520 for (pos->col = 0; pos->col < max_col; ) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3521 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3522 VTermScreenCell cell; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3523 int c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3524 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3525 if (vterm_screen_get_cell(screen, *pos, &cell) == 0) |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3526 CLEAR_FIELD(cell); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3527 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3528 c = cell.chars[0]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3529 if (c == NUL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3530 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3531 ScreenLines[off] = ' '; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3532 if (enc_utf8) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3533 ScreenLinesUC[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3534 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3535 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3536 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3537 if (enc_utf8) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3538 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3539 int i; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3540 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3541 // composing chars |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3542 for (i = 0; i < Screen_mco |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3543 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3544 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3545 ScreenLinesC[i][off] = cell.chars[i + 1]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3546 if (cell.chars[i + 1] == 0) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3547 break; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3548 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3549 if (c >= 0x80 || (Screen_mco > 0 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3550 && ScreenLinesC[0][off] != 0)) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3551 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3552 ScreenLines[off] = ' '; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3553 ScreenLinesUC[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3554 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3555 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3556 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3557 ScreenLines[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3558 ScreenLinesUC[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3559 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3560 } |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3561 #ifdef MSWIN |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3562 else if (has_mbyte && c >= 0x80) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3563 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3564 char_u mb[MB_MAXBYTES+1]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3565 WCHAR wc = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3566 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3567 if (WideCharToMultiByte(GetACP(), 0, &wc, 1, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3568 (char*)mb, 2, 0, 0) > 1) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3569 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3570 ScreenLines[off] = mb[0]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3571 ScreenLines[off + 1] = mb[1]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3572 cell.width = mb_ptr2cells(mb); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3573 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3574 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3575 ScreenLines[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3576 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3577 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3578 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3579 ScreenLines[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3580 } |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3581 ScreenAttrs[off] = cell2attr(term, wp, cell.attrs, cell.fg, cell.bg); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3582 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3583 ++pos->col; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3584 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3585 if (cell.width == 2) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3586 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3587 if (enc_utf8) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3588 ScreenLinesUC[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3589 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3590 // don't set the second byte to NUL for a DBCS encoding, it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3591 // has been set above |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3592 if (enc_utf8 || !has_mbyte) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3593 ScreenLines[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3594 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3595 ++pos->col; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3596 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3597 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3598 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3599 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3600 |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3601 #if defined(FEAT_GUI) |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3602 static void |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3603 update_system_term(term_T *term) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3604 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3605 VTermPos pos; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3606 VTermScreen *screen; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3607 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3608 if (term->tl_vterm == NULL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3609 return; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3610 screen = vterm_obtain_screen(term->tl_vterm); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3611 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3612 // Scroll up to make more room for terminal lines if needed. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3613 while (term->tl_toprow > 0 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3614 && (Rows - term->tl_toprow) < term->tl_dirty_row_end) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3615 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3616 int save_p_more = p_more; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3617 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3618 p_more = FALSE; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3619 msg_row = Rows - 1; |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
3620 msg_puts("\n"); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3621 p_more = save_p_more; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3622 --term->tl_toprow; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3623 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3624 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3625 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3626 && pos.row < Rows; ++pos.row) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3627 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3628 if (pos.row < term->tl_rows) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3629 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3630 int max_col = MIN(Columns, term->tl_cols); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3631 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3632 term_line2screenline(term, NULL, screen, &pos, max_col); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3633 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3634 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3635 pos.col = 0; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3636 |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3637 screen_line(term->tl_toprow + pos.row, 0, pos.col, Columns, 0); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3638 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3639 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3640 term->tl_dirty_row_start = MAX_ROW; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3641 term->tl_dirty_row_end = 0; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3642 } |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3643 #endif |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3644 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3645 /* |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3646 * Return TRUE if window "wp" is to be redrawn with term_update_window(). |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3647 * Returns FALSE when there is no terminal running in this window or it is in |
12502 | 3648 * Terminal-Normal mode. |
3649 */ | |
3650 int | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3651 term_do_update_window(win_T *wp) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3652 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3653 term_T *term = wp->w_buffer->b_term; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3654 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3655 return term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3656 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3657 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3658 /* |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3659 * Called to update a window that contains an active terminal. |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3660 */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3661 void |
12502 | 3662 term_update_window(win_T *wp) |
3663 { | |
3664 term_T *term = wp->w_buffer->b_term; | |
3665 VTerm *vterm; | |
3666 VTermScreen *screen; | |
3667 VTermState *state; | |
3668 VTermPos pos; | |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3669 int rows, cols; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3670 int newrows, newcols; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3671 int minsize; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3672 win_T *twp; |
12502 | 3673 |
3674 vterm = term->tl_vterm; | |
3675 screen = vterm_obtain_screen(vterm); | |
3676 state = vterm_obtain_state(vterm); | |
3677 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3678 // We use NOT_VALID on a resize or scroll, redraw everything then. With |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3679 // SOME_VALID only redraw what was marked dirty. |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3680 if (wp->w_redr_type > SOME_VALID) |
12590
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3681 { |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3682 term->tl_dirty_row_start = 0; |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3683 term->tl_dirty_row_end = MAX_ROW; |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3684 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3685 if (term->tl_postponed_scroll > 0 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3686 && term->tl_postponed_scroll < term->tl_rows / 3) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3687 // Scrolling is usually faster than redrawing, when there are only |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3688 // a few lines to scroll. |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3689 term_scroll_up(term, 0, term->tl_postponed_scroll); |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3690 term->tl_postponed_scroll = 0; |
12590
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3691 } |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3692 |
12502 | 3693 /* |
3694 * If the window was resized a redraw will be triggered and we get here. | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3695 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size. |
12502 | 3696 */ |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3697 minsize = parse_termwinsize(wp, &rows, &cols); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3698 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3699 newrows = 99999; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3700 newcols = 99999; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3701 for (twp = firstwin; ; twp = twp->w_next) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3702 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3703 // Always use curwin, it may be a popup window. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3704 win_T *wwp = twp == NULL ? curwin : twp; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3705 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3706 // When more than one window shows the same terminal, use the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3707 // smallest size. |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3708 if (wwp->w_buffer == term->tl_buffer) |
12502 | 3709 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3710 newrows = MIN(newrows, wwp->w_height); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3711 newcols = MIN(newcols, wwp->w_width); |
12502 | 3712 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3713 if (twp == NULL) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3714 break; |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3715 } |
18162
9c3347b21b89
patch 8.1.2076: crash when trying to put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3716 if (newrows == 99999 || newcols == 99999) |
9c3347b21b89
patch 8.1.2076: crash when trying to put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3717 return; // safety exit |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3718 newrows = rows == 0 ? newrows : minsize ? MAX(rows, newrows) : rows; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3719 newcols = cols == 0 ? newcols : minsize ? MAX(cols, newcols) : cols; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3720 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3721 if (term->tl_rows != newrows || term->tl_cols != newcols) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3722 { |
12502 | 3723 term->tl_vterm_size_changed = TRUE; |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3724 vterm_set_size(vterm, newrows, newcols); |
12502 | 3725 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines", |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3726 newrows); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3727 term_report_winsize(term, newrows, newcols); |
14311
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3728 |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3729 // Updating the terminal size will cause the snapshot to be cleared. |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3730 // When not in terminal_loop() we need to restore it. |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3731 if (term != in_terminal_loop) |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3732 may_move_terminal_to_buffer(term, FALSE); |
12502 | 3733 } |
3734 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3735 // The cursor may have been moved when resizing. |
12502 | 3736 vterm_state_get_cursorpos(state, &pos); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3737 position_cursor(wp, &pos, FALSE); |
12502 | 3738 |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3739 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3740 && pos.row < wp->w_height; ++pos.row) |
12502 | 3741 { |
3742 if (pos.row < term->tl_rows) | |
3743 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3744 int max_col = MIN(wp->w_width, term->tl_cols); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3745 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3746 term_line2screenline(term, wp, screen, &pos, max_col); |
12502 | 3747 } |
3748 else | |
3749 pos.col = 0; | |
3750 | |
13458
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3751 screen_line(wp->w_winrow + pos.row |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3752 #ifdef FEAT_MENU |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3753 + winbar_height(wp) |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3754 #endif |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3755 , wp->w_wincol, pos.col, wp->w_width, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3756 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3757 popup_is_popup(wp) ? SLF_POPUP : |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3758 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3759 0); |
12502 | 3760 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3761 term->tl_dirty_row_start = MAX_ROW; |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3762 term->tl_dirty_row_end = 0; |
12502 | 3763 } |
3764 | |
3765 /* | |
3766 * Return TRUE if "wp" is a terminal window where the job has finished. | |
3767 */ | |
3768 int | |
3769 term_is_finished(buf_T *buf) | |
3770 { | |
3771 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL; | |
3772 } | |
3773 | |
3774 /* | |
3775 * Return TRUE if "wp" is a terminal window where the job has finished or we | |
3776 * are in Terminal-Normal mode, thus we show the buffer contents. | |
3777 */ | |
3778 int | |
3779 term_show_buffer(buf_T *buf) | |
3780 { | |
3781 term_T *term = buf->b_term; | |
3782 | |
3783 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode); | |
3784 } | |
3785 | |
3786 /* | |
3787 * The current buffer is going to be changed. If there is terminal | |
3788 * highlighting remove it now. | |
3789 */ | |
3790 void | |
3791 term_change_in_curbuf(void) | |
3792 { | |
3793 term_T *term = curbuf->b_term; | |
3794 | |
3795 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) | |
3796 { | |
3797 free_scrollback(term); | |
3798 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3799 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3800 // The buffer is now like a normal buffer, it cannot be easily |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3801 // abandoned when changed. |
12502 | 3802 set_string_option_direct((char_u *)"buftype", -1, |
3803 (char_u *)"", OPT_FREE|OPT_LOCAL, 0); | |
3804 } | |
3805 } | |
3806 | |
3807 /* | |
3808 * Get the screen attribute for a position in the buffer. | |
3809 * Use a negative "col" to get the filler background color. | |
3810 */ | |
3811 int | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3812 term_get_attr(win_T *wp, linenr_T lnum, int col) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3813 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3814 buf_T *buf = wp->w_buffer; |
12502 | 3815 term_T *term = buf->b_term; |
3816 sb_line_T *line; | |
3817 cellattr_T *cellattr; | |
3818 | |
3819 if (lnum > term->tl_scrollback.ga_len) | |
3820 cellattr = &term->tl_default_color; | |
3821 else | |
3822 { | |
3823 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1; | |
3824 if (col < 0 || col >= line->sb_cols) | |
3825 cellattr = &line->sb_fill_attr; | |
3826 else | |
3827 cellattr = line->sb_cells + col; | |
3828 } | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3829 return cell2attr(term, wp, cellattr->attrs, cellattr->fg, cellattr->bg); |
12502 | 3830 } |
3831 | |
3832 /* | |
3833 * Convert a cterm color number 0 - 255 to RGB. | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3834 * This is compatible with xterm. |
12502 | 3835 */ |
3836 static void | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3837 cterm_color2vterm(int nr, VTermColor *rgb) |
12502 | 3838 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3839 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->index); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3840 if (rgb->index == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3841 rgb->type = VTERM_COLOR_RGB; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3842 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3843 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3844 rgb->type = VTERM_COLOR_INDEXED; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3845 --rgb->index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3846 } |
12502 | 3847 } |
3848 | |
3849 /* | |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3850 * Initialize term->tl_default_color from the environment. |
12502 | 3851 */ |
3852 static void | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3853 init_default_colors(term_T *term, win_T *wp) |
12502 | 3854 { |
3855 VTermColor *fg, *bg; | |
3856 int fgval, bgval; | |
3857 int id; | |
3858 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3859 CLEAR_FIELD(term->tl_default_color.attrs); |
12502 | 3860 term->tl_default_color.width = 1; |
3861 fg = &term->tl_default_color.fg; | |
3862 bg = &term->tl_default_color.bg; | |
3863 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3864 // Vterm uses a default black background. Set it to white when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3865 // 'background' is "light". |
12502 | 3866 if (*p_bg == 'l') |
3867 { | |
3868 fgval = 0; | |
3869 bgval = 255; | |
3870 } | |
3871 else | |
3872 { | |
3873 fgval = 255; | |
3874 bgval = 0; | |
3875 } | |
3876 fg->red = fg->green = fg->blue = fgval; | |
3877 bg->red = bg->green = bg->blue = bgval; | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3878 fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3879 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG; |
12502 | 3880 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3881 // The 'wincolor' or the highlight group overrules the defaults. |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3882 if (wp != NULL && *wp->w_p_wcr != NUL) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3883 id = syn_name2id(wp->w_p_wcr); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3884 else |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3885 id = syn_name2id(term_get_highlight_name(term)); |
12502 | 3886 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3887 // Use the actual color for the GUI and when 'termguicolors' is set. |
12502 | 3888 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
3889 if (0 | |
3890 # ifdef FEAT_GUI | |
3891 || gui.in_use | |
3892 # endif | |
3893 # ifdef FEAT_TERMGUICOLORS | |
3894 || p_tgc | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3895 # ifdef FEAT_VTP |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3896 // Finally get INVALCOLOR on this execution path |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3897 || (!p_tgc && t_colors >= 256) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3898 # endif |
12502 | 3899 # endif |
3900 ) | |
3901 { | |
3902 guicolor_T fg_rgb = INVALCOLOR; | |
3903 guicolor_T bg_rgb = INVALCOLOR; | |
3904 | |
3905 if (id != 0) | |
3906 syn_id2colors(id, &fg_rgb, &bg_rgb); | |
3907 | |
3908 # ifdef FEAT_GUI | |
3909 if (gui.in_use) | |
3910 { | |
3911 if (fg_rgb == INVALCOLOR) | |
3912 fg_rgb = gui.norm_pixel; | |
3913 if (bg_rgb == INVALCOLOR) | |
3914 bg_rgb = gui.back_pixel; | |
3915 } | |
3916 # ifdef FEAT_TERMGUICOLORS | |
3917 else | |
3918 # endif | |
3919 # endif | |
3920 # ifdef FEAT_TERMGUICOLORS | |
3921 { | |
3922 if (fg_rgb == INVALCOLOR) | |
3923 fg_rgb = cterm_normal_fg_gui_color; | |
3924 if (bg_rgb == INVALCOLOR) | |
3925 bg_rgb = cterm_normal_bg_gui_color; | |
3926 } | |
3927 # endif | |
3928 if (fg_rgb != INVALCOLOR) | |
3929 { | |
3930 long_u rgb = GUI_MCH_GET_RGB(fg_rgb); | |
3931 | |
3932 fg->red = (unsigned)(rgb >> 16); | |
3933 fg->green = (unsigned)(rgb >> 8) & 255; | |
3934 fg->blue = (unsigned)rgb & 255; | |
3935 } | |
3936 if (bg_rgb != INVALCOLOR) | |
3937 { | |
3938 long_u rgb = GUI_MCH_GET_RGB(bg_rgb); | |
3939 | |
3940 bg->red = (unsigned)(rgb >> 16); | |
3941 bg->green = (unsigned)(rgb >> 8) & 255; | |
3942 bg->blue = (unsigned)rgb & 255; | |
3943 } | |
3944 } | |
3945 else | |
3946 #endif | |
3947 if (id != 0 && t_colors >= 16) | |
3948 { | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3949 int cterm_fg = get_default_cterm_fg(term); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3950 int cterm_bg = get_default_cterm_bg(term); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3951 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3952 if (cterm_fg >= 0) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3953 cterm_color2vterm(cterm_fg, fg); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3954 if (cterm_bg >= 0) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3955 cterm_color2vterm(cterm_bg, bg); |
12502 | 3956 } |
3957 else | |
3958 { | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3959 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
12502 | 3960 int tmp; |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3961 #endif |
12502 | 3962 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3963 // In an MS-Windows console we know the normal colors. |
12502 | 3964 if (cterm_normal_fg_color > 0) |
3965 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3966 cterm_color2vterm(cterm_normal_fg_color - 1, fg); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3967 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3968 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3969 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3970 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3971 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3972 tmp = fg->red; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3973 fg->red = fg->blue; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3974 fg->blue = tmp; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3975 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3976 # endif |
12502 | 3977 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
3978 # ifdef FEAT_TERMRESPONSE |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3979 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3980 term_get_fg_color(&fg->red, &fg->green, &fg->blue); |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
3981 # endif |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3982 |
12502 | 3983 if (cterm_normal_bg_color > 0) |
3984 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3985 cterm_color2vterm(cterm_normal_bg_color - 1, bg); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3986 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3987 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3988 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3989 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3990 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3991 tmp = fg->red; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3992 fg->red = fg->blue; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3993 fg->blue = tmp; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
3994 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3995 # endif |
12502 | 3996 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
3997 # ifdef FEAT_TERMRESPONSE |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3998 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3999 term_get_bg_color(&bg->red, &bg->green, &bg->blue); |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4000 # endif |
12502 | 4001 } |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4002 } |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4003 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4004 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4005 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4006 * Set the 16 ANSI colors from array of RGB values |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4007 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4008 static void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4009 set_vterm_palette(VTerm *vterm, long_u *rgb) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4010 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4011 int index = 0; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4012 VTermState *state = vterm_obtain_state(vterm); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4013 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4014 for (; index < 16; index++) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4015 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4016 VTermColor color; |
16283
1298cb5c1f72
patch 8.1.1146: in MS-Windows console colors in a terminal window are wrong
Bram Moolenaar <Bram@vim.org>
parents:
16253
diff
changeset
|
4017 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4018 color.red = (unsigned)(rgb[index] >> 16); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4019 color.green = (unsigned)(rgb[index] >> 8) & 255; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4020 color.blue = (unsigned)rgb[index] & 255; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4021 vterm_state_set_palette_color(state, index, &color); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4022 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4023 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4024 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4025 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4026 * Set the ANSI color palette from a list of colors |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4027 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4028 static int |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4029 set_ansi_colors_list(VTerm *vterm, list_T *list) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4030 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4031 int n = 0; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4032 long_u rgb[16]; |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4033 listitem_T *li; |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4034 |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4035 for (li = list->lv_first; li != NULL && n < 16; li = li->li_next, n++) |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4036 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4037 char_u *color_name; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4038 guicolor_T guicolor; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4039 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4040 color_name = tv_get_string_chk(&li->li_tv); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4041 if (color_name == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4042 return FAIL; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4043 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4044 guicolor = GUI_GET_COLOR(color_name); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4045 if (guicolor == INVALCOLOR) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4046 return FAIL; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4047 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4048 rgb[n] = GUI_MCH_GET_RGB(guicolor); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4049 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4050 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4051 if (n != 16 || li != NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4052 return FAIL; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4053 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4054 set_vterm_palette(vterm, rgb); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4055 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4056 return OK; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4057 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4058 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4059 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4060 * Initialize the ANSI color palette from g:terminal_ansi_colors[0:15] |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4061 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4062 static void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4063 init_vterm_ansi_colors(VTerm *vterm) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4064 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4065 dictitem_T *var = find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4066 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4067 if (var != NULL |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4068 && (var->di_tv.v_type != VAR_LIST |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4069 || var->di_tv.vval.v_list == NULL |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4070 || var->di_tv.vval.v_list->lv_first == &range_list_item |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4071 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4072 semsg(_(e_invarg2), "g:terminal_ansi_colors"); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4073 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4074 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4075 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4076 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4077 * Handles a "drop" command from the job in the terminal. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4078 * "item" is the file name, "item->li_next" may have options. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4079 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4080 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4081 handle_drop_command(listitem_T *item) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4082 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4083 char_u *fname = tv_get_string(&item->li_tv); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4084 listitem_T *opt_item = item->li_next; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4085 int bufnr; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4086 win_T *wp; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4087 tabpage_T *tp; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4088 exarg_T ea; |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4089 char_u *tofree = NULL; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4090 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4091 bufnr = buflist_add(fname, BLN_LISTED | BLN_NOOPT); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4092 FOR_ALL_TAB_WINDOWS(tp, wp) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4093 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4094 if (wp->w_buffer->b_fnum == bufnr) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4095 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4096 // buffer is in a window already, go there |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4097 goto_tabpage_win(tp, wp); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4098 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4099 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4100 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4101 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4102 CLEAR_FIELD(ea); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4103 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4104 if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4105 && opt_item->li_tv.vval.v_dict != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4106 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4107 dict_T *dict = opt_item->li_tv.vval.v_dict; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4108 char_u *p; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4109 |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4110 p = dict_get_string(dict, (char_u *)"ff", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4111 if (p == NULL) |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4112 p = dict_get_string(dict, (char_u *)"fileformat", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4113 if (p != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4114 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4115 if (check_ff_value(p) == FAIL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4116 ch_log(NULL, "Invalid ff argument to drop: %s", p); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4117 else |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4118 ea.force_ff = *p; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4119 } |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4120 p = dict_get_string(dict, (char_u *)"enc", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4121 if (p == NULL) |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4122 p = dict_get_string(dict, (char_u *)"encoding", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4123 if (p != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4124 { |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4125 ea.cmd = alloc(STRLEN(p) + 12); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4126 if (ea.cmd != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4127 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4128 sprintf((char *)ea.cmd, "sbuf ++enc=%s", p); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4129 ea.force_enc = 11; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4130 tofree = ea.cmd; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4131 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4132 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4133 |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4134 p = dict_get_string(dict, (char_u *)"bad", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4135 if (p != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4136 get_bad_opt(p, &ea); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4137 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4138 if (dict_find(dict, (char_u *)"bin", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4139 ea.force_bin = FORCE_BIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4140 if (dict_find(dict, (char_u *)"binary", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4141 ea.force_bin = FORCE_BIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4142 if (dict_find(dict, (char_u *)"nobin", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4143 ea.force_bin = FORCE_NOBIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4144 if (dict_find(dict, (char_u *)"nobinary", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4145 ea.force_bin = FORCE_NOBIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4146 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4147 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4148 // open in new window, like ":split fname" |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4149 if (ea.cmd == NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4150 ea.cmd = (char_u *)"split"; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4151 ea.arg = fname; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4152 ea.cmdidx = CMD_split; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4153 ex_splitview(&ea); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4154 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4155 vim_free(tofree); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4156 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4157 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4158 /* |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4159 * Return TRUE if "func" starts with "pat" and "pat" isn't empty. |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4160 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4161 static int |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4162 is_permitted_term_api(char_u *func, char_u *pat) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4163 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4164 return pat != NULL && *pat != NUL && STRNICMP(func, pat, STRLEN(pat)) == 0; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4165 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4166 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4167 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4168 * Handles a function call from the job running in a terminal. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4169 * "item" is the function name, "item->li_next" has the arguments. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4170 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4171 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4172 handle_call_command(term_T *term, channel_T *channel, listitem_T *item) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4173 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4174 char_u *func; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4175 typval_T argvars[2]; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4176 typval_T rettv; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4177 funcexe_T funcexe; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4178 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4179 if (item->li_next == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4180 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4181 ch_log(channel, "Missing function arguments for call"); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4182 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4183 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4184 func = tv_get_string(&item->li_tv); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4185 |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4186 if (!is_permitted_term_api(func, term->tl_api)) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4187 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4188 ch_log(channel, "Unpermitted function: %s", func); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4189 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4190 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4191 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4192 argvars[0].v_type = VAR_NUMBER; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4193 argvars[0].vval.v_number = term->tl_buffer->b_fnum; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4194 argvars[1] = item->li_next->li_tv; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4195 CLEAR_FIELD(funcexe); |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4196 funcexe.firstline = 1L; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4197 funcexe.lastline = 1L; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4198 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4199 if (call_func(func, -1, &rettv, 2, argvars, &funcexe) == OK) |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4200 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4201 clear_tv(&rettv); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4202 ch_log(channel, "Function %s called", func); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4203 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4204 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4205 ch_log(channel, "Calling function %s failed", func); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4206 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4207 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4208 /* |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4209 * Called by libvterm when it cannot recognize an OSC sequence. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4210 * We recognize a terminal API command. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4211 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4212 static int |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4213 parse_osc(int command, VTermStringFragment frag, void *user) |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4214 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4215 term_T *term = (term_T *)user; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4216 js_read_T reader; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4217 typval_T tv; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4218 channel_T *channel = term->tl_job == NULL ? NULL |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4219 : term->tl_job->jv_channel; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4220 garray_T *gap = &term->tl_osc_buf; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4221 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4222 // We recognize only OSC 5 1 ; {command} |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4223 if (command != 51) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4224 return 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4225 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4226 // Concatenate what was received until the final piece is found. |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4227 if (ga_grow(gap, (int)frag.len + 1) == FAIL) |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4228 { |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4229 ga_clear(gap); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4230 return 1; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4231 } |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4232 mch_memmove((char *)gap->ga_data + gap->ga_len, frag.str, frag.len); |
20555
eedaa9a30ab4
patch 8.2.0831: compiler warnings for integer sizes
Bram Moolenaar <Bram@vim.org>
parents:
20508
diff
changeset
|
4233 gap->ga_len += (int)frag.len; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4234 if (!frag.final) |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4235 return 1; |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4236 |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4237 ((char *)gap->ga_data)[gap->ga_len] = 0; |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4238 reader.js_buf = gap->ga_data; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4239 reader.js_fill = NULL; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4240 reader.js_used = 0; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4241 if (json_decode(&reader, &tv, 0) == OK |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4242 && tv.v_type == VAR_LIST |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4243 && tv.vval.v_list != NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4244 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4245 listitem_T *item = tv.vval.v_list->lv_first; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4246 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4247 if (item == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4248 ch_log(channel, "Missing command"); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4249 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4250 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4251 char_u *cmd = tv_get_string(&item->li_tv); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4252 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4253 // Make sure an invoked command doesn't delete the buffer (and the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4254 // terminal) under our fingers. |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
4255 ++term->tl_buffer->b_locked; |
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
4256 |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4257 item = item->li_next; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4258 if (item == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4259 ch_log(channel, "Missing argument for %s", cmd); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4260 else if (STRCMP(cmd, "drop") == 0) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4261 handle_drop_command(item); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4262 else if (STRCMP(cmd, "call") == 0) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4263 handle_call_command(term, channel, item); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4264 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4265 ch_log(channel, "Invalid command received: %s", cmd); |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
4266 --term->tl_buffer->b_locked; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4267 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4268 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4269 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4270 ch_log(channel, "Invalid JSON received"); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4271 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4272 ga_clear(gap); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4273 clear_tv(&tv); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4274 return 1; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4275 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4276 |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4277 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4278 * Called by libvterm when it cannot recognize a CSI sequence. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4279 * We recognize the window position report. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4280 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4281 static int |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4282 parse_csi( |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4283 const char *leader UNUSED, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4284 const long args[], |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4285 int argcount, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4286 const char *intermed UNUSED, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4287 char command, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4288 void *user) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4289 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4290 term_T *term = (term_T *)user; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4291 char buf[100]; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4292 int len; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4293 int x = 0; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4294 int y = 0; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4295 win_T *wp; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4296 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4297 // We recognize only CSI 13 t |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4298 if (command != 't' || argcount != 1 || args[0] != 13) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4299 return 0; // not handled |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4300 |
16245
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
4301 // When getting the window position is not possible or it fails it results |
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
4302 // in zero/zero. |
16253
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
4303 #if defined(FEAT_GUI) \ |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
4304 || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \ |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
4305 || defined(MSWIN) |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4306 (void)ui_get_winpos(&x, &y, (varnumber_T)100); |
16245
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
4307 #endif |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4308 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4309 FOR_ALL_WINDOWS(wp) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4310 if (wp->w_buffer == term->tl_buffer) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4311 break; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4312 if (wp != NULL) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4313 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4314 #ifdef FEAT_GUI |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4315 if (gui.in_use) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4316 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4317 x += wp->w_wincol * gui.char_width; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4318 y += W_WINROW(wp) * gui.char_height; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4319 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4320 else |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4321 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4322 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4323 // We roughly estimate the position of the terminal window inside |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4324 // the Vim window by assuming a 10 x 7 character cell. |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4325 x += wp->w_wincol * 7; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4326 y += W_WINROW(wp) * 10; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4327 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4328 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4329 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4330 len = vim_snprintf(buf, 100, "\x1b[3;%d;%dt", x, y); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4331 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4332 (char_u *)buf, len, NULL); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4333 return 1; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4334 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4335 |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4336 static VTermStateFallbacks state_fallbacks = { |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4337 NULL, // control |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4338 parse_csi, // csi |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4339 parse_osc, // osc |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4340 NULL // dcs |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4341 }; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4342 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4343 /* |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4344 * Use Vim's allocation functions for vterm so profiling works. |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4345 */ |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4346 static void * |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4347 vterm_malloc(size_t size, void *data UNUSED) |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4348 { |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16656
diff
changeset
|
4349 return alloc_clear(size); |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4350 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4351 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4352 static void |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4353 vterm_memfree(void *ptr, void *data UNUSED) |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4354 { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4355 vim_free(ptr); |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4356 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4357 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4358 static VTermAllocatorFunctions vterm_allocator = { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4359 &vterm_malloc, |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4360 &vterm_memfree |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4361 }; |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4362 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4363 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4364 * Create a new vterm and initialize it. |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4365 * Return FAIL when out of memory. |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4366 */ |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4367 static int |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4368 create_vterm(term_T *term, int rows, int cols) |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4369 { |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4370 VTerm *vterm; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4371 VTermScreen *screen; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4372 VTermState *state; |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4373 VTermValue value; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4374 |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4375 vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4376 term->tl_vterm = vterm; |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4377 if (vterm == NULL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4378 return FAIL; |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4379 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4380 // Allocate screen and state here, so we can bail out if that fails. |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4381 state = vterm_obtain_state(vterm); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4382 screen = vterm_obtain_screen(vterm); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4383 if (state == NULL || screen == NULL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4384 { |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4385 vterm_free(vterm); |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4386 return FAIL; |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4387 } |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4388 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4389 vterm_screen_set_callbacks(screen, &screen_callbacks, term); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4390 // TODO: depends on 'encoding'. |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4391 vterm_set_utf8(vterm, 1); |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4392 |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4393 init_default_colors(term, NULL); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4394 |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4395 vterm_state_set_default_colors( |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4396 state, |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4397 &term->tl_default_color.fg, |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4398 &term->tl_default_color.bg); |
12502 | 4399 |
16656
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4400 if (t_colors < 16) |
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4401 // Less than 16 colors: assume that bold means using a bright color for |
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4402 // the foreground color. |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4403 vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4404 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4405 // Required to initialize most things. |
12502 | 4406 vterm_screen_reset(screen, 1 /* hard */); |
4407 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4408 // Allow using alternate screen. |
12502 | 4409 vterm_screen_enable_altscreen(screen, 1); |
4410 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4411 // For unix do not use a blinking cursor. In an xterm this causes the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4412 // cursor to blink if it's blinking in the xterm. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4413 // For Windows we respect the system wide setting. |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
4414 #ifdef MSWIN |
12502 | 4415 if (GetCaretBlinkTime() == INFINITE) |
4416 value.boolean = 0; | |
4417 else | |
4418 value.boolean = 1; | |
4419 #else | |
4420 value.boolean = 0; | |
4421 #endif | |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4422 vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value); |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4423 vterm_state_set_unrecognised_fallbacks(state, &state_fallbacks, term); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4424 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4425 return OK; |
12502 | 4426 } |
4427 | |
4428 /* | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4429 * Called when 'wincolor' was set. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4430 */ |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4431 void |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4432 term_update_colors(void) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4433 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4434 term_T *term = curwin->w_buffer->b_term; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4435 |
19358
734ca70c1f12
patch 8.2.0237: crash when setting 'wincolor' on finished terminal window
Bram Moolenaar <Bram@vim.org>
parents:
19275
diff
changeset
|
4436 if (term->tl_vterm == NULL) |
734ca70c1f12
patch 8.2.0237: crash when setting 'wincolor' on finished terminal window
Bram Moolenaar <Bram@vim.org>
parents:
19275
diff
changeset
|
4437 return; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4438 init_default_colors(term, curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4439 vterm_state_set_default_colors( |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4440 vterm_obtain_state(term->tl_vterm), |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4441 &term->tl_default_color.fg, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4442 &term->tl_default_color.bg); |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
4443 |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
4444 redraw_later(NOT_VALID); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4445 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4446 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4447 /* |
12502 | 4448 * Return the text to show for the buffer name and status. |
4449 */ | |
4450 char_u * | |
4451 term_get_status_text(term_T *term) | |
4452 { | |
4453 if (term->tl_status_text == NULL) | |
4454 { | |
4455 char_u *txt; | |
4456 size_t len; | |
4457 | |
4458 if (term->tl_normal_mode) | |
4459 { | |
4460 if (term_job_running(term)) | |
4461 txt = (char_u *)_("Terminal"); | |
4462 else | |
4463 txt = (char_u *)_("Terminal-finished"); | |
4464 } | |
4465 else if (term->tl_title != NULL) | |
4466 txt = term->tl_title; | |
4467 else if (term_none_open(term)) | |
4468 txt = (char_u *)_("active"); | |
4469 else if (term_job_running(term)) | |
4470 txt = (char_u *)_("running"); | |
4471 else | |
4472 txt = (char_u *)_("finished"); | |
4473 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt); | |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4474 term->tl_status_text = alloc(len); |
12502 | 4475 if (term->tl_status_text != NULL) |
4476 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]", | |
4477 term->tl_buffer->b_fname, txt); | |
4478 } | |
4479 return term->tl_status_text; | |
4480 } | |
4481 | |
4482 /* | |
4483 * Mark references in jobs of terminals. | |
4484 */ | |
4485 int | |
4486 set_ref_in_term(int copyID) | |
4487 { | |
4488 int abort = FALSE; | |
4489 term_T *term; | |
4490 typval_T tv; | |
4491 | |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17133
diff
changeset
|
4492 for (term = first_term; !abort && term != NULL; term = term->tl_next) |
12502 | 4493 if (term->tl_job != NULL) |
4494 { | |
4495 tv.v_type = VAR_JOB; | |
4496 tv.vval.v_job = term->tl_job; | |
4497 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); | |
4498 } | |
4499 return abort; | |
4500 } | |
4501 | |
4502 /* | |
4503 * Get the buffer from the first argument in "argvars". | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4504 * Returns NULL when the buffer is not for a terminal window and logs a message |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4505 * with "where". |
12502 | 4506 */ |
4507 static buf_T * | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4508 term_get_buf(typval_T *argvars, char *where) |
12502 | 4509 { |
4510 buf_T *buf; | |
4511 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4512 (void)tv_get_number(&argvars[0]); // issue errmsg if type error |
12502 | 4513 ++emsg_off; |
15355
73b153ed5af8
patch 8.1.0685: get_buf_tv() is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
15273
diff
changeset
|
4514 buf = tv_get_buf(&argvars[0], FALSE); |
12502 | 4515 --emsg_off; |
4516 if (buf == NULL || buf->b_term == NULL) | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4517 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4518 ch_log(NULL, "%s: invalid buffer argument", where); |
12502 | 4519 return NULL; |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4520 } |
12502 | 4521 return buf; |
4522 } | |
4523 | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4524 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4525 clear_cell(VTermScreenCell *cell) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4526 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4527 CLEAR_FIELD(*cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4528 cell->fg.type = VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4529 cell->bg.type = VTERM_COLOR_DEFAULT_BG; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4530 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4531 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4532 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4533 dump_term_color(FILE *fd, VTermColor *color) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4534 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4535 int index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4536 |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4537 if (VTERM_COLOR_IS_INDEXED(color)) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4538 index = color->index + 1; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4539 else if (color->type == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4540 // use RGB values |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4541 index = 255; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4542 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4543 // default color |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4544 index = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4545 fprintf(fd, "%02x%02x%02x%d", |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4546 (int)color->red, (int)color->green, (int)color->blue, |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4547 index); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4548 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4549 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4550 /* |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4551 * "term_dumpwrite(buf, filename, options)" function |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4552 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4553 * Each screen cell in full is: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4554 * |{characters}+{attributes}#{fg-color}{color-idx}#{bg-color}{color-idx} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4555 * {characters} is a space for an empty cell |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4556 * For a double-width character "+" is changed to "*" and the next cell is |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4557 * skipped. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4558 * {attributes} is the decimal value of HL_BOLD + HL_UNDERLINE, etc. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4559 * when "&" use the same as the previous cell. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4560 * {fg-color} is hex RGB, when "&" use the same as the previous cell. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4561 * {bg-color} is hex RGB, when "&" use the same as the previous cell. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4562 * {color-idx} is a number from 0 to 255 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4563 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4564 * Screen cell with same width, attributes and color as the previous one: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4565 * |{characters} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4566 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4567 * To use the color of the previous cell, use "&" instead of {color}-{idx}. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4568 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4569 * Repeating the previous screen cell: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4570 * @{count} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4571 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4572 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4573 f_term_dumpwrite(typval_T *argvars, typval_T *rettv UNUSED) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4574 { |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4575 buf_T *buf = term_get_buf(argvars, "term_dumpwrite()"); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4576 term_T *term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4577 char_u *fname; |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4578 int max_height = 0; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4579 int max_width = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4580 stat_T st; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4581 FILE *fd; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4582 VTermPos pos; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4583 VTermScreen *screen; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4584 VTermScreenCell prev_cell; |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4585 VTermState *state; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4586 VTermPos cursor_pos; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4587 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4588 if (check_restricted() || check_secure()) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4589 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4590 if (buf == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4591 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4592 term = buf->b_term; |
14691
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4593 if (term->tl_vterm == NULL) |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4594 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4595 emsg(_("E958: Job already finished")); |
14691
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4596 return; |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4597 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4598 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4599 if (argvars[2].v_type != VAR_UNKNOWN) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4600 { |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4601 dict_T *d; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4602 |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4603 if (argvars[2].v_type != VAR_DICT) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4604 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4605 emsg(_(e_dictreq)); |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4606 return; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4607 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4608 d = argvars[2].vval.v_dict; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4609 if (d != NULL) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4610 { |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4611 max_height = dict_get_number(d, (char_u *)"rows"); |
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4612 max_width = dict_get_number(d, (char_u *)"columns"); |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4613 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4614 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4615 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4616 fname = tv_get_string_chk(&argvars[1]); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4617 if (fname == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4618 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4619 if (mch_stat((char *)fname, &st) >= 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4620 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4621 semsg(_("E953: File exists: %s"), fname); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4622 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4623 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4624 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4625 if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4626 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4627 semsg(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4628 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4629 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4630 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4631 clear_cell(&prev_cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4632 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4633 screen = vterm_obtain_screen(term->tl_vterm); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4634 state = vterm_obtain_state(term->tl_vterm); |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4635 vterm_state_get_cursorpos(state, &cursor_pos); |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4636 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4637 for (pos.row = 0; (max_height == 0 || pos.row < max_height) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4638 && pos.row < term->tl_rows; ++pos.row) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4639 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4640 int repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4641 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4642 for (pos.col = 0; (max_width == 0 || pos.col < max_width) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4643 && pos.col < term->tl_cols; ++pos.col) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4644 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4645 VTermScreenCell cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4646 int same_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4647 int same_chars = TRUE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4648 int i; |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4649 int is_cursor_pos = (pos.col == cursor_pos.col |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4650 && pos.row == cursor_pos.row); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4651 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4652 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4653 clear_cell(&cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4654 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4655 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4656 { |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4657 int c = cell.chars[i]; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4658 int pc = prev_cell.chars[i]; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4659 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4660 // For the first character NUL is the same as space. |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4661 if (i == 0) |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4662 { |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4663 c = (c == NUL) ? ' ' : c; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4664 pc = (pc == NUL) ? ' ' : pc; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4665 } |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
4666 if (c != pc) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4667 same_chars = FALSE; |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
4668 if (c == NUL || pc == NUL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4669 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4670 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4671 same_attr = vtermAttr2hl(cell.attrs) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4672 == vtermAttr2hl(prev_cell.attrs) |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4673 && vterm_color_is_equal(&cell.fg, &prev_cell.fg) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4674 && vterm_color_is_equal(&cell.bg, &prev_cell.bg); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4675 if (same_chars && cell.width == prev_cell.width && same_attr |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4676 && !is_cursor_pos) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4677 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4678 ++repeat; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4679 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4680 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4681 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4682 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4683 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4684 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4685 repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4686 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4687 fputs(is_cursor_pos ? ">" : "|", fd); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4688 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4689 if (cell.chars[0] == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4690 fputs(" ", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4691 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4692 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4693 char_u charbuf[10]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4694 int len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4695 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4696 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4697 && cell.chars[i] != NUL; ++i) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4698 { |
13557
4911058c43eb
patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents:
13547
diff
changeset
|
4699 len = utf_char2bytes(cell.chars[i], charbuf); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4700 fwrite(charbuf, len, 1, fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4701 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4702 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4703 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4704 // When only the characters differ we don't write anything, the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4705 // following "|", "@" or NL will indicate using the same |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4706 // attributes. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4707 if (cell.width != prev_cell.width || !same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4708 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4709 if (cell.width == 2) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4710 fputs("*", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4711 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4712 fputs("+", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4713 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4714 if (same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4715 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4716 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4717 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4718 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4719 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4720 fprintf(fd, "%d", vtermAttr2hl(cell.attrs)); |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4721 if (vterm_color_is_equal(&cell.fg, &prev_cell.fg)) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4722 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4723 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4724 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4725 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4726 dump_term_color(fd, &cell.fg); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4727 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4728 if (vterm_color_is_equal(&cell.bg, &prev_cell.bg)) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4729 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4730 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4731 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4732 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4733 dump_term_color(fd, &cell.bg); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4734 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4735 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4736 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4737 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4738 prev_cell = cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4739 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4740 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4741 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4742 ++pos.col; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4743 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4744 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4745 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4746 fputs("\n", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4747 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4748 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4749 fclose(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4750 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4751 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4752 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4753 * Called when a dump is corrupted. Put a breakpoint here when debugging. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4754 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4755 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4756 dump_is_corrupt(garray_T *gap) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4757 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4758 ga_concat(gap, (char_u *)"CORRUPT"); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4759 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4760 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4761 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4762 append_cell(garray_T *gap, cellattr_T *cell) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4763 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4764 if (ga_grow(gap, 1) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4765 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4766 *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4767 ++gap->ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4768 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4769 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4770 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4771 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4772 clear_cellattr(cellattr_T *cell) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4773 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4774 CLEAR_FIELD(*cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4775 cell->fg.type = VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4776 cell->bg.type = VTERM_COLOR_DEFAULT_BG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4777 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4778 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4779 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4780 * Read the dump file from "fd" and append lines to the current buffer. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4781 * Return the cell width of the longest line. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4782 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4783 static int |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4784 read_dump_file(FILE *fd, VTermPos *cursor_pos) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4785 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4786 int c; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4787 garray_T ga_text; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4788 garray_T ga_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4789 char_u *prev_char = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4790 int attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4791 cellattr_T cell; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4792 cellattr_T empty_cell; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4793 term_T *term = curbuf->b_term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4794 int max_cells = 0; |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4795 int start_row = term->tl_scrollback.ga_len; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4796 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4797 ga_init2(&ga_text, 1, 90); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4798 ga_init2(&ga_cell, sizeof(cellattr_T), 90); |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4799 clear_cellattr(&cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4800 clear_cellattr(&empty_cell); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4801 cursor_pos->row = -1; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4802 cursor_pos->col = -1; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4803 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4804 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4805 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4806 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4807 if (c == EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4808 break; |
14960
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4809 if (c == '\r') |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4810 { |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4811 // DOS line endings? Ignore. |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4812 c = fgetc(fd); |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4813 } |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4814 else if (c == '\n') |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4815 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4816 // End of a line: append it to the buffer. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4817 if (ga_text.ga_data == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4818 dump_is_corrupt(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4819 if (ga_grow(&term->tl_scrollback, 1) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4820 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4821 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4822 + term->tl_scrollback.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4823 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4824 if (max_cells < ga_cell.ga_len) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4825 max_cells = ga_cell.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4826 line->sb_cols = ga_cell.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4827 line->sb_cells = ga_cell.ga_data; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4828 line->sb_fill_attr = term->tl_default_color; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4829 ++term->tl_scrollback.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4830 ga_init(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4831 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4832 ga_append(&ga_text, NUL); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4833 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4834 ga_text.ga_len, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4835 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4836 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4837 ga_clear(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4838 ga_text.ga_len = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4839 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4840 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4841 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4842 else if (c == '|' || c == '>') |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4843 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4844 int prev_len = ga_text.ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4845 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4846 if (c == '>') |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4847 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4848 if (cursor_pos->row != -1) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4849 dump_is_corrupt(&ga_text); // duplicate cursor |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4850 cursor_pos->row = term->tl_scrollback.ga_len - start_row; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4851 cursor_pos->col = ga_cell.ga_len; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4852 } |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4853 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4854 // normal character(s) followed by "+", "*", "|", "@" or NL |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4855 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4856 if (c != EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4857 ga_append(&ga_text, c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4858 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4859 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4860 c = fgetc(fd); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4861 if (c == '+' || c == '*' || c == '|' || c == '>' || c == '@' |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4862 || c == EOF || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4863 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4864 ga_append(&ga_text, c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4865 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4866 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4867 // save the character for repeating it |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4868 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4869 if (ga_text.ga_data != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4870 prev_char = vim_strnsave(((char_u *)ga_text.ga_data) + prev_len, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4871 ga_text.ga_len - prev_len); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4872 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4873 if (c == '@' || c == '|' || c == '>' || c == '\n') |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4874 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4875 // use all attributes from previous cell |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4876 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4877 else if (c == '+' || c == '*') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4878 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4879 int is_bg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4880 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4881 cell.width = c == '+' ? 1 : 2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4882 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4883 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4884 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4885 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4886 // use same attr as previous cell |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4887 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4888 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4889 else if (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4890 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4891 // get the decimal attribute |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4892 attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4893 while (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4894 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4895 attr = attr * 10 + (c - '0'); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4896 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4897 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4898 hl2vtermAttr(attr, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4899 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4900 // is_bg == 0: fg, is_bg == 1: bg |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4901 for (is_bg = 0; is_bg <= 1; ++is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4902 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4903 if (c == '&') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4904 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4905 // use same color as previous cell |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4906 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4907 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4908 else if (c == '#') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4909 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4910 int red, green, blue, index = 0, type; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4911 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4912 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4913 red = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4914 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4915 red = (red << 4) + hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4916 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4917 green = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4918 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4919 green = (green << 4) + hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4920 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4921 blue = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4922 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4923 blue = (blue << 4) + hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4924 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4925 if (!isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4926 dump_is_corrupt(&ga_text); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4927 while (isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4928 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4929 index = index * 10 + (c - '0'); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4930 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4931 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4932 if (index == 0 || index == 255) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4933 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4934 type = VTERM_COLOR_RGB; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4935 if (index == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4936 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4937 if (is_bg) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4938 type |= VTERM_COLOR_DEFAULT_BG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4939 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4940 type |= VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4941 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4942 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4943 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4944 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4945 type = VTERM_COLOR_INDEXED; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4946 index -= 1; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4947 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4948 if (is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4949 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4950 cell.bg.type = type; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4951 cell.bg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4952 cell.bg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4953 cell.bg.blue = blue; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4954 cell.bg.index = index; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4955 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4956 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4957 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4958 cell.fg.type = type; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4959 cell.fg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4960 cell.fg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4961 cell.fg.blue = blue; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4962 cell.fg.index = index; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4963 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4964 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4965 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4966 dump_is_corrupt(&ga_text); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4967 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4968 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4969 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4970 dump_is_corrupt(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4971 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4972 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4973 dump_is_corrupt(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4974 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4975 append_cell(&ga_cell, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4976 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4977 append_cell(&ga_cell, &empty_cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4978 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4979 else if (c == '@') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4980 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4981 if (prev_char == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4982 dump_is_corrupt(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4983 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4984 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4985 int count = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4986 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4987 // repeat previous character, get the count |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4988 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4989 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4990 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4991 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4992 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4993 count = count * 10 + (c - '0'); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4994 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4995 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4996 while (count-- > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4997 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4998 ga_concat(&ga_text, prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4999 append_cell(&ga_cell, &cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5000 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5001 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5002 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5003 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5004 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5005 dump_is_corrupt(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5006 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5007 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5008 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5009 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5010 if (ga_text.ga_len > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5011 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5012 // trailing characters after last NL |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5013 dump_is_corrupt(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5014 ga_append(&ga_text, NUL); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5015 ml_append(curbuf->b_ml.ml_line_count, ga_text.ga_data, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5016 ga_text.ga_len, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5017 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5018 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5019 ga_clear(&ga_text); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
5020 ga_clear(&ga_cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5021 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5022 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5023 return max_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5024 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5025 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5026 /* |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5027 * Return an allocated string with at least "text_width" "=" characters and |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5028 * "fname" inserted in the middle. |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5029 */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5030 static char_u * |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5031 get_separator(int text_width, char_u *fname) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5032 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5033 int width = MAX(text_width, curwin->w_width); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5034 char_u *textline; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5035 int fname_size; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5036 char_u *p = fname; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5037 int i; |
13630
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5038 size_t off; |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5039 |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5040 textline = alloc(width + (int)STRLEN(fname) + 1); |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5041 if (textline == NULL) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5042 return NULL; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5043 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5044 fname_size = vim_strsize(fname); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5045 if (fname_size < width - 8) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5046 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5047 // enough room, don't use the full window width |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5048 width = MAX(text_width, fname_size + 8); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5049 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5050 else if (fname_size > width - 8) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5051 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5052 // full name doesn't fit, use only the tail |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5053 p = gettail(fname); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5054 fname_size = vim_strsize(p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5055 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5056 // skip characters until the name fits |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5057 while (fname_size > width - 8) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5058 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5059 p += (*mb_ptr2len)(p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5060 fname_size = vim_strsize(p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5061 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5062 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5063 for (i = 0; i < (width - fname_size) / 2 - 1; ++i) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5064 textline[i] = '='; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5065 textline[i++] = ' '; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5066 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5067 STRCPY(textline + i, p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5068 off = STRLEN(textline); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5069 textline[off] = ' '; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5070 for (i = 1; i < (width - fname_size) / 2; ++i) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5071 textline[off + i] = '='; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5072 textline[off + i] = NUL; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5073 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5074 return textline; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5075 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5076 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5077 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5078 * Common for "term_dumpdiff()" and "term_dumpload()". |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5079 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5080 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5081 term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5082 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5083 jobopt_T opt; |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5084 buf_T *buf = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5085 char_u buf1[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5086 char_u buf2[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5087 char_u *fname1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5088 char_u *fname2 = NULL; |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5089 char_u *fname_tofree = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5090 FILE *fd1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5091 FILE *fd2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5092 char_u *textline = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5093 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5094 // First open the files. If this fails bail out. |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5095 fname1 = tv_get_string_buf_chk(&argvars[0], buf1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5096 if (do_diff) |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5097 fname2 = tv_get_string_buf_chk(&argvars[1], buf2); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5098 if (fname1 == NULL || (do_diff && fname2 == NULL)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5099 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5100 emsg(_(e_invarg)); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5101 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5102 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5103 fd1 = mch_fopen((char *)fname1, READBIN); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5104 if (fd1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5105 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5106 semsg(_(e_notread), fname1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5107 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5108 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5109 if (do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5110 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5111 fd2 = mch_fopen((char *)fname2, READBIN); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5112 if (fd2 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5113 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5114 fclose(fd1); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5115 semsg(_(e_notread), fname2); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5116 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5117 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5118 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5119 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5120 init_job_options(&opt); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5121 if (argvars[do_diff ? 2 : 1].v_type != VAR_UNKNOWN |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5122 && get_job_options(&argvars[do_diff ? 2 : 1], &opt, 0, |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5123 JO2_TERM_NAME + JO2_TERM_COLS + JO2_TERM_ROWS |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5124 + JO2_VERTICAL + JO2_CURWIN + JO2_NORESTORE) == FAIL) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5125 goto theend; |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5126 |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5127 if (opt.jo_term_name == NULL) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5128 { |
13505
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
5129 size_t len = STRLEN(fname1) + 12; |
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
5130 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
5131 fname_tofree = alloc(len); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5132 if (fname_tofree != NULL) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5133 { |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5134 vim_snprintf((char *)fname_tofree, len, "dump diff %s", fname1); |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5135 opt.jo_term_name = fname_tofree; |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5136 } |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5137 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5138 |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5139 if (opt.jo_bufnr_buf != NULL) |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5140 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5141 win_T *wp = buf_jump_open_win(opt.jo_bufnr_buf); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5142 |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5143 // With "bufnr" argument: enter the window with this buffer and make it |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5144 // empty. |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5145 if (wp == NULL) |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5146 semsg(_(e_invarg2), "bufnr"); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5147 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5148 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5149 buf = curbuf; |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5150 while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5151 ml_delete((linenr_T)1); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
5152 free_scrollback(curbuf->b_term); |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5153 redraw_later(NOT_VALID); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5154 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5155 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5156 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5157 // Create a new terminal window. |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5158 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5159 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5160 if (buf != NULL && buf->b_term != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5161 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5162 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5163 linenr_T bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5164 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5165 term_T *term = buf->b_term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5166 int width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5167 int width2; |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5168 VTermPos cursor_pos1; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5169 VTermPos cursor_pos2; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5170 |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
5171 init_default_colors(term, NULL); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
5172 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5173 rettv->vval.v_number = buf->b_fnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5174 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5175 // read the files, fill the buffer with the diff |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5176 width = read_dump_file(fd1, &cursor_pos1); |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5177 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5178 // position the cursor |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5179 if (cursor_pos1.row >= 0) |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5180 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5181 curwin->w_cursor.lnum = cursor_pos1.row + 1; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5182 coladvance(cursor_pos1.col); |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5183 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5184 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5185 // Delete the empty line that was in the empty buffer. |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5186 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5187 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5188 // For term_dumpload() we are done here. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5189 if (!do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5190 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5191 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5192 term->tl_top_diff_rows = curbuf->b_ml.ml_line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5193 |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5194 textline = get_separator(width, fname1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5195 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5196 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5197 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5198 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE); |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5199 vim_free(textline); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5200 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5201 textline = get_separator(width, fname2); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5202 if (textline == NULL) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5203 goto theend; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5204 if (add_empty_scrollback(term, &term->tl_default_color, 0) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5205 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE); |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5206 textline[width] = NUL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5207 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5208 bot_lnum = curbuf->b_ml.ml_line_count; |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5209 width2 = read_dump_file(fd2, &cursor_pos2); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5210 if (width2 > width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5211 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5212 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5213 textline = alloc(width2 + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5214 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5215 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5216 width = width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5217 textline[width] = NUL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5218 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5219 term->tl_bot_diff_rows = curbuf->b_ml.ml_line_count - bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5220 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5221 for (lnum = 1; lnum <= term->tl_top_diff_rows; ++lnum) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5222 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5223 if (lnum + bot_lnum > curbuf->b_ml.ml_line_count) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5224 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5225 // bottom part has fewer rows, fill with "-" |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5226 for (i = 0; i < width; ++i) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5227 textline[i] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5228 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5229 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5230 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5231 char_u *line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5232 char_u *line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5233 char_u *p1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5234 char_u *p2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5235 int col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5236 sb_line_T *sb_line = (sb_line_T *)term->tl_scrollback.ga_data; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5237 cellattr_T *cellattr1 = (sb_line + lnum - 1)->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5238 cellattr_T *cellattr2 = (sb_line + lnum + bot_lnum - 1) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5239 ->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5240 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5241 // Make a copy, getting the second line will invalidate it. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5242 line1 = vim_strsave(ml_get(lnum)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5243 if (line1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5244 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5245 p1 = line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5246 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5247 line2 = ml_get(lnum + bot_lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5248 p2 = line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5249 for (col = 0; col < width && *p1 != NUL && *p2 != NUL; ++col) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5250 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5251 int len1 = utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5252 int len2 = utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5253 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5254 textline[col] = ' '; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5255 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5256 // text differs |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5257 textline[col] = 'X'; |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5258 else if (lnum == cursor_pos1.row + 1 |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5259 && col == cursor_pos1.col |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5260 && (cursor_pos1.row != cursor_pos2.row |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5261 || cursor_pos1.col != cursor_pos2.col)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5262 // cursor in first but not in second |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5263 textline[col] = '>'; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5264 else if (lnum == cursor_pos2.row + 1 |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5265 && col == cursor_pos2.col |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5266 && (cursor_pos1.row != cursor_pos2.row |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5267 || cursor_pos1.col != cursor_pos2.col)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5268 // cursor in second but not in first |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5269 textline[col] = '<'; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5270 else if (cellattr1 != NULL && cellattr2 != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5271 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5272 if ((cellattr1 + col)->width |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5273 != (cellattr2 + col)->width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5274 textline[col] = 'w'; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5275 else if (!vterm_color_is_equal(&(cellattr1 + col)->fg, |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5276 &(cellattr2 + col)->fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5277 textline[col] = 'f'; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5278 else if (!vterm_color_is_equal(&(cellattr1 + col)->bg, |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5279 &(cellattr2 + col)->bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5280 textline[col] = 'b'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5281 else if (vtermAttr2hl((cellattr1 + col)->attrs) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5282 != vtermAttr2hl(((cellattr2 + col)->attrs))) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5283 textline[col] = 'a'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5284 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5285 p1 += len1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5286 p2 += len2; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5287 // TODO: handle different width |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5288 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5289 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5290 while (col < width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5291 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5292 if (*p1 == NUL && *p2 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5293 textline[col] = '?'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5294 else if (*p1 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5295 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5296 textline[col] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5297 p2 += utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5298 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5299 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5300 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5301 textline[col] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5302 p1 += utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5303 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5304 ++col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5305 } |
15828
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5306 |
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5307 vim_free(line1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5308 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5309 if (add_empty_scrollback(term, &term->tl_default_color, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5310 term->tl_top_diff_rows) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5311 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5312 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5313 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5314 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5315 while (lnum + bot_lnum <= curbuf->b_ml.ml_line_count) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5316 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5317 // bottom part has more rows, fill with "+" |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5318 for (i = 0; i < width; ++i) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5319 textline[i] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5320 if (add_empty_scrollback(term, &term->tl_default_color, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5321 term->tl_top_diff_rows) == OK) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5322 ml_append(term->tl_top_diff_rows + lnum, textline, 0, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5323 ++lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5324 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5325 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5326 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5327 term->tl_cols = width; |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5328 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5329 // looks better without wrapping |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5330 curwin->w_p_wrap = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5331 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5332 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5333 theend: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5334 vim_free(textline); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5335 vim_free(fname_tofree); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5336 fclose(fd1); |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5337 if (fd2 != NULL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5338 fclose(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5339 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5340 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5341 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5342 * If the current buffer shows the output of term_dumpdiff(), swap the top and |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5343 * bottom files. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5344 * Return FAIL when this is not possible. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5345 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5346 int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5347 term_swap_diff() |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5348 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5349 term_T *term = curbuf->b_term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5350 linenr_T line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5351 linenr_T top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5352 linenr_T bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5353 linenr_T bot_start; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5354 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5355 char_u *p; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5356 sb_line_T *sb_line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5357 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5358 if (term == NULL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5359 || !term_is_finished(curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5360 || term->tl_top_diff_rows == 0 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5361 || term->tl_scrollback.ga_len == 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5362 return FAIL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5363 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5364 line_count = curbuf->b_ml.ml_line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5365 top_rows = term->tl_top_diff_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5366 bot_rows = term->tl_bot_diff_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5367 bot_start = line_count - bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5368 sb_line = (sb_line_T *)term->tl_scrollback.ga_data; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5369 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5370 // move lines from top to above the bottom part |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5371 for (lnum = 1; lnum <= top_rows; ++lnum) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5372 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5373 p = vim_strsave(ml_get(1)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5374 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5375 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5376 ml_append(bot_start, p, 0, FALSE); |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5377 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5378 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5379 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5380 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5381 // move lines from bottom to the top |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5382 for (lnum = 1; lnum <= bot_rows; ++lnum) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5383 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5384 p = vim_strsave(ml_get(bot_start + lnum)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5385 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5386 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5387 ml_delete(bot_start + lnum); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5388 ml_append(lnum - 1, p, 0, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5389 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5390 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5391 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5392 // move top title to bottom |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5393 p = vim_strsave(ml_get(bot_rows + 1)); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5394 if (p == NULL) |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5395 return OK; |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5396 ml_append(line_count - top_rows - 1, p, 0, FALSE); |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5397 ml_delete(bot_rows + 1); |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5398 vim_free(p); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5399 |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5400 // move bottom title to top |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5401 p = vim_strsave(ml_get(line_count - top_rows)); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5402 if (p == NULL) |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5403 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5404 ml_delete(line_count - top_rows); |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5405 ml_append(bot_rows, p, 0, FALSE); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5406 vim_free(p); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5407 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5408 if (top_rows == bot_rows) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5409 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5410 // rows counts are equal, can swap cell properties |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5411 for (lnum = 0; lnum < top_rows; ++lnum) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5412 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5413 sb_line_T temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5414 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5415 temp = *(sb_line + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5416 *(sb_line + lnum) = *(sb_line + bot_start + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5417 *(sb_line + bot_start + lnum) = temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5418 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5419 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5420 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5421 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5422 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5423 sb_line_T *temp = alloc(size); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5424 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5425 // need to copy cell properties into temp memory |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5426 if (temp != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5427 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5428 mch_memmove(temp, term->tl_scrollback.ga_data, size); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5429 mch_memmove(term->tl_scrollback.ga_data, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5430 temp + bot_start, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5431 sizeof(sb_line_T) * bot_rows); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5432 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data + bot_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5433 temp + top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5434 sizeof(sb_line_T) * (line_count - top_rows - bot_rows)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5435 mch_memmove((sb_line_T *)term->tl_scrollback.ga_data |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5436 + line_count - top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5437 temp, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5438 sizeof(sb_line_T) * top_rows); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5439 vim_free(temp); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5440 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5441 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5442 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5443 term->tl_top_diff_rows = bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5444 term->tl_bot_diff_rows = top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5445 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5446 update_screen(NOT_VALID); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5447 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5448 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5449 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5450 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5451 * "term_dumpdiff(filename, filename, options)" function |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5452 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5453 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5454 f_term_dumpdiff(typval_T *argvars, typval_T *rettv) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5455 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5456 term_load_dump(argvars, rettv, TRUE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5457 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5458 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5459 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5460 * "term_dumpload(filename, options)" function |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5461 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5462 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5463 f_term_dumpload(typval_T *argvars, typval_T *rettv) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5464 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5465 term_load_dump(argvars, rettv, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5466 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5467 |
12502 | 5468 /* |
5469 * "term_getaltscreen(buf)" function | |
5470 */ | |
5471 void | |
5472 f_term_getaltscreen(typval_T *argvars, typval_T *rettv) | |
5473 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5474 buf_T *buf = term_get_buf(argvars, "term_getaltscreen()"); |
12502 | 5475 |
5476 if (buf == NULL) | |
5477 return; | |
5478 rettv->vval.v_number = buf->b_term->tl_using_altscreen; | |
5479 } | |
5480 | |
5481 /* | |
5482 * "term_getattr(attr, name)" function | |
5483 */ | |
5484 void | |
5485 f_term_getattr(typval_T *argvars, typval_T *rettv) | |
5486 { | |
5487 int attr; | |
5488 size_t i; | |
5489 char_u *name; | |
5490 | |
5491 static struct { | |
5492 char *name; | |
5493 int attr; | |
5494 } attrs[] = { | |
5495 {"bold", HL_BOLD}, | |
5496 {"italic", HL_ITALIC}, | |
5497 {"underline", HL_UNDERLINE}, | |
5498 {"strike", HL_STRIKETHROUGH}, | |
5499 {"reverse", HL_INVERSE}, | |
5500 }; | |
5501 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5502 attr = tv_get_number(&argvars[0]); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5503 name = tv_get_string_chk(&argvars[1]); |
12502 | 5504 if (name == NULL) |
5505 return; | |
5506 | |
18033
049a7481d737
patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17702
diff
changeset
|
5507 if (attr > HL_ALL) |
049a7481d737
patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17702
diff
changeset
|
5508 attr = syn_attr2attr(attr); |
12502 | 5509 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i) |
5510 if (STRCMP(name, attrs[i].name) == 0) | |
5511 { | |
5512 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0; | |
5513 break; | |
5514 } | |
5515 } | |
5516 | |
5517 /* | |
5518 * "term_getcursor(buf)" function | |
5519 */ | |
5520 void | |
5521 f_term_getcursor(typval_T *argvars, typval_T *rettv) | |
5522 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5523 buf_T *buf = term_get_buf(argvars, "term_getcursor()"); |
12502 | 5524 term_T *term; |
5525 list_T *l; | |
5526 dict_T *d; | |
5527 | |
5528 if (rettv_list_alloc(rettv) == FAIL) | |
5529 return; | |
5530 if (buf == NULL) | |
5531 return; | |
5532 term = buf->b_term; | |
5533 | |
5534 l = rettv->vval.v_list; | |
5535 list_append_number(l, term->tl_cursor_pos.row + 1); | |
5536 list_append_number(l, term->tl_cursor_pos.col + 1); | |
5537 | |
5538 d = dict_alloc(); | |
5539 if (d != NULL) | |
5540 { | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5541 dict_add_number(d, "visible", term->tl_cursor_visible); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5542 dict_add_number(d, "blink", blink_state_is_inverted() |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5543 ? !term->tl_cursor_blink : term->tl_cursor_blink); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5544 dict_add_number(d, "shape", term->tl_cursor_shape); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5545 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color)); |
12502 | 5546 list_append_dict(l, d); |
5547 } | |
5548 } | |
5549 | |
5550 /* | |
5551 * "term_getjob(buf)" function | |
5552 */ | |
5553 void | |
5554 f_term_getjob(typval_T *argvars, typval_T *rettv) | |
5555 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5556 buf_T *buf = term_get_buf(argvars, "term_getjob()"); |
12502 | 5557 |
15217
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5558 if (buf == NULL) |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5559 { |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5560 rettv->v_type = VAR_SPECIAL; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5561 rettv->vval.v_number = VVAL_NULL; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5562 return; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5563 } |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5564 |
12502 | 5565 rettv->v_type = VAR_JOB; |
5566 rettv->vval.v_job = buf->b_term->tl_job; | |
5567 if (rettv->vval.v_job != NULL) | |
5568 ++rettv->vval.v_job->jv_refcount; | |
5569 } | |
5570 | |
5571 static int | |
5572 get_row_number(typval_T *tv, term_T *term) | |
5573 { | |
5574 if (tv->v_type == VAR_STRING | |
5575 && tv->vval.v_string != NULL | |
5576 && STRCMP(tv->vval.v_string, ".") == 0) | |
5577 return term->tl_cursor_pos.row; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5578 return (int)tv_get_number(tv) - 1; |
12502 | 5579 } |
5580 | |
5581 /* | |
5582 * "term_getline(buf, row)" function | |
5583 */ | |
5584 void | |
5585 f_term_getline(typval_T *argvars, typval_T *rettv) | |
5586 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5587 buf_T *buf = term_get_buf(argvars, "term_getline()"); |
12502 | 5588 term_T *term; |
5589 int row; | |
5590 | |
5591 rettv->v_type = VAR_STRING; | |
5592 if (buf == NULL) | |
5593 return; | |
5594 term = buf->b_term; | |
5595 row = get_row_number(&argvars[1], term); | |
5596 | |
5597 if (term->tl_vterm == NULL) | |
5598 { | |
5599 linenr_T lnum = row + term->tl_scrollback_scrolled + 1; | |
5600 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5601 // vterm is finished, get the text from the buffer |
12502 | 5602 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count) |
5603 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE)); | |
5604 } | |
5605 else | |
5606 { | |
5607 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm); | |
5608 VTermRect rect; | |
5609 int len; | |
5610 char_u *p; | |
5611 | |
5612 if (row < 0 || row >= term->tl_rows) | |
5613 return; | |
5614 len = term->tl_cols * MB_MAXBYTES + 1; | |
5615 p = alloc(len); | |
5616 if (p == NULL) | |
5617 return; | |
5618 rettv->vval.v_string = p; | |
5619 | |
5620 rect.start_col = 0; | |
5621 rect.end_col = term->tl_cols; | |
5622 rect.start_row = row; | |
5623 rect.end_row = row + 1; | |
5624 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL; | |
5625 } | |
5626 } | |
5627 | |
5628 /* | |
5629 * "term_getscrolled(buf)" function | |
5630 */ | |
5631 void | |
5632 f_term_getscrolled(typval_T *argvars, typval_T *rettv) | |
5633 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5634 buf_T *buf = term_get_buf(argvars, "term_getscrolled()"); |
12502 | 5635 |
5636 if (buf == NULL) | |
5637 return; | |
5638 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled; | |
5639 } | |
5640 | |
5641 /* | |
5642 * "term_getsize(buf)" function | |
5643 */ | |
5644 void | |
5645 f_term_getsize(typval_T *argvars, typval_T *rettv) | |
5646 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5647 buf_T *buf = term_get_buf(argvars, "term_getsize()"); |
12502 | 5648 list_T *l; |
5649 | |
5650 if (rettv_list_alloc(rettv) == FAIL) | |
5651 return; | |
5652 if (buf == NULL) | |
5653 return; | |
5654 | |
5655 l = rettv->vval.v_list; | |
5656 list_append_number(l, buf->b_term->tl_rows); | |
5657 list_append_number(l, buf->b_term->tl_cols); | |
5658 } | |
5659 | |
5660 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5661 * "term_setsize(buf, rows, cols)" function |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5662 */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5663 void |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5664 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5665 { |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5666 buf_T *buf = term_get_buf(argvars, "term_setsize()"); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5667 term_T *term; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5668 varnumber_T rows, cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5669 |
13684
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5670 if (buf == NULL) |
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5671 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5672 emsg(_("E955: Not a terminal buffer")); |
13684
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5673 return; |
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5674 } |
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5675 if (buf->b_term->tl_vterm == NULL) |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5676 return; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5677 term = buf->b_term; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5678 rows = tv_get_number(&argvars[1]); |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5679 rows = rows <= 0 ? term->tl_rows : rows; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5680 cols = tv_get_number(&argvars[2]); |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5681 cols = cols <= 0 ? term->tl_cols : cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5682 vterm_set_size(term->tl_vterm, rows, cols); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5683 // handle_resize() will resize the windows |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5684 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5685 // Get and remember the size we ended up with. Update the pty. |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5686 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5687 term_report_winsize(term, term->tl_rows, term->tl_cols); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5688 } |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5689 |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5690 /* |
12502 | 5691 * "term_getstatus(buf)" function |
5692 */ | |
5693 void | |
5694 f_term_getstatus(typval_T *argvars, typval_T *rettv) | |
5695 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5696 buf_T *buf = term_get_buf(argvars, "term_getstatus()"); |
12502 | 5697 term_T *term; |
5698 char_u val[100]; | |
5699 | |
5700 rettv->v_type = VAR_STRING; | |
5701 if (buf == NULL) | |
5702 return; | |
5703 term = buf->b_term; | |
5704 | |
5705 if (term_job_running(term)) | |
5706 STRCPY(val, "running"); | |
5707 else | |
5708 STRCPY(val, "finished"); | |
5709 if (term->tl_normal_mode) | |
5710 STRCAT(val, ",normal"); | |
5711 rettv->vval.v_string = vim_strsave(val); | |
5712 } | |
5713 | |
5714 /* | |
5715 * "term_gettitle(buf)" function | |
5716 */ | |
5717 void | |
5718 f_term_gettitle(typval_T *argvars, typval_T *rettv) | |
5719 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5720 buf_T *buf = term_get_buf(argvars, "term_gettitle()"); |
12502 | 5721 |
5722 rettv->v_type = VAR_STRING; | |
5723 if (buf == NULL) | |
5724 return; | |
5725 | |
5726 if (buf->b_term->tl_title != NULL) | |
5727 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title); | |
5728 } | |
5729 | |
5730 /* | |
5731 * "term_gettty(buf)" function | |
5732 */ | |
5733 void | |
5734 f_term_gettty(typval_T *argvars, typval_T *rettv) | |
5735 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5736 buf_T *buf = term_get_buf(argvars, "term_gettty()"); |
13864
de8455bd2d05
patch 8.0.1803: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13862
diff
changeset
|
5737 char_u *p = NULL; |
12502 | 5738 int num = 0; |
5739 | |
5740 rettv->v_type = VAR_STRING; | |
5741 if (buf == NULL) | |
5742 return; | |
5743 if (argvars[1].v_type != VAR_UNKNOWN) | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5744 num = tv_get_number(&argvars[1]); |
12502 | 5745 |
5746 switch (num) | |
5747 { | |
5748 case 0: | |
5749 if (buf->b_term->tl_job != NULL) | |
5750 p = buf->b_term->tl_job->jv_tty_out; | |
5751 break; | |
5752 case 1: | |
5753 if (buf->b_term->tl_job != NULL) | |
5754 p = buf->b_term->tl_job->jv_tty_in; | |
5755 break; | |
5756 default: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5757 semsg(_(e_invarg2), tv_get_string(&argvars[1])); |
12502 | 5758 return; |
5759 } | |
5760 if (p != NULL) | |
5761 rettv->vval.v_string = vim_strsave(p); | |
5762 } | |
5763 | |
5764 /* | |
5765 * "term_list()" function | |
5766 */ | |
5767 void | |
5768 f_term_list(typval_T *argvars UNUSED, typval_T *rettv) | |
5769 { | |
5770 term_T *tp; | |
5771 list_T *l; | |
5772 | |
5773 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL) | |
5774 return; | |
5775 | |
5776 l = rettv->vval.v_list; | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
5777 FOR_ALL_TERMS(tp) |
12502 | 5778 if (tp != NULL && tp->tl_buffer != NULL) |
5779 if (list_append_number(l, | |
5780 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL) | |
5781 return; | |
5782 } | |
5783 | |
5784 /* | |
5785 * "term_scrape(buf, row)" function | |
5786 */ | |
5787 void | |
5788 f_term_scrape(typval_T *argvars, typval_T *rettv) | |
5789 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5790 buf_T *buf = term_get_buf(argvars, "term_scrape()"); |
12502 | 5791 VTermScreen *screen = NULL; |
5792 VTermPos pos; | |
5793 list_T *l; | |
5794 term_T *term; | |
5795 char_u *p; | |
5796 sb_line_T *line; | |
5797 | |
5798 if (rettv_list_alloc(rettv) == FAIL) | |
5799 return; | |
5800 if (buf == NULL) | |
5801 return; | |
5802 term = buf->b_term; | |
5803 | |
5804 l = rettv->vval.v_list; | |
5805 pos.row = get_row_number(&argvars[1], term); | |
5806 | |
5807 if (term->tl_vterm != NULL) | |
5808 { | |
5809 screen = vterm_obtain_screen(term->tl_vterm); | |
15273
19272aa12962
patch 8.1.0645: Coverity warns for possible use of NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
15249
diff
changeset
|
5810 if (screen == NULL) // can't really happen |
19272aa12962
patch 8.1.0645: Coverity warns for possible use of NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
15249
diff
changeset
|
5811 return; |
12502 | 5812 p = NULL; |
5813 line = NULL; | |
5814 } | |
5815 else | |
5816 { | |
5817 linenr_T lnum = pos.row + term->tl_scrollback_scrolled; | |
5818 | |
5819 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len) | |
5820 return; | |
5821 p = ml_get_buf(buf, lnum + 1, FALSE); | |
5822 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | |
5823 } | |
5824 | |
5825 for (pos.col = 0; pos.col < term->tl_cols; ) | |
5826 { | |
5827 dict_T *dcell; | |
5828 int width; | |
5829 VTermScreenCellAttrs attrs; | |
5830 VTermColor fg, bg; | |
5831 char_u rgb[8]; | |
5832 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1]; | |
5833 int off = 0; | |
5834 int i; | |
5835 | |
5836 if (screen == NULL) | |
5837 { | |
5838 cellattr_T *cellattr; | |
5839 int len; | |
5840 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5841 // vterm has finished, get the cell from scrollback |
12502 | 5842 if (pos.col >= line->sb_cols) |
5843 break; | |
5844 cellattr = line->sb_cells + pos.col; | |
5845 width = cellattr->width; | |
5846 attrs = cellattr->attrs; | |
5847 fg = cellattr->fg; | |
5848 bg = cellattr->bg; | |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
5849 len = mb_ptr2len(p); |
12502 | 5850 mch_memmove(mbs, p, len); |
5851 mbs[len] = NUL; | |
5852 p += len; | |
5853 } | |
5854 else | |
5855 { | |
5856 VTermScreenCell cell; | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5857 |
12502 | 5858 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
5859 break; | |
5860 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | |
5861 { | |
5862 if (cell.chars[i] == 0) | |
5863 break; | |
5864 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off); | |
5865 } | |
5866 mbs[off] = NUL; | |
5867 width = cell.width; | |
5868 attrs = cell.attrs; | |
5869 fg = cell.fg; | |
5870 bg = cell.bg; | |
5871 } | |
5872 dcell = dict_alloc(); | |
13250
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5873 if (dcell == NULL) |
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5874 break; |
12502 | 5875 list_append_dict(l, dcell); |
5876 | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5877 dict_add_string(dcell, "chars", mbs); |
12502 | 5878 |
5879 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
5880 fg.red, fg.green, fg.blue); | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5881 dict_add_string(dcell, "fg", rgb); |
12502 | 5882 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", |
5883 bg.red, bg.green, bg.blue); | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5884 dict_add_string(dcell, "bg", rgb); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5885 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
5886 dict_add_number(dcell, "attr", cell2attr(term, NULL, attrs, fg, bg)); |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5887 dict_add_number(dcell, "width", width); |
12502 | 5888 |
5889 ++pos.col; | |
5890 if (width == 2) | |
5891 ++pos.col; | |
5892 } | |
5893 } | |
5894 | |
5895 /* | |
5896 * "term_sendkeys(buf, keys)" function | |
5897 */ | |
5898 void | |
19633
dd3e5533a7d2
patch 8.2.0373: type of term_sendkeys() is unknown
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
5899 f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED) |
12502 | 5900 { |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5901 buf_T *buf = term_get_buf(argvars, "term_sendkeys()"); |
12502 | 5902 char_u *msg; |
5903 term_T *term; | |
5904 | |
5905 if (buf == NULL) | |
5906 return; | |
5907 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5908 msg = tv_get_string_chk(&argvars[1]); |
12502 | 5909 if (msg == NULL) |
5910 return; | |
5911 term = buf->b_term; | |
5912 if (term->tl_vterm == NULL) | |
5913 return; | |
5914 | |
5915 while (*msg != NUL) | |
5916 { | |
14029
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5917 int c; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5918 |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5919 if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL) |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5920 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5921 c = TO_SPECIAL(msg[1], msg[2]); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5922 msg += 3; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5923 } |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5924 else |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5925 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5926 c = PTR2CHAR(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5927 msg += MB_CPTR2LEN(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5928 } |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
5929 send_keys_to_term(term, c, 0, FALSE); |
12502 | 5930 } |
5931 } | |
5932 | |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5933 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5934 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5935 * "term_getansicolors(buf)" function |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5936 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5937 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5938 f_term_getansicolors(typval_T *argvars, typval_T *rettv) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5939 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5940 buf_T *buf = term_get_buf(argvars, "term_getansicolors()"); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5941 term_T *term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5942 VTermState *state; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5943 VTermColor color; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5944 char_u hexbuf[10]; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5945 int index; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5946 list_T *list; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5947 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5948 if (rettv_list_alloc(rettv) == FAIL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5949 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5950 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5951 if (buf == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5952 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5953 term = buf->b_term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5954 if (term->tl_vterm == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5955 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5956 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5957 list = rettv->vval.v_list; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5958 state = vterm_obtain_state(term->tl_vterm); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5959 for (index = 0; index < 16; index++) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5960 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5961 vterm_state_get_palette_color(state, index, &color); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5962 sprintf((char *)hexbuf, "#%02x%02x%02x", |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5963 color.red, color.green, color.blue); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5964 if (list_append_string(list, hexbuf, 7) == FAIL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5965 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5966 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5967 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5968 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5969 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5970 * "term_setansicolors(buf, list)" function |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5971 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5972 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5973 f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5974 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5975 buf_T *buf = term_get_buf(argvars, "term_setansicolors()"); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5976 term_T *term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5977 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5978 if (buf == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5979 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5980 term = buf->b_term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5981 if (term->tl_vterm == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5982 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5983 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5984 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5985 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5986 emsg(_(e_listreq)); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5987 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5988 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5989 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5990 if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5991 emsg(_(e_invarg)); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5992 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5993 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5994 |
12502 | 5995 /* |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
5996 * "term_setapi(buf, api)" function |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
5997 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
5998 void |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
5999 f_term_setapi(typval_T *argvars, typval_T *rettv UNUSED) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6000 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6001 buf_T *buf = term_get_buf(argvars, "term_setapi()"); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6002 term_T *term; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6003 char_u *api; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6004 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6005 if (buf == NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6006 return; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6007 term = buf->b_term; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6008 vim_free(term->tl_api); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6009 api = tv_get_string_chk(&argvars[1]); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6010 if (api != NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6011 term->tl_api = vim_strsave(api); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6012 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6013 term->tl_api = NULL; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6014 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6015 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6016 /* |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6017 * "term_setrestore(buf, command)" function |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6018 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6019 void |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6020 f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6021 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6022 #if defined(FEAT_SESSION) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6023 buf_T *buf = term_get_buf(argvars, "term_setrestore()"); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6024 term_T *term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6025 char_u *cmd; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6026 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6027 if (buf == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6028 return; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6029 term = buf->b_term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6030 vim_free(term->tl_command); |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
6031 cmd = tv_get_string_chk(&argvars[1]); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6032 if (cmd != NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6033 term->tl_command = vim_strsave(cmd); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6034 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6035 term->tl_command = NULL; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6036 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6037 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6038 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6039 /* |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6040 * "term_setkill(buf, how)" function |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6041 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6042 void |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6043 f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6044 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6045 buf_T *buf = term_get_buf(argvars, "term_setkill()"); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6046 term_T *term; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6047 char_u *how; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6048 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6049 if (buf == NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6050 return; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6051 term = buf->b_term; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6052 vim_free(term->tl_kill); |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
6053 how = tv_get_string_chk(&argvars[1]); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6054 if (how != NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6055 term->tl_kill = vim_strsave(how); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6056 else |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6057 term->tl_kill = NULL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6058 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6059 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6060 /* |
12502 | 6061 * "term_start(command, options)" function |
6062 */ | |
6063 void | |
6064 f_term_start(typval_T *argvars, typval_T *rettv) | |
6065 { | |
6066 jobopt_T opt; | |
6067 buf_T *buf; | |
6068 | |
6069 init_job_options(&opt); | |
6070 if (argvars[1].v_type != VAR_UNKNOWN | |
6071 && get_job_options(&argvars[1], &opt, | |
6072 JO_TIMEOUT_ALL + JO_STOPONEXIT | |
6073 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK | |
6074 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO, | |
6075 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD | |
6076 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6077 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
6078 + JO2_NORESTORE + JO2_TERM_KILL + JO2_TERM_HIGHLIGHT |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6079 + JO2_ANSI_COLORS + JO2_TTY_TYPE + JO2_TERM_API) == FAIL) |
12502 | 6080 return; |
6081 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6082 buf = term_start(&argvars[0], NULL, &opt, 0); |
12502 | 6083 |
6084 if (buf != NULL && buf->b_term != NULL) | |
6085 rettv->vval.v_number = buf->b_fnum; | |
6086 } | |
6087 | |
6088 /* | |
6089 * "term_wait" function | |
6090 */ | |
6091 void | |
6092 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | |
6093 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6094 buf_T *buf = term_get_buf(argvars, "term_wait()"); |
12502 | 6095 |
6096 if (buf == NULL) | |
6097 return; | |
6098 if (buf->b_term->tl_job == NULL) | |
6099 { | |
6100 ch_log(NULL, "term_wait(): no job to wait for"); | |
6101 return; | |
6102 } | |
6103 if (buf->b_term->tl_job->jv_channel == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6104 // channel is closed, nothing to do |
12502 | 6105 return; |
6106 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6107 // Get the job status, this will detect a job that finished. |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
6108 if (!buf->b_term->tl_job->jv_channel->ch_keep_open |
12502 | 6109 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) |
6110 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6111 // The job is dead, keep reading channel I/O until the channel is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6112 // closed. buf->b_term may become NULL if the terminal was closed while |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6113 // waiting. |
12502 | 6114 ch_log(NULL, "term_wait(): waiting for channel to close"); |
6115 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) | |
6116 { | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6117 term_flush_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6118 |
13996
59121ffd7fce
patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
13994
diff
changeset
|
6119 ui_delay(10L, FALSE); |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
6120 if (!buf_valid(buf)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6121 // If the terminal is closed when the channel is closed the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6122 // buffer disappears. |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
6123 break; |
12502 | 6124 } |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6125 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6126 term_flush_messages(); |
12502 | 6127 } |
6128 else | |
6129 { | |
6130 long wait = 10L; | |
6131 | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6132 term_flush_messages(); |
12502 | 6133 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6134 // Wait for some time for any channel I/O. |
12502 | 6135 if (argvars[1].v_type != VAR_UNKNOWN) |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
6136 wait = tv_get_number(&argvars[1]); |
12502 | 6137 ui_delay(wait, TRUE); |
6138 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6139 // Flushing messages on channels is hopefully sufficient. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6140 // TODO: is there a better way? |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6141 term_flush_messages(); |
12502 | 6142 } |
6143 } | |
6144 | |
6145 /* | |
6146 * Called when a channel has sent all the lines to a terminal. | |
6147 * Send a CTRL-D to mark the end of the text. | |
6148 */ | |
6149 void | |
6150 term_send_eof(channel_T *ch) | |
6151 { | |
6152 term_T *term; | |
6153 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
6154 FOR_ALL_TERMS(term) |
12502 | 6155 if (term->tl_job == ch->ch_job) |
6156 { | |
6157 if (term->tl_eof_chars != NULL) | |
6158 { | |
6159 channel_send(ch, PART_IN, term->tl_eof_chars, | |
6160 (int)STRLEN(term->tl_eof_chars), NULL); | |
6161 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL); | |
6162 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6163 # ifdef MSWIN |
12502 | 6164 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6165 // Default: CTRL-D |
12502 | 6166 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL); |
6167 # endif | |
6168 } | |
6169 } | |
6170 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6171 #if defined(FEAT_GUI) || defined(PROTO) |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
6172 job_T * |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
6173 term_getjob(term_T *term) |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
6174 { |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
6175 return term != NULL ? term->tl_job : NULL; |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
6176 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6177 #endif |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
6178 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6179 # if defined(MSWIN) || defined(PROTO) |
12502 | 6180 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6181 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6182 // 2. MS-Windows implementation. |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6183 #ifdef PROTO |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6184 typedef int COORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6185 typedef int DWORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6186 typedef int HANDLE; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6187 typedef int *DWORD_PTR; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6188 typedef int HPCON; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6189 typedef int HRESULT; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6190 typedef int LPPROC_THREAD_ATTRIBUTE_LIST; |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16354
diff
changeset
|
6191 typedef int SIZE_T; |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6192 typedef int PSIZE_T; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6193 typedef int PVOID; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
6194 typedef int BOOL; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
6195 # define WINAPI |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6196 #endif |
12502 | 6197 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6198 HRESULT (WINAPI *pCreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON*); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6199 HRESULT (WINAPI *pResizePseudoConsole)(HPCON, COORD); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6200 HRESULT (WINAPI *pClosePseudoConsole)(HPCON); |
15786
ec39beb7e61f
patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
6201 BOOL (WINAPI *pInitializeProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T); |
ec39beb7e61f
patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
6202 BOOL (WINAPI *pUpdateProcThreadAttribute)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T); |
ec39beb7e61f
patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
6203 void (WINAPI *pDeleteProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6204 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6205 static int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6206 dyn_conpty_init(int verbose) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6207 { |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6208 static HMODULE hKerneldll = NULL; |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6209 int i; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6210 static struct |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6211 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6212 char *name; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6213 FARPROC *ptr; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6214 } conpty_entry[] = |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6215 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6216 {"CreatePseudoConsole", (FARPROC*)&pCreatePseudoConsole}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6217 {"ResizePseudoConsole", (FARPROC*)&pResizePseudoConsole}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6218 {"ClosePseudoConsole", (FARPROC*)&pClosePseudoConsole}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6219 {"InitializeProcThreadAttributeList", |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6220 (FARPROC*)&pInitializeProcThreadAttributeList}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6221 {"UpdateProcThreadAttribute", |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6222 (FARPROC*)&pUpdateProcThreadAttribute}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6223 {"DeleteProcThreadAttributeList", |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6224 (FARPROC*)&pDeleteProcThreadAttributeList}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6225 {NULL, NULL} |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6226 }; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6227 |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15786
diff
changeset
|
6228 if (!has_conpty_working()) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6229 { |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6230 if (verbose) |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6231 emsg(_("E982: ConPTY is not available")); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6232 return FAIL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6233 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6234 |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6235 // No need to initialize twice. |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6236 if (hKerneldll) |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6237 return OK; |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6238 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6239 hKerneldll = vimLoadLib("kernel32.dll"); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6240 for (i = 0; conpty_entry[i].name != NULL |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6241 && conpty_entry[i].ptr != NULL; ++i) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6242 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6243 if ((*conpty_entry[i].ptr = (FARPROC)GetProcAddress(hKerneldll, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6244 conpty_entry[i].name)) == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6245 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6246 if (verbose) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6247 semsg(_(e_loadfunc), conpty_entry[i].name); |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6248 hKerneldll = NULL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6249 return FAIL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6250 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6251 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6252 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6253 return OK; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6254 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6255 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6256 static int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6257 conpty_term_and_job_init( |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6258 term_T *term, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6259 typval_T *argvar, |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
6260 char **argv UNUSED, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6261 jobopt_T *opt, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6262 jobopt_T *orig_opt) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6263 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6264 WCHAR *cmd_wchar = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6265 WCHAR *cmd_wchar_copy = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6266 WCHAR *cwd_wchar = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6267 WCHAR *env_wchar = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6268 channel_T *channel = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6269 job_T *job = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6270 HANDLE jo = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6271 garray_T ga_cmd, ga_env; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6272 char_u *cmd = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6273 HRESULT hr; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6274 COORD consize; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6275 SIZE_T breq; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6276 PROCESS_INFORMATION proc_info; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6277 HANDLE i_theirs = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6278 HANDLE o_theirs = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6279 HANDLE i_ours = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6280 HANDLE o_ours = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6281 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6282 ga_init2(&ga_cmd, (int)sizeof(char*), 20); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6283 ga_init2(&ga_env, (int)sizeof(char*), 20); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6284 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6285 if (argvar->v_type == VAR_STRING) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6286 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6287 cmd = argvar->vval.v_string; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6288 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6289 else if (argvar->v_type == VAR_LIST) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6290 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6291 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6292 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6293 cmd = ga_cmd.ga_data; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6294 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6295 if (cmd == NULL || *cmd == NUL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6296 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6297 emsg(_(e_invarg)); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6298 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6299 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6300 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6301 term->tl_arg0_cmd = vim_strsave(cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6302 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6303 cmd_wchar = enc_to_utf16(cmd, NULL); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6304 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6305 if (cmd_wchar != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6306 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6307 // Request by CreateProcessW |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6308 breq = wcslen(cmd_wchar) + 1 + 1; // Addition of NUL by API |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6309 cmd_wchar_copy = ALLOC_MULT(WCHAR, breq); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6310 wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6311 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6312 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6313 ga_clear(&ga_cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6314 if (cmd_wchar == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6315 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6316 if (opt->jo_cwd != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6317 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6318 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6319 win32_build_env(opt->jo_env, &ga_env, TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6320 env_wchar = ga_env.ga_data; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6321 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6322 if (!CreatePipe(&i_theirs, &i_ours, NULL, 0)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6323 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6324 if (!CreatePipe(&o_ours, &o_theirs, NULL, 0)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6325 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6326 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6327 consize.X = term->tl_cols; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6328 consize.Y = term->tl_rows; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6329 hr = pCreatePseudoConsole(consize, i_theirs, o_theirs, 0, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6330 &term->tl_conpty); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6331 if (FAILED(hr)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6332 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6333 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6334 term->tl_siex.StartupInfo.cb = sizeof(term->tl_siex); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6335 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6336 // Set up pipe inheritance safely: Vista or later. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6337 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6338 term->tl_siex.lpAttributeList = alloc(breq); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6339 if (!term->tl_siex.lpAttributeList) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6340 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6341 if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6342 0, &breq)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6343 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6344 if (!pUpdateProcThreadAttribute( |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6345 term->tl_siex.lpAttributeList, 0, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6346 PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, term->tl_conpty, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6347 sizeof(HPCON), NULL, NULL)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6348 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6349 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6350 channel = add_channel(); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6351 if (channel == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6352 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6353 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6354 job = job_alloc(); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6355 if (job == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6356 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6357 if (argvar->v_type == VAR_STRING) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6358 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6359 int argc; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6360 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6361 build_argv_from_string(cmd, &job->jv_argv, &argc); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6362 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6363 else |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6364 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6365 int argc; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6366 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6367 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6368 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6369 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6370 if (opt->jo_set & JO_IN_BUF) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6371 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6372 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6373 if (!CreateProcessW(NULL, cmd_wchar_copy, NULL, NULL, FALSE, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6374 EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT |
20179
28d82a342331
patch 8.2.0645: MS-Windows terminal: CTRL-C does not get to child job
Bram Moolenaar <Bram@vim.org>
parents:
20176
diff
changeset
|
6375 | CREATE_SUSPENDED | CREATE_DEFAULT_ERROR_MODE, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6376 env_wchar, cwd_wchar, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6377 &term->tl_siex.StartupInfo, &proc_info)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6378 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6379 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6380 CloseHandle(i_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6381 CloseHandle(o_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6382 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6383 channel_set_pipes(channel, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6384 (sock_T)i_ours, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6385 (sock_T)o_ours, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6386 (sock_T)o_ours); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6387 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6388 // Write lines with CR instead of NL. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6389 channel->ch_write_text_mode = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6390 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6391 // Use to explicitly delete anonymous pipe handle. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6392 channel->ch_anonymous_pipe = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6393 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6394 jo = CreateJobObject(NULL, NULL); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6395 if (jo == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6396 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6397 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6398 if (!AssignProcessToJobObject(jo, proc_info.hProcess)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6399 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6400 // Failed, switch the way to terminate process with TerminateProcess. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6401 CloseHandle(jo); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6402 jo = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6403 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6404 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6405 ResumeThread(proc_info.hThread); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6406 CloseHandle(proc_info.hThread); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6407 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6408 vim_free(cmd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6409 vim_free(cmd_wchar_copy); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6410 vim_free(cwd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6411 vim_free(env_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6412 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6413 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6414 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6415 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6416 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6417 if (opt->jo_set2 & JO2_ANSI_COLORS) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6418 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6419 else |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6420 init_vterm_ansi_colors(term->tl_vterm); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6421 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6422 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6423 channel_set_job(channel, job, opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6424 job_set_options(job, opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6425 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6426 job->jv_channel = channel; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6427 job->jv_proc_info = proc_info; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6428 job->jv_job_object = jo; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6429 job->jv_status = JOB_STARTED; |
15810
5523665fdf80
patch 8.1.0912: MS-Windows: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
6430 job->jv_tty_type = vim_strsave((char_u *)"conpty"); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6431 ++job->jv_refcount; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6432 term->tl_job = job; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6433 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6434 // Redirecting stdout and stderr doesn't work at the job level. Instead |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6435 // open the file here and handle it in. opt->jo_io was changed in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6436 // setup_job_options(), use the original flags here. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6437 if (orig_opt->jo_io[PART_OUT] == JIO_FILE) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6438 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6439 char_u *fname = opt->jo_io_name[PART_OUT]; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6440 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6441 ch_log(channel, "Opening output file %s", fname); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6442 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6443 if (term->tl_out_fd == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6444 semsg(_(e_notopen), fname); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6445 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6446 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6447 return OK; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6448 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6449 failed: |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6450 ga_clear(&ga_cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6451 ga_clear(&ga_env); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6452 vim_free(cmd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6453 vim_free(cmd_wchar_copy); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6454 vim_free(cwd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6455 if (channel != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6456 channel_clear(channel); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6457 if (job != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6458 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6459 job->jv_channel = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6460 job_cleanup(job); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6461 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6462 term->tl_job = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6463 if (jo != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6464 CloseHandle(jo); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6465 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6466 if (term->tl_siex.lpAttributeList != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6467 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6468 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6469 vim_free(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6470 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6471 term->tl_siex.lpAttributeList = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6472 if (o_theirs != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6473 CloseHandle(o_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6474 if (o_ours != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6475 CloseHandle(o_ours); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6476 if (i_ours != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6477 CloseHandle(i_ours); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6478 if (i_theirs != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6479 CloseHandle(i_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6480 if (term->tl_conpty != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6481 pClosePseudoConsole(term->tl_conpty); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6482 term->tl_conpty = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6483 return FAIL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6484 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6485 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6486 static void |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6487 conpty_term_report_winsize(term_T *term, int rows, int cols) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6488 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6489 COORD consize; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6490 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6491 consize.X = cols; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6492 consize.Y = rows; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6493 pResizePseudoConsole(term->tl_conpty, consize); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6494 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6495 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
18033
diff
changeset
|
6496 static void |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6497 term_free_conpty(term_T *term) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6498 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6499 if (term->tl_siex.lpAttributeList != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6500 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6501 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6502 vim_free(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6503 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6504 term->tl_siex.lpAttributeList = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6505 if (term->tl_conpty != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6506 pClosePseudoConsole(term->tl_conpty); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6507 term->tl_conpty = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6508 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6509 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6510 int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6511 use_conpty(void) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6512 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6513 return has_conpty; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6514 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6515 |
12502 | 6516 # ifndef PROTO |
6517 | |
6518 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul | |
6519 #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull | |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
6520 #define WINPTY_MOUSE_MODE_FORCE 2 |
12502 | 6521 |
6522 void* (*winpty_config_new)(UINT64, void*); | |
6523 void* (*winpty_open)(void*, void*); | |
6524 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*); | |
6525 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*); | |
6526 void (*winpty_config_set_mouse_mode)(void*, int); | |
6527 void (*winpty_config_set_initial_size)(void*, int, int); | |
6528 LPCWSTR (*winpty_conin_name)(void*); | |
6529 LPCWSTR (*winpty_conout_name)(void*); | |
6530 LPCWSTR (*winpty_conerr_name)(void*); | |
6531 void (*winpty_free)(void*); | |
6532 void (*winpty_config_free)(void*); | |
6533 void (*winpty_spawn_config_free)(void*); | |
6534 void (*winpty_error_free)(void*); | |
6535 LPCWSTR (*winpty_error_msg)(void*); | |
6536 BOOL (*winpty_set_size)(void*, int, int, void*); | |
6537 HANDLE (*winpty_agent_process)(void*); | |
6538 | |
6539 #define WINPTY_DLL "winpty.dll" | |
6540 | |
6541 static HINSTANCE hWinPtyDLL = NULL; | |
6542 # endif | |
6543 | |
6544 static int | |
6545 dyn_winpty_init(int verbose) | |
6546 { | |
6547 int i; | |
6548 static struct | |
6549 { | |
6550 char *name; | |
6551 FARPROC *ptr; | |
6552 } winpty_entry[] = | |
6553 { | |
6554 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name}, | |
6555 {"winpty_config_free", (FARPROC*)&winpty_config_free}, | |
6556 {"winpty_config_new", (FARPROC*)&winpty_config_new}, | |
6557 {"winpty_config_set_mouse_mode", | |
6558 (FARPROC*)&winpty_config_set_mouse_mode}, | |
6559 {"winpty_config_set_initial_size", | |
6560 (FARPROC*)&winpty_config_set_initial_size}, | |
6561 {"winpty_conin_name", (FARPROC*)&winpty_conin_name}, | |
6562 {"winpty_conout_name", (FARPROC*)&winpty_conout_name}, | |
6563 {"winpty_error_free", (FARPROC*)&winpty_error_free}, | |
6564 {"winpty_free", (FARPROC*)&winpty_free}, | |
6565 {"winpty_open", (FARPROC*)&winpty_open}, | |
6566 {"winpty_spawn", (FARPROC*)&winpty_spawn}, | |
6567 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free}, | |
6568 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new}, | |
6569 {"winpty_error_msg", (FARPROC*)&winpty_error_msg}, | |
6570 {"winpty_set_size", (FARPROC*)&winpty_set_size}, | |
6571 {"winpty_agent_process", (FARPROC*)&winpty_agent_process}, | |
6572 {NULL, NULL} | |
6573 }; | |
6574 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6575 // No need to initialize twice. |
12502 | 6576 if (hWinPtyDLL) |
6577 return OK; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6578 // Load winpty.dll, prefer using the 'winptydll' option, fall back to just |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6579 // winpty.dll. |
12502 | 6580 if (*p_winptydll != NUL) |
6581 hWinPtyDLL = vimLoadLib((char *)p_winptydll); | |
6582 if (!hWinPtyDLL) | |
6583 hWinPtyDLL = vimLoadLib(WINPTY_DLL); | |
6584 if (!hWinPtyDLL) | |
6585 { | |
6586 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6587 semsg(_(e_loadlib), *p_winptydll != NUL ? p_winptydll |
12502 | 6588 : (char_u *)WINPTY_DLL); |
6589 return FAIL; | |
6590 } | |
6591 for (i = 0; winpty_entry[i].name != NULL | |
6592 && winpty_entry[i].ptr != NULL; ++i) | |
6593 { | |
6594 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL, | |
6595 winpty_entry[i].name)) == NULL) | |
6596 { | |
6597 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6598 semsg(_(e_loadfunc), winpty_entry[i].name); |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6599 hWinPtyDLL = NULL; |
12502 | 6600 return FAIL; |
6601 } | |
6602 } | |
6603 | |
6604 return OK; | |
6605 } | |
6606 | |
6607 static int | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6608 winpty_term_and_job_init( |
12502 | 6609 term_T *term, |
6610 typval_T *argvar, | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
6611 char **argv UNUSED, |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6612 jobopt_T *opt, |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6613 jobopt_T *orig_opt) |
12502 | 6614 { |
6615 WCHAR *cmd_wchar = NULL; | |
6616 WCHAR *cwd_wchar = NULL; | |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6617 WCHAR *env_wchar = NULL; |
12502 | 6618 channel_T *channel = NULL; |
6619 job_T *job = NULL; | |
6620 DWORD error; | |
6621 HANDLE jo = NULL; | |
6622 HANDLE child_process_handle; | |
6623 HANDLE child_thread_handle; | |
13111
149347fda678
patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents:
13109
diff
changeset
|
6624 void *winpty_err = NULL; |
12502 | 6625 void *spawn_config = NULL; |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6626 garray_T ga_cmd, ga_env; |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6627 char_u *cmd = NULL; |
12502 | 6628 |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6629 ga_init2(&ga_cmd, (int)sizeof(char*), 20); |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6630 ga_init2(&ga_env, (int)sizeof(char*), 20); |
12502 | 6631 |
6632 if (argvar->v_type == VAR_STRING) | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6633 { |
12502 | 6634 cmd = argvar->vval.v_string; |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6635 } |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6636 else if (argvar->v_type == VAR_LIST) |
12502 | 6637 { |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6638 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
12502 | 6639 goto failed; |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6640 cmd = ga_cmd.ga_data; |
12502 | 6641 } |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6642 if (cmd == NULL || *cmd == NUL) |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6643 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6644 emsg(_(e_invarg)); |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6645 goto failed; |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6646 } |
12502 | 6647 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6648 term->tl_arg0_cmd = vim_strsave(cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6649 |
12502 | 6650 cmd_wchar = enc_to_utf16(cmd, NULL); |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6651 ga_clear(&ga_cmd); |
12502 | 6652 if (cmd_wchar == NULL) |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6653 goto failed; |
12502 | 6654 if (opt->jo_cwd != NULL) |
6655 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL); | |
12907
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12903
diff
changeset
|
6656 |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12903
diff
changeset
|
6657 win32_build_env(opt->jo_env, &ga_env, TRUE); |
32531a3eab1f
patch 8.0.1330: MS-Windows: job in terminal can't get back to Vim
Christian Brabandt <cb@256bit.org>
parents:
12903
diff
changeset
|
6658 env_wchar = ga_env.ga_data; |
12502 | 6659 |
6660 term->tl_winpty_config = winpty_config_new(0, &winpty_err); | |
6661 if (term->tl_winpty_config == NULL) | |
6662 goto failed; | |
6663 | |
6664 winpty_config_set_mouse_mode(term->tl_winpty_config, | |
6665 WINPTY_MOUSE_MODE_FORCE); | |
6666 winpty_config_set_initial_size(term->tl_winpty_config, | |
6667 term->tl_cols, term->tl_rows); | |
6668 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err); | |
6669 if (term->tl_winpty == NULL) | |
6670 goto failed; | |
6671 | |
6672 spawn_config = winpty_spawn_config_new( | |
6673 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN | | |
6674 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN, | |
6675 NULL, | |
6676 cmd_wchar, | |
6677 cwd_wchar, | |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6678 env_wchar, |
12502 | 6679 &winpty_err); |
6680 if (spawn_config == NULL) | |
6681 goto failed; | |
6682 | |
6683 channel = add_channel(); | |
6684 if (channel == NULL) | |
6685 goto failed; | |
6686 | |
6687 job = job_alloc(); | |
6688 if (job == NULL) | |
6689 goto failed; | |
13750
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6690 if (argvar->v_type == VAR_STRING) |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6691 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6692 int argc; |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6693 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6694 build_argv_from_string(cmd, &job->jv_argv, &argc); |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6695 } |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6696 else |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6697 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6698 int argc; |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6699 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6700 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc); |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6701 } |
12502 | 6702 |
6703 if (opt->jo_set & JO_IN_BUF) | |
6704 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); | |
6705 | |
6706 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle, | |
6707 &child_thread_handle, &error, &winpty_err)) | |
6708 goto failed; | |
6709 | |
6710 channel_set_pipes(channel, | |
6711 (sock_T)CreateFileW( | |
6712 winpty_conin_name(term->tl_winpty), | |
6713 GENERIC_WRITE, 0, NULL, | |
6714 OPEN_EXISTING, 0, NULL), | |
6715 (sock_T)CreateFileW( | |
6716 winpty_conout_name(term->tl_winpty), | |
6717 GENERIC_READ, 0, NULL, | |
6718 OPEN_EXISTING, 0, NULL), | |
6719 (sock_T)CreateFileW( | |
6720 winpty_conerr_name(term->tl_winpty), | |
6721 GENERIC_READ, 0, NULL, | |
6722 OPEN_EXISTING, 0, NULL)); | |
6723 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6724 // Write lines with CR instead of NL. |
12502 | 6725 channel->ch_write_text_mode = TRUE; |
6726 | |
6727 jo = CreateJobObject(NULL, NULL); | |
6728 if (jo == NULL) | |
6729 goto failed; | |
6730 | |
6731 if (!AssignProcessToJobObject(jo, child_process_handle)) | |
6732 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6733 // Failed, switch the way to terminate process with TerminateProcess. |
12502 | 6734 CloseHandle(jo); |
6735 jo = NULL; | |
6736 } | |
6737 | |
6738 winpty_spawn_config_free(spawn_config); | |
6739 vim_free(cmd_wchar); | |
6740 vim_free(cwd_wchar); | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6741 vim_free(env_wchar); |
12502 | 6742 |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6743 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6744 goto failed; |
12502 | 6745 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6746 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6747 if (opt->jo_set2 & JO2_ANSI_COLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6748 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6749 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6750 init_vterm_ansi_colors(term->tl_vterm); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6751 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6752 |
12502 | 6753 channel_set_job(channel, job, opt); |
6754 job_set_options(job, opt); | |
6755 | |
6756 job->jv_channel = channel; | |
6757 job->jv_proc_info.hProcess = child_process_handle; | |
6758 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle); | |
6759 job->jv_job_object = jo; | |
6760 job->jv_status = JOB_STARTED; | |
6761 job->jv_tty_in = utf16_to_enc( | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6762 (short_u *)winpty_conin_name(term->tl_winpty), NULL); |
12502 | 6763 job->jv_tty_out = utf16_to_enc( |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6764 (short_u *)winpty_conout_name(term->tl_winpty), NULL); |
15810
5523665fdf80
patch 8.1.0912: MS-Windows: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
6765 job->jv_tty_type = vim_strsave((char_u *)"winpty"); |
12502 | 6766 ++job->jv_refcount; |
6767 term->tl_job = job; | |
6768 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6769 // Redirecting stdout and stderr doesn't work at the job level. Instead |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6770 // open the file here and handle it in. opt->jo_io was changed in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6771 // setup_job_options(), use the original flags here. |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6772 if (orig_opt->jo_io[PART_OUT] == JIO_FILE) |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6773 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6774 char_u *fname = opt->jo_io_name[PART_OUT]; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6775 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6776 ch_log(channel, "Opening output file %s", fname); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6777 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6778 if (term->tl_out_fd == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6779 semsg(_(e_notopen), fname); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6780 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6781 |
12502 | 6782 return OK; |
6783 | |
6784 failed: | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6785 ga_clear(&ga_cmd); |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6786 ga_clear(&ga_env); |
12502 | 6787 vim_free(cmd_wchar); |
6788 vim_free(cwd_wchar); | |
6789 if (spawn_config != NULL) | |
6790 winpty_spawn_config_free(spawn_config); | |
6791 if (channel != NULL) | |
6792 channel_clear(channel); | |
6793 if (job != NULL) | |
6794 { | |
6795 job->jv_channel = NULL; | |
6796 job_cleanup(job); | |
6797 } | |
6798 term->tl_job = NULL; | |
6799 if (jo != NULL) | |
6800 CloseHandle(jo); | |
6801 if (term->tl_winpty != NULL) | |
6802 winpty_free(term->tl_winpty); | |
6803 term->tl_winpty = NULL; | |
6804 if (term->tl_winpty_config != NULL) | |
6805 winpty_config_free(term->tl_winpty_config); | |
6806 term->tl_winpty_config = NULL; | |
6807 if (winpty_err != NULL) | |
6808 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6809 char *msg = (char *)utf16_to_enc( |
12502 | 6810 (short_u *)winpty_error_msg(winpty_err), NULL); |
6811 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6812 emsg(msg); |
12502 | 6813 winpty_error_free(winpty_err); |
6814 } | |
6815 return FAIL; | |
6816 } | |
6817 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6818 /* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6819 * Create a new terminal of "rows" by "cols" cells. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6820 * Store a reference in "term". |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6821 * Return OK or FAIL. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6822 */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6823 static int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6824 term_and_job_init( |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6825 term_T *term, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6826 typval_T *argvar, |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
6827 char **argv, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6828 jobopt_T *opt, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6829 jobopt_T *orig_opt) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6830 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6831 int use_winpty = FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6832 int use_conpty = FALSE; |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6833 int tty_type = *p_twt; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6834 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6835 has_winpty = dyn_winpty_init(FALSE) != FAIL ? TRUE : FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6836 has_conpty = dyn_conpty_init(FALSE) != FAIL ? TRUE : FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6837 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6838 if (!has_winpty && !has_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6839 // If neither is available give the errors for winpty, since when |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6840 // conpty is not available it can't be installed either. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6841 return dyn_winpty_init(TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6842 |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6843 if (opt->jo_tty_type != NUL) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6844 tty_type = opt->jo_tty_type; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6845 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6846 if (tty_type == NUL) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6847 { |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15786
diff
changeset
|
6848 if (has_conpty && (is_conpty_stable() || !has_winpty)) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6849 use_conpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6850 else if (has_winpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6851 use_winpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6852 // else: error |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6853 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6854 else if (tty_type == 'w') // winpty |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6855 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6856 if (has_winpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6857 use_winpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6858 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6859 else if (tty_type == 'c') // conpty |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6860 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6861 if (has_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6862 use_conpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6863 else |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6864 return dyn_conpty_init(TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6865 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6866 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6867 if (use_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6868 return conpty_term_and_job_init(term, argvar, argv, opt, orig_opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6869 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6870 if (use_winpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6871 return winpty_term_and_job_init(term, argvar, argv, opt, orig_opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6872 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6873 // error |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6874 return dyn_winpty_init(TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6875 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6876 |
12502 | 6877 static int |
6878 create_pty_only(term_T *term, jobopt_T *options) | |
6879 { | |
6880 HANDLE hPipeIn = INVALID_HANDLE_VALUE; | |
6881 HANDLE hPipeOut = INVALID_HANDLE_VALUE; | |
6882 char in_name[80], out_name[80]; | |
6883 channel_T *channel = NULL; | |
6884 | |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6885 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6886 return FAIL; |
12502 | 6887 |
6888 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d", | |
6889 GetCurrentProcessId(), | |
6890 curbuf->b_fnum); | |
6891 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND, | |
6892 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
6893 PIPE_UNLIMITED_INSTANCES, | |
6894 0, 0, NMPWAIT_NOWAIT, NULL); | |
6895 if (hPipeIn == INVALID_HANDLE_VALUE) | |
6896 goto failed; | |
6897 | |
6898 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d", | |
6899 GetCurrentProcessId(), | |
6900 curbuf->b_fnum); | |
6901 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND, | |
6902 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
6903 PIPE_UNLIMITED_INSTANCES, | |
6904 0, 0, 0, NULL); | |
6905 if (hPipeOut == INVALID_HANDLE_VALUE) | |
6906 goto failed; | |
6907 | |
6908 ConnectNamedPipe(hPipeIn, NULL); | |
6909 ConnectNamedPipe(hPipeOut, NULL); | |
6910 | |
6911 term->tl_job = job_alloc(); | |
6912 if (term->tl_job == NULL) | |
6913 goto failed; | |
6914 ++term->tl_job->jv_refcount; | |
6915 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6916 // behave like the job is already finished |
12502 | 6917 term->tl_job->jv_status = JOB_FINISHED; |
6918 | |
6919 channel = add_channel(); | |
6920 if (channel == NULL) | |
6921 goto failed; | |
6922 term->tl_job->jv_channel = channel; | |
6923 channel->ch_keep_open = TRUE; | |
6924 channel->ch_named_pipe = TRUE; | |
6925 | |
6926 channel_set_pipes(channel, | |
6927 (sock_T)hPipeIn, | |
6928 (sock_T)hPipeOut, | |
6929 (sock_T)hPipeOut); | |
6930 channel_set_job(channel, term->tl_job, options); | |
6931 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name); | |
6932 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name); | |
6933 | |
6934 return OK; | |
6935 | |
6936 failed: | |
6937 if (hPipeIn != NULL) | |
6938 CloseHandle(hPipeIn); | |
6939 if (hPipeOut != NULL) | |
6940 CloseHandle(hPipeOut); | |
6941 return FAIL; | |
6942 } | |
6943 | |
6944 /* | |
6945 * Free the terminal emulator part of "term". | |
6946 */ | |
6947 static void | |
6948 term_free_vterm(term_T *term) | |
6949 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6950 term_free_conpty(term); |
12502 | 6951 if (term->tl_winpty != NULL) |
6952 winpty_free(term->tl_winpty); | |
6953 term->tl_winpty = NULL; | |
6954 if (term->tl_winpty_config != NULL) | |
6955 winpty_config_free(term->tl_winpty_config); | |
6956 term->tl_winpty_config = NULL; | |
6957 if (term->tl_vterm != NULL) | |
6958 vterm_free(term->tl_vterm); | |
6959 term->tl_vterm = NULL; | |
6960 } | |
6961 | |
6962 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6963 * Report the size to the terminal. |
12502 | 6964 */ |
6965 static void | |
6966 term_report_winsize(term_T *term, int rows, int cols) | |
6967 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6968 if (term->tl_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6969 conpty_term_report_winsize(term, rows, cols); |
12502 | 6970 if (term->tl_winpty) |
6971 winpty_set_size(term->tl_winpty, cols, rows, NULL); | |
6972 } | |
6973 | |
6974 int | |
6975 terminal_enabled(void) | |
6976 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6977 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK; |
12502 | 6978 } |
6979 | |
6980 # else | |
6981 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6982 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6983 // 3. Unix-like implementation. |
12502 | 6984 |
6985 /* | |
6986 * Create a new terminal of "rows" by "cols" cells. | |
6987 * Start job for "cmd". | |
6988 * Store the pointers in "term". | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6989 * When "argv" is not NULL then "argvar" is not used. |
12502 | 6990 * Return OK or FAIL. |
6991 */ | |
6992 static int | |
6993 term_and_job_init( | |
6994 term_T *term, | |
6995 typval_T *argvar, | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6996 char **argv, |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6997 jobopt_T *opt, |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6998 jobopt_T *orig_opt UNUSED) |
12502 | 6999 { |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7000 term->tl_arg0_cmd = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7001 |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
7002 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
7003 return FAIL; |
12502 | 7004 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7005 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7006 if (opt->jo_set2 & JO2_ANSI_COLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7007 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7008 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7009 init_vterm_ansi_colors(term->tl_vterm); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7010 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7011 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7012 // This may change a string in "argvar". |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
7013 term->tl_job = job_start(argvar, argv, opt, &term->tl_job); |
12502 | 7014 if (term->tl_job != NULL) |
7015 ++term->tl_job->jv_refcount; | |
7016 | |
7017 return term->tl_job != NULL | |
7018 && term->tl_job->jv_channel != NULL | |
7019 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL; | |
7020 } | |
7021 | |
7022 static int | |
7023 create_pty_only(term_T *term, jobopt_T *opt) | |
7024 { | |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
7025 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
7026 return FAIL; |
12502 | 7027 |
7028 term->tl_job = job_alloc(); | |
7029 if (term->tl_job == NULL) | |
7030 return FAIL; | |
7031 ++term->tl_job->jv_refcount; | |
7032 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7033 // behave like the job is already finished |
12502 | 7034 term->tl_job->jv_status = JOB_FINISHED; |
7035 | |
7036 return mch_create_pty_channel(term->tl_job, opt); | |
7037 } | |
7038 | |
7039 /* | |
7040 * Free the terminal emulator part of "term". | |
7041 */ | |
7042 static void | |
7043 term_free_vterm(term_T *term) | |
7044 { | |
7045 if (term->tl_vterm != NULL) | |
7046 vterm_free(term->tl_vterm); | |
7047 term->tl_vterm = NULL; | |
7048 } | |
7049 | |
7050 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7051 * Report the size to the terminal. |
12502 | 7052 */ |
7053 static void | |
7054 term_report_winsize(term_T *term, int rows, int cols) | |
7055 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7056 // Use an ioctl() to report the new window size to the job. |
12502 | 7057 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) |
7058 { | |
7059 int fd = -1; | |
7060 int part; | |
7061 | |
7062 for (part = PART_OUT; part < PART_COUNT; ++part) | |
7063 { | |
7064 fd = term->tl_job->jv_channel->ch_part[part].ch_fd; | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7065 if (mch_isatty(fd)) |
12502 | 7066 break; |
7067 } | |
7068 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) | |
7069 mch_signal_job(term->tl_job, (char_u *)"winch"); | |
7070 } | |
7071 } | |
7072 | |
7073 # endif | |
7074 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7075 #endif // FEAT_TERMINAL |