Mercurial > vim
annotate src/terminal.c @ 24908:f2d35a98ae9c
Added tag v8.2.2991 for changeset 8388176a09541a12dccd42652a6fa0761592e1d3
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 13 Jun 2021 17:30:03 +0200 |
parents | 7334bf933510 |
children | eafc0e07b188 |
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 | |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
283 set_term_and_win_size(term_T *term, jobopt_T *opt) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
284 { |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
285 int rows, cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
286 int minsize; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
287 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
288 #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
|
289 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
|
290 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
291 // 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
|
292 // 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
|
293 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
|
294 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
|
295 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
|
296 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
297 #endif |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
298 term->tl_rows = curwin->w_height; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
299 term->tl_cols = curwin->w_width; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
300 |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
301 minsize = parse_termwinsize(curwin, &rows, &cols); |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
302 if (minsize) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
303 { |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
304 if (term->tl_rows < rows) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
305 term->tl_rows = rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
306 if (term->tl_cols < cols) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
307 term->tl_cols = cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
308 } |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
309 if ((opt->jo_set2 & JO2_TERM_ROWS)) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
310 term->tl_rows = opt->jo_term_rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
311 else if (rows != 0) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
312 term->tl_rows = rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
313 if ((opt->jo_set2 & JO2_TERM_COLS)) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
314 term->tl_cols = opt->jo_term_cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
315 else if (cols != 0) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
316 term->tl_cols = cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
317 |
22097
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
318 if (!opt->jo_hidden) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
319 { |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
320 if (term->tl_rows != curwin->w_height) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
321 win_setheight_win(term->tl_rows, curwin); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
322 if (term->tl_cols != curwin->w_width) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
323 win_setwidth_win(term->tl_cols, curwin); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
324 |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
325 // Set 'winsize' now to avoid a resize at the next redraw. |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
326 if (!minsize && *curwin->w_p_tws != NUL) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
327 { |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
328 char_u buf[100]; |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
329 |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
330 vim_snprintf((char *)buf, 100, "%dx%d", |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
331 term->tl_rows, term->tl_cols); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
332 set_option_value((char_u *)"termwinsize", 0L, buf, OPT_LOCAL); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
333 } |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
334 } |
12502 | 335 } |
336 | |
337 /* | |
338 * Initialize job options for a terminal job. | |
339 * Caller may overrule some of them. | |
340 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
341 void |
12502 | 342 init_job_options(jobopt_T *opt) |
343 { | |
344 clear_job_options(opt); | |
345 | |
346 opt->jo_mode = MODE_RAW; | |
347 opt->jo_out_mode = MODE_RAW; | |
348 opt->jo_err_mode = MODE_RAW; | |
349 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; | |
350 } | |
351 | |
352 /* | |
353 * Set job options mandatory for a terminal job. | |
354 */ | |
355 static void | |
356 setup_job_options(jobopt_T *opt, int rows, int cols) | |
357 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
358 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
359 // 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
|
360 // here. |
12502 | 361 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
|
362 #endif |
12502 | 363 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
364 // Connect stdout to the terminal. |
12502 | 365 opt->jo_io[PART_OUT] = JIO_BUFFER; |
366 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; | |
367 opt->jo_modifiable[PART_OUT] = 0; | |
368 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE; | |
369 } | |
370 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
371 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
372 // 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
|
373 // here. |
12502 | 374 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
|
375 #endif |
12502 | 376 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
377 // Connect stderr to the terminal. |
12502 | 378 opt->jo_io[PART_ERR] = JIO_BUFFER; |
379 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; | |
380 opt->jo_modifiable[PART_ERR] = 0; | |
381 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE; | |
382 } | |
383 | |
384 opt->jo_pty = TRUE; | |
385 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0) | |
386 opt->jo_term_rows = rows; | |
387 if ((opt->jo_set2 & JO2_TERM_COLS) == 0) | |
388 opt->jo_term_cols = cols; | |
389 } | |
390 | |
391 /* | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
392 * Flush messages on channels. |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
393 */ |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
394 static void |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
395 term_flush_messages() |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
396 { |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
397 mch_check_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
398 parse_queued_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
399 } |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
400 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
401 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
402 * 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
|
403 * fails. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
404 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
405 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
406 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
|
407 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
408 free_terminal(buf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
409 if (old_curbuf != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
410 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
411 --curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
412 curbuf = old_curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
413 curwin->w_buffer = curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
414 ++curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
415 } |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19542
diff
changeset
|
416 CHECK_CURBUF; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
417 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
418 // 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
|
419 // free_terminal(). |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
420 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
|
421 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
422 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
423 /* |
12502 | 424 * 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
|
425 * 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
|
426 * 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
|
427 * the window. |
12502 | 428 * Returns NULL when failed. |
429 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 int flags) |
12502 | 436 { |
437 exarg_T split_ea; | |
438 win_T *old_curwin = curwin; | |
439 term_T *term; | |
440 buf_T *old_curbuf = NULL; | |
441 int res; | |
442 buf_T *newbuf; | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
443 int vertical = opt->jo_vertical || (cmdmod.cmod_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
|
444 jobopt_T orig_opt; // only partly filled |
12502 | 445 |
446 if (check_restricted() || check_secure()) | |
447 return NULL; | |
24739
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
448 #ifdef FEAT_CMDWIN |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
449 if (cmdwin_type != 0) |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
450 { |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
451 emsg(_(e_cannot_open_terminal_from_command_line_window)); |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
452 return NULL; |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
453 } |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
454 #endif |
12502 | 455 |
456 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)) | |
457 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO) | |
458 || (!(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
|
459 || (!(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
|
460 || (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
|
461 && 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
|
462 && 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
|
463 && argvar->vval.v_list->lv_first == &range_list_item)) |
12502 | 464 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
465 emsg(_(e_invarg)); |
12502 | 466 return NULL; |
467 } | |
468 | |
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
|
469 term = ALLOC_CLEAR_ONE(term_T); |
12502 | 470 if (term == NULL) |
471 return NULL; | |
472 term->tl_dirty_row_end = MAX_ROW; | |
473 term->tl_cursor_visible = TRUE; | |
474 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | |
475 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
|
476 #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
|
477 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
|
478 #endif |
12502 | 479 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
|
480 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
|
481 ga_init2(&term->tl_osc_buf, sizeof(char), 300); |
12502 | 482 |
24557
7a4cc4d3a40a
patch 8.2.2818: no jump added when opening terminal in current window
Bram Moolenaar <Bram@vim.org>
parents:
24268
diff
changeset
|
483 setpcmark(); |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
484 CLEAR_FIELD(split_ea); |
12502 | 485 if (opt->jo_curwin) |
486 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
487 // 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
|
488 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT)) |
12502 | 489 { |
490 no_write_message(); | |
491 vim_free(term); | |
492 return NULL; | |
493 } | |
494 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
|
495 (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
|
496 + ((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
|
497 curwin) == FAIL) |
12502 | 498 { |
499 vim_free(term); | |
500 return NULL; | |
501 } | |
502 } | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
503 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM)) |
12502 | 504 { |
505 buf_T *buf; | |
506 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
507 // 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
|
508 // a moment to be able to do the initializations. |
12502 | 509 buf = buflist_new((char_u *)"", NULL, (linenr_T)0, |
510 BLN_NEW | BLN_LISTED); | |
511 if (buf == NULL || ml_open(buf) == FAIL) | |
512 { | |
513 vim_free(term); | |
514 return NULL; | |
515 } | |
516 old_curbuf = curbuf; | |
517 --curbuf->b_nwindows; | |
518 curbuf = buf; | |
519 curwin->w_buffer = buf; | |
520 ++curbuf->b_nwindows; | |
521 } | |
522 else | |
523 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
524 // Open a new window or tab. |
12502 | 525 split_ea.cmdidx = CMD_new; |
526 split_ea.cmd = (char_u *)"new"; | |
527 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
|
528 if (opt->jo_term_rows > 0 && !vertical) |
12502 | 529 { |
530 split_ea.line2 = opt->jo_term_rows; | |
531 split_ea.addr_count = 1; | |
532 } | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
533 if (opt->jo_term_cols > 0 && vertical) |
12502 | 534 { |
535 split_ea.line2 = opt->jo_term_cols; | |
536 split_ea.addr_count = 1; | |
537 } | |
538 | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
539 if (vertical) |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
540 cmdmod.cmod_split |= WSP_VERT; |
12502 | 541 ex_splitview(&split_ea); |
542 if (curwin == old_curwin) | |
543 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
544 // split failed |
12502 | 545 vim_free(term); |
546 return NULL; | |
547 } | |
548 } | |
549 term->tl_buffer = curbuf; | |
550 curbuf->b_term = term; | |
551 | |
552 if (!opt->jo_hidden) | |
553 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
554 // 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
|
555 // "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
|
556 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical)) |
12502 | 557 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
|
558 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical)) |
12502 | 559 win_setwidth(opt->jo_term_cols); |
560 } | |
561 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
562 // Link the new terminal in the list of active terminals. |
12502 | 563 term->tl_next = first_term; |
564 first_term = term; | |
565 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
566 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
|
567 |
12502 | 568 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
|
569 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
570 vim_free(curbuf->b_ffname); |
12502 | 571 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
|
572 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
573 else if (argv != NULL) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
574 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
575 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
|
576 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
|
577 } |
12502 | 578 else |
579 { | |
580 int i; | |
581 size_t len; | |
582 char_u *cmd, *p; | |
583 | |
584 if (argvar->v_type == VAR_STRING) | |
585 { | |
586 cmd = argvar->vval.v_string; | |
587 if (cmd == NULL) | |
588 cmd = (char_u *)""; | |
589 else if (STRCMP(cmd, "NONE") == 0) | |
590 cmd = (char_u *)"pty"; | |
591 } | |
592 else if (argvar->v_type != VAR_LIST | |
593 || 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
|
594 || 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
|
595 || (cmd = tv_get_string_chk( |
12502 | 596 &argvar->vval.v_list->lv_first->li_tv)) == NULL) |
597 cmd = (char_u*)""; | |
598 | |
599 len = STRLEN(cmd) + 10; | |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
600 p = alloc(len); |
12502 | 601 |
602 for (i = 0; p != NULL; ++i) | |
603 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
604 // 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
|
605 // the executable, otherwise ":w!" would overwrite it. |
12502 | 606 if (i == 0) |
607 vim_snprintf((char *)p, len, "!%s", cmd); | |
608 else | |
609 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i); | |
610 if (buflist_findname(p) == NULL) | |
611 { | |
612 vim_free(curbuf->b_ffname); | |
613 curbuf->b_ffname = p; | |
614 break; | |
615 } | |
616 } | |
617 } | |
19513
274052873790
patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
19358
diff
changeset
|
618 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
|
619 curbuf->b_sfname = vim_strsave(curbuf->b_ffname); |
12502 | 620 curbuf->b_fname = curbuf->b_ffname; |
621 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
622 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
|
623 |
12502 | 624 if (opt->jo_term_opencmd != NULL) |
625 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); | |
626 | |
627 if (opt->jo_eof_chars != NULL) | |
628 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); | |
629 | |
630 set_string_option_direct((char_u *)"buftype", -1, | |
631 (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
|
632 // 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
|
633 curbuf->b_p_initialized = TRUE; |
12502 | 634 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
635 // 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
|
636 // the job finished. |
12502 | 637 curbuf->b_p_ma = FALSE; |
638 | |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
639 set_term_and_win_size(term, opt); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
640 #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
|
641 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
|
642 #endif |
12502 | 643 setup_job_options(opt, term->tl_rows, term->tl_cols); |
644 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
645 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
|
646 return curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
647 |
13435
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 defined(FEAT_SESSION) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
649 // 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
|
650 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
|
651 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
|
652 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
|
653 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
654 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
|
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 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
|
657 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
|
658 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
659 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
|
660 && 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
|
661 && 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
|
662 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
663 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
|
664 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
|
665 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
666 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
|
667 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
|
668 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
669 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
|
670 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
|
671 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
672 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
|
673 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
674 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
|
675 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
|
676 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
677 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
|
678 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
|
679 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
|
680 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
681 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
|
682 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
683 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
|
684 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
|
685 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
686 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
687 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
|
688 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
689 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
690 |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
691 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
|
692 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
693 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
|
694 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
695 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
|
696 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
697 |
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
|
698 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
|
699 { |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
700 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
|
701 |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
702 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
|
703 } |
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
|
704 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
|
705 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
|
706 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
707 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
|
708 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
|
709 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
710 // 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
|
711 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
|
712 && argvar->v_type == VAR_STRING |
12502 | 713 && argvar->vval.v_string != NULL |
714 && STRCMP(argvar->vval.v_string, "NONE") == 0) | |
715 res = create_pty_only(term, opt); | |
716 else | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
717 res = term_and_job_init(term, argvar, argv, opt, &orig_opt); |
12502 | 718 |
719 newbuf = curbuf; | |
720 if (res == OK) | |
721 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
722 // Get and remember the size we ended up with. Update the pty. |
12502 | 723 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); |
724 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
|
725 #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
|
726 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
|
727 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
728 // 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
|
729 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
|
730 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
|
731 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
732 #endif |
12502 | 733 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
734 // 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
|
735 // a deadlock if the job is waiting for Vim to read. |
12502 | 736 channel_set_nonblock(term->tl_job->jv_channel, PART_IN); |
737 | |
13835
8e583c52eb44
patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13829
diff
changeset
|
738 if (old_curbuf != NULL) |
12502 | 739 { |
740 --curbuf->b_nwindows; | |
741 curbuf = old_curbuf; | |
742 curwin->w_buffer = curbuf; | |
743 ++curbuf->b_nwindows; | |
744 } | |
745 } | |
746 else | |
747 { | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
748 term_close_buffer(curbuf, old_curbuf); |
12502 | 749 return NULL; |
750 } | |
13444
9f06f7aca74c
patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
751 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
752 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
|
753 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
|
754 apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf); |
12502 | 755 return newbuf; |
756 } | |
757 | |
758 /* | |
759 * ":terminal": open a terminal window and execute a job in it. | |
760 */ | |
761 void | |
762 ex_terminal(exarg_T *eap) | |
763 { | |
764 typval_T argvar[2]; | |
765 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
|
766 int opt_shell = FALSE; |
12502 | 767 char_u *cmd; |
768 char_u *tofree = NULL; | |
769 | |
770 init_job_options(&opt); | |
771 | |
772 cmd = eap->arg; | |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
773 while (*cmd == '+' && *(cmd + 1) == '+') |
12502 | 774 { |
775 char_u *p, *ep; | |
776 | |
777 cmd += 2; | |
778 p = skiptowhite(cmd); | |
779 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
|
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 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
|
783 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
|
784 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
|
785 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
|
786 } |
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 # 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
|
789 && 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
|
790 if (OPTARG_HAS("close")) |
12502 | 791 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
|
792 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
|
793 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
|
794 else if (OPTARG_HAS("open")) |
12502 | 795 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
|
796 else if (OPTARG_HAS("curwin")) |
12502 | 797 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
|
798 else if (OPTARG_HAS("hidden")) |
12502 | 799 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
806 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
|
807 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
|
808 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
|
809 } |
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
|
810 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
|
811 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
812 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
|
813 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
|
814 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
815 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
|
816 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
|
817 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
818 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
|
819 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
|
820 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
821 else if (OPTARG_HAS("rows") && ep != NULL && isdigit(ep[1])) |
12502 | 822 { |
823 opt.jo_set2 |= JO2_TERM_ROWS; | |
824 opt.jo_term_rows = atoi((char *)ep + 1); | |
825 p = skiptowhite(cmd); | |
826 } | |
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
|
827 else if (OPTARG_HAS("cols") && ep != NULL && isdigit(ep[1])) |
12502 | 828 { |
829 opt.jo_set2 |= JO2_TERM_COLS; | |
830 opt.jo_term_cols = atoi((char *)ep + 1); | |
831 p = skiptowhite(cmd); | |
832 } | |
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
|
833 else if (OPTARG_HAS("eof") && ep != NULL) |
12502 | 834 { |
835 char_u *buf = NULL; | |
836 char_u *keys; | |
837 | |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
838 vim_free(opt.jo_eof_chars); |
12502 | 839 p = skiptowhite(cmd); |
840 *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
|
841 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
|
842 REPTERM_FROM_PART | REPTERM_DO_LT | REPTERM_SPECIAL, NULL); |
12502 | 843 opt.jo_set2 |= JO2_EOF_CHARS; |
844 opt.jo_eof_chars = vim_strsave(keys); | |
845 vim_free(buf); | |
846 *p = ' '; | |
847 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
848 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
849 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
|
850 && 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
|
851 { |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
852 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
|
853 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
854 p = skiptowhite(cmd); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
855 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
|
856 tty_type = 'w'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
857 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
|
858 tty_type = 'c'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
859 else |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
860 { |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
861 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
|
862 goto theend; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
863 } |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
864 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
|
865 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
|
866 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
867 #endif |
12502 | 868 else |
869 { | |
870 if (*p) | |
871 *p = NUL; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
872 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
|
873 goto theend; |
12502 | 874 } |
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
|
875 # undef OPTARG_HAS |
12502 | 876 cmd = skipwhite(p); |
877 } | |
878 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
|
879 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
880 // Make a copy of 'shell', an autocommand may change the option. |
12502 | 881 tofree = cmd = vim_strsave(p_sh); |
882 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
883 // 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
|
884 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
|
885 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
|
886 } |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
887 |
12502 | 888 if (eap->addr_count > 0) |
889 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
890 // Write lines from current buffer to the job. |
12502 | 891 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; |
892 opt.jo_io[PART_IN] = JIO_BUFFER; | |
893 opt.jo_io_buf[PART_IN] = curbuf->b_fnum; | |
894 opt.jo_in_top = eap->line1; | |
895 opt.jo_in_bot = eap->line2; | |
896 } | |
897 | |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
898 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
|
899 { |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
900 #ifdef UNIX |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
901 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
|
902 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
|
903 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
|
904 |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
905 // :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
|
906 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
|
907 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
|
908 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
|
909 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
|
910 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
|
911 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
|
912 #else |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
913 # ifdef MSWIN |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
914 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
|
915 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
|
916 |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
917 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
|
918 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
|
919 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
920 tofree = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
921 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
|
922 cmd = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
923 # else |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
924 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
|
925 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
926 # endif |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
927 #endif |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
928 } |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
929 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
|
930 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
|
931 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
|
932 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
|
933 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
934 theend: |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
935 vim_free(tofree); |
12502 | 936 vim_free(opt.jo_eof_chars); |
937 } | |
938 | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
939 #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
|
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 * 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
|
942 * 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
|
943 * 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
|
944 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
945 int |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
946 term_write_session(FILE *fd, win_T *wp, hashtab_T *terminal_bufs) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
947 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
948 const int bufnr = wp->w_buffer->b_fnum; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
949 term_T *term = wp->w_buffer->b_term; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
950 |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
951 if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
952 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
953 // There are multiple views into this terminal buffer. We don't want to |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
954 // create the terminal multiple times. If it's the first time, create, |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
955 // otherwise link to the first buffer. |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
956 char id_as_str[NUMBUFLEN]; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
957 hashitem_T *entry; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
958 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
959 vim_snprintf(id_as_str, sizeof(id_as_str), "%d", bufnr); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
960 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
961 entry = hash_find(terminal_bufs, (char_u *)id_as_str); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
962 if (!HASHITEM_EMPTY(entry)) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
963 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
964 // we've already opened this terminal buffer |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
965 if (fprintf(fd, "execute 'buffer ' . s:term_buf_%d", bufnr) < 0) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
966 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
967 return put_eol(fd); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
968 } |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
969 } |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
970 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
971 // 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
|
972 // 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
|
973 // 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
|
974 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
|
975 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
|
976 return FAIL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
977 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
978 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
|
979 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
|
980 #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
|
981 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
|
982 return FAIL; |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
983 if (put_eol(fd) != OK) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
984 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
985 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
986 if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
987 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
988 |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
989 if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
990 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
991 char *hash_key = alloc(NUMBUFLEN); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
992 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
993 vim_snprintf(hash_key, NUMBUFLEN, "%d", bufnr); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
994 hash_add(terminal_bufs, (char_u *)hash_key); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
995 } |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
996 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
997 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
|
998 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
999 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1000 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1001 * 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
|
1002 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1003 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1004 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
|
1005 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1006 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
|
1007 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1008 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
|
1009 || 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
|
1010 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1011 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1012 |
12502 | 1013 /* |
1014 * Free the scrollback buffer for "term". | |
1015 */ | |
1016 static void | |
1017 free_scrollback(term_T *term) | |
1018 { | |
1019 int i; | |
1020 | |
1021 for (i = 0; i < term->tl_scrollback.ga_len; ++i) | |
1022 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); | |
1023 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
|
1024 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
|
1025 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
|
1026 ga_clear(&term->tl_scrollback_postponed); |
12502 | 1027 } |
1028 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1029 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1030 // 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
|
1031 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
|
1032 |
12502 | 1033 /* |
1034 * Free a terminal and everything it refers to. | |
1035 * Kills the job if there is one. | |
1036 * 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
|
1037 * 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
|
1038 * 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
|
1039 * referenced. |
12502 | 1040 */ |
1041 void | |
1042 free_terminal(buf_T *buf) | |
1043 { | |
1044 term_T *term = buf->b_term; | |
1045 term_T *tp; | |
1046 | |
1047 if (term == NULL) | |
1048 return; | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1049 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1050 // Unlink the terminal form the list of terminals. |
12502 | 1051 if (first_term == term) |
1052 first_term = term->tl_next; | |
1053 else | |
1054 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next) | |
1055 if (tp->tl_next == term) | |
1056 { | |
1057 tp->tl_next = term->tl_next; | |
1058 break; | |
1059 } | |
1060 | |
1061 if (term->tl_job != NULL) | |
1062 { | |
1063 if (term->tl_job->jv_status != JOB_ENDED | |
1064 && 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
|
1065 && term->tl_job->jv_status != JOB_FAILED) |
12502 | 1066 job_stop(term->tl_job, NULL, "kill"); |
1067 job_unref(term->tl_job); | |
1068 } | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1069 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
|
1070 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
|
1071 |
12502 | 1072 buf->b_term = NULL; |
1073 if (in_terminal_loop == term) | |
1074 in_terminal_loop = NULL; | |
1075 } | |
1076 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1077 void |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1078 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
|
1079 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1080 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
|
1081 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1082 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
|
1083 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1084 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
|
1085 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1086 free_scrollback(term); |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
1087 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
|
1088 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1089 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
|
1090 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
|
1091 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
|
1092 #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
|
1093 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
|
1094 #endif |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 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
|
1100 #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
|
1101 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
|
1102 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
|
1103 #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
|
1104 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
|
1105 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
|
1106 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
|
1107 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1108 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1109 |
12502 | 1110 /* |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1111 * 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
|
1112 * 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
|
1113 * 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
|
1114 */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1115 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
|
1116 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
|
1117 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1118 #ifdef UNIX |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1119 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
|
1120 int i; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1121 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1122 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
|
1123 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1124 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
|
1125 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1126 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
|
1127 return parts[i]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1128 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1129 #endif |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1130 return PART_IN; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1131 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1132 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1133 /* |
12502 | 1134 * Write job output "msg[len]" to the vterm. |
1135 */ | |
1136 static void | |
1137 term_write_job_output(term_T *term, char_u *msg, size_t len) | |
1138 { | |
1139 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
|
1140 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
|
1141 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1142 vterm_input_write(vterm, (char *)msg, len); |
12502 | 1143 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1144 // 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
|
1145 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
|
1146 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1147 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
|
1148 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
|
1149 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1150 if (curlen > 0) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1151 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
|
1152 (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
|
1153 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1154 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1155 // this invokes the damage callbacks |
12502 | 1156 vterm_screen_flush_damage(vterm_obtain_screen(vterm)); |
1157 } | |
1158 | |
1159 static void | |
1160 update_cursor(term_T *term, int redraw) | |
1161 { | |
1162 if (term->tl_normal_mode) | |
1163 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
|
1164 #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
|
1165 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
|
1166 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
|
1167 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
|
1168 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1169 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1170 setcursor(); |
12502 | 1171 if (redraw) |
1172 { | |
1173 if (term->tl_buffer == curbuf && term->tl_cursor_visible) | |
1174 cursor_on(); | |
1175 out_flush(); | |
1176 #ifdef FEAT_GUI | |
1177 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
|
1178 { |
12502 | 1179 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
|
1180 gui_mch_flush(); |
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1181 } |
12502 | 1182 #endif |
1183 } | |
1184 } | |
1185 | |
1186 /* | |
1187 * Invoked when "msg" output from a job was received. Write it to the terminal | |
1188 * of "buffer". | |
1189 */ | |
1190 void | |
1191 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel) | |
1192 { | |
1193 size_t len = STRLEN(msg); | |
1194 term_T *term = buffer->b_term; | |
1195 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1196 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1197 // 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
|
1198 // 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
|
1199 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
|
1200 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1201 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
|
1202 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
|
1203 return; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1204 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1205 #endif |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1206 |
12502 | 1207 if (term->tl_vterm == NULL) |
1208 { | |
1209 ch_log(channel, "NOT writing %d bytes to terminal", (int)len); | |
1210 return; | |
1211 } | |
1212 ch_log(channel, "writing %d bytes to terminal", (int)len); | |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
1213 cursor_off(); |
12502 | 1214 term_write_job_output(term, msg, len); |
1215 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1216 #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
|
1217 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
|
1218 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1219 // 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
|
1220 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
|
1221 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
|
1222 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1223 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1224 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1225 // 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
|
1226 // contents, thus no screen update is needed. |
12502 | 1227 if (!term->tl_normal_mode) |
1228 { | |
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
|
1229 // 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
|
1230 // 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
|
1231 // TODO: only update once in a while. |
12502 | 1232 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
|
1233 if (buffer == curbuf && (State & CMDLINE) == 0) |
12502 | 1234 { |
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
|
1235 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
|
1236 // 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
|
1237 // already |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1238 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
|
1239 update_cursor(curbuf->b_term, TRUE); |
12502 | 1240 } |
1241 else | |
1242 redraw_after_callback(TRUE); | |
1243 } | |
1244 } | |
1245 | |
1246 /* | |
1247 * Send a mouse position and click to the vterm | |
1248 */ | |
1249 static int | |
1250 term_send_mouse(VTerm *vterm, int button, int pressed) | |
1251 { | |
1252 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
|
1253 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
|
1254 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
|
1255 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1256 #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
|
1257 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
|
1258 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1259 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
|
1260 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
|
1261 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1262 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1263 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
|
1264 if (button != 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1265 vterm_mouse_button(vterm, button, pressed, mod); |
12502 | 1266 return TRUE; |
1267 } | |
1268 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1269 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
|
1270 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
|
1271 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1272 /* |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1273 * 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
|
1274 * 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
|
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 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
|
1277 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
|
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 #if defined(FEAT_CLIPBOARD) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1280 // 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
|
1281 // 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
|
1282 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
|
1283 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
|
1284 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1285 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
|
1286 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
|
1287 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1288 // 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
|
1289 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
|
1290 { |
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_LEFTDRAG: |
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_LEFTRELEASE: |
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_RIGHTDRAG: |
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_RIGHTRELEASE: |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1295 // 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
|
1296 // 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
|
1297 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
|
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 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
|
1300 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1301 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
|
1302 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1303 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1304 // 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
|
1305 // 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
|
1306 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
|
1307 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
|
1308 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
|
1309 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
|
1310 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
|
1311 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
|
1312 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
|
1313 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1314 // 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
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 else |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1320 ignore_drag_release = FALSE; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1321 // 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
|
1322 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
|
1323 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1324 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
|
1325 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1326 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
|
1327 &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
|
1328 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
|
1329 && (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
|
1330 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1331 // 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
|
1332 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
|
1333 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
|
1334 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1335 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
|
1336 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1337 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1338 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1339 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
|
1340 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
|
1341 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
|
1342 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1343 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1344 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
|
1345 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
|
1346 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1347 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1348 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
|
1349 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1350 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
|
1351 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1352 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
|
1353 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
|
1354 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
|
1355 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
|
1356 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
|
1357 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
|
1358 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
|
1359 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
|
1360 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
|
1361 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
|
1362 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
|
1363 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
|
1364 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1365 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
|
1366 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1367 |
12502 | 1368 /* |
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
|
1369 * 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
|
1370 * job. |
12502 | 1371 * Return the number of bytes in "buf". |
1372 */ | |
1373 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
|
1374 term_convert_key(term_T *term, int c, int modmask, char *buf) |
12502 | 1375 { |
1376 VTerm *vterm = term->tl_vterm; | |
1377 VTermKey key = VTERM_KEY_NONE; | |
1378 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
|
1379 int other = FALSE; |
12502 | 1380 |
1381 switch (c) | |
1382 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1383 // 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
|
1384 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1385 // 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
|
1386 // becomes 0x7f DEL |
12502 | 1387 case K_BS: c = term_backspace_char; break; |
1388 | |
1389 case ESC: key = VTERM_KEY_ESCAPE; break; | |
1390 case K_DEL: key = VTERM_KEY_DEL; break; | |
1391 case K_DOWN: key = VTERM_KEY_DOWN; break; | |
1392 case K_S_DOWN: mod = VTERM_MOD_SHIFT; | |
1393 key = VTERM_KEY_DOWN; break; | |
1394 case K_END: key = VTERM_KEY_END; break; | |
1395 case K_S_END: mod = VTERM_MOD_SHIFT; | |
1396 key = VTERM_KEY_END; break; | |
1397 case K_C_END: mod = VTERM_MOD_CTRL; | |
1398 key = VTERM_KEY_END; break; | |
1399 case K_F10: key = VTERM_KEY_FUNCTION(10); break; | |
1400 case K_F11: key = VTERM_KEY_FUNCTION(11); break; | |
1401 case K_F12: key = VTERM_KEY_FUNCTION(12); break; | |
1402 case K_F1: key = VTERM_KEY_FUNCTION(1); break; | |
1403 case K_F2: key = VTERM_KEY_FUNCTION(2); break; | |
1404 case K_F3: key = VTERM_KEY_FUNCTION(3); break; | |
1405 case K_F4: key = VTERM_KEY_FUNCTION(4); break; | |
1406 case K_F5: key = VTERM_KEY_FUNCTION(5); break; | |
1407 case K_F6: key = VTERM_KEY_FUNCTION(6); break; | |
1408 case K_F7: key = VTERM_KEY_FUNCTION(7); break; | |
1409 case K_F8: key = VTERM_KEY_FUNCTION(8); break; | |
1410 case K_F9: key = VTERM_KEY_FUNCTION(9); break; | |
1411 case K_HOME: key = VTERM_KEY_HOME; break; | |
1412 case K_S_HOME: mod = VTERM_MOD_SHIFT; | |
1413 key = VTERM_KEY_HOME; break; | |
1414 case K_C_HOME: mod = VTERM_MOD_CTRL; | |
1415 key = VTERM_KEY_HOME; break; | |
1416 case K_INS: key = VTERM_KEY_INS; break; | |
1417 case K_K0: key = VTERM_KEY_KP_0; break; | |
1418 case K_K1: key = VTERM_KEY_KP_1; break; | |
1419 case K_K2: key = VTERM_KEY_KP_2; break; | |
1420 case K_K3: key = VTERM_KEY_KP_3; break; | |
1421 case K_K4: key = VTERM_KEY_KP_4; break; | |
1422 case K_K5: key = VTERM_KEY_KP_5; break; | |
1423 case K_K6: key = VTERM_KEY_KP_6; break; | |
1424 case K_K7: key = VTERM_KEY_KP_7; break; | |
1425 case K_K8: key = VTERM_KEY_KP_8; break; | |
1426 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
|
1427 case K_KDEL: key = VTERM_KEY_DEL; break; // TODO |
12502 | 1428 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
|
1429 case K_KEND: key = VTERM_KEY_KP_1; break; // TODO |
12502 | 1430 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
|
1431 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
|
1432 case K_KINS: key = VTERM_KEY_KP_0; break; // TODO |
12502 | 1433 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break; |
1434 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
|
1435 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
|
1436 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; // TODO |
12502 | 1437 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break; |
1438 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break; | |
1439 case K_LEFT: key = VTERM_KEY_LEFT; break; | |
1440 case K_S_LEFT: mod = VTERM_MOD_SHIFT; | |
1441 key = VTERM_KEY_LEFT; break; | |
1442 case K_C_LEFT: mod = VTERM_MOD_CTRL; | |
1443 key = VTERM_KEY_LEFT; break; | |
1444 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break; | |
1445 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break; | |
1446 case K_RIGHT: key = VTERM_KEY_RIGHT; break; | |
1447 case K_S_RIGHT: mod = VTERM_MOD_SHIFT; | |
1448 key = VTERM_KEY_RIGHT; break; | |
1449 case K_C_RIGHT: mod = VTERM_MOD_CTRL; | |
1450 key = VTERM_KEY_RIGHT; break; | |
1451 case K_UP: key = VTERM_KEY_UP; break; | |
1452 case K_S_UP: mod = VTERM_MOD_SHIFT; | |
1453 key = VTERM_KEY_UP; break; | |
1454 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
|
1455 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
|
1456 key = VTERM_KEY_TAB; break; |
12502 | 1457 |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1458 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
|
1459 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break; |
21114
d0265fdadec9
patch 8.2.1108: mouse left-right scroll is not supported in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1460 case K_MOUSELEFT: other = term_send_mouse(vterm, 7, 1); break; |
d0265fdadec9
patch 8.2.1108: mouse left-right scroll is not supported in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1461 case K_MOUSERIGHT: other = term_send_mouse(vterm, 6, 1); break; |
12502 | 1462 |
1463 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
|
1464 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
|
1465 case K_LEFTDRAG: |
12502 | 1466 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
|
1467 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
|
1468 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
|
1469 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
|
1470 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
|
1471 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
|
1472 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
|
1473 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
|
1474 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
|
1475 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
|
1476 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
|
1477 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1478 |
12502 | 1479 case K_X1MOUSE: /* TODO */ return 0; |
1480 case K_X1DRAG: /* TODO */ return 0; | |
1481 case K_X1RELEASE: /* TODO */ return 0; | |
1482 case K_X2MOUSE: /* TODO */ return 0; | |
1483 case K_X2DRAG: /* TODO */ return 0; | |
1484 case K_X2RELEASE: /* TODO */ return 0; | |
1485 | |
1486 case K_IGNORE: return 0; | |
1487 case K_NOP: return 0; | |
1488 case K_UNDO: return 0; | |
1489 case K_HELP: return 0; | |
1490 case K_XF1: key = VTERM_KEY_FUNCTION(1); break; | |
1491 case K_XF2: key = VTERM_KEY_FUNCTION(2); break; | |
1492 case K_XF3: key = VTERM_KEY_FUNCTION(3); break; | |
1493 case K_XF4: key = VTERM_KEY_FUNCTION(4); break; | |
1494 case K_SELECT: return 0; | |
1495 #ifdef FEAT_GUI | |
1496 case K_VER_SCROLLBAR: return 0; | |
1497 case K_HOR_SCROLLBAR: return 0; | |
1498 #endif | |
1499 #ifdef FEAT_GUI_TABLINE | |
1500 case K_TABLINE: return 0; | |
1501 case K_TABMENU: return 0; | |
1502 #endif | |
1503 #ifdef FEAT_NETBEANS_INTG | |
1504 case K_F21: key = VTERM_KEY_FUNCTION(21); break; | |
1505 #endif | |
1506 #ifdef FEAT_DND | |
1507 case K_DROP: return 0; | |
1508 #endif | |
1509 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
|
1510 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
|
1511 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
|
1512 break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1513 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
|
1514 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
|
1515 break; |
12502 | 1516 } |
1517 | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1518 // 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
|
1519 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
|
1520 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
|
1521 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
|
1522 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
|
1523 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
|
1524 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
|
1525 |
12502 | 1526 /* |
1527 * Convert special keys to vterm keys: | |
1528 * - Write keys to vterm: vterm_keyboard_key() | |
1529 * - Write output to channel. | |
1530 */ | |
1531 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
|
1532 // Special key, let vterm convert it. |
12502 | 1533 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
|
1534 else if (!other) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1535 // Normal character, let vterm convert it. |
12502 | 1536 vterm_keyboard_unichar(vterm, c, mod); |
1537 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1538 // Read back the converted escape sequence. |
12502 | 1539 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); |
1540 } | |
1541 | |
1542 /* | |
1543 * 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
|
1544 * 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
|
1545 * 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
|
1546 */ |
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
|
1547 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
|
1548 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
|
1549 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1550 // 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
|
1551 // 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
|
1552 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
|
1553 && 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
|
1554 && 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
|
1555 { |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1556 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
|
1557 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1558 // 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
|
1559 // 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
|
1560 // 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
|
1561 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
|
1562 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
|
1563 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
|
1564 || (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
|
1565 } |
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
|
1566 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
|
1567 } |
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
|
1568 |
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
|
1569 /* |
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
|
1570 * Return TRUE if the job for "term" is still running. |
12502 | 1571 */ |
1572 int | |
1573 term_job_running(term_T *term) | |
1574 { | |
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
|
1575 return term_job_running_check(term, FALSE); |
12502 | 1576 } |
1577 | |
1578 /* | |
1579 * Return TRUE if "term" has an active channel and used ":term NONE". | |
1580 */ | |
1581 int | |
1582 term_none_open(term_T *term) | |
1583 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1584 // 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
|
1585 // race condition when updating the title. |
12502 | 1586 return term != NULL |
1587 && term->tl_job != NULL | |
1588 && channel_is_open(term->tl_job->jv_channel) | |
1589 && term->tl_job->jv_channel->ch_keep_open; | |
1590 } | |
1591 | |
1592 /* | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1593 * 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
|
1594 * 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
|
1595 * 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
|
1596 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1597 int |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1598 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
|
1599 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1600 int count; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1601 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
|
1602 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1603 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
1604 if ((how == NULL || *how == NUL) |
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
1605 && (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM))) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1606 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1607 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
|
1608 int ret; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1609 |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1610 dialog_msg(buff, _("Kill job in \"%s\"?"), buf_get_fname(buf)); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1611 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
|
1612 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
|
1613 how = "kill"; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1614 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
|
1615 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1616 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1617 #endif |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1618 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
|
1619 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1620 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1621 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
|
1622 |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1623 // 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
|
1624 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
|
1625 { |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1626 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
|
1627 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1628 // 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
|
1629 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
|
1630 || 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
|
1631 || 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
|
1632 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
|
1633 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
|
1634 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1635 // 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
|
1636 // 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
|
1637 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
|
1638 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
|
1639 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
|
1640 |
18420
3a3efaaa05c5
patch 8.1.2204: crash on exit when closing terminals
Bram Moolenaar <Bram@vim.org>
parents:
18402
diff
changeset
|
1641 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
|
1642 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
|
1643 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1644 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1645 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1646 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1647 /* |
12502 | 1648 * Add the last line of the scrollback buffer to the buffer in the window. |
1649 */ | |
1650 static void | |
1651 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) | |
1652 { | |
1653 buf_T *buf = term->tl_buffer; | |
1654 int empty = (buf->b_ml.ml_flags & ML_EMPTY); | |
1655 linenr_T lnum = buf->b_ml.ml_line_count; | |
1656 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1657 #ifdef MSWIN |
12502 | 1658 if (!enc_utf8 && enc_codepage > 0) |
1659 { | |
1660 WCHAR *ret = NULL; | |
1661 int length = 0; | |
1662 | |
1663 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, | |
1664 &ret, &length); | |
1665 if (ret != NULL) | |
1666 { | |
1667 WideCharToMultiByte_alloc(enc_codepage, 0, | |
1668 ret, length, (char **)&text, &len, 0, 0); | |
1669 vim_free(ret); | |
1670 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); | |
1671 vim_free(text); | |
1672 } | |
1673 } | |
1674 else | |
1675 #endif | |
1676 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); | |
1677 if (empty) | |
1678 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1679 // Delete the empty line that was in the empty buffer. |
12502 | 1680 curbuf = buf; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1681 ml_delete(1); |
12502 | 1682 curbuf = curwin->w_buffer; |
1683 } | |
1684 } | |
1685 | |
1686 static void | |
1687 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr) | |
1688 { | |
1689 attr->width = cell->width; | |
1690 attr->attrs = cell->attrs; | |
1691 attr->fg = cell->fg; | |
1692 attr->bg = cell->bg; | |
1693 } | |
1694 | |
1695 static int | |
1696 equal_celattr(cellattr_T *a, cellattr_T *b) | |
1697 { | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
1698 // 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
|
1699 // Thus black set explicitly is equal the background black. |
12502 | 1700 return a->fg.red == b->fg.red |
1701 && a->fg.green == b->fg.green | |
1702 && a->fg.blue == b->fg.blue | |
1703 && a->bg.red == b->bg.red | |
1704 && a->bg.green == b->bg.green | |
1705 && a->bg.blue == b->bg.blue; | |
1706 } | |
1707 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1708 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1709 * 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
|
1710 * 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
|
1711 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1712 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1713 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
|
1714 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1715 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
|
1716 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1717 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
|
1718 + 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
|
1719 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1720 if (lnum > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1721 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1722 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1723 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1724 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
|
1725 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1726 *line = *(line - 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1727 --line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1728 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1729 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1730 line->sb_cols = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1731 line->sb_cells = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1732 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
|
1733 ++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
|
1734 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1735 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1736 return FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1737 } |
12502 | 1738 |
1739 /* | |
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
|
1740 * 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
|
1741 * 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
|
1742 * 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
|
1743 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1744 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
|
1745 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
|
1746 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1747 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
|
1748 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
|
1749 |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1750 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
|
1751 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
|
1752 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
|
1753 && 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
|
1754 { |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1755 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
|
1756 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
|
1757 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
|
1758 --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
|
1759 } |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1760 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
|
1761 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
|
1762 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
|
1763 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1764 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1765 /* |
12502 | 1766 * Add the current lines of the terminal to scrollback and to the buffer. |
1767 */ | |
1768 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
|
1769 update_snapshot(term_T *term) |
12502 | 1770 { |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1771 VTermScreen *screen; |
12502 | 1772 int len; |
1773 int lines_skipped = 0; | |
1774 VTermPos pos; | |
1775 VTermScreenCell cell; | |
1776 cellattr_T fill_attr, new_fill_attr; | |
1777 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
|
1778 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1779 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
|
1780 "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
|
1781 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1782 // 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
|
1783 // 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
|
1784 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
|
1785 |
12502 | 1786 screen = vterm_obtain_screen(term->tl_vterm); |
1787 fill_attr = new_fill_attr = term->tl_default_color; | |
1788 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row) | |
1789 { | |
1790 len = 0; | |
1791 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | |
1792 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | |
1793 && cell.chars[0] != NUL) | |
1794 { | |
1795 len = pos.col + 1; | |
1796 new_fill_attr = term->tl_default_color; | |
1797 } | |
1798 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1799 // Assume the last attr is the filler attr. |
12502 | 1800 cell2cellattr(&cell, &new_fill_attr); |
1801 | |
1802 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr)) | |
1803 ++lines_skipped; | |
1804 else | |
1805 { | |
1806 while (lines_skipped > 0) | |
1807 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1808 // Line was skipped, add an empty line. |
12502 | 1809 --lines_skipped; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1810 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
12502 | 1811 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
1812 } | |
1813 | |
1814 if (len == 0) | |
1815 p = NULL; | |
1816 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
|
1817 p = ALLOC_MULT(cellattr_T, len); |
12502 | 1818 if ((p != NULL || len == 0) |
1819 && ga_grow(&term->tl_scrollback, 1) == OK) | |
1820 { | |
1821 garray_T ga; | |
1822 int width; | |
1823 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | |
1824 + term->tl_scrollback.ga_len; | |
1825 | |
1826 ga_init2(&ga, 1, 100); | |
1827 for (pos.col = 0; pos.col < len; pos.col += width) | |
1828 { | |
1829 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
1830 { | |
1831 width = 1; | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1832 CLEAR_POINTER(p + pos.col); |
12502 | 1833 if (ga_grow(&ga, 1) == OK) |
1834 ga.ga_len += utf_char2bytes(' ', | |
1835 (char_u *)ga.ga_data + ga.ga_len); | |
1836 } | |
1837 else | |
1838 { | |
1839 width = cell.width; | |
1840 | |
1841 cell2cellattr(&cell, &p[pos.col]); | |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1842 if (width == 2) |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1843 // second cell of double-width character has the |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1844 // same attributes. |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1845 p[pos.col + 1] = p[pos.col]; |
12502 | 1846 |
15203
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1847 // 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
|
1848 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK) |
12502 | 1849 { |
1850 int i; | |
1851 int c; | |
1852 | |
1853 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) | |
1854 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
1855 (char_u *)ga.ga_data + ga.ga_len); | |
1856 } | |
1857 } | |
1858 } | |
1859 line->sb_cols = len; | |
1860 line->sb_cells = p; | |
1861 line->sb_fill_attr = new_fill_attr; | |
1862 fill_attr = new_fill_attr; | |
1863 ++term->tl_scrollback.ga_len; | |
1864 | |
1865 if (ga_grow(&ga, 1) == FAIL) | |
1866 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
1867 else | |
1868 { | |
1869 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
1870 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
1871 } | |
1872 ga_clear(&ga); | |
1873 } | |
1874 else | |
1875 vim_free(p); | |
1876 } | |
1877 } | |
1878 | |
15022
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1879 // 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
|
1880 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
|
1881 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
|
1882 ++pos.row) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1883 { |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1884 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
|
1885 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
|
1886 } |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1887 |
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
|
1888 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
|
1889 #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
|
1890 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
|
1891 #endif |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1892 } |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1893 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1894 /* |
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
|
1895 * 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
|
1896 * 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
|
1897 * 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
|
1898 */ |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1899 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
|
1900 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
|
1901 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1902 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
|
1903 *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
|
1904 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
|
1905 *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
|
1906 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
|
1907 *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
|
1908 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
|
1909 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
|
1910 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
|
1911 *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
|
1912 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
|
1913 } |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1914 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1915 /* |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1916 * 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
|
1917 * 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
|
1918 * 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
|
1919 * 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
|
1920 */ |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1921 static void |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1922 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
|
1923 { |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1924 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
|
1925 return; |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1926 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1927 // 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
|
1928 // 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
|
1929 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
|
1930 <= 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
|
1931 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
|
1932 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1933 // Obtain the current background color. |
12502 | 1934 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
1935 &term->tl_default_color.fg, &term->tl_default_color.bg); | |
1936 | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1937 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
|
1938 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1939 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
|
1940 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
|
1941 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1942 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 1943 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1944 if (wp->w_buffer == term->tl_buffer) |
12502 | 1945 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1946 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
|
1947 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
|
1948 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
|
1949 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
|
1950 { |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1951 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
|
1952 |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1953 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
|
1954 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
|
1955 } |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1956 redraw_win_later(wp, NOT_VALID); |
12502 | 1957 } |
1958 } | |
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
|
1959 } |
12502 | 1960 } |
1961 | |
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
|
1962 #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
|
1963 /* |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1964 * 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
|
1965 * 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
|
1966 * 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
|
1967 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1968 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
|
1969 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
|
1970 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1971 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
|
1972 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
|
1973 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
1974 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
|
1975 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1976 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
|
1977 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1978 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
|
1979 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1980 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
|
1981 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1982 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
|
1983 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
|
1984 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1985 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
|
1986 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
|
1987 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1988 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1989 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1990 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
|
1991 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1992 #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
|
1993 |
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
|
1994 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1995 * 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
|
1996 * 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
|
1997 */ |
12502 | 1998 static void |
1999 set_terminal_mode(term_T *term, int normal_mode) | |
2000 { | |
2001 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
|
2002 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
|
2003 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
|
2004 VIM_CLEAR(term->tl_status_text); |
12502 | 2005 if (term->tl_buffer == curbuf) |
2006 maketitle(); | |
2007 } | |
2008 | |
2009 /* | |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2010 * Called after the job is finished and Terminal mode is not active: |
12502 | 2011 * Move the vterm contents into the scrollback buffer and free the vterm. |
2012 */ | |
2013 static void | |
2014 cleanup_vterm(term_T *term) | |
2015 { | |
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
|
2016 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
|
2017 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
|
2018 may_move_terminal_to_buffer(term, TRUE); |
12502 | 2019 term_free_vterm(term); |
2020 } | |
2021 | |
2022 /* | |
2023 * Switch from Terminal-Job mode to Terminal-Normal mode. | |
2024 * Suspends updating the terminal window. | |
2025 */ | |
2026 static void | |
2027 term_enter_normal_mode(void) | |
2028 { | |
2029 term_T *term = curbuf->b_term; | |
2030 | |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2031 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
|
2032 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2033 // 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
|
2034 may_move_terminal_to_buffer(term, TRUE); |
12502 | 2035 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2036 // 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
|
2037 // terminal. |
12502 | 2038 curwin->w_cursor.lnum = term->tl_scrollback_scrolled |
2039 + term->tl_cursor_pos.row + 1; | |
2040 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
|
2041 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
|
2042 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
|
2043 curwin->w_set_curswant = TRUE; |
12502 | 2044 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2045 // Display the same lines as in the terminal. |
12502 | 2046 curwin->w_topline = term->tl_scrollback_scrolled + 1; |
2047 } | |
2048 | |
2049 /* | |
2050 * Returns TRUE if the current window contains a terminal and we are in | |
2051 * Terminal-Normal mode. | |
2052 */ | |
2053 int | |
2054 term_in_normal_mode(void) | |
2055 { | |
2056 term_T *term = curbuf->b_term; | |
2057 | |
2058 return term != NULL && term->tl_normal_mode; | |
2059 } | |
2060 | |
2061 /* | |
2062 * Switch from Terminal-Normal mode to Terminal-Job mode. | |
2063 * Restores updating the terminal window. | |
2064 */ | |
2065 void | |
2066 term_enter_job_mode() | |
2067 { | |
2068 term_T *term = curbuf->b_term; | |
2069 | |
2070 set_terminal_mode(term, FALSE); | |
2071 | |
2072 if (term->tl_channel_closed) | |
2073 cleanup_vterm(term); | |
2074 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
|
2075 #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
|
2076 if (WIN_IS_POPUP(curwin)) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
2077 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
|
2078 #endif |
12502 | 2079 } |
2080 | |
2081 /* | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2082 * Get a key from the user with terminal mode mappings. |
12502 | 2083 * Note: while waiting a terminal may be closed and freed if the channel is |
2084 * closed and ++close was used. | |
2085 */ | |
2086 static int | |
2087 term_vgetc() | |
2088 { | |
2089 int c; | |
2090 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
|
2091 int modify_other_keys = |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2092 vterm_is_modify_other_keys(curbuf->b_term->tl_vterm); |
12502 | 2093 |
2094 State = TERMINAL; | |
2095 got_int = FALSE; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2096 #ifdef MSWIN |
12502 | 2097 ctrl_break_was_pressed = FALSE; |
2098 #endif | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2099 if (modify_other_keys) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2100 ++no_reduce_keys; |
12502 | 2101 c = vgetc(); |
2102 got_int = FALSE; | |
2103 State = save_State; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2104 if (modify_other_keys) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2105 --no_reduce_keys; |
12502 | 2106 return c; |
2107 } | |
2108 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2109 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
|
2110 |
12502 | 2111 /* |
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
|
2112 * Send key "c" with modifiers "modmask" to terminal. |
12502 | 2113 * Return FAIL when the key needs to be handled in Normal mode. |
2114 * Return OK when the key was dropped or sent to the terminal. | |
2115 */ | |
2116 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
|
2117 send_keys_to_term(term_T *term, int c, int modmask, int typed) |
12502 | 2118 { |
2119 char msg[KEY_BUF_LEN]; | |
2120 size_t len; | |
2121 int dragging_outside = FALSE; | |
2122 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2123 // Catch keys that need to be handled as in Normal mode. |
12502 | 2124 switch (c) |
2125 { | |
2126 case NUL: | |
2127 case K_ZERO: | |
2128 if (typed) | |
2129 stuffcharReadbuff(c); | |
2130 return FAIL; | |
2131 | |
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
|
2132 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
|
2133 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
|
2134 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
|
2135 |
12502 | 2136 case K_IGNORE: |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2137 case K_CANCEL: // used for :normal when running out of chars |
12502 | 2138 return FAIL; |
2139 | |
2140 case K_LEFTDRAG: | |
2141 case K_MIDDLEDRAG: | |
2142 case K_RIGHTDRAG: | |
2143 case K_X1DRAG: | |
2144 case K_X2DRAG: | |
2145 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
|
2146 // FALLTHROUGH |
12502 | 2147 case K_LEFTMOUSE: |
2148 case K_LEFTMOUSE_NM: | |
2149 case K_LEFTRELEASE: | |
2150 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
|
2151 case K_MOUSEMOVE: |
12502 | 2152 case K_MIDDLEMOUSE: |
2153 case K_MIDDLERELEASE: | |
2154 case K_RIGHTMOUSE: | |
2155 case K_RIGHTRELEASE: | |
2156 case K_X1MOUSE: | |
2157 case K_X1RELEASE: | |
2158 case K_X2MOUSE: | |
2159 case K_X2RELEASE: | |
2160 | |
2161 case K_MOUSEUP: | |
2162 case K_MOUSEDOWN: | |
2163 case K_MOUSELEFT: | |
2164 case K_MOUSERIGHT: | |
2165 { | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2166 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
|
2167 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
|
2168 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2169 #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
|
2170 if (popup_is_popup(curwin)) |
12502 | 2171 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2172 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
|
2173 col -= popup_left_extra(curwin); |
12502 | 2174 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2175 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2176 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
|
2177 || 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
|
2178 || 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
|
2179 || 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
|
2180 || dragging_outside) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2181 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2182 // 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
|
2183 // 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
|
2184 if (typed) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2185 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2186 stuffcharReadbuff(c); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2187 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
|
2188 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2189 return FAIL; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2190 } |
12502 | 2191 } |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2192 break; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2193 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2194 case K_COMMAND: |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2195 return do_cmdline(NULL, getcmdkeycmd, NULL, 0); |
12502 | 2196 } |
2197 if (typed) | |
2198 mouse_was_outside = FALSE; | |
2199 | |
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
|
2200 // 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
|
2201 len = term_convert_key(term, c, modmask, msg); |
12502 | 2202 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
|
2203 // TODO: if FAIL is returned, stop? |
12502 | 2204 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
2205 (char_u *)msg, (int)len, NULL); | |
2206 | |
2207 return OK; | |
2208 } | |
2209 | |
2210 static void | |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2211 position_cursor(win_T *wp, VTermPos *pos) |
12502 | 2212 { |
2213 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); | |
2214 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
|
2215 #ifdef FEAT_PROP_POPUP |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2216 if (popup_is_popup(wp)) |
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2217 { |
23041
139573353c6d
patch 8.2.2067: cursor position in popup terminal is wrong
Bram Moolenaar <Bram@vim.org>
parents:
23035
diff
changeset
|
2218 wp->w_wrow += popup_top_extra(wp); |
139573353c6d
patch 8.2.2067: cursor position in popup terminal is wrong
Bram Moolenaar <Bram@vim.org>
parents:
23035
diff
changeset
|
2219 wp->w_wcol += popup_left_extra(wp); |
22886
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2220 wp->w_flags |= WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED; |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2221 } |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2222 else |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2223 wp->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2224 #endif |
12502 | 2225 wp->w_valid |= (VALID_WCOL|VALID_WROW); |
2226 } | |
2227 | |
2228 /* | |
2229 * Handle CTRL-W "": send register contents to the job. | |
2230 */ | |
2231 static void | |
2232 term_paste_register(int prev_c UNUSED) | |
2233 { | |
2234 int c; | |
2235 list_T *l; | |
2236 listitem_T *item; | |
2237 long reglen = 0; | |
2238 int type; | |
2239 | |
2240 #ifdef FEAT_CMDL_INFO | |
2241 if (add_to_showcmd(prev_c)) | |
2242 if (add_to_showcmd('"')) | |
2243 out_flush(); | |
2244 #endif | |
2245 c = term_vgetc(); | |
2246 #ifdef FEAT_CMDL_INFO | |
2247 clear_showcmd(); | |
2248 #endif | |
2249 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2250 // job finished while waiting for a character |
12502 | 2251 return; |
2252 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2253 // CTRL-W "= prompt for expression to evaluate. |
12502 | 2254 if (c == '=' && get_expr_register() != '=') |
2255 return; | |
2256 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2257 // job finished while waiting for a character |
12502 | 2258 return; |
2259 | |
2260 l = (list_T *)get_reg_contents(c, GREG_LIST); | |
2261 if (l != NULL) | |
2262 { | |
2263 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
|
2264 FOR_ALL_LIST_ITEMS(l, item) |
12502 | 2265 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
2266 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
|
2267 #ifdef MSWIN |
12502 | 2268 char_u *tmp = s; |
2269 | |
2270 if (!enc_utf8 && enc_codepage > 0) | |
2271 { | |
2272 WCHAR *ret = NULL; | |
2273 int length = 0; | |
2274 | |
2275 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s, | |
2276 (int)STRLEN(s), &ret, &length); | |
2277 if (ret != NULL) | |
2278 { | |
2279 WideCharToMultiByte_alloc(CP_UTF8, 0, | |
2280 ret, length, (char **)&s, &length, 0, 0); | |
2281 vim_free(ret); | |
2282 } | |
2283 } | |
2284 #endif | |
2285 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2286 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
|
2287 #ifdef MSWIN |
12502 | 2288 if (tmp != s) |
2289 vim_free(s); | |
2290 #endif | |
2291 | |
2292 if (item->li_next != NULL || type == MLINE) | |
2293 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2294 (char_u *)"\r", 1, NULL); | |
2295 } | |
2296 list_free(l); | |
2297 } | |
2298 } | |
2299 | |
2300 /* | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2301 * 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
|
2302 * terminal should be displayed. |
12502 | 2303 */ |
2304 int | |
2305 terminal_is_active() | |
2306 { | |
2307 return in_terminal_loop != NULL; | |
2308 } | |
2309 | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2310 /* |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2311 * 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
|
2312 */ |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2313 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
|
2314 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
|
2315 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2316 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
|
2317 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
|
2318 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
|
2319 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2320 |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2321 #if defined(FEAT_GUI) || defined(PROTO) |
12502 | 2322 cursorentry_T * |
2323 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) | |
2324 { | |
2325 term_T *term = in_terminal_loop; | |
2326 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
|
2327 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
|
2328 guicolor_T term_fg, term_bg; |
12502 | 2329 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2330 CLEAR_FIELD(entry); |
12502 | 2331 entry.shape = entry.mshape = |
2332 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : | |
2333 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : | |
2334 SHAPE_BLOCK; | |
2335 entry.percentage = 20; | |
2336 if (term->tl_cursor_blink) | |
2337 { | |
2338 entry.blinkwait = 700; | |
2339 entry.blinkon = 400; | |
2340 entry.blinkoff = 250; | |
2341 } | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2342 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2343 // 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
|
2344 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
|
2345 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
|
2346 { |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2347 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
|
2348 *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
|
2349 } |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2350 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2351 *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
|
2352 |
12502 | 2353 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
|
2354 { |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2355 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
|
2356 *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
|
2357 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2358 *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
|
2359 } |
12502 | 2360 else |
2361 *bg = color_name2handle(term->tl_cursor_color); | |
2362 entry.name = "n"; | |
2363 entry.used_for = SHAPE_CURSOR; | |
2364 | |
2365 return &entry; | |
2366 } | |
2367 #endif | |
2368 | |
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
|
2369 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
|
2370 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
|
2371 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2372 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
|
2373 || 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
|
2374 || 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
|
2375 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2376 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
|
2377 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
|
2378 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
|
2379 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
|
2380 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
|
2381 // 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
|
2382 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
|
2383 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
|
2384 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
|
2385 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2386 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2387 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2388 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2389 * 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
|
2390 */ |
12502 | 2391 static void |
2392 may_set_cursor_props(term_T *term) | |
2393 { | |
2394 #ifdef FEAT_GUI | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2395 // 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
|
2396 // term_get_cursor_shape(). |
12502 | 2397 if (gui.in_use) |
2398 return; | |
2399 #endif | |
2400 if (in_terminal_loop == term) | |
2401 { | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2402 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
|
2403 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
|
2404 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
|
2405 may_output_cursor_props(); |
12502 | 2406 } |
2407 } | |
2408 | |
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
|
2409 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2410 * 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
|
2411 */ |
12502 | 2412 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
|
2413 prepare_restore_cursor_props(void) |
12502 | 2414 { |
2415 #ifdef FEAT_GUI | |
2416 if (gui.in_use) | |
2417 return; | |
2418 #endif | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2419 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
|
2420 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
|
2421 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
|
2422 may_output_cursor_props(); |
12502 | 2423 } |
2424 | |
2425 /* | |
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
|
2426 * 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
|
2427 * 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
|
2428 * 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
|
2429 */ |
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
|
2430 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
|
2431 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
|
2432 { |
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
|
2433 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
|
2434 |
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
|
2435 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
|
2436 && !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
|
2437 && 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
|
2438 && 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
|
2439 } |
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
|
2440 |
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
|
2441 /* |
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
|
2442 * 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
|
2443 * 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
|
2444 */ |
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
|
2445 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
|
2446 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
|
2447 { |
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
|
2448 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
|
2449 } |
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
|
2450 |
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
|
2451 /* |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2452 * 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
|
2453 * 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
|
2454 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2455 void |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2456 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
|
2457 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2458 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
|
2459 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2460 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
|
2461 { |
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
|
2462 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
|
2463 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2464 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
|
2465 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
|
2466 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
|
2467 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2468 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
|
2469 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
|
2470 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
|
2471 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2472 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2473 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2474 /* |
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
|
2475 * 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
|
2476 * 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
|
2477 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2478 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
|
2479 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
|
2480 { |
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 ((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
|
2482 && ((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
|
2483 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
|
2484 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
|
2485 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2486 |
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 /* |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2488 * 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
|
2489 * 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
|
2490 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2491 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
|
2492 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
|
2493 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2494 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
|
2495 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2496 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
|
2497 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
|
2498 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2499 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
|
2500 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2501 |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2502 /* |
12502 | 2503 * Wait for input and send it to the job. |
2504 * When "blocking" is TRUE wait for a character to be typed. Otherwise return | |
2505 * when there is no more typahead. | |
2506 * Return when the start of a CTRL-W command is typed or anything else that | |
2507 * should be handled as a Normal mode command. | |
2508 * Returns OK if a typed character is to be handled in Normal mode, FAIL if | |
2509 * the terminal was closed. | |
2510 */ | |
2511 int | |
2512 terminal_loop(int blocking) | |
2513 { | |
2514 int c; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2515 int raw_c; |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2516 int termwinkey = 0; |
12502 | 2517 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
|
2518 #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
|
2519 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
|
2520 ->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
|
2521 #endif |
13906
0ae89b121c58
patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents:
13900
diff
changeset
|
2522 int restore_cursor = FALSE; |
12502 | 2523 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2524 // 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
|
2525 // 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
|
2526 // 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
|
2527 // stored reference. |
12502 | 2528 in_terminal_loop = curbuf->b_term; |
2529 | |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2530 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
|
2531 { |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2532 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
|
2533 if (termwinkey == Ctrl_W) |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2534 termwinkey = 0; |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2535 } |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2536 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos); |
12502 | 2537 may_set_cursor_props(curbuf->b_term); |
2538 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2539 while (blocking || vpeekc_nomap() != NUL) |
12502 | 2540 { |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2541 #ifdef FEAT_GUI |
22876
b952e0a3af2f
patch 8.2.1985: crash when closing terminal popup with <Cmd> mapping
Bram Moolenaar <Bram@vim.org>
parents:
22864
diff
changeset
|
2542 if (curbuf->b_term != NULL && !curbuf->b_term->tl_system) |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2543 #endif |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2544 // 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
|
2545 // 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
|
2546 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
|
2547 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
|
2548 break; |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2549 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
|
2550 // 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
|
2551 break; |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2552 |
12502 | 2553 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
|
2554 restore_cursor = TRUE; |
12502 | 2555 |
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
|
2556 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
|
2557 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
|
2558 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2559 // 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
|
2560 // 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
|
2561 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
|
2562 vungetc(raw_c); |
12502 | 2563 break; |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2564 } |
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
|
2565 if (raw_c == K_IGNORE) |
12502 | 2566 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
|
2567 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
|
2568 |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2569 #ifdef UNIX |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2570 /* |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2571 * 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
|
2572 * 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
|
2573 * 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
|
2574 */ |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2575 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
|
2576 { |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2577 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
|
2578 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2579 // 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
|
2580 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
|
2581 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
|
2582 } |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2583 #endif |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2584 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2585 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2586 // 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
|
2587 // Use CTRL-BREAK to kill the job. |
12502 | 2588 if (ctrl_break_was_pressed) |
2589 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
2590 #endif | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2591 // 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
|
2592 // 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
|
2593 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
|
2594 #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
|
2595 && !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
|
2596 #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
|
2597 ) |
12502 | 2598 { |
2599 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
|
2600 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
|
2601 int prev_mod_mask = mod_mask; |
12502 | 2602 |
2603 #ifdef FEAT_CMDL_INFO | |
2604 if (add_to_showcmd(c)) | |
2605 out_flush(); | |
2606 #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
|
2607 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
|
2608 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
|
2609 |
12502 | 2610 #ifdef FEAT_CMDL_INFO |
2611 clear_showcmd(); | |
2612 #endif | |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2613 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
|
2614 || 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
|
2615 // job finished while waiting for a character |
12502 | 2616 break; |
2617 | |
2618 if (prev_c == Ctrl_BSL) | |
2619 { | |
2620 if (c == Ctrl_N) | |
2621 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2622 // CTRL-\ CTRL-N : go to Terminal-Normal mode. |
12502 | 2623 term_enter_normal_mode(); |
2624 ret = FAIL; | |
2625 goto theend; | |
2626 } | |
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
|
2627 // 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
|
2628 // 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
|
2629 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
|
2630 TRUE); |
12502 | 2631 } |
2632 else if (c == Ctrl_C) | |
2633 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2634 // "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job |
12502 | 2635 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); |
2636 } | |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2637 else if (c == '.') |
12502 | 2638 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2639 // "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
|
2640 // "'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
|
2641 raw_c = ctrl_to_raw_c(termwinkey == 0 ? Ctrl_W : termwinkey); |
12502 | 2642 } |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2643 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
|
2644 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2645 // "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
|
2646 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
|
2647 } |
12502 | 2648 else if (c == 'N') |
2649 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2650 // CTRL-W N : go to Terminal-Normal mode. |
12502 | 2651 term_enter_normal_mode(); |
2652 ret = FAIL; | |
2653 goto theend; | |
2654 } | |
2655 else if (c == '"') | |
2656 { | |
2657 term_paste_register(prev_c); | |
2658 continue; | |
2659 } | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2660 else if (termwinkey == 0 || c != termwinkey) |
12502 | 2661 { |
22448
5e287462487e
patch 8.2.1772: cannot use CTRL-W <Down> to move out of a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
2662 // space for CTRL-W, modifier, multi-byte char and NUL |
5e287462487e
patch 8.2.1772: cannot use CTRL-W <Down> to move out of a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
2663 char_u buf[1 + 3 + MB_MAXBYTES + 1]; |
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
|
2664 |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2665 // 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
|
2666 // 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
|
2667 buf[0] = Ctrl_W; |
22448
5e287462487e
patch 8.2.1772: cannot use CTRL-W <Down> to move out of a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
2668 buf[special_to_buf(c, mod_mask, FALSE, buf + 1) + 1] = NUL; |
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
|
2669 ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE); |
12502 | 2670 ret = OK; |
2671 goto theend; | |
2672 } | |
2673 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2674 # 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
|
2675 if (!enc_utf8 && has_mbyte && raw_c >= 0x80) |
12502 | 2676 { |
2677 WCHAR wc; | |
2678 char_u mb[3]; | |
2679 | |
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
|
2680 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
|
2681 mb[1] = raw_c; |
12502 | 2682 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
|
2683 raw_c = wc; |
12502 | 2684 } |
2685 # 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
|
2686 if (send_keys_to_term(curbuf->b_term, raw_c, mod_mask, TRUE) != OK) |
12502 | 2687 { |
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
|
2688 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
|
2689 // 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
|
2690 // 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
|
2691 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
|
2692 |
12502 | 2693 ret = OK; |
2694 goto theend; | |
2695 } | |
2696 } | |
2697 ret = FAIL; | |
2698 | |
2699 theend: | |
2700 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
|
2701 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
|
2702 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
|
2703 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2704 // 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
|
2705 // 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
|
2706 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
|
2707 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
|
2708 |
12502 | 2709 return ret; |
2710 } | |
2711 | |
2712 static void | |
2713 may_toggle_cursor(term_T *term) | |
2714 { | |
2715 if (in_terminal_loop == term) | |
2716 { | |
2717 if (term->tl_cursor_visible) | |
2718 cursor_on(); | |
2719 else | |
2720 cursor_off(); | |
2721 } | |
2722 } | |
2723 | |
2724 /* | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2725 * 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
|
2726 */ |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2727 void |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2728 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
|
2729 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2730 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
|
2731 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
|
2732 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2733 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2734 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
|
2735 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
|
2736 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2737 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
|
2738 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2739 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
|
2740 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
|
2741 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
|
2742 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2743 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
|
2744 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
|
2745 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
|
2746 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2747 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
|
2748 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2749 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2750 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
|
2751 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
|
2752 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2753 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
|
2754 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2755 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
|
2756 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
|
2757 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
|
2758 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2759 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
|
2760 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
|
2761 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
|
2762 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2763 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
|
2764 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2765 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2766 /* |
12502 | 2767 * 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
|
2768 * First color is 1. Return 0 if no match found (default color). |
12502 | 2769 */ |
2770 static int | |
2771 color2index(VTermColor *color, int fg, int *boldp) | |
2772 { | |
2773 int red = color->red; | |
2774 int blue = color->blue; | |
2775 int green = color->green; | |
2776 | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2777 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
|
2778 || 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
|
2779 return 0; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2780 if (VTERM_COLOR_IS_INDEXED(color)) |
12502 | 2781 { |
16312
46e8430738fa
patch 8.1.1161: unreachable code
Bram Moolenaar <Bram@vim.org>
parents:
16283
diff
changeset
|
2782 // 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
|
2783 switch (color->index + 1) |
12502 | 2784 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2785 case 0: return 0; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2786 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
|
2787 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
|
2788 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
|
2789 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
|
2790 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
|
2791 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
|
2792 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
|
2793 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
|
2794 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
|
2795 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
|
2796 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
|
2797 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
|
2798 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
|
2799 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
|
2800 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
|
2801 case 16: return lookup_color(26, fg, boldp) + 1; // white |
12502 | 2802 } |
2803 } | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2804 |
12502 | 2805 if (t_colors >= 256) |
2806 { | |
2807 if (red == blue && red == green) | |
2808 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2809 // 24-color greyscale plus white and black |
12502 | 2810 static int cutoff[23] = { |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2811 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
|
2812 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
|
2813 0xD5, 0xDF, 0xE9}; |
12502 | 2814 int i; |
2815 | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2816 if (red < 5) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2817 return 17; // 00/00/00 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2818 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
|
2819 return 232; |
12502 | 2820 for (i = 0; i < 23; ++i) |
2821 if (red < cutoff[i]) | |
2822 return i + 233; | |
2823 return 256; | |
2824 } | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2825 { |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2826 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
|
2827 int ri, gi, bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2828 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2829 // 216-color cube |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2830 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
|
2831 if (red < cutoff[ri]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2832 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2833 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
|
2834 if (green < cutoff[gi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2835 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2836 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
|
2837 if (blue < cutoff[bi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2838 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2839 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
|
2840 } |
12502 | 2841 } |
2842 return 0; | |
2843 } | |
2844 | |
2845 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2846 * Convert Vterm attributes to highlight flags. |
12502 | 2847 */ |
2848 static int | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2849 vtermAttr2hl(VTermScreenCellAttrs cellattrs) |
12502 | 2850 { |
2851 int attr = 0; | |
2852 | |
2853 if (cellattrs.bold) | |
2854 attr |= HL_BOLD; | |
2855 if (cellattrs.underline) | |
2856 attr |= HL_UNDERLINE; | |
2857 if (cellattrs.italic) | |
2858 attr |= HL_ITALIC; | |
2859 if (cellattrs.strike) | |
2860 attr |= HL_STRIKETHROUGH; | |
2861 if (cellattrs.reverse) | |
2862 attr |= HL_INVERSE; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2863 return attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2864 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2865 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2866 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2867 * 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
|
2868 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2869 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2870 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
|
2871 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2872 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
|
2873 if (attr & HL_BOLD) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2874 cell->attrs.bold = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2875 if (attr & HL_UNDERLINE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2876 cell->attrs.underline = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2877 if (attr & HL_ITALIC) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2878 cell->attrs.italic = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2879 if (attr & HL_STRIKETHROUGH) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2880 cell->attrs.strike = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2881 if (attr & HL_INVERSE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2882 cell->attrs.reverse = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2883 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2884 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2885 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2886 * 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
|
2887 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2888 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
|
2889 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
|
2890 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
|
2891 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
|
2892 VTermScreenCellAttrs cellattrs, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2893 VTermColor cellfg, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2894 VTermColor cellbg) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2895 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2896 int attr = vtermAttr2hl(cellattrs); |
12502 | 2897 |
2898 #ifdef FEAT_GUI | |
2899 if (gui.in_use) | |
2900 { | |
2901 guicolor_T fg, bg; | |
2902 | |
2903 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue); | |
2904 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue); | |
2905 return get_gui_attr_idx(attr, fg, bg); | |
2906 } | |
2907 else | |
2908 #endif | |
2909 #ifdef FEAT_TERMGUICOLORS | |
2910 if (p_tgc) | |
2911 { | |
2912 guicolor_T fg, bg; | |
2913 | |
2914 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue); | |
2915 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue); | |
2916 | |
2917 return get_tgc_attr_idx(attr, fg, bg); | |
2918 } | |
2919 else | |
2920 #endif | |
2921 { | |
2922 int bold = MAYBE; | |
2923 int fg = color2index(&cellfg, TRUE, &bold); | |
2924 int bg = color2index(&cellbg, FALSE, &bold); | |
2925 | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2926 // 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
|
2927 // colors. |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2928 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
|
2929 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2930 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
|
2931 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
|
2932 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2933 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
|
2934 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2935 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
|
2936 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2937 // 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
|
2938 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
|
2939 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
|
2940 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2941 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
|
2942 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2943 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
|
2944 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
|
2945 else |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2946 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2947 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
|
2948 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2949 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
|
2950 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
|
2951 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2952 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2953 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
|
2954 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2955 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
|
2956 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
|
2957 else |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2958 { |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2959 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
|
2960 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2961 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
|
2962 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
|
2963 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2964 } |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2965 } |
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2966 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2967 // with 8 colors set the bold attribute to get a bright foreground |
12502 | 2968 if (bold == TRUE) |
2969 attr |= HL_BOLD; | |
2970 return get_cterm_attr_idx(attr, fg, bg); | |
2971 } | |
2972 return 0; | |
2973 } | |
2974 | |
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
|
2975 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
|
2976 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
|
2977 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2978 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
|
2979 #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
|
2980 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
|
2981 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2982 // 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
|
2983 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
|
2984 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
|
2985 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2986 #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
|
2987 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2988 |
12502 | 2989 static int |
2990 handle_damage(VTermRect rect, void *user) | |
2991 { | |
2992 term_T *term = (term_T *)user; | |
2993 | |
2994 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row); | |
2995 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
|
2996 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
|
2997 redraw_buf_later(term->tl_buffer, SOME_VALID); |
12502 | 2998 return 1; |
2999 } | |
3000 | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3001 static void |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3002 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
|
3003 { |
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
|
3004 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
|
3005 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
|
3006 VTermColor fg, bg; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3007 VTermScreenCellAttrs attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3008 int clear_attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3009 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3010 CLEAR_FIELD(attr); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3011 |
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
|
3012 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
|
3013 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3014 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
|
3015 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3016 // 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
|
3017 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
|
3018 &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
|
3019 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
|
3020 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
|
3021 } |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3022 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3023 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3024 |
12502 | 3025 static int |
3026 handle_moverect(VTermRect dest, VTermRect src, void *user) | |
3027 { | |
3028 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
|
3029 int count = src.start_row - dest.start_row; |
12502 | 3030 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3031 // 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
|
3032 // 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
|
3033 // the redraw happens. |
12502 | 3034 if (dest.start_col == src.start_col |
3035 && dest.end_col == src.end_col | |
3036 && dest.start_row < src.start_row) | |
3037 { | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3038 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
|
3039 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
|
3040 else |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3041 term_scroll_up(term, dest.start_row, count); |
12502 | 3042 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3043 |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3044 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
|
3045 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
|
3046 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
|
3047 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3048 // 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
|
3049 // redraw later. |
12502 | 3050 redraw_buf_later(term->tl_buffer, NOT_VALID); |
3051 return 1; | |
3052 } | |
3053 | |
3054 static int | |
3055 handle_movecursor( | |
3056 VTermPos pos, | |
3057 VTermPos oldpos UNUSED, | |
3058 int visible, | |
3059 void *user) | |
3060 { | |
3061 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
|
3062 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
|
3063 int did_curwin = FALSE; |
12502 | 3064 |
3065 term->tl_cursor_pos = pos; | |
3066 term->tl_cursor_visible = visible; | |
3067 | |
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
|
3068 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 3069 { |
3070 if (wp->w_buffer == term->tl_buffer) | |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
3071 position_cursor(wp, &pos); |
12502 | 3072 } |
3073 if (term->tl_buffer == curbuf && !term->tl_normal_mode) | |
3074 update_cursor(term, term->tl_cursor_visible); | |
3075 | |
3076 return 1; | |
3077 } | |
3078 | |
3079 static int | |
3080 handle_settermprop( | |
3081 VTermProp prop, | |
3082 VTermValue *value, | |
3083 void *user) | |
3084 { | |
3085 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
|
3086 char_u *strval = NULL; |
12502 | 3087 |
3088 switch (prop) | |
3089 { | |
3090 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
|
3091 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
|
3092 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
|
3093 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3094 break; |
12502 | 3095 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
|
3096 // 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
|
3097 // displayed |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3098 if (*skipwhite(strval) == NUL) |
12502 | 3099 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
|
3100 // 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
|
3101 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
|
3102 && 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
|
3103 (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
|
3104 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
|
3105 // 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
|
3106 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
|
3107 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
|
3108 #ifdef MSWIN |
12502 | 3109 else if (!enc_utf8 && enc_codepage > 0) |
3110 { | |
3111 WCHAR *ret = NULL; | |
3112 int length = 0; | |
3113 | |
3114 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
|
3115 (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
|
3116 (int)value->string.len, &ret, &length); |
12502 | 3117 if (ret != NULL) |
3118 { | |
3119 WideCharToMultiByte_alloc(enc_codepage, 0, | |
3120 ret, length, (char**)&term->tl_title, | |
3121 &length, 0, 0); | |
3122 vim_free(ret); | |
3123 } | |
3124 } | |
3125 #endif | |
3126 else | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3127 { |
20508
357dea6b9fde
patch 8.2.0808: not enough testing for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20500
diff
changeset
|
3128 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
|
3129 strval = NULL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3130 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3131 VIM_CLEAR(term->tl_status_text); |
12502 | 3132 if (term == curbuf->b_term) |
3133 maketitle(); | |
3134 break; | |
3135 | |
3136 case VTERM_PROP_CURSORVISIBLE: | |
3137 term->tl_cursor_visible = value->boolean; | |
3138 may_toggle_cursor(term); | |
3139 out_flush(); | |
3140 break; | |
3141 | |
3142 case VTERM_PROP_CURSORBLINK: | |
3143 term->tl_cursor_blink = value->boolean; | |
3144 may_set_cursor_props(term); | |
3145 break; | |
3146 | |
3147 case VTERM_PROP_CURSORSHAPE: | |
3148 term->tl_cursor_shape = value->number; | |
3149 may_set_cursor_props(term); | |
3150 break; | |
3151 | |
3152 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
|
3153 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
|
3154 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
|
3155 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3156 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3157 cursor_color_copy(&term->tl_cursor_color, strval); |
12502 | 3158 may_set_cursor_props(term); |
3159 break; | |
3160 | |
3161 case VTERM_PROP_ALTSCREEN: | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3162 // TODO: do anything else? |
12502 | 3163 term->tl_using_altscreen = value->boolean; |
3164 break; | |
3165 | |
3166 default: | |
3167 break; | |
3168 } | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3169 vim_free(strval); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3170 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3171 // Always return 1, otherwise vterm doesn't store the value internally. |
12502 | 3172 return 1; |
3173 } | |
3174 | |
3175 /* | |
3176 * The job running in the terminal resized the terminal. | |
3177 */ | |
3178 static int | |
3179 handle_resize(int rows, int cols, void *user) | |
3180 { | |
3181 term_T *term = (term_T *)user; | |
3182 win_T *wp; | |
3183 | |
3184 term->tl_rows = rows; | |
3185 term->tl_cols = cols; | |
3186 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
|
3187 // Size was set by vterm_set_size(), don't set the window size. |
12502 | 3188 term->tl_vterm_size_changed = FALSE; |
3189 else | |
3190 { | |
3191 FOR_ALL_WINDOWS(wp) | |
3192 { | |
3193 if (wp->w_buffer == term->tl_buffer) | |
3194 { | |
3195 win_setheight_win(rows, wp); | |
3196 win_setwidth_win(cols, wp); | |
3197 } | |
3198 } | |
3199 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3200 } | |
3201 return 1; | |
3202 } | |
3203 | |
3204 /* | |
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
|
3205 * 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
|
3206 * 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
|
3207 * "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
|
3208 * "update_buffer" is TRUE when the buffer should be updated. |
12502 | 3209 */ |
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
|
3210 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
|
3211 limit_scrollback(term_T *term, garray_T *gap, int update_buffer) |
12502 | 3212 { |
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
|
3213 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
|
3214 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
3215 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
|
3216 int i; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3217 |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3218 curbuf = term->tl_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3219 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
|
3220 { |
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
|
3221 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
|
3222 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
|
3223 ml_delete(1); |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3224 } |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3225 curbuf = curwin->w_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3226 |
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
|
3227 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
|
3228 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
|
3229 (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
|
3230 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
|
3231 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
|
3232 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
|
3233 } |
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 } |
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 |
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 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3237 * 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
|
3238 */ |
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 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
|
3240 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
|
3241 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3242 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
|
3243 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
|
3244 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
|
3245 |
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 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
|
3247 { |
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 // 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
|
3249 // 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
|
3250 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
|
3251 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
|
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 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
|
3254 { |
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 // 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
|
3256 // 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
|
3257 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
|
3258 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
|
3259 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
|
3260 } |
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 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
|
3263 |
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 if (ga_grow(gap, 1) == OK) |
12502 | 3265 { |
3266 cellattr_T *p = NULL; | |
3267 int len = 0; | |
3268 int i; | |
3269 int c; | |
3270 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
|
3271 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
|
3272 char_u *text; |
12502 | 3273 sb_line_T *line; |
3274 garray_T ga; | |
3275 cellattr_T fill_attr = term->tl_default_color; | |
3276 | |
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
|
3277 // do not store empty cells at the end |
12502 | 3278 for (i = 0; i < cols; ++i) |
3279 if (cells[i].chars[0] != 0) | |
3280 len = i + 1; | |
3281 else | |
3282 cell2cellattr(&cells[i], &fill_attr); | |
3283 | |
3284 ga_init2(&ga, 1, 100); | |
3285 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
|
3286 p = ALLOC_MULT(cellattr_T, len); |
12502 | 3287 if (p != NULL) |
3288 { | |
3289 for (col = 0; col < len; col += cells[col].width) | |
3290 { | |
3291 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | |
3292 { | |
3293 ga.ga_len = 0; | |
3294 break; | |
3295 } | |
3296 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i) | |
3297 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
3298 (char_u *)ga.ga_data + ga.ga_len); | |
3299 cell2cellattr(&cells[col], &p[col]); | |
3300 } | |
3301 } | |
3302 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
|
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 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
|
3305 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
|
3306 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
|
3307 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
|
3308 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
|
3309 } |
12502 | 3310 else |
3311 { | |
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
|
3312 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
|
3313 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
|
3314 *(text + text_len) = NUL; |
12502 | 3315 } |
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
|
3316 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
|
3317 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
|
3318 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3319 line = (sb_line_T *)gap->ga_data + gap->ga_len; |
12502 | 3320 line->sb_cols = len; |
3321 line->sb_cells = p; | |
3322 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
|
3323 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
|
3324 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3325 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
|
3326 ++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
|
3327 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
|
3328 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3329 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
|
3330 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3331 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
|
3332 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
|
3333 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3334 ++gap->ga_len; |
12502 | 3335 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3336 return 0; // ignored |
12502 | 3337 } |
3338 | |
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
|
3339 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3340 * 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
|
3341 * 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
|
3342 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3343 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
|
3344 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
|
3345 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3346 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
|
3347 |
16026
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3348 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
|
3349 return; |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3350 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
|
3351 |
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
|
3352 // 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
|
3353 // 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
|
3354 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
|
3355 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3356 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
|
3357 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3358 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
|
3359 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
|
3360 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
|
3361 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3362 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
|
3363 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
|
3364 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
|
3365 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3366 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
|
3367 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
|
3368 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
|
3369 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
|
3370 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
|
3371 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3372 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
|
3373 + 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
|
3374 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
|
3375 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
|
3376 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
|
3377 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
|
3378 ++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
|
3379 ++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
|
3380 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3381 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3382 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
|
3383 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
|
3384 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3385 |
12502 | 3386 static VTermScreenCallbacks screen_callbacks = { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3387 handle_damage, // damage |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3388 handle_moverect, // moverect |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3389 handle_movecursor, // movecursor |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3390 handle_settermprop, // settermprop |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3391 NULL, // bell |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3392 handle_resize, // resize |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3393 handle_pushline, // sb_pushline |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3394 NULL // sb_popline |
12502 | 3395 }; |
3396 | |
3397 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3398 * 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
|
3399 * 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
|
3400 * 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
|
3401 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3402 static int |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3403 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
|
3404 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3405 // 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
|
3406 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
|
3407 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3408 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
|
3409 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3410 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
|
3411 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3412 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
|
3413 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3414 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
|
3415 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
|
3416 #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
|
3417 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
|
3418 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3419 // 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
|
3420 // previous window. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3421 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
|
3422 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3423 pwin = curwin; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3424 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
|
3425 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
|
3426 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3427 else |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3428 #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
|
3429 // 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
|
3430 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
|
3431 { |
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
|
3432 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
|
3433 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3434 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
|
3435 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
|
3436 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
|
3437 } |
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
|
3438 |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3439 // ++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
|
3440 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
|
3441 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
|
3442 // 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
|
3443 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
|
3444 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
|
3445 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
|
3446 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
|
3447 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
|
3448 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
|
3449 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
|
3450 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
|
3451 #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
|
3452 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
|
3453 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
|
3454 #endif |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3455 return TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3456 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3457 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
|
3458 && 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
|
3459 { |
22864
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3460 char *cmd = term->tl_opencmd == NULL |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3461 ? "botright sbuf %d" |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3462 : (char *)term->tl_opencmd; |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3463 size_t len = strlen(cmd) + 50; |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3464 char *buf = alloc(len); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3465 |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3466 if (buf != NULL) |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3467 { |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3468 ch_log(NULL, "terminal job finished, opening window"); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3469 vim_snprintf(buf, len, cmd, fnum); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3470 do_cmdline_cmd((char_u *)buf); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3471 vim_free(buf); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3472 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3473 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3474 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3475 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
|
3476 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3477 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3478 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
|
3479 return FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3480 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3481 |
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
|
3482 #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
|
3483 /* |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3484 * 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
|
3485 * 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
|
3486 * 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
|
3487 */ |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3488 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
|
3489 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
|
3490 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3491 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
|
3492 && !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
|
3493 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3494 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
|
3495 |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3496 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
|
3497 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
|
3498 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
|
3499 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
|
3500 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3501 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
|
3502 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3503 #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
|
3504 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3505 /* |
12502 | 3506 * Called when a channel has been closed. |
3507 * If this was a channel for a terminal window then finish it up. | |
3508 */ | |
3509 void | |
3510 term_channel_closed(channel_T *ch) | |
3511 { | |
3512 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
|
3513 term_T *next_term; |
12502 | 3514 int did_one = FALSE; |
3515 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3516 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
|
3517 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3518 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
|
3519 if (term->tl_job == ch->ch_job && !term->tl_channel_closed) |
12502 | 3520 { |
3521 term->tl_channel_closed = TRUE; | |
3522 did_one = TRUE; | |
3523 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3524 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
|
3525 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
|
3526 #ifdef MSWIN |
13862
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3527 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
|
3528 { |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3529 fclose(term->tl_out_fd); |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3530 term->tl_out_fd = NULL; |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3531 } |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3532 #endif |
12502 | 3533 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3534 if (updating_screen) |
12502 | 3535 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3536 // 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
|
3537 // '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
|
3538 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
|
3539 continue; |
12502 | 3540 } |
3541 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3542 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
|
3543 next_term = first_term; |
12502 | 3544 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3545 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3546 |
12502 | 3547 if (did_one) |
3548 { | |
3549 redraw_statuslines(); | |
3550 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3551 // 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
|
3552 ins_char_typebuf(K_IGNORE, 0); |
12502 | 3553 typebuf_was_filled = TRUE; |
3554 | |
3555 term = curbuf->b_term; | |
3556 if (term != NULL) | |
3557 { | |
3558 if (term->tl_job == ch->ch_job) | |
3559 maketitle(); | |
3560 update_cursor(term, term->tl_cursor_visible); | |
3561 } | |
3562 } | |
3563 } | |
3564 | |
3565 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3566 * 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
|
3567 * 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
|
3568 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3569 void |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3570 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
|
3571 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3572 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
|
3573 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
|
3574 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3575 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
|
3576 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3577 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
|
3578 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
|
3579 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3580 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
|
3581 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
|
3582 // 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
|
3583 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
|
3584 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3585 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3586 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3587 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3588 /* |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3589 * 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
|
3590 * 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
|
3591 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3592 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
|
3593 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
|
3594 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
|
3595 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
|
3596 VTermScreen *screen, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3597 VTermPos *pos, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3598 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
|
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 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
|
3601 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3602 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
|
3603 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3604 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
|
3605 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
|
3606 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3607 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
|
3608 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
|
3609 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3610 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
|
3611 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
|
3612 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3613 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
|
3614 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
|
3615 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
|
3616 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3617 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3618 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3619 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
|
3620 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3621 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
|
3622 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3623 // 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
|
3624 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
|
3625 && 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
|
3626 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3627 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
|
3628 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
|
3629 break; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3630 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3631 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
|
3632 && 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
|
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 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
|
3635 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
|
3636 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3637 else |
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 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
|
3640 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
|
3641 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3642 } |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3643 #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
|
3644 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
|
3645 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3646 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
|
3647 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
|
3648 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3649 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
|
3650 (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
|
3651 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3652 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
|
3653 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
|
3654 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
|
3655 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3656 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3657 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
|
3658 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3659 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3660 else |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3661 // This will only store the lower byte of "c". |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3662 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
|
3663 } |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3664 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
|
3665 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3666 ++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
|
3667 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3668 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
|
3669 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3670 // 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
|
3671 // has been set above |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3672 if (enc_utf8) |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3673 { |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3674 ScreenLinesUC[off] = NUL; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3675 ScreenLines[off] = NUL; |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3676 } |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3677 else if (!has_mbyte) |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3678 { |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3679 // Can't show a double-width character with a single-byte |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3680 // 'encoding', just use a space. |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3681 ScreenLines[off] = ' '; |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3682 ScreenAttrs[off] = ScreenAttrs[off - 1]; |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3683 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3684 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3685 ++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
|
3686 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3687 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3688 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3689 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3690 |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3691 #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
|
3692 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
|
3693 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
|
3694 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3695 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
|
3696 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
|
3697 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3698 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
|
3699 return; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3700 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
|
3701 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3702 // 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
|
3703 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
|
3704 && (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
|
3705 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3706 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
|
3707 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3708 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
|
3709 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
|
3710 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
|
3711 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
|
3712 --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
|
3713 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3714 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3715 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
|
3716 && 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
|
3717 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3718 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
|
3719 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3720 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
|
3721 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3722 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
|
3723 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3724 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3725 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
|
3726 |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3727 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
|
3728 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3729 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3730 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
|
3731 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
|
3732 } |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3733 #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
|
3734 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3735 /* |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3736 * 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
|
3737 * Returns FALSE when there is no terminal running in this window or it is in |
12502 | 3738 * Terminal-Normal mode. |
3739 */ | |
3740 int | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3741 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
|
3742 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3743 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
|
3744 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3745 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
|
3746 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3747 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3748 /* |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3749 * 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
|
3750 */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3751 void |
12502 | 3752 term_update_window(win_T *wp) |
3753 { | |
3754 term_T *term = wp->w_buffer->b_term; | |
3755 VTerm *vterm; | |
3756 VTermScreen *screen; | |
3757 VTermState *state; | |
3758 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
|
3759 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
|
3760 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
|
3761 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
|
3762 win_T *twp; |
12502 | 3763 |
3764 vterm = term->tl_vterm; | |
3765 screen = vterm_obtain_screen(vterm); | |
3766 state = vterm_obtain_state(vterm); | |
3767 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3768 // 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
|
3769 // 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
|
3770 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
|
3771 { |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3772 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
|
3773 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
|
3774 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3775 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
|
3776 && 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
|
3777 // 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
|
3778 // 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
|
3779 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
|
3780 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
|
3781 } |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3782 |
12502 | 3783 /* |
3784 * 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
|
3785 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size. |
12502 | 3786 */ |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3787 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
|
3788 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3789 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
|
3790 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
|
3791 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
|
3792 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3793 // 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
|
3794 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
|
3795 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3796 // 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
|
3797 // 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
|
3798 if (wwp->w_buffer == term->tl_buffer) |
12502 | 3799 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3800 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
|
3801 newcols = MIN(newcols, wwp->w_width); |
12502 | 3802 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3803 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
|
3804 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
|
3805 } |
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
|
3806 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
|
3807 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
|
3808 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
|
3809 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
|
3810 |
24006
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3811 // If no cell is visible there is no point in resizing. Also, vterm can't |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3812 // handle a zero height. |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3813 if (newrows == 0 || newcols == 0) |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3814 return; |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3815 |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3816 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
|
3817 { |
12502 | 3818 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
|
3819 vterm_set_size(vterm, newrows, newcols); |
12502 | 3820 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
|
3821 newrows); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3822 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
|
3823 |
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
|
3824 // 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
|
3825 // 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
|
3826 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
|
3827 may_move_terminal_to_buffer(term, FALSE); |
12502 | 3828 } |
3829 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3830 // The cursor may have been moved when resizing. |
12502 | 3831 vterm_state_get_cursorpos(state, &pos); |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
3832 position_cursor(wp, &pos); |
12502 | 3833 |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3834 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
|
3835 && pos.row < wp->w_height; ++pos.row) |
12502 | 3836 { |
3837 if (pos.row < term->tl_rows) | |
3838 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3839 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
|
3840 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3841 term_line2screenline(term, wp, screen, &pos, max_col); |
12502 | 3842 } |
3843 else | |
3844 pos.col = 0; | |
3845 | |
13458
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3846 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
|
3847 #ifdef FEAT_MENU |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3848 + winbar_height(wp) |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3849 #endif |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3850 , 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
|
3851 #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
|
3852 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
|
3853 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3854 0); |
12502 | 3855 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3856 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
|
3857 term->tl_dirty_row_end = 0; |
12502 | 3858 } |
3859 | |
3860 /* | |
3861 * Return TRUE if "wp" is a terminal window where the job has finished. | |
3862 */ | |
3863 int | |
3864 term_is_finished(buf_T *buf) | |
3865 { | |
3866 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL; | |
3867 } | |
3868 | |
3869 /* | |
3870 * Return TRUE if "wp" is a terminal window where the job has finished or we | |
3871 * are in Terminal-Normal mode, thus we show the buffer contents. | |
3872 */ | |
3873 int | |
3874 term_show_buffer(buf_T *buf) | |
3875 { | |
3876 term_T *term = buf->b_term; | |
3877 | |
3878 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode); | |
3879 } | |
3880 | |
3881 /* | |
3882 * The current buffer is going to be changed. If there is terminal | |
3883 * highlighting remove it now. | |
3884 */ | |
3885 void | |
3886 term_change_in_curbuf(void) | |
3887 { | |
3888 term_T *term = curbuf->b_term; | |
3889 | |
3890 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) | |
3891 { | |
3892 free_scrollback(term); | |
3893 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3894 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3895 // 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
|
3896 // abandoned when changed. |
12502 | 3897 set_string_option_direct((char_u *)"buftype", -1, |
3898 (char_u *)"", OPT_FREE|OPT_LOCAL, 0); | |
3899 } | |
3900 } | |
3901 | |
3902 /* | |
3903 * Get the screen attribute for a position in the buffer. | |
3904 * Use a negative "col" to get the filler background color. | |
3905 */ | |
3906 int | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3907 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
|
3908 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3909 buf_T *buf = wp->w_buffer; |
12502 | 3910 term_T *term = buf->b_term; |
3911 sb_line_T *line; | |
3912 cellattr_T *cellattr; | |
3913 | |
3914 if (lnum > term->tl_scrollback.ga_len) | |
3915 cellattr = &term->tl_default_color; | |
3916 else | |
3917 { | |
3918 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1; | |
3919 if (col < 0 || col >= line->sb_cols) | |
3920 cellattr = &line->sb_fill_attr; | |
3921 else | |
3922 cellattr = line->sb_cells + col; | |
3923 } | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3924 return cell2attr(term, wp, cellattr->attrs, cellattr->fg, cellattr->bg); |
12502 | 3925 } |
3926 | |
3927 /* | |
3928 * 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
|
3929 * This is compatible with xterm. |
12502 | 3930 */ |
3931 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
|
3932 cterm_color2vterm(int nr, VTermColor *rgb) |
12502 | 3933 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3934 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
|
3935 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
|
3936 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
|
3937 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3938 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3939 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
|
3940 --rgb->index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3941 } |
12502 | 3942 } |
3943 | |
3944 /* | |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3945 * Initialize term->tl_default_color from the environment. |
12502 | 3946 */ |
3947 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
|
3948 init_default_colors(term_T *term, win_T *wp) |
12502 | 3949 { |
3950 VTermColor *fg, *bg; | |
3951 int fgval, bgval; | |
3952 int id; | |
3953 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3954 CLEAR_FIELD(term->tl_default_color.attrs); |
12502 | 3955 term->tl_default_color.width = 1; |
3956 fg = &term->tl_default_color.fg; | |
3957 bg = &term->tl_default_color.bg; | |
3958 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3959 // 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
|
3960 // 'background' is "light". |
12502 | 3961 if (*p_bg == 'l') |
3962 { | |
3963 fgval = 0; | |
3964 bgval = 255; | |
3965 } | |
3966 else | |
3967 { | |
3968 fgval = 255; | |
3969 bgval = 0; | |
3970 } | |
3971 fg->red = fg->green = fg->blue = fgval; | |
3972 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
|
3973 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
|
3974 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG; |
12502 | 3975 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3976 // 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
|
3977 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
|
3978 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
|
3979 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
|
3980 id = syn_name2id(term_get_highlight_name(term)); |
12502 | 3981 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3982 // Use the actual color for the GUI and when 'termguicolors' is set. |
12502 | 3983 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
3984 if (0 | |
3985 # ifdef FEAT_GUI | |
3986 || gui.in_use | |
3987 # endif | |
3988 # ifdef FEAT_TERMGUICOLORS | |
3989 || 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
|
3990 # ifdef FEAT_VTP |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3991 // 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
|
3992 || (!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
|
3993 # endif |
12502 | 3994 # endif |
3995 ) | |
3996 { | |
3997 guicolor_T fg_rgb = INVALCOLOR; | |
3998 guicolor_T bg_rgb = INVALCOLOR; | |
3999 | |
4000 if (id != 0) | |
4001 syn_id2colors(id, &fg_rgb, &bg_rgb); | |
4002 | |
4003 # ifdef FEAT_GUI | |
4004 if (gui.in_use) | |
4005 { | |
4006 if (fg_rgb == INVALCOLOR) | |
4007 fg_rgb = gui.norm_pixel; | |
4008 if (bg_rgb == INVALCOLOR) | |
4009 bg_rgb = gui.back_pixel; | |
4010 } | |
4011 # ifdef FEAT_TERMGUICOLORS | |
4012 else | |
4013 # endif | |
4014 # endif | |
4015 # ifdef FEAT_TERMGUICOLORS | |
4016 { | |
4017 if (fg_rgb == INVALCOLOR) | |
4018 fg_rgb = cterm_normal_fg_gui_color; | |
4019 if (bg_rgb == INVALCOLOR) | |
4020 bg_rgb = cterm_normal_bg_gui_color; | |
4021 } | |
4022 # endif | |
4023 if (fg_rgb != INVALCOLOR) | |
4024 { | |
4025 long_u rgb = GUI_MCH_GET_RGB(fg_rgb); | |
4026 | |
4027 fg->red = (unsigned)(rgb >> 16); | |
4028 fg->green = (unsigned)(rgb >> 8) & 255; | |
4029 fg->blue = (unsigned)rgb & 255; | |
4030 } | |
4031 if (bg_rgb != INVALCOLOR) | |
4032 { | |
4033 long_u rgb = GUI_MCH_GET_RGB(bg_rgb); | |
4034 | |
4035 bg->red = (unsigned)(rgb >> 16); | |
4036 bg->green = (unsigned)(rgb >> 8) & 255; | |
4037 bg->blue = (unsigned)rgb & 255; | |
4038 } | |
4039 } | |
4040 else | |
4041 #endif | |
4042 if (id != 0 && t_colors >= 16) | |
4043 { | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
4044 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
|
4045 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
|
4046 |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
4047 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
|
4048 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
|
4049 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
|
4050 cterm_color2vterm(cterm_bg, bg); |
12502 | 4051 } |
4052 else | |
4053 { | |
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
|
4054 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
12502 | 4055 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
|
4056 #endif |
12502 | 4057 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4058 // In an MS-Windows console we know the normal colors. |
12502 | 4059 if (cterm_normal_fg_color > 0) |
4060 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
4061 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
|
4062 # 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
|
4063 # 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
|
4064 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
|
4065 # 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
|
4066 { |
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
|
4067 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
|
4068 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
|
4069 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
|
4070 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4071 # endif |
12502 | 4072 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4073 # 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
|
4074 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4075 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
|
4076 # 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
|
4077 |
12502 | 4078 if (cterm_normal_bg_color > 0) |
4079 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
4080 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
|
4081 # 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
|
4082 # 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
|
4083 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
|
4084 # 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
|
4085 { |
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
|
4086 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
|
4087 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
|
4088 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
|
4089 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4090 # endif |
12502 | 4091 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4092 # 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
|
4093 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4094 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
|
4095 # endif |
12502 | 4096 } |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4097 } |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4098 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4099 #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
|
4100 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4101 * 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
|
4102 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4103 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
|
4104 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
|
4105 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4106 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
|
4107 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
|
4108 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4109 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
|
4110 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4111 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
|
4112 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4113 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
|
4114 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
|
4115 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
|
4116 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
|
4117 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4118 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4119 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4120 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4121 * 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
|
4122 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4123 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
|
4124 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
|
4125 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4126 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
|
4127 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
|
4128 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
|
4129 |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4130 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
|
4131 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4132 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
|
4133 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
|
4134 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4135 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
|
4136 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
|
4137 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
|
4138 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4139 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
|
4140 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
|
4141 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
|
4142 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4143 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
|
4144 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4145 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4146 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
|
4147 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
|
4148 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4149 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
|
4150 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4151 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
|
4152 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4153 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4154 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4155 * 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
|
4156 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4157 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
|
4158 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
|
4159 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4160 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
|
4161 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4162 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
|
4163 && (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
|
4164 || 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
|
4165 || 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
|
4166 || 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
|
4167 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
|
4168 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4169 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4170 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4171 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4172 * 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
|
4173 * "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
|
4174 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4175 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4176 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
|
4177 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4178 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
|
4179 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
|
4180 int bufnr; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4181 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
|
4182 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
|
4183 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
|
4184 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
|
4185 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4186 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
|
4187 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
|
4188 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4189 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
|
4190 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4191 // 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
|
4192 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
|
4193 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4194 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4195 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4196 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4197 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
|
4198 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4199 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
|
4200 && 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
|
4201 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4202 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
|
4203 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
|
4204 |
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
|
4205 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
|
4206 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
|
4207 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
|
4208 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
|
4209 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4210 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
|
4211 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
|
4212 else |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4213 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
|
4214 } |
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
|
4215 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
|
4216 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
|
4217 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
|
4218 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
|
4219 { |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4220 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
|
4221 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
|
4222 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4223 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
|
4224 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
|
4225 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
|
4226 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4227 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4228 |
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
|
4229 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
|
4230 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
|
4231 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
|
4232 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4233 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
|
4234 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
|
4235 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
|
4236 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
|
4237 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
|
4238 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
|
4239 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
|
4240 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
|
4241 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4242 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4243 // 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
|
4244 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
|
4245 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
|
4246 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
|
4247 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
|
4248 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
|
4249 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4250 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
|
4251 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4252 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4253 /* |
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
|
4254 * 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
|
4255 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4256 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
|
4257 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
|
4258 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4259 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
|
4260 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4261 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4262 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4263 * 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
|
4264 * "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
|
4265 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4266 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4267 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
|
4268 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4269 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
|
4270 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
|
4271 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
|
4272 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
|
4273 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4274 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
|
4275 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4276 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
|
4277 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4278 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4279 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
|
4280 |
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
|
4281 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
|
4282 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4283 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
|
4284 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4285 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4286 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4287 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
|
4288 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
|
4289 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
|
4290 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
|
4291 funcexe.firstline = 1L; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4292 funcexe.lastline = 1L; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4293 funcexe.evaluate = TRUE; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4294 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
|
4295 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4296 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
|
4297 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
|
4298 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4299 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4300 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
|
4301 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4302 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4303 /* |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4304 * URL decoding (also know as Percent-encoding). |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4305 * |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4306 * Note this function currently is only used for decoding shell's |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4307 * OSC 7 escape sequence which we can assume all bytes are valid |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4308 * UTF-8 bytes. Thus we don't need to deal with invalid UTF-8 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4309 * encoding bytes like 0xfe, 0xff. |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4310 */ |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4311 static size_t |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4312 url_decode(const char *src, const size_t len, char_u *dst) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4313 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4314 size_t i = 0, j = 0; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4315 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4316 while (i < len) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4317 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4318 if (src[i] == '%' && i + 2 < len) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4319 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4320 dst[j] = hexhex2nr((char_u *)&src[i + 1]); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4321 j++; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4322 i += 3; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4323 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4324 else |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4325 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4326 dst[j] = src[i]; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4327 i++; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4328 j++; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4329 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4330 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4331 dst[j] = '\0'; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4332 return j; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4333 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4334 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4335 /* |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4336 * Sync terminal buffer's cwd with shell's pwd with the help of OSC 7. |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4337 * |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4338 * The OSC 7 sequence has the format of |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4339 * "\033]7;file://HOSTNAME/CURRENT/DIR\033\\" |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4340 * and what VTerm provides via VTermStringFragment is |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4341 * "file://HOSTNAME/CURRENT/DIR" |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4342 */ |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4343 static void |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4344 sync_shell_dir(VTermStringFragment *frag) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4345 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4346 int offset = 7; // len of "file://" is 7 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4347 char *pos = (char *)frag->str + offset; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4348 char_u *new_dir; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4349 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4350 // remove HOSTNAME to get PWD |
24612
d957c7bbacf3
patch 8.2.2845: MS-Windows: warning for signed/unsigned comparison
Bram Moolenaar <Bram@vim.org>
parents:
24582
diff
changeset
|
4351 while (*pos != '/' && offset < (int)frag->len) |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4352 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4353 offset += 1; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4354 pos += 1; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4355 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4356 |
24612
d957c7bbacf3
patch 8.2.2845: MS-Windows: warning for signed/unsigned comparison
Bram Moolenaar <Bram@vim.org>
parents:
24582
diff
changeset
|
4357 if (offset >= (int)frag->len) |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4358 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4359 semsg(_(e_failed_to_extract_pwd_from_str_check_your_shell_config), |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4360 frag->str); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4361 return; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4362 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4363 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4364 new_dir = alloc(frag->len - offset + 1); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4365 url_decode(pos, frag->len-offset, new_dir); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4366 changedir_func(new_dir, TRUE, CDSCOPE_WINDOW); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4367 vim_free(new_dir); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4368 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4369 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4370 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4371 * 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
|
4372 * 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
|
4373 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4374 static int |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4375 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
|
4376 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4377 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
|
4378 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
|
4379 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
|
4380 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
|
4381 : 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
|
4382 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
|
4383 |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4384 // We recognize only OSC 5 1 ; {command} and OSC 7 ; {command} |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4385 if (p_asd && command == 7) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4386 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4387 sync_shell_dir(&frag); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4388 return 1; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4389 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4390 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4391 if (command != 51) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4392 return 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4393 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4394 // 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
|
4395 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
|
4396 { |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4397 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
|
4398 return 1; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4399 } |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4400 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
|
4401 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
|
4402 if (!frag.final) |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4403 return 1; |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4404 |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4405 ((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
|
4406 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
|
4407 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
|
4408 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
|
4409 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
|
4410 && 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
|
4411 && 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
|
4412 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4413 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
|
4414 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4415 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
|
4416 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
|
4417 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4418 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4419 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
|
4420 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4421 // 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
|
4422 // 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
|
4423 ++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
|
4424 |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4425 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
|
4426 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
|
4427 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
|
4428 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
|
4429 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
|
4430 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
|
4431 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
|
4432 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4433 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
|
4434 --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
|
4435 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4436 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4437 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4438 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
|
4439 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4440 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
|
4441 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
|
4442 return 1; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4443 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4444 |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4445 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4446 * 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
|
4447 * 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
|
4448 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4449 static int |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4450 parse_csi( |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4451 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
|
4452 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
|
4453 int argcount, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4454 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
|
4455 char command, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4456 void *user) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4457 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4458 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
|
4459 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
|
4460 int len; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4461 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
|
4462 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
|
4463 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
|
4464 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4465 // 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
|
4466 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
|
4467 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
|
4468 |
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
|
4469 // 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
|
4470 // 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
|
4471 #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
|
4472 || (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
|
4473 || 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
|
4474 (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
|
4475 #endif |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4476 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4477 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
|
4478 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
|
4479 break; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4480 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
|
4481 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4482 #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
|
4483 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
|
4484 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4485 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
|
4486 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
|
4487 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4488 else |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4489 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4490 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4491 // 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
|
4492 // 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
|
4493 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
|
4494 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
|
4495 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4496 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4497 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4498 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
|
4499 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
|
4500 (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
|
4501 return 1; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4502 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4503 |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4504 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
|
4505 NULL, // control |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4506 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
|
4507 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
|
4508 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
|
4509 }; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4510 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4511 /* |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4512 * 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
|
4513 */ |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4514 static void * |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4515 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
|
4516 { |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16656
diff
changeset
|
4517 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
|
4518 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4519 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4520 static void |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4521 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
|
4522 { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4523 vim_free(ptr); |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4524 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4525 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4526 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
|
4527 &vterm_malloc, |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4528 &vterm_memfree |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4529 }; |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4530 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4531 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4532 * 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
|
4533 * 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
|
4534 */ |
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
|
4535 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
|
4536 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
|
4537 { |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4538 VTerm *vterm; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4539 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
|
4540 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
|
4541 VTermValue value; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4542 |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4543 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
|
4544 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
|
4545 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
|
4546 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
|
4547 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4548 // 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
|
4549 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
|
4550 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
|
4551 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
|
4552 { |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4553 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
|
4554 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
|
4555 } |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4556 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4557 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
|
4558 // 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
|
4559 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
|
4560 |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4561 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
|
4562 |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4563 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
|
4564 state, |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4565 &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
|
4566 &term->tl_default_color.bg); |
12502 | 4567 |
16656
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4568 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
|
4569 // 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
|
4570 // 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
|
4571 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
|
4572 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4573 // Required to initialize most things. |
12502 | 4574 vterm_screen_reset(screen, 1 /* hard */); |
4575 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4576 // Allow using alternate screen. |
12502 | 4577 vterm_screen_enable_altscreen(screen, 1); |
4578 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4579 // 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
|
4580 // 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
|
4581 // 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
|
4582 #ifdef MSWIN |
12502 | 4583 if (GetCaretBlinkTime() == INFINITE) |
4584 value.boolean = 0; | |
4585 else | |
4586 value.boolean = 1; | |
4587 #else | |
4588 value.boolean = 0; | |
4589 #endif | |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4590 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
|
4591 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
|
4592 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4593 return OK; |
12502 | 4594 } |
4595 | |
4596 /* | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4597 * 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
|
4598 */ |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4599 void |
24582
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4600 term_update_colors(term_T *term) |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4601 { |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4602 win_T *wp; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4603 |
19358
734ca70c1f12
patch 8.2.0237: crash when setting 'wincolor' on finished terminal window
Bram Moolenaar <Bram@vim.org>
parents:
19275
diff
changeset
|
4604 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
|
4605 return; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4606 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
|
4607 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
|
4608 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
|
4609 &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
|
4610 &term->tl_default_color.bg); |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
4611 |
24582
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4612 FOR_ALL_WINDOWS(wp) |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4613 if (wp->w_buffer == term->tl_buffer) |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4614 redraw_win_later(wp, NOT_VALID); |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4615 } |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4616 |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4617 /* |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4618 * Called when 'background' was set. |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4619 */ |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4620 void |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4621 term_update_colors_all(void) |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4622 { |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4623 term_T *tp; |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4624 |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4625 FOR_ALL_TERMS(tp) |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4626 term_update_colors(tp); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4627 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4628 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4629 /* |
12502 | 4630 * Return the text to show for the buffer name and status. |
4631 */ | |
4632 char_u * | |
4633 term_get_status_text(term_T *term) | |
4634 { | |
4635 if (term->tl_status_text == NULL) | |
4636 { | |
4637 char_u *txt; | |
4638 size_t len; | |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4639 char_u *fname; |
12502 | 4640 |
4641 if (term->tl_normal_mode) | |
4642 { | |
4643 if (term_job_running(term)) | |
4644 txt = (char_u *)_("Terminal"); | |
4645 else | |
4646 txt = (char_u *)_("Terminal-finished"); | |
4647 } | |
4648 else if (term->tl_title != NULL) | |
4649 txt = term->tl_title; | |
4650 else if (term_none_open(term)) | |
4651 txt = (char_u *)_("active"); | |
4652 else if (term_job_running(term)) | |
4653 txt = (char_u *)_("running"); | |
4654 else | |
4655 txt = (char_u *)_("finished"); | |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4656 fname = buf_get_fname(term->tl_buffer); |
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4657 len = 9 + STRLEN(fname) + STRLEN(txt); |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4658 term->tl_status_text = alloc(len); |
12502 | 4659 if (term->tl_status_text != NULL) |
4660 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]", | |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4661 fname, txt); |
12502 | 4662 } |
4663 return term->tl_status_text; | |
4664 } | |
4665 | |
4666 /* | |
4667 * Mark references in jobs of terminals. | |
4668 */ | |
4669 int | |
4670 set_ref_in_term(int copyID) | |
4671 { | |
4672 int abort = FALSE; | |
4673 term_T *term; | |
4674 typval_T tv; | |
4675 | |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17133
diff
changeset
|
4676 for (term = first_term; !abort && term != NULL; term = term->tl_next) |
12502 | 4677 if (term->tl_job != NULL) |
4678 { | |
4679 tv.v_type = VAR_JOB; | |
4680 tv.vval.v_job = term->tl_job; | |
4681 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); | |
4682 } | |
4683 return abort; | |
4684 } | |
4685 | |
4686 /* | |
4687 * 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
|
4688 * 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
|
4689 * with "where". |
12502 | 4690 */ |
4691 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
|
4692 term_get_buf(typval_T *argvars, char *where) |
12502 | 4693 { |
4694 buf_T *buf; | |
4695 | |
4696 ++emsg_off; | |
15355
73b153ed5af8
patch 8.1.0685: get_buf_tv() is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
15273
diff
changeset
|
4697 buf = tv_get_buf(&argvars[0], FALSE); |
12502 | 4698 --emsg_off; |
4699 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
|
4700 { |
23029
bc3a083b50cb
patch 8.2.2061: Vim9: E1030 error when using empty string for term_sendkeys()
Bram Moolenaar <Bram@vim.org>
parents:
22886
diff
changeset
|
4701 (void)tv_get_number(&argvars[0]); // issue errmsg if type error |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4702 ch_log(NULL, "%s: invalid buffer argument", where); |
12502 | 4703 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
|
4704 } |
12502 | 4705 return buf; |
4706 } | |
4707 | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4708 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4709 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
|
4710 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4711 CLEAR_FIELD(*cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4712 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
|
4713 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
|
4714 } |
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 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4717 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
|
4718 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4719 int index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4720 |
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_INDEXED(color)) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4722 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
|
4723 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
|
4724 // use RGB values |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4725 index = 255; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4726 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4727 // default color |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4728 index = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4729 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
|
4730 (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
|
4731 index); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4732 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4733 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4734 /* |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4735 * "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
|
4736 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4737 * 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
|
4738 * |{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
|
4739 * {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
|
4740 * 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
|
4741 * skipped. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4742 * {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
|
4743 * 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
|
4744 * {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
|
4745 * {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
|
4746 * {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
|
4747 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4748 * 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
|
4749 * |{characters} |
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 * 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
|
4752 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4753 * 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
|
4754 * @{count} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4755 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4756 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4757 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
|
4758 { |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4759 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
|
4760 term_T *term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4761 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
|
4762 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
|
4763 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
|
4764 stat_T st; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4765 FILE *fd; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4766 VTermPos pos; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4767 VTermScreen *screen; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4768 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
|
4769 VTermState *state; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4770 VTermPos cursor_pos; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4771 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4772 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
|
4773 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4774 if (buf == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4775 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4776 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
|
4777 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
|
4778 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4779 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
|
4780 return; |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4781 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4782 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4783 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
|
4784 { |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4785 dict_T *d; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4786 |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4787 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
|
4788 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4789 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
|
4790 return; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4791 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4792 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
|
4793 if (d != NULL) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4794 { |
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
|
4795 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
|
4796 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
|
4797 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4798 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4799 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4800 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
|
4801 if (fname == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4802 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4803 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
|
4804 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4805 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
|
4806 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4807 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4808 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4809 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
|
4810 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4811 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
|
4812 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4813 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4814 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4815 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
|
4816 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4817 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
|
4818 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
|
4819 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
|
4820 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4821 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
|
4822 && 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
|
4823 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4824 int repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4825 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4826 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
|
4827 && 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
|
4828 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4829 VTermScreenCell cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4830 int same_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4831 int same_chars = TRUE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4832 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
|
4833 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
|
4834 && 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
|
4835 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4836 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
|
4837 clear_cell(&cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4838 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4839 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
|
4840 { |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4841 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
|
4842 int pc = prev_cell.chars[i]; |
22687
73688eec32ca
patch 8.2.1892: valgrind warns for using uninitialized access in tests
Bram Moolenaar <Bram@vim.org>
parents:
22448
diff
changeset
|
4843 int should_break = c == NUL || pc == NUL; |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4844 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4845 // 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
|
4846 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
|
4847 { |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4848 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
|
4849 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
|
4850 } |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
4851 if (c != pc) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4852 same_chars = FALSE; |
22687
73688eec32ca
patch 8.2.1892: valgrind warns for using uninitialized access in tests
Bram Moolenaar <Bram@vim.org>
parents:
22448
diff
changeset
|
4853 if (should_break) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4854 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4855 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4856 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
|
4857 == 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
|
4858 && 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
|
4859 && 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
|
4860 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
|
4861 && !is_cursor_pos) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4862 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4863 ++repeat; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4864 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4865 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4866 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4867 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4868 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4869 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4870 repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4871 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4872 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
|
4873 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4874 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
|
4875 fputs(" ", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4876 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4877 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4878 char_u charbuf[10]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4879 int len; |
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 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
|
4882 && 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
|
4883 { |
13557
4911058c43eb
patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents:
13547
diff
changeset
|
4884 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
|
4885 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
|
4886 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4887 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4888 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4889 // 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
|
4890 // 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
|
4891 // attributes. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4892 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
|
4893 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4894 if (cell.width == 2) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4895 fputs("*", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4896 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4897 fputs("+", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4898 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4899 if (same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4900 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4901 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4902 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4903 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4904 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4905 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
|
4906 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
|
4907 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4908 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4909 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4910 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4911 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
|
4912 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4913 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
|
4914 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4915 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4916 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4917 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4918 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
|
4919 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4920 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4921 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4922 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4923 prev_cell = cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4924 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4925 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4926 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4927 ++pos.col; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4928 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4929 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4930 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4931 fputs("\n", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4932 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4933 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4934 fclose(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4935 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4936 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4937 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4938 * 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
|
4939 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4940 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4941 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
|
4942 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4943 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
|
4944 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4945 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4946 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4947 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
|
4948 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4949 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
|
4950 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4951 *(((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
|
4952 ++gap->ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4953 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4954 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4955 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4956 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4957 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
|
4958 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4959 CLEAR_FIELD(*cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4960 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
|
4961 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
|
4962 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4963 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4964 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4965 * 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
|
4966 * 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
|
4967 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4968 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
|
4969 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
|
4970 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4971 int c; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4972 garray_T ga_text; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4973 garray_T ga_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4974 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
|
4975 int attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4976 cellattr_T cell; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4977 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
|
4978 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
|
4979 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
|
4980 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
|
4981 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4982 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
|
4983 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
|
4984 clear_cellattr(&cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4985 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
|
4986 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
|
4987 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
|
4988 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4989 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4990 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4991 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4992 if (c == EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4993 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
|
4994 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
|
4995 { |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4996 // 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
|
4997 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
|
4998 } |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4999 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
|
5000 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5001 // 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
|
5002 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
|
5003 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
|
5004 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
|
5005 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5006 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
|
5007 + 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
|
5008 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5009 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
|
5010 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
|
5011 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
|
5012 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
|
5013 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
|
5014 ++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
|
5015 ga_init(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5016 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5017 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
|
5018 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
|
5019 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
|
5020 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5021 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5022 ga_clear(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5023 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
|
5024 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5025 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5026 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5027 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
|
5028 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5029 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
|
5030 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5031 if (c == '>') |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5032 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5033 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
|
5034 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
|
5035 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
|
5036 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
|
5037 } |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5038 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5039 // 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
|
5040 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5041 if (c != EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5042 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
|
5043 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5044 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5045 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
|
5046 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
|
5047 || c == EOF || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5048 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5049 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
|
5050 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5051 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5052 // 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
|
5053 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5054 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
|
5055 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
|
5056 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
|
5057 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5058 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
|
5059 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5060 // 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
|
5061 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5062 else if (c == '+' || c == '*') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5063 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5064 int is_bg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5065 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5066 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
|
5067 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5068 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5069 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5070 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5071 // 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
|
5072 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5073 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5074 else if (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5075 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5076 // 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
|
5077 attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5078 while (isdigit(c)) |
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 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
|
5081 c = fgetc(fd); |
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 hl2vtermAttr(attr, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5084 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5085 // 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
|
5086 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
|
5087 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5088 if (c == '&') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5089 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5090 // 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
|
5091 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5092 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5093 else if (c == '#') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5094 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5095 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
|
5096 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5097 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5098 red = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5099 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5100 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
|
5101 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5102 green = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5103 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5104 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
|
5105 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5106 blue = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5107 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5108 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
|
5109 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5110 if (!isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5111 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
|
5112 while (isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5113 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5114 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
|
5115 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5116 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5117 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
|
5118 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5119 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
|
5120 if (index == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5121 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5122 if (is_bg) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5123 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
|
5124 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5125 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
|
5126 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5127 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5128 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5129 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5130 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
|
5131 index -= 1; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5132 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5133 if (is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5134 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5135 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
|
5136 cell.bg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5137 cell.bg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5138 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
|
5139 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
|
5140 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5141 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5142 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5143 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
|
5144 cell.fg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5145 cell.fg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5146 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
|
5147 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
|
5148 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5149 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5150 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5151 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
|
5152 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5153 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5154 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5155 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
|
5156 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5157 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5158 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
|
5159 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5160 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
|
5161 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5162 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
|
5163 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5164 else if (c == '@') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5165 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5166 if (prev_char == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5167 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
|
5168 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5169 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5170 int count = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5171 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5172 // 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
|
5173 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5174 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5175 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5176 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5177 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5178 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
|
5179 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5180 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5181 while (count-- > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5182 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5183 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
|
5184 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
|
5185 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5186 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5187 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5188 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5189 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5190 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
|
5191 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5192 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5193 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5194 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5195 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
|
5196 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5197 // 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
|
5198 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
|
5199 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
|
5200 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
|
5201 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
|
5202 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5203 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5204 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
|
5205 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
|
5206 vim_free(prev_char); |
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 return max_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5209 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5210 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5211 /* |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5212 * 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
|
5213 * "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
|
5214 */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5215 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
|
5216 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
|
5217 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5218 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
|
5219 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
|
5220 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
|
5221 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
|
5222 int i; |
13630
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5223 size_t off; |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5224 |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5225 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
|
5226 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
|
5227 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
|
5228 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5229 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
|
5230 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
|
5231 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5232 // 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
|
5233 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
|
5234 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5235 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
|
5236 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5237 // 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
|
5238 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
|
5239 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
|
5240 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5241 // 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
|
5242 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
|
5243 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5244 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
|
5245 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
|
5246 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5247 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5248 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
|
5249 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
|
5250 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
|
5251 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5252 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
|
5253 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
|
5254 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
|
5255 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
|
5256 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
|
5257 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
|
5258 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5259 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
|
5260 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5261 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5262 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5263 * 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
|
5264 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5265 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5266 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
|
5267 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5268 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
|
5269 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
|
5270 char_u buf1[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5271 char_u buf2[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5272 char_u *fname1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5273 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
|
5274 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
|
5275 FILE *fd1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5276 FILE *fd2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5277 char_u *textline = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5278 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5279 // 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
|
5280 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
|
5281 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
|
5282 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
|
5283 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
|
5284 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5285 emsg(_(e_invarg)); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5286 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5287 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5288 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
|
5289 if (fd1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5290 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5291 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
|
5292 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5293 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5294 if (do_diff) |
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 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
|
5297 if (fd2 == NULL) |
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 fclose(fd1); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5300 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
|
5301 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5302 } |
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 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5305 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
|
5306 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
|
5307 && 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
|
5308 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
|
5309 + 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
|
5310 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
|
5311 |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5312 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
|
5313 { |
13505
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
5314 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
|
5315 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
5316 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
|
5317 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
|
5318 { |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5319 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
|
5320 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
|
5321 } |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5322 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5323 |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5324 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
|
5325 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5326 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
|
5327 |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5328 // 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
|
5329 // empty. |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5330 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
|
5331 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
|
5332 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5333 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5334 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
|
5335 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
|
5336 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
|
5337 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
|
5338 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
|
5339 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5340 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5341 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5342 // 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
|
5343 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
|
5344 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5345 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
|
5346 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5347 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5348 linenr_T bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5349 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5350 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
|
5351 int width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5352 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
|
5353 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
|
5354 VTermPos cursor_pos2; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5355 |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
5356 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
|
5357 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5358 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
|
5359 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5360 // 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
|
5361 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
|
5362 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5363 // 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
|
5364 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
|
5365 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5366 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
|
5367 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
|
5368 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5369 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5370 // 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
|
5371 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5372 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5373 // 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
|
5374 if (!do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5375 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5376 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5377 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
|
5378 |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5379 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
|
5380 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5381 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5382 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
|
5383 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
|
5384 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
|
5385 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5386 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
|
5387 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
|
5388 goto theend; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5389 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
|
5390 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
|
5391 textline[width] = NUL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5392 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5393 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
|
5394 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
|
5395 if (width2 > width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5396 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5397 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5398 textline = alloc(width2 + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5399 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5400 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5401 width = width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5402 textline[width] = NUL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5403 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5404 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
|
5405 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5406 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
|
5407 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5408 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
|
5409 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5410 // 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
|
5411 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
|
5412 textline[i] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5413 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5414 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5415 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5416 char_u *line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5417 char_u *line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5418 char_u *p1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5419 char_u *p2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5420 int col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5421 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
|
5422 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
|
5423 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
|
5424 ->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5425 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5426 // 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
|
5427 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
|
5428 if (line1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5429 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5430 p1 = line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5431 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5432 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
|
5433 p2 = line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5434 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
|
5435 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5436 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
|
5437 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
|
5438 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5439 textline[col] = ' '; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5440 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
|
5441 // text differs |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5442 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
|
5443 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
|
5444 && 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
|
5445 && (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
|
5446 || 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
|
5447 // 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
|
5448 textline[col] = '>'; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5449 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
|
5450 && 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
|
5451 && (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
|
5452 || 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
|
5453 // 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
|
5454 textline[col] = '<'; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5455 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
|
5456 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5457 if ((cellattr1 + col)->width |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5458 != (cellattr2 + col)->width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5459 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
|
5460 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
|
5461 &(cellattr2 + col)->fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5462 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
|
5463 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
|
5464 &(cellattr2 + col)->bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5465 textline[col] = 'b'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5466 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
|
5467 != vtermAttr2hl(((cellattr2 + col)->attrs))) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5468 textline[col] = 'a'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5469 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5470 p1 += len1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5471 p2 += len2; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5472 // 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
|
5473 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5474 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5475 while (col < width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5476 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5477 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
|
5478 textline[col] = '?'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5479 else if (*p1 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5480 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5481 textline[col] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5482 p2 += utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5483 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5484 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5485 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5486 textline[col] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5487 p1 += utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5488 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5489 ++col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5490 } |
15828
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5491 |
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5492 vim_free(line1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5493 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5494 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
|
5495 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
|
5496 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
|
5497 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5498 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5499 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5500 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
|
5501 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5502 // 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
|
5503 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
|
5504 textline[i] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5505 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
|
5506 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
|
5507 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
|
5508 ++lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5509 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5510 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5511 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5512 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
|
5513 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5514 // 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
|
5515 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
|
5516 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5517 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5518 theend: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5519 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
|
5520 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
|
5521 fclose(fd1); |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5522 if (fd2 != NULL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5523 fclose(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5524 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5525 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5526 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5527 * 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
|
5528 * bottom files. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5529 * 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
|
5530 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5531 int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5532 term_swap_diff() |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5533 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5534 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
|
5535 linenr_T line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5536 linenr_T top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5537 linenr_T bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5538 linenr_T bot_start; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5539 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5540 char_u *p; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5541 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
|
5542 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5543 if (term == NULL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5544 || !term_is_finished(curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5545 || 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
|
5546 || 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
|
5547 return FAIL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5548 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5549 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
|
5550 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
|
5551 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
|
5552 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
|
5553 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
|
5554 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5555 // 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
|
5556 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
|
5557 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5558 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
|
5559 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5560 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5561 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
|
5562 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5563 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5564 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5565 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5566 // 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
|
5567 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
|
5568 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5569 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
|
5570 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5571 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5572 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
|
5573 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
|
5574 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5575 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5576 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5577 // 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
|
5578 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
|
5579 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
|
5580 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
|
5581 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
|
5582 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
|
5583 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
|
5584 |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5585 // 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
|
5586 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
|
5587 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
|
5588 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5589 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
|
5590 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
|
5591 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
|
5592 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5593 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
|
5594 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5595 // 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
|
5596 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
|
5597 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5598 sb_line_T temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5599 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5600 temp = *(sb_line + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5601 *(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
|
5602 *(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
|
5603 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5604 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5605 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5606 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5607 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
|
5608 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
|
5609 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5610 // 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
|
5611 if (temp != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5612 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5613 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
|
5614 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
|
5615 temp + bot_start, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5616 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
|
5617 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
|
5618 temp + top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5619 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
|
5620 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
|
5621 + line_count - top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5622 temp, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5623 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
|
5624 vim_free(temp); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5625 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5626 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5627 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5628 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
|
5629 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
|
5630 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5631 update_screen(NOT_VALID); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5632 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5633 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5634 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5635 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5636 * "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
|
5637 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5638 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5639 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
|
5640 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5641 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
|
5642 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5643 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5644 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5645 * "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
|
5646 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5647 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5648 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
|
5649 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5650 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
|
5651 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5652 |
12502 | 5653 /* |
5654 * "term_getaltscreen(buf)" function | |
5655 */ | |
5656 void | |
5657 f_term_getaltscreen(typval_T *argvars, typval_T *rettv) | |
5658 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5659 buf_T *buf = term_get_buf(argvars, "term_getaltscreen()"); |
12502 | 5660 |
5661 if (buf == NULL) | |
5662 return; | |
5663 rettv->vval.v_number = buf->b_term->tl_using_altscreen; | |
5664 } | |
5665 | |
5666 /* | |
5667 * "term_getattr(attr, name)" function | |
5668 */ | |
5669 void | |
5670 f_term_getattr(typval_T *argvars, typval_T *rettv) | |
5671 { | |
5672 int attr; | |
5673 size_t i; | |
5674 char_u *name; | |
5675 | |
5676 static struct { | |
5677 char *name; | |
5678 int attr; | |
5679 } attrs[] = { | |
5680 {"bold", HL_BOLD}, | |
5681 {"italic", HL_ITALIC}, | |
5682 {"underline", HL_UNDERLINE}, | |
5683 {"strike", HL_STRIKETHROUGH}, | |
5684 {"reverse", HL_INVERSE}, | |
5685 }; | |
5686 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5687 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
|
5688 name = tv_get_string_chk(&argvars[1]); |
12502 | 5689 if (name == NULL) |
5690 return; | |
5691 | |
18033
049a7481d737
patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17702
diff
changeset
|
5692 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
|
5693 attr = syn_attr2attr(attr); |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24739
diff
changeset
|
5694 for (i = 0; i < ARRAY_LENGTH(attrs); ++i) |
12502 | 5695 if (STRCMP(name, attrs[i].name) == 0) |
5696 { | |
5697 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0; | |
5698 break; | |
5699 } | |
5700 } | |
5701 | |
5702 /* | |
5703 * "term_getcursor(buf)" function | |
5704 */ | |
5705 void | |
5706 f_term_getcursor(typval_T *argvars, typval_T *rettv) | |
5707 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5708 buf_T *buf = term_get_buf(argvars, "term_getcursor()"); |
12502 | 5709 term_T *term; |
5710 list_T *l; | |
5711 dict_T *d; | |
5712 | |
5713 if (rettv_list_alloc(rettv) == FAIL) | |
5714 return; | |
5715 if (buf == NULL) | |
5716 return; | |
5717 term = buf->b_term; | |
5718 | |
5719 l = rettv->vval.v_list; | |
5720 list_append_number(l, term->tl_cursor_pos.row + 1); | |
5721 list_append_number(l, term->tl_cursor_pos.col + 1); | |
5722 | |
5723 d = dict_alloc(); | |
5724 if (d != NULL) | |
5725 { | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5726 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
|
5727 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
|
5728 ? !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
|
5729 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
|
5730 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color)); |
12502 | 5731 list_append_dict(l, d); |
5732 } | |
5733 } | |
5734 | |
5735 /* | |
5736 * "term_getjob(buf)" function | |
5737 */ | |
5738 void | |
5739 f_term_getjob(typval_T *argvars, typval_T *rettv) | |
5740 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5741 buf_T *buf = term_get_buf(argvars, "term_getjob()"); |
12502 | 5742 |
15217
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5743 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
|
5744 { |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5745 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
|
5746 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
|
5747 return; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5748 } |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5749 |
12502 | 5750 rettv->v_type = VAR_JOB; |
5751 rettv->vval.v_job = buf->b_term->tl_job; | |
5752 if (rettv->vval.v_job != NULL) | |
5753 ++rettv->vval.v_job->jv_refcount; | |
5754 } | |
5755 | |
5756 static int | |
5757 get_row_number(typval_T *tv, term_T *term) | |
5758 { | |
5759 if (tv->v_type == VAR_STRING | |
5760 && tv->vval.v_string != NULL | |
5761 && STRCMP(tv->vval.v_string, ".") == 0) | |
5762 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
|
5763 return (int)tv_get_number(tv) - 1; |
12502 | 5764 } |
5765 | |
5766 /* | |
5767 * "term_getline(buf, row)" function | |
5768 */ | |
5769 void | |
5770 f_term_getline(typval_T *argvars, typval_T *rettv) | |
5771 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5772 buf_T *buf = term_get_buf(argvars, "term_getline()"); |
12502 | 5773 term_T *term; |
5774 int row; | |
5775 | |
5776 rettv->v_type = VAR_STRING; | |
5777 if (buf == NULL) | |
5778 return; | |
5779 term = buf->b_term; | |
5780 row = get_row_number(&argvars[1], term); | |
5781 | |
5782 if (term->tl_vterm == NULL) | |
5783 { | |
5784 linenr_T lnum = row + term->tl_scrollback_scrolled + 1; | |
5785 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5786 // vterm is finished, get the text from the buffer |
12502 | 5787 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count) |
5788 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE)); | |
5789 } | |
5790 else | |
5791 { | |
5792 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm); | |
5793 VTermRect rect; | |
5794 int len; | |
5795 char_u *p; | |
5796 | |
5797 if (row < 0 || row >= term->tl_rows) | |
5798 return; | |
5799 len = term->tl_cols * MB_MAXBYTES + 1; | |
5800 p = alloc(len); | |
5801 if (p == NULL) | |
5802 return; | |
5803 rettv->vval.v_string = p; | |
5804 | |
5805 rect.start_col = 0; | |
5806 rect.end_col = term->tl_cols; | |
5807 rect.start_row = row; | |
5808 rect.end_row = row + 1; | |
5809 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL; | |
5810 } | |
5811 } | |
5812 | |
5813 /* | |
5814 * "term_getscrolled(buf)" function | |
5815 */ | |
5816 void | |
5817 f_term_getscrolled(typval_T *argvars, typval_T *rettv) | |
5818 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5819 buf_T *buf = term_get_buf(argvars, "term_getscrolled()"); |
12502 | 5820 |
5821 if (buf == NULL) | |
5822 return; | |
5823 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled; | |
5824 } | |
5825 | |
5826 /* | |
5827 * "term_getsize(buf)" function | |
5828 */ | |
5829 void | |
5830 f_term_getsize(typval_T *argvars, typval_T *rettv) | |
5831 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5832 buf_T *buf = term_get_buf(argvars, "term_getsize()"); |
12502 | 5833 list_T *l; |
5834 | |
5835 if (rettv_list_alloc(rettv) == FAIL) | |
5836 return; | |
5837 if (buf == NULL) | |
5838 return; | |
5839 | |
5840 l = rettv->vval.v_list; | |
5841 list_append_number(l, buf->b_term->tl_rows); | |
5842 list_append_number(l, buf->b_term->tl_cols); | |
5843 } | |
5844 | |
5845 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5846 * "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
|
5847 */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5848 void |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5849 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
|
5850 { |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5851 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
|
5852 term_T *term; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5853 varnumber_T rows, cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5854 |
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
|
5855 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
|
5856 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5857 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
|
5858 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
|
5859 } |
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
|
5860 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
|
5861 return; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5862 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
|
5863 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
|
5864 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
|
5865 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
|
5866 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
|
5867 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
|
5868 // 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
|
5869 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5870 // 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
|
5871 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
|
5872 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
|
5873 } |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5874 |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5875 /* |
12502 | 5876 * "term_getstatus(buf)" function |
5877 */ | |
5878 void | |
5879 f_term_getstatus(typval_T *argvars, typval_T *rettv) | |
5880 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5881 buf_T *buf = term_get_buf(argvars, "term_getstatus()"); |
12502 | 5882 term_T *term; |
5883 char_u val[100]; | |
5884 | |
5885 rettv->v_type = VAR_STRING; | |
5886 if (buf == NULL) | |
5887 return; | |
5888 term = buf->b_term; | |
5889 | |
5890 if (term_job_running(term)) | |
5891 STRCPY(val, "running"); | |
5892 else | |
5893 STRCPY(val, "finished"); | |
5894 if (term->tl_normal_mode) | |
5895 STRCAT(val, ",normal"); | |
5896 rettv->vval.v_string = vim_strsave(val); | |
5897 } | |
5898 | |
5899 /* | |
5900 * "term_gettitle(buf)" function | |
5901 */ | |
5902 void | |
5903 f_term_gettitle(typval_T *argvars, typval_T *rettv) | |
5904 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5905 buf_T *buf = term_get_buf(argvars, "term_gettitle()"); |
12502 | 5906 |
5907 rettv->v_type = VAR_STRING; | |
5908 if (buf == NULL) | |
5909 return; | |
5910 | |
5911 if (buf->b_term->tl_title != NULL) | |
5912 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title); | |
5913 } | |
5914 | |
5915 /* | |
5916 * "term_gettty(buf)" function | |
5917 */ | |
5918 void | |
5919 f_term_gettty(typval_T *argvars, typval_T *rettv) | |
5920 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5921 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
|
5922 char_u *p = NULL; |
12502 | 5923 int num = 0; |
5924 | |
5925 rettv->v_type = VAR_STRING; | |
5926 if (buf == NULL) | |
5927 return; | |
5928 if (argvars[1].v_type != VAR_UNKNOWN) | |
22155
de47cb7b41e6
patch 8.2.1627: Vim9: cannot pass "true" to submatch/term_gettty/term_start
Bram Moolenaar <Bram@vim.org>
parents:
22097
diff
changeset
|
5929 num = tv_get_bool(&argvars[1]); |
12502 | 5930 |
5931 switch (num) | |
5932 { | |
5933 case 0: | |
5934 if (buf->b_term->tl_job != NULL) | |
5935 p = buf->b_term->tl_job->jv_tty_out; | |
5936 break; | |
5937 case 1: | |
5938 if (buf->b_term->tl_job != NULL) | |
5939 p = buf->b_term->tl_job->jv_tty_in; | |
5940 break; | |
5941 default: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5942 semsg(_(e_invarg2), tv_get_string(&argvars[1])); |
12502 | 5943 return; |
5944 } | |
5945 if (p != NULL) | |
5946 rettv->vval.v_string = vim_strsave(p); | |
5947 } | |
5948 | |
5949 /* | |
5950 * "term_list()" function | |
5951 */ | |
5952 void | |
5953 f_term_list(typval_T *argvars UNUSED, typval_T *rettv) | |
5954 { | |
5955 term_T *tp; | |
5956 list_T *l; | |
5957 | |
5958 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL) | |
5959 return; | |
5960 | |
5961 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
|
5962 FOR_ALL_TERMS(tp) |
24582
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
5963 if (tp->tl_buffer != NULL) |
12502 | 5964 if (list_append_number(l, |
5965 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL) | |
5966 return; | |
5967 } | |
5968 | |
5969 /* | |
5970 * "term_scrape(buf, row)" function | |
5971 */ | |
5972 void | |
5973 f_term_scrape(typval_T *argvars, typval_T *rettv) | |
5974 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5975 buf_T *buf = term_get_buf(argvars, "term_scrape()"); |
12502 | 5976 VTermScreen *screen = NULL; |
5977 VTermPos pos; | |
5978 list_T *l; | |
5979 term_T *term; | |
5980 char_u *p; | |
5981 sb_line_T *line; | |
5982 | |
5983 if (rettv_list_alloc(rettv) == FAIL) | |
5984 return; | |
5985 if (buf == NULL) | |
5986 return; | |
5987 term = buf->b_term; | |
5988 | |
5989 l = rettv->vval.v_list; | |
5990 pos.row = get_row_number(&argvars[1], term); | |
5991 | |
5992 if (term->tl_vterm != NULL) | |
5993 { | |
5994 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
|
5995 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
|
5996 return; |
12502 | 5997 p = NULL; |
5998 line = NULL; | |
5999 } | |
6000 else | |
6001 { | |
6002 linenr_T lnum = pos.row + term->tl_scrollback_scrolled; | |
6003 | |
6004 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len) | |
6005 return; | |
6006 p = ml_get_buf(buf, lnum + 1, FALSE); | |
6007 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | |
6008 } | |
6009 | |
6010 for (pos.col = 0; pos.col < term->tl_cols; ) | |
6011 { | |
6012 dict_T *dcell; | |
6013 int width; | |
6014 VTermScreenCellAttrs attrs; | |
6015 VTermColor fg, bg; | |
6016 char_u rgb[8]; | |
6017 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1]; | |
6018 int off = 0; | |
6019 int i; | |
6020 | |
6021 if (screen == NULL) | |
6022 { | |
6023 cellattr_T *cellattr; | |
6024 int len; | |
6025 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6026 // vterm has finished, get the cell from scrollback |
12502 | 6027 if (pos.col >= line->sb_cols) |
6028 break; | |
6029 cellattr = line->sb_cells + pos.col; | |
6030 width = cellattr->width; | |
6031 attrs = cellattr->attrs; | |
6032 fg = cellattr->fg; | |
6033 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
|
6034 len = mb_ptr2len(p); |
12502 | 6035 mch_memmove(mbs, p, len); |
6036 mbs[len] = NUL; | |
6037 p += len; | |
6038 } | |
6039 else | |
6040 { | |
6041 VTermScreenCell cell; | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
6042 |
12502 | 6043 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
6044 break; | |
6045 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | |
6046 { | |
6047 if (cell.chars[i] == 0) | |
6048 break; | |
6049 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off); | |
6050 } | |
6051 mbs[off] = NUL; | |
6052 width = cell.width; | |
6053 attrs = cell.attrs; | |
6054 fg = cell.fg; | |
6055 bg = cell.bg; | |
6056 } | |
6057 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
|
6058 if (dcell == NULL) |
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6059 break; |
12502 | 6060 list_append_dict(l, dcell); |
6061 | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
6062 dict_add_string(dcell, "chars", mbs); |
12502 | 6063 |
6064 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
6065 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
|
6066 dict_add_string(dcell, "fg", rgb); |
12502 | 6067 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", |
6068 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
|
6069 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
|
6070 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
6071 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
|
6072 dict_add_number(dcell, "width", width); |
12502 | 6073 |
6074 ++pos.col; | |
6075 if (width == 2) | |
6076 ++pos.col; | |
6077 } | |
6078 } | |
6079 | |
6080 /* | |
6081 * "term_sendkeys(buf, keys)" function | |
6082 */ | |
6083 void | |
19633
dd3e5533a7d2
patch 8.2.0373: type of term_sendkeys() is unknown
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
6084 f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED) |
12502 | 6085 { |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6086 buf_T *buf = term_get_buf(argvars, "term_sendkeys()"); |
12502 | 6087 char_u *msg; |
6088 term_T *term; | |
6089 | |
6090 if (buf == NULL) | |
6091 return; | |
6092 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
6093 msg = tv_get_string_chk(&argvars[1]); |
12502 | 6094 if (msg == NULL) |
6095 return; | |
6096 term = buf->b_term; | |
6097 if (term->tl_vterm == NULL) | |
6098 return; | |
6099 | |
6100 while (*msg != NUL) | |
6101 { | |
14029
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6102 int c; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6103 |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6104 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
|
6105 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6106 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
|
6107 msg += 3; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6108 } |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6109 else |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6110 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6111 c = PTR2CHAR(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6112 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
|
6113 } |
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
|
6114 send_keys_to_term(term, c, 0, FALSE); |
12502 | 6115 } |
6116 } | |
6117 | |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6118 #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
|
6119 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6120 * "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
|
6121 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6122 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6123 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
|
6124 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6125 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
|
6126 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
|
6127 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
|
6128 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
|
6129 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
|
6130 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
|
6131 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
|
6132 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6133 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
|
6134 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6135 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6136 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
|
6137 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6138 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
|
6139 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
|
6140 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6141 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6142 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
|
6143 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
|
6144 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
|
6145 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6146 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
|
6147 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
|
6148 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
|
6149 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
|
6150 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6151 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6152 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6153 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6154 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6155 * "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
|
6156 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6157 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6158 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
|
6159 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6160 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
|
6161 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
|
6162 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6163 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
|
6164 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6165 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
|
6166 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
|
6167 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6168 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6169 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
|
6170 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6171 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
|
6172 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6173 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6174 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6175 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
|
6176 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
|
6177 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6178 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6179 |
12502 | 6180 /* |
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
|
6181 * "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
|
6182 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6183 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
|
6184 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
|
6185 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6186 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
|
6187 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
|
6188 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
|
6189 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6190 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
|
6191 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
|
6192 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
|
6193 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
|
6194 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
|
6195 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
|
6196 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
|
6197 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
|
6198 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
|
6199 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6200 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6201 /* |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6202 * "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
|
6203 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6204 void |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6205 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
|
6206 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6207 #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
|
6208 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
|
6209 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
|
6210 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
|
6211 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6212 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
|
6213 return; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6214 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
|
6215 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
|
6216 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
|
6217 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
|
6218 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
|
6219 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6220 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
|
6221 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6222 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6223 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6224 /* |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6225 * "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
|
6226 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6227 void |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6228 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
|
6229 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6230 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
|
6231 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
|
6232 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
|
6233 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6234 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
|
6235 return; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6236 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
|
6237 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
|
6238 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
|
6239 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
|
6240 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
|
6241 else |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6242 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
|
6243 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6244 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6245 /* |
12502 | 6246 * "term_start(command, options)" function |
6247 */ | |
6248 void | |
6249 f_term_start(typval_T *argvars, typval_T *rettv) | |
6250 { | |
6251 jobopt_T opt; | |
6252 buf_T *buf; | |
6253 | |
6254 init_job_options(&opt); | |
6255 if (argvars[1].v_type != VAR_UNKNOWN | |
6256 && get_job_options(&argvars[1], &opt, | |
6257 JO_TIMEOUT_ALL + JO_STOPONEXIT | |
6258 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK | |
6259 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO, | |
6260 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD | |
6261 + 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
|
6262 + 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
|
6263 + 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
|
6264 + JO2_ANSI_COLORS + JO2_TTY_TYPE + JO2_TERM_API) == FAIL) |
12502 | 6265 return; |
6266 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6267 buf = term_start(&argvars[0], NULL, &opt, 0); |
12502 | 6268 |
6269 if (buf != NULL && buf->b_term != NULL) | |
6270 rettv->vval.v_number = buf->b_fnum; | |
6271 } | |
6272 | |
6273 /* | |
6274 * "term_wait" function | |
6275 */ | |
6276 void | |
6277 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | |
6278 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6279 buf_T *buf = term_get_buf(argvars, "term_wait()"); |
12502 | 6280 |
6281 if (buf == NULL) | |
6282 return; | |
6283 if (buf->b_term->tl_job == NULL) | |
6284 { | |
6285 ch_log(NULL, "term_wait(): no job to wait for"); | |
6286 return; | |
6287 } | |
6288 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
|
6289 // channel is closed, nothing to do |
12502 | 6290 return; |
6291 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6292 // 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
|
6293 if (!buf->b_term->tl_job->jv_channel->ch_keep_open |
12502 | 6294 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) |
6295 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6296 // 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
|
6297 // 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
|
6298 // waiting. |
12502 | 6299 ch_log(NULL, "term_wait(): waiting for channel to close"); |
6300 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) | |
6301 { | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6302 term_flush_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6303 |
13996
59121ffd7fce
patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
13994
diff
changeset
|
6304 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
|
6305 if (!buf_valid(buf)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6306 // 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
|
6307 // buffer disappears. |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
6308 break; |
12502 | 6309 } |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6310 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6311 term_flush_messages(); |
12502 | 6312 } |
6313 else | |
6314 { | |
6315 long wait = 10L; | |
6316 | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6317 term_flush_messages(); |
12502 | 6318 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6319 // Wait for some time for any channel I/O. |
12502 | 6320 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
|
6321 wait = tv_get_number(&argvars[1]); |
12502 | 6322 ui_delay(wait, TRUE); |
6323 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6324 // 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
|
6325 // 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
|
6326 term_flush_messages(); |
12502 | 6327 } |
6328 } | |
6329 | |
6330 /* | |
6331 * Called when a channel has sent all the lines to a terminal. | |
6332 * Send a CTRL-D to mark the end of the text. | |
6333 */ | |
6334 void | |
6335 term_send_eof(channel_T *ch) | |
6336 { | |
6337 term_T *term; | |
6338 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
6339 FOR_ALL_TERMS(term) |
12502 | 6340 if (term->tl_job == ch->ch_job) |
6341 { | |
6342 if (term->tl_eof_chars != NULL) | |
6343 { | |
6344 channel_send(ch, PART_IN, term->tl_eof_chars, | |
6345 (int)STRLEN(term->tl_eof_chars), NULL); | |
6346 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL); | |
6347 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6348 # ifdef MSWIN |
12502 | 6349 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6350 // Default: CTRL-D |
12502 | 6351 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL); |
6352 # endif | |
6353 } | |
6354 } | |
6355 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6356 #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
|
6357 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
|
6358 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
|
6359 { |
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
|
6360 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
|
6361 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6362 #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
|
6363 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6364 # if defined(MSWIN) || defined(PROTO) |
12502 | 6365 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6366 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6367 // 2. MS-Windows implementation. |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6368 #ifdef PROTO |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6369 typedef int COORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6370 typedef int DWORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6371 typedef int HANDLE; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6372 typedef int *DWORD_PTR; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6373 typedef int HPCON; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6374 typedef int HRESULT; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6375 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
|
6376 typedef int SIZE_T; |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6377 typedef int PSIZE_T; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6378 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
|
6379 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
|
6380 # define WINAPI |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6381 #endif |
12502 | 6382 |
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
|
6383 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
|
6384 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
|
6385 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
|
6386 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
|
6387 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
|
6388 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
|
6389 |
a3e2e7948ee4
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 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
|
6391 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
|
6392 { |
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
|
6393 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
|
6394 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
|
6395 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
|
6396 { |
a3e2e7948ee4
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 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
|
6398 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
|
6399 } 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
|
6400 { |
a3e2e7948ee4
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 {"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
|
6402 {"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
|
6403 {"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
|
6404 {"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
|
6405 (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
|
6406 {"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
|
6407 (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
|
6408 {"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
|
6409 (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
|
6410 {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
|
6411 }; |
a3e2e7948ee4
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 |
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
|
6413 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
|
6414 { |
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
|
6415 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
|
6416 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
|
6417 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
|
6418 } |
a3e2e7948ee4
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 |
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
|
6420 // 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
|
6421 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
|
6422 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
|
6423 |
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
|
6424 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
|
6425 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
|
6426 && 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
|
6427 { |
a3e2e7948ee4
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 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
|
6429 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
|
6430 { |
a3e2e7948ee4
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 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
|
6432 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
|
6433 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
|
6434 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
|
6435 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6436 } |
a3e2e7948ee4
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 |
a3e2e7948ee4
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 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
|
6439 } |
a3e2e7948ee4
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 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
|
6442 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
|
6443 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
|
6444 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
|
6445 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
|
6446 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
|
6447 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
|
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 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
|
6450 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
|
6451 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
|
6452 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
|
6453 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
|
6454 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
|
6455 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
|
6456 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
|
6457 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
|
6458 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
|
6459 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
|
6460 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
|
6461 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
|
6462 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
|
6463 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
|
6464 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
|
6465 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
|
6466 |
a3e2e7948ee4
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 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
|
6468 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
|
6469 |
a3e2e7948ee4
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 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
|
6471 { |
a3e2e7948ee4
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 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
|
6473 } |
a3e2e7948ee4
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 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
|
6475 { |
a3e2e7948ee4
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 (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
|
6477 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
|
6478 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
|
6479 } |
a3e2e7948ee4
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 (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
|
6481 { |
a3e2e7948ee4
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 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
|
6483 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
|
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 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
|
6487 |
a3e2e7948ee4
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 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
|
6489 |
a3e2e7948ee4
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 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
|
6491 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6492 // Request by CreateProcessW |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6493 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
|
6494 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
|
6495 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
|
6496 } |
a3e2e7948ee4
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 |
a3e2e7948ee4
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 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
|
6499 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
|
6500 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
|
6501 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
|
6502 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
|
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 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
|
6505 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
|
6506 |
a3e2e7948ee4
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 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
|
6508 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
|
6509 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
|
6510 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
|
6511 |
a3e2e7948ee4
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 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
|
6513 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
|
6514 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
|
6515 &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
|
6516 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
|
6517 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
|
6518 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6519 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
|
6520 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6521 // 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
|
6522 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
|
6523 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
|
6524 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
|
6525 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
|
6526 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
|
6527 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
|
6528 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
|
6529 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
|
6530 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
|
6531 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
|
6532 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
|
6533 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
|
6534 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6535 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
|
6536 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
|
6537 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
|
6538 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6539 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
|
6540 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
|
6541 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
|
6542 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
|
6543 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6544 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
|
6545 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6546 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
|
6547 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6548 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
|
6549 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6550 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
|
6551 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6552 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
|
6553 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6554 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6555 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
|
6556 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
|
6557 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6558 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
|
6559 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
|
6560 | 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
|
6561 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
|
6562 &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
|
6563 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
|
6564 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6565 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
|
6566 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
|
6567 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6568 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
|
6569 (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
|
6570 (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
|
6571 (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
|
6572 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6573 // 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
|
6574 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
|
6575 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6576 // 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
|
6577 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
|
6578 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6579 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
|
6580 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
|
6581 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
|
6582 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6583 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
|
6584 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6585 // 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
|
6586 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
|
6587 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
|
6588 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6589 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6590 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
|
6591 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
|
6592 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6593 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
|
6594 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
|
6595 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
|
6596 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
|
6597 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6598 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
|
6599 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
|
6600 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6601 #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
|
6602 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
|
6603 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
|
6604 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
|
6605 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
|
6606 #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
|
6607 |
a3e2e7948ee4
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 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
|
6609 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
|
6610 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6611 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
|
6612 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
|
6613 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
|
6614 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
|
6615 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
|
6616 ++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
|
6617 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
|
6618 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6619 // 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
|
6620 // 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
|
6621 // 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
|
6622 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
|
6623 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6624 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
|
6625 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6626 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
|
6627 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
|
6628 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
|
6629 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
|
6630 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6631 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6632 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
|
6633 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6634 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
|
6635 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
|
6636 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
|
6637 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
|
6638 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
|
6639 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
|
6640 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
|
6641 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
|
6642 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
|
6643 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6644 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
|
6645 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
|
6646 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6647 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
|
6648 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
|
6649 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
|
6650 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6651 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
|
6652 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6653 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
|
6654 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
|
6655 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6656 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
|
6657 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
|
6658 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
|
6659 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
|
6660 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
|
6661 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
|
6662 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
|
6663 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
|
6664 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
|
6665 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
|
6666 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
|
6667 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
|
6668 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
|
6669 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6670 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6671 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
|
6672 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
|
6673 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6674 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
|
6675 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6676 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
|
6677 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
|
6678 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
|
6679 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6680 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
18033
diff
changeset
|
6681 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
|
6682 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
|
6683 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6684 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
|
6685 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6686 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
|
6687 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
|
6688 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6689 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
|
6690 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
|
6691 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
|
6692 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
|
6693 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6694 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6695 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
|
6696 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
|
6697 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6698 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
|
6699 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6700 |
12502 | 6701 # ifndef PROTO |
6702 | |
6703 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul | |
6704 #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
|
6705 #define WINPTY_MOUSE_MODE_FORCE 2 |
12502 | 6706 |
6707 void* (*winpty_config_new)(UINT64, void*); | |
6708 void* (*winpty_open)(void*, void*); | |
6709 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*); | |
6710 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*); | |
6711 void (*winpty_config_set_mouse_mode)(void*, int); | |
6712 void (*winpty_config_set_initial_size)(void*, int, int); | |
6713 LPCWSTR (*winpty_conin_name)(void*); | |
6714 LPCWSTR (*winpty_conout_name)(void*); | |
6715 LPCWSTR (*winpty_conerr_name)(void*); | |
6716 void (*winpty_free)(void*); | |
6717 void (*winpty_config_free)(void*); | |
6718 void (*winpty_spawn_config_free)(void*); | |
6719 void (*winpty_error_free)(void*); | |
6720 LPCWSTR (*winpty_error_msg)(void*); | |
6721 BOOL (*winpty_set_size)(void*, int, int, void*); | |
6722 HANDLE (*winpty_agent_process)(void*); | |
6723 | |
6724 #define WINPTY_DLL "winpty.dll" | |
6725 | |
6726 static HINSTANCE hWinPtyDLL = NULL; | |
6727 # endif | |
6728 | |
6729 static int | |
6730 dyn_winpty_init(int verbose) | |
6731 { | |
6732 int i; | |
6733 static struct | |
6734 { | |
6735 char *name; | |
6736 FARPROC *ptr; | |
6737 } winpty_entry[] = | |
6738 { | |
6739 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name}, | |
6740 {"winpty_config_free", (FARPROC*)&winpty_config_free}, | |
6741 {"winpty_config_new", (FARPROC*)&winpty_config_new}, | |
6742 {"winpty_config_set_mouse_mode", | |
6743 (FARPROC*)&winpty_config_set_mouse_mode}, | |
6744 {"winpty_config_set_initial_size", | |
6745 (FARPROC*)&winpty_config_set_initial_size}, | |
6746 {"winpty_conin_name", (FARPROC*)&winpty_conin_name}, | |
6747 {"winpty_conout_name", (FARPROC*)&winpty_conout_name}, | |
6748 {"winpty_error_free", (FARPROC*)&winpty_error_free}, | |
6749 {"winpty_free", (FARPROC*)&winpty_free}, | |
6750 {"winpty_open", (FARPROC*)&winpty_open}, | |
6751 {"winpty_spawn", (FARPROC*)&winpty_spawn}, | |
6752 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free}, | |
6753 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new}, | |
6754 {"winpty_error_msg", (FARPROC*)&winpty_error_msg}, | |
6755 {"winpty_set_size", (FARPROC*)&winpty_set_size}, | |
6756 {"winpty_agent_process", (FARPROC*)&winpty_agent_process}, | |
6757 {NULL, NULL} | |
6758 }; | |
6759 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6760 // No need to initialize twice. |
12502 | 6761 if (hWinPtyDLL) |
6762 return OK; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6763 // 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
|
6764 // winpty.dll. |
12502 | 6765 if (*p_winptydll != NUL) |
6766 hWinPtyDLL = vimLoadLib((char *)p_winptydll); | |
6767 if (!hWinPtyDLL) | |
6768 hWinPtyDLL = vimLoadLib(WINPTY_DLL); | |
6769 if (!hWinPtyDLL) | |
6770 { | |
6771 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6772 semsg(_(e_loadlib), *p_winptydll != NUL ? p_winptydll |
12502 | 6773 : (char_u *)WINPTY_DLL); |
6774 return FAIL; | |
6775 } | |
6776 for (i = 0; winpty_entry[i].name != NULL | |
6777 && winpty_entry[i].ptr != NULL; ++i) | |
6778 { | |
6779 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL, | |
6780 winpty_entry[i].name)) == NULL) | |
6781 { | |
6782 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6783 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
|
6784 hWinPtyDLL = NULL; |
12502 | 6785 return FAIL; |
6786 } | |
6787 } | |
6788 | |
6789 return OK; | |
6790 } | |
6791 | |
6792 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
|
6793 winpty_term_and_job_init( |
12502 | 6794 term_T *term, |
6795 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
|
6796 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
|
6797 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
|
6798 jobopt_T *orig_opt) |
12502 | 6799 { |
6800 WCHAR *cmd_wchar = NULL; | |
6801 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
|
6802 WCHAR *env_wchar = NULL; |
12502 | 6803 channel_T *channel = NULL; |
6804 job_T *job = NULL; | |
6805 DWORD error; | |
6806 HANDLE jo = NULL; | |
6807 HANDLE child_process_handle; | |
6808 HANDLE child_thread_handle; | |
13111
149347fda678
patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents:
13109
diff
changeset
|
6809 void *winpty_err = NULL; |
12502 | 6810 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
|
6811 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
|
6812 char_u *cmd = NULL; |
12502 | 6813 |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6814 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
|
6815 ga_init2(&ga_env, (int)sizeof(char*), 20); |
12502 | 6816 |
6817 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
|
6818 { |
12502 | 6819 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
|
6820 } |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6821 else if (argvar->v_type == VAR_LIST) |
12502 | 6822 { |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6823 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
12502 | 6824 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
|
6825 cmd = ga_cmd.ga_data; |
12502 | 6826 } |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6827 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
|
6828 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6829 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
|
6830 goto failed; |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6831 } |
12502 | 6832 |
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
|
6833 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
|
6834 |
12502 | 6835 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
|
6836 ga_clear(&ga_cmd); |
12502 | 6837 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
|
6838 goto failed; |
12502 | 6839 if (opt->jo_cwd != NULL) |
6840 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
|
6841 |
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
|
6842 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
|
6843 env_wchar = ga_env.ga_data; |
12502 | 6844 |
6845 term->tl_winpty_config = winpty_config_new(0, &winpty_err); | |
6846 if (term->tl_winpty_config == NULL) | |
6847 goto failed; | |
6848 | |
6849 winpty_config_set_mouse_mode(term->tl_winpty_config, | |
6850 WINPTY_MOUSE_MODE_FORCE); | |
6851 winpty_config_set_initial_size(term->tl_winpty_config, | |
6852 term->tl_cols, term->tl_rows); | |
6853 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err); | |
6854 if (term->tl_winpty == NULL) | |
6855 goto failed; | |
6856 | |
6857 spawn_config = winpty_spawn_config_new( | |
6858 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN | | |
6859 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN, | |
6860 NULL, | |
6861 cmd_wchar, | |
6862 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
|
6863 env_wchar, |
12502 | 6864 &winpty_err); |
6865 if (spawn_config == NULL) | |
6866 goto failed; | |
6867 | |
6868 channel = add_channel(); | |
6869 if (channel == NULL) | |
6870 goto failed; | |
6871 | |
6872 job = job_alloc(); | |
6873 if (job == NULL) | |
6874 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
|
6875 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
|
6876 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6877 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
|
6878 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6879 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
|
6880 } |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6881 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
|
6882 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6883 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
|
6884 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6885 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
|
6886 } |
12502 | 6887 |
6888 if (opt->jo_set & JO_IN_BUF) | |
6889 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); | |
6890 | |
6891 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle, | |
6892 &child_thread_handle, &error, &winpty_err)) | |
6893 goto failed; | |
6894 | |
6895 channel_set_pipes(channel, | |
6896 (sock_T)CreateFileW( | |
6897 winpty_conin_name(term->tl_winpty), | |
6898 GENERIC_WRITE, 0, NULL, | |
6899 OPEN_EXISTING, 0, NULL), | |
6900 (sock_T)CreateFileW( | |
6901 winpty_conout_name(term->tl_winpty), | |
6902 GENERIC_READ, 0, NULL, | |
6903 OPEN_EXISTING, 0, NULL), | |
6904 (sock_T)CreateFileW( | |
6905 winpty_conerr_name(term->tl_winpty), | |
6906 GENERIC_READ, 0, NULL, | |
6907 OPEN_EXISTING, 0, NULL)); | |
6908 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6909 // Write lines with CR instead of NL. |
12502 | 6910 channel->ch_write_text_mode = TRUE; |
6911 | |
6912 jo = CreateJobObject(NULL, NULL); | |
6913 if (jo == NULL) | |
6914 goto failed; | |
6915 | |
6916 if (!AssignProcessToJobObject(jo, child_process_handle)) | |
6917 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6918 // Failed, switch the way to terminate process with TerminateProcess. |
12502 | 6919 CloseHandle(jo); |
6920 jo = NULL; | |
6921 } | |
6922 | |
6923 winpty_spawn_config_free(spawn_config); | |
6924 vim_free(cmd_wchar); | |
6925 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
|
6926 vim_free(env_wchar); |
12502 | 6927 |
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
|
6928 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
|
6929 goto failed; |
12502 | 6930 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6931 #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
|
6932 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
|
6933 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
|
6934 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6935 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
|
6936 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6937 |
12502 | 6938 channel_set_job(channel, job, opt); |
6939 job_set_options(job, opt); | |
6940 | |
6941 job->jv_channel = channel; | |
6942 job->jv_proc_info.hProcess = child_process_handle; | |
6943 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle); | |
6944 job->jv_job_object = jo; | |
6945 job->jv_status = JOB_STARTED; | |
6946 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
|
6947 (short_u *)winpty_conin_name(term->tl_winpty), NULL); |
12502 | 6948 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
|
6949 (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
|
6950 job->jv_tty_type = vim_strsave((char_u *)"winpty"); |
12502 | 6951 ++job->jv_refcount; |
6952 term->tl_job = job; | |
6953 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6954 // 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
|
6955 // 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
|
6956 // 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
|
6957 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
|
6958 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6959 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
|
6960 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6961 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
|
6962 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
|
6963 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
|
6964 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
|
6965 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6966 |
12502 | 6967 return OK; |
6968 | |
6969 failed: | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6970 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
|
6971 ga_clear(&ga_env); |
12502 | 6972 vim_free(cmd_wchar); |
6973 vim_free(cwd_wchar); | |
6974 if (spawn_config != NULL) | |
6975 winpty_spawn_config_free(spawn_config); | |
6976 if (channel != NULL) | |
6977 channel_clear(channel); | |
6978 if (job != NULL) | |
6979 { | |
6980 job->jv_channel = NULL; | |
6981 job_cleanup(job); | |
6982 } | |
6983 term->tl_job = NULL; | |
6984 if (jo != NULL) | |
6985 CloseHandle(jo); | |
6986 if (term->tl_winpty != NULL) | |
6987 winpty_free(term->tl_winpty); | |
6988 term->tl_winpty = NULL; | |
6989 if (term->tl_winpty_config != NULL) | |
6990 winpty_config_free(term->tl_winpty_config); | |
6991 term->tl_winpty_config = NULL; | |
6992 if (winpty_err != NULL) | |
6993 { | |
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
|
6994 char *msg = (char *)utf16_to_enc( |
12502 | 6995 (short_u *)winpty_error_msg(winpty_err), NULL); |
6996 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6997 emsg(msg); |
12502 | 6998 winpty_error_free(winpty_err); |
6999 } | |
7000 return FAIL; | |
7001 } | |
7002 | |
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
|
7003 /* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7004 * 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
|
7005 * 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
|
7006 * 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
|
7007 */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7008 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
|
7009 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
|
7010 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
|
7011 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
|
7012 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
|
7013 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
|
7014 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
|
7015 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7016 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
|
7017 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
|
7018 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
|
7019 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7020 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
|
7021 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
|
7022 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7023 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
|
7024 // 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
|
7025 // 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
|
7026 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
|
7027 |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7028 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
|
7029 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
|
7030 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7031 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
|
7032 { |
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
|
7033 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
|
7034 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
|
7035 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
|
7036 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
|
7037 // 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
|
7038 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7039 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
|
7040 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7041 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
|
7042 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
|
7043 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7044 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
|
7045 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7046 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
|
7047 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
|
7048 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
|
7049 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
|
7050 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7051 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7052 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
|
7053 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
|
7054 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7055 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
|
7056 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
|
7057 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7058 // 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
|
7059 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
|
7060 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7061 |
12502 | 7062 static int |
7063 create_pty_only(term_T *term, jobopt_T *options) | |
7064 { | |
7065 HANDLE hPipeIn = INVALID_HANDLE_VALUE; | |
7066 HANDLE hPipeOut = INVALID_HANDLE_VALUE; | |
7067 char in_name[80], out_name[80]; | |
7068 channel_T *channel = NULL; | |
7069 | |
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
|
7070 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
|
7071 return FAIL; |
12502 | 7072 |
7073 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d", | |
7074 GetCurrentProcessId(), | |
7075 curbuf->b_fnum); | |
7076 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND, | |
7077 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
7078 PIPE_UNLIMITED_INSTANCES, | |
7079 0, 0, NMPWAIT_NOWAIT, NULL); | |
7080 if (hPipeIn == INVALID_HANDLE_VALUE) | |
7081 goto failed; | |
7082 | |
7083 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d", | |
7084 GetCurrentProcessId(), | |
7085 curbuf->b_fnum); | |
7086 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND, | |
7087 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
7088 PIPE_UNLIMITED_INSTANCES, | |
7089 0, 0, 0, NULL); | |
7090 if (hPipeOut == INVALID_HANDLE_VALUE) | |
7091 goto failed; | |
7092 | |
7093 ConnectNamedPipe(hPipeIn, NULL); | |
7094 ConnectNamedPipe(hPipeOut, NULL); | |
7095 | |
7096 term->tl_job = job_alloc(); | |
7097 if (term->tl_job == NULL) | |
7098 goto failed; | |
7099 ++term->tl_job->jv_refcount; | |
7100 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7101 // behave like the job is already finished |
12502 | 7102 term->tl_job->jv_status = JOB_FINISHED; |
7103 | |
7104 channel = add_channel(); | |
7105 if (channel == NULL) | |
7106 goto failed; | |
7107 term->tl_job->jv_channel = channel; | |
7108 channel->ch_keep_open = TRUE; | |
7109 channel->ch_named_pipe = TRUE; | |
7110 | |
7111 channel_set_pipes(channel, | |
7112 (sock_T)hPipeIn, | |
7113 (sock_T)hPipeOut, | |
7114 (sock_T)hPipeOut); | |
7115 channel_set_job(channel, term->tl_job, options); | |
7116 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name); | |
7117 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name); | |
7118 | |
7119 return OK; | |
7120 | |
7121 failed: | |
7122 if (hPipeIn != NULL) | |
7123 CloseHandle(hPipeIn); | |
7124 if (hPipeOut != NULL) | |
7125 CloseHandle(hPipeOut); | |
7126 return FAIL; | |
7127 } | |
7128 | |
7129 /* | |
7130 * Free the terminal emulator part of "term". | |
7131 */ | |
7132 static void | |
7133 term_free_vterm(term_T *term) | |
7134 { | |
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
|
7135 term_free_conpty(term); |
12502 | 7136 if (term->tl_winpty != NULL) |
7137 winpty_free(term->tl_winpty); | |
7138 term->tl_winpty = NULL; | |
7139 if (term->tl_winpty_config != NULL) | |
7140 winpty_config_free(term->tl_winpty_config); | |
7141 term->tl_winpty_config = NULL; | |
7142 if (term->tl_vterm != NULL) | |
7143 vterm_free(term->tl_vterm); | |
7144 term->tl_vterm = NULL; | |
7145 } | |
7146 | |
7147 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7148 * Report the size to the terminal. |
12502 | 7149 */ |
7150 static void | |
7151 term_report_winsize(term_T *term, int rows, int cols) | |
7152 { | |
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
|
7153 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
|
7154 conpty_term_report_winsize(term, rows, cols); |
12502 | 7155 if (term->tl_winpty) |
7156 winpty_set_size(term->tl_winpty, cols, rows, NULL); | |
7157 } | |
7158 | |
7159 int | |
7160 terminal_enabled(void) | |
7161 { | |
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
|
7162 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK; |
12502 | 7163 } |
7164 | |
7165 # else | |
7166 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7167 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7168 // 3. Unix-like implementation. |
12502 | 7169 |
7170 /* | |
7171 * Create a new terminal of "rows" by "cols" cells. | |
7172 * Start job for "cmd". | |
7173 * 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
|
7174 * When "argv" is not NULL then "argvar" is not used. |
12502 | 7175 * Return OK or FAIL. |
7176 */ | |
7177 static int | |
7178 term_and_job_init( | |
7179 term_T *term, | |
7180 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
|
7181 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
|
7182 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
|
7183 jobopt_T *orig_opt UNUSED) |
12502 | 7184 { |
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
|
7185 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
|
7186 |
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
|
7187 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
|
7188 return FAIL; |
12502 | 7189 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7190 #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
|
7191 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
|
7192 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
|
7193 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7194 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
|
7195 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7196 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7197 // 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
|
7198 term->tl_job = job_start(argvar, argv, opt, &term->tl_job); |
12502 | 7199 if (term->tl_job != NULL) |
7200 ++term->tl_job->jv_refcount; | |
7201 | |
7202 return term->tl_job != NULL | |
7203 && term->tl_job->jv_channel != NULL | |
7204 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL; | |
7205 } | |
7206 | |
7207 static int | |
7208 create_pty_only(term_T *term, jobopt_T *opt) | |
7209 { | |
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
|
7210 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
|
7211 return FAIL; |
12502 | 7212 |
7213 term->tl_job = job_alloc(); | |
7214 if (term->tl_job == NULL) | |
7215 return FAIL; | |
7216 ++term->tl_job->jv_refcount; | |
7217 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7218 // behave like the job is already finished |
12502 | 7219 term->tl_job->jv_status = JOB_FINISHED; |
7220 | |
7221 return mch_create_pty_channel(term->tl_job, opt); | |
7222 } | |
7223 | |
7224 /* | |
7225 * Free the terminal emulator part of "term". | |
7226 */ | |
7227 static void | |
7228 term_free_vterm(term_T *term) | |
7229 { | |
7230 if (term->tl_vterm != NULL) | |
7231 vterm_free(term->tl_vterm); | |
7232 term->tl_vterm = NULL; | |
7233 } | |
7234 | |
7235 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7236 * Report the size to the terminal. |
12502 | 7237 */ |
7238 static void | |
7239 term_report_winsize(term_T *term, int rows, int cols) | |
7240 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7241 // Use an ioctl() to report the new window size to the job. |
12502 | 7242 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) |
7243 { | |
7244 int fd = -1; | |
7245 int part; | |
7246 | |
7247 for (part = PART_OUT; part < PART_COUNT; ++part) | |
7248 { | |
7249 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
|
7250 if (mch_isatty(fd)) |
12502 | 7251 break; |
7252 } | |
7253 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) | |
7254 mch_signal_job(term->tl_job, (char_u *)"winch"); | |
7255 } | |
7256 } | |
7257 | |
7258 # endif | |
7259 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7260 #endif // FEAT_TERMINAL |