Mercurial > vim
annotate src/terminal.c @ 13304:013c44d9dc09 v8.0.1526
patch 8.0.1526: no test using a screen dump yet
commit https://github.com/vim/vim/commit/da65058a9c4774dc534c7ae98d24c58b5db669fa
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Feb 20 15:51:40 2018 +0100
patch 8.0.1526: no test using a screen dump yet
Problem: No test using a screen dump yet.
Solution: Add a test for C syntax highlighting. Add helper functions.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 20 Feb 2018 16:00:06 +0100 |
parents | 803294329951 |
children | 424321d6eea7 |
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 * TODO: | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
41 * - When using 'termguicolors' still use the 16 ANSI colors as-is. Helps for |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
42 * a job that uses 16 colors while Vim is using > 256. |
12502 | 43 * - in GUI vertical split causes problems. Cursor is flickering. (Hirohito |
44 * Higashi, 2017 Sep 19) | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
45 * - Trigger TerminalOpen event? #2422 patch in #2484 |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
46 * - after resizing windows overlap. (Boris Staletic, #2164) |
12502 | 47 * - Redirecting output does not work on MS-Windows, Test_terminal_redir_file() |
48 * is disabled. | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
49 * - cursor blinks in terminal on widows with a timer. (xtal8, #2142) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
50 * - What to store in a session file? Shell at the prompt would be OK to |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
51 * restore, but others may not. Open the window and let the user start the |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
52 * command? Also see #2650. |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
53 * - When closing gvim with an active terminal buffer, the dialog suggests |
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
54 * saving the buffer. Should say something else. (Manas Thakur, #2215) |
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
55 * Also: #2223 |
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
56 * - Termdebug does not work when Vim build with mzscheme. gdb hangs. |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
57 * - MS-Windows GUI: WinBar has tearoff item |
12903
411a30bd7e8a
patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
58 * - Adding WinBar to terminal window doesn't display, text isn't shifted down. |
12502 | 59 * - MS-Windows GUI: still need to type a key after shell exits? #1924 |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
60 * - After executing a shell command the status line isn't redraw. |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
61 * - implement term_setsize() |
12502 | 62 * - add test for giving error for invalid 'termsize' value. |
63 * - support minimal size when 'termsize' is "rows*cols". | |
64 * - support minimal size when 'termsize' is empty? | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
65 * - if the job in the terminal does not support the mouse, we can use the |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
66 * mouse in the Terminal window for copy/paste and scrolling. |
12502 | 67 * - GUI: when using tabs, focus in terminal, click on tab does not work. |
68 * - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save | |
69 * changes to "!shell". | |
70 * (justrajdeep, 2017 Aug 22) | |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
71 * - Redrawing is slow with Athena and Motif. Also other GUI? (Ramel Eshed) |
12502 | 72 * - For the GUI fill termios with default values, perhaps like pangoterm: |
73 * http://bazaar.launchpad.net/~leonerd/pangoterm/trunk/view/head:/main.c#L134 | |
74 * - when 'encoding' is not utf-8, or the job is using another encoding, setup | |
75 * conversions. | |
76 * - In the GUI use a terminal emulator for :!cmd. Make the height the same as | |
77 * the window and position it higher up when it gets filled, so it looks like | |
78 * the text scrolls up. | |
79 * - Copy text in the vterm to the Vim buffer once in a while, so that | |
80 * completion works. | |
81 * - add an optional limit for the scrollback size. When reaching it remove | |
82 * 10% at the start. | |
83 */ | |
84 | |
85 #include "vim.h" | |
86 | |
87 #if defined(FEAT_TERMINAL) || defined(PROTO) | |
88 | |
89 #ifndef MIN | |
90 # define MIN(x,y) ((x) < (y) ? (x) : (y)) | |
91 #endif | |
92 #ifndef MAX | |
93 # define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
94 #endif | |
95 | |
96 #include "libvterm/include/vterm.h" | |
97 | |
98 /* This is VTermScreenCell without the characters, thus much smaller. */ | |
99 typedef struct { | |
100 VTermScreenCellAttrs attrs; | |
101 char width; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
102 VTermColor fg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
103 VTermColor bg; |
12502 | 104 } cellattr_T; |
105 | |
106 typedef struct sb_line_S { | |
107 int sb_cols; /* can differ per line */ | |
108 cellattr_T *sb_cells; /* allocated */ | |
109 cellattr_T sb_fill_attr; /* for short line */ | |
110 } sb_line_T; | |
111 | |
112 /* typedef term_T in structs.h */ | |
113 struct terminal_S { | |
114 term_T *tl_next; | |
115 | |
116 VTerm *tl_vterm; | |
117 job_T *tl_job; | |
118 buf_T *tl_buffer; | |
119 | |
120 /* Set when setting the size of a vterm, reset after redrawing. */ | |
121 int tl_vterm_size_changed; | |
122 | |
123 /* used when tl_job is NULL and only a pty was created */ | |
124 int tl_tty_fd; | |
125 char_u *tl_tty_in; | |
126 char_u *tl_tty_out; | |
127 | |
128 int tl_normal_mode; /* TRUE: Terminal-Normal mode */ | |
129 int tl_channel_closed; | |
130 int tl_finish; /* 'c' for ++close, 'o' for ++open */ | |
131 char_u *tl_opencmd; | |
132 char_u *tl_eof_chars; | |
133 | |
134 #ifdef WIN3264 | |
135 void *tl_winpty_config; | |
136 void *tl_winpty; | |
137 #endif | |
138 | |
139 /* last known vterm size */ | |
140 int tl_rows; | |
141 int tl_cols; | |
142 /* vterm size does not follow window size */ | |
143 int tl_rows_fixed; | |
144 int tl_cols_fixed; | |
145 | |
146 char_u *tl_title; /* NULL or allocated */ | |
147 char_u *tl_status_text; /* NULL or allocated */ | |
148 | |
149 /* Range of screen rows to update. Zero based. */ | |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
150 int tl_dirty_row_start; /* MAX_ROW if nothing dirty */ |
12502 | 151 int tl_dirty_row_end; /* row below last one to update */ |
152 | |
153 garray_T tl_scrollback; | |
154 int tl_scrollback_scrolled; | |
155 cellattr_T tl_default_color; | |
156 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
157 linenr_T tl_top_diff_rows; /* rows of top diff file or zero */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
158 linenr_T tl_bot_diff_rows; /* rows of bottom diff file */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
159 |
12502 | 160 VTermPos tl_cursor_pos; |
161 int tl_cursor_visible; | |
162 int tl_cursor_blink; | |
163 int tl_cursor_shape; /* 1: block, 2: underline, 3: bar */ | |
164 char_u *tl_cursor_color; /* NULL or allocated */ | |
165 | |
166 int tl_using_altscreen; | |
167 }; | |
168 | |
169 #define TMODE_ONCE 1 /* CTRL-\ CTRL-N used */ | |
170 #define TMODE_LOOP 2 /* CTRL-W N used */ | |
171 | |
172 /* | |
173 * List of all active terminals. | |
174 */ | |
175 static term_T *first_term = NULL; | |
176 | |
177 /* Terminal active in terminal_loop(). */ | |
178 static term_T *in_terminal_loop = NULL; | |
179 | |
180 #define MAX_ROW 999999 /* used for tl_dirty_row_end to update all rows */ | |
181 #define KEY_BUF_LEN 200 | |
182 | |
183 /* | |
184 * Functions with separate implementation for MS-Windows and Unix-like systems. | |
185 */ | |
186 static int term_and_job_init(term_T *term, typval_T *argvar, jobopt_T *opt); | |
187 static int create_pty_only(term_T *term, jobopt_T *opt); | |
188 static void term_report_winsize(term_T *term, int rows, int cols); | |
189 static void term_free_vterm(term_T *term); | |
190 | |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
191 /* The character that we know (or assume) that the terminal expects for the |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
192 * backspace key. */ |
12502 | 193 static int term_backspace_char = BS; |
194 | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
195 /* "Terminal" highlight group colors. */ |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
196 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
|
197 static int term_default_cterm_bg = -1; |
12502 | 198 |
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
|
199 /* Store the last set and the desired cursor properties, so that we only update |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
200 * them when needed. Doing it unnecessary may result in flicker. */ |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
201 static char_u *last_set_cursor_color = (char_u *)""; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
202 static char_u *desired_cursor_color = (char_u *)""; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 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
|
207 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
208 |
12502 | 209 /************************************** |
210 * 1. Generic code for all systems. | |
211 */ | |
212 | |
213 /* | |
214 * Determine the terminal size from 'termsize' and the current window. | |
215 * Assumes term->tl_rows and term->tl_cols are zero. | |
216 */ | |
217 static void | |
218 set_term_and_win_size(term_T *term) | |
219 { | |
220 if (*curwin->w_p_tms != NUL) | |
221 { | |
222 char_u *p = vim_strchr(curwin->w_p_tms, 'x') + 1; | |
223 | |
224 term->tl_rows = atoi((char *)curwin->w_p_tms); | |
225 term->tl_cols = atoi((char *)p); | |
226 } | |
227 if (term->tl_rows == 0) | |
228 term->tl_rows = curwin->w_height; | |
229 else | |
230 { | |
231 win_setheight_win(term->tl_rows, curwin); | |
232 term->tl_rows_fixed = TRUE; | |
233 } | |
234 if (term->tl_cols == 0) | |
235 term->tl_cols = curwin->w_width; | |
236 else | |
237 { | |
238 win_setwidth_win(term->tl_cols, curwin); | |
239 term->tl_cols_fixed = TRUE; | |
240 } | |
241 } | |
242 | |
243 /* | |
244 * Initialize job options for a terminal job. | |
245 * Caller may overrule some of them. | |
246 */ | |
247 static void | |
248 init_job_options(jobopt_T *opt) | |
249 { | |
250 clear_job_options(opt); | |
251 | |
252 opt->jo_mode = MODE_RAW; | |
253 opt->jo_out_mode = MODE_RAW; | |
254 opt->jo_err_mode = MODE_RAW; | |
255 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; | |
256 } | |
257 | |
258 /* | |
259 * Set job options mandatory for a terminal job. | |
260 */ | |
261 static void | |
262 setup_job_options(jobopt_T *opt, int rows, int cols) | |
263 { | |
264 if (!(opt->jo_set & JO_OUT_IO)) | |
265 { | |
266 /* Connect stdout to the terminal. */ | |
267 opt->jo_io[PART_OUT] = JIO_BUFFER; | |
268 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; | |
269 opt->jo_modifiable[PART_OUT] = 0; | |
270 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE; | |
271 } | |
272 | |
273 if (!(opt->jo_set & JO_ERR_IO)) | |
274 { | |
275 /* Connect stderr to the terminal. */ | |
276 opt->jo_io[PART_ERR] = JIO_BUFFER; | |
277 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; | |
278 opt->jo_modifiable[PART_ERR] = 0; | |
279 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE; | |
280 } | |
281 | |
282 opt->jo_pty = TRUE; | |
283 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0) | |
284 opt->jo_term_rows = rows; | |
285 if ((opt->jo_set2 & JO2_TERM_COLS) == 0) | |
286 opt->jo_term_cols = cols; | |
287 } | |
288 | |
289 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
290 * 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
|
291 * fails. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
292 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
293 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
294 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
|
295 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
296 free_terminal(buf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
297 if (old_curbuf != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
298 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
299 --curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
300 curbuf = old_curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
301 curwin->w_buffer = curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
302 ++curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
303 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
304 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
305 /* Wiping out the buffer will also close the window and call |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
306 * free_terminal(). */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
307 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
|
308 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
309 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
310 /* |
12502 | 311 * Start a terminal window and return its buffer. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
312 * When "without_job" is TRUE only create the buffer, b_term and open the |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
313 * window. |
12502 | 314 * Returns NULL when failed. |
315 */ | |
316 static buf_T * | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
317 term_start(typval_T *argvar, jobopt_T *opt, int without_job, int forceit) |
12502 | 318 { |
319 exarg_T split_ea; | |
320 win_T *old_curwin = curwin; | |
321 term_T *term; | |
322 buf_T *old_curbuf = NULL; | |
323 int res; | |
324 buf_T *newbuf; | |
325 | |
326 if (check_restricted() || check_secure()) | |
327 return NULL; | |
328 | |
329 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)) | |
330 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO) | |
331 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF)) | |
332 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF))) | |
333 { | |
334 EMSG(_(e_invarg)); | |
335 return NULL; | |
336 } | |
337 | |
338 term = (term_T *)alloc_clear(sizeof(term_T)); | |
339 if (term == NULL) | |
340 return NULL; | |
341 term->tl_dirty_row_end = MAX_ROW; | |
342 term->tl_cursor_visible = TRUE; | |
343 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | |
344 term->tl_finish = opt->jo_term_finish; | |
345 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300); | |
346 | |
347 vim_memset(&split_ea, 0, sizeof(split_ea)); | |
348 if (opt->jo_curwin) | |
349 { | |
350 /* Create a new buffer in the current window. */ | |
351 if (!can_abandon(curbuf, forceit)) | |
352 { | |
353 no_write_message(); | |
354 vim_free(term); | |
355 return NULL; | |
356 } | |
357 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE, | |
358 ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) | |
359 { | |
360 vim_free(term); | |
361 return NULL; | |
362 } | |
363 } | |
364 else if (opt->jo_hidden) | |
365 { | |
366 buf_T *buf; | |
367 | |
368 /* Create a new buffer without a window. Make it the current buffer for | |
369 * a moment to be able to do the initialisations. */ | |
370 buf = buflist_new((char_u *)"", NULL, (linenr_T)0, | |
371 BLN_NEW | BLN_LISTED); | |
372 if (buf == NULL || ml_open(buf) == FAIL) | |
373 { | |
374 vim_free(term); | |
375 return NULL; | |
376 } | |
377 old_curbuf = curbuf; | |
378 --curbuf->b_nwindows; | |
379 curbuf = buf; | |
380 curwin->w_buffer = buf; | |
381 ++curbuf->b_nwindows; | |
382 } | |
383 else | |
384 { | |
385 /* Open a new window or tab. */ | |
386 split_ea.cmdidx = CMD_new; | |
387 split_ea.cmd = (char_u *)"new"; | |
388 split_ea.arg = (char_u *)""; | |
389 if (opt->jo_term_rows > 0 && !(cmdmod.split & WSP_VERT)) | |
390 { | |
391 split_ea.line2 = opt->jo_term_rows; | |
392 split_ea.addr_count = 1; | |
393 } | |
394 if (opt->jo_term_cols > 0 && (cmdmod.split & WSP_VERT)) | |
395 { | |
396 split_ea.line2 = opt->jo_term_cols; | |
397 split_ea.addr_count = 1; | |
398 } | |
399 | |
400 ex_splitview(&split_ea); | |
401 if (curwin == old_curwin) | |
402 { | |
403 /* split failed */ | |
404 vim_free(term); | |
405 return NULL; | |
406 } | |
407 } | |
408 term->tl_buffer = curbuf; | |
409 curbuf->b_term = term; | |
410 | |
411 if (!opt->jo_hidden) | |
412 { | |
13304
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
413 /* Only one size was taken care of with :new, do the other one. With |
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
414 * "curwin" both need to be done. */ |
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
415 if (opt->jo_term_rows > 0 && (opt->jo_curwin |
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
416 || (cmdmod.split & WSP_VERT))) |
12502 | 417 win_setheight(opt->jo_term_rows); |
13304
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
418 if (opt->jo_term_cols > 0 && (opt->jo_curwin |
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
419 || !(cmdmod.split & WSP_VERT))) |
12502 | 420 win_setwidth(opt->jo_term_cols); |
421 } | |
422 | |
423 /* Link the new terminal in the list of active terminals. */ | |
424 term->tl_next = first_term; | |
425 first_term = term; | |
426 | |
427 if (opt->jo_term_name != NULL) | |
428 curbuf->b_ffname = vim_strsave(opt->jo_term_name); | |
429 else | |
430 { | |
431 int i; | |
432 size_t len; | |
433 char_u *cmd, *p; | |
434 | |
435 if (argvar->v_type == VAR_STRING) | |
436 { | |
437 cmd = argvar->vval.v_string; | |
438 if (cmd == NULL) | |
439 cmd = (char_u *)""; | |
440 else if (STRCMP(cmd, "NONE") == 0) | |
441 cmd = (char_u *)"pty"; | |
442 } | |
443 else if (argvar->v_type != VAR_LIST | |
444 || argvar->vval.v_list == NULL | |
445 || argvar->vval.v_list->lv_len < 1 | |
446 || (cmd = get_tv_string_chk( | |
447 &argvar->vval.v_list->lv_first->li_tv)) == NULL) | |
448 cmd = (char_u*)""; | |
449 | |
450 len = STRLEN(cmd) + 10; | |
451 p = alloc((int)len); | |
452 | |
453 for (i = 0; p != NULL; ++i) | |
454 { | |
455 /* Prepend a ! to the command name to avoid the buffer name equals | |
456 * the executable, otherwise ":w!" would overwrite it. */ | |
457 if (i == 0) | |
458 vim_snprintf((char *)p, len, "!%s", cmd); | |
459 else | |
460 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i); | |
461 if (buflist_findname(p) == NULL) | |
462 { | |
463 vim_free(curbuf->b_ffname); | |
464 curbuf->b_ffname = p; | |
465 break; | |
466 } | |
467 } | |
468 } | |
469 curbuf->b_fname = curbuf->b_ffname; | |
470 | |
471 if (opt->jo_term_opencmd != NULL) | |
472 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); | |
473 | |
474 if (opt->jo_eof_chars != NULL) | |
475 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); | |
476 | |
477 set_string_option_direct((char_u *)"buftype", -1, | |
478 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0); | |
479 | |
480 /* Mark the buffer as not modifiable. It can only be made modifiable after | |
481 * the job finished. */ | |
482 curbuf->b_p_ma = FALSE; | |
483 | |
484 set_term_and_win_size(term); | |
485 setup_job_options(opt, term->tl_rows, term->tl_cols); | |
486 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
487 if (without_job) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
488 return curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
489 |
12502 | 490 /* System dependent: setup the vterm and maybe start the job in it. */ |
491 if (argvar->v_type == VAR_STRING | |
492 && argvar->vval.v_string != NULL | |
493 && STRCMP(argvar->vval.v_string, "NONE") == 0) | |
494 res = create_pty_only(term, opt); | |
495 else | |
496 res = term_and_job_init(term, argvar, opt); | |
497 | |
498 newbuf = curbuf; | |
499 if (res == OK) | |
500 { | |
501 /* Get and remember the size we ended up with. Update the pty. */ | |
502 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); | |
503 term_report_winsize(term, term->tl_rows, term->tl_cols); | |
504 | |
505 /* Make sure we don't get stuck on sending keys to the job, it leads to | |
506 * a deadlock if the job is waiting for Vim to read. */ | |
507 channel_set_nonblock(term->tl_job->jv_channel, PART_IN); | |
508 | |
12509
1fd4594eb74a
Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents:
12502
diff
changeset
|
509 #ifdef FEAT_AUTOCMD |
13282
8db0345053b9
patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
13250
diff
changeset
|
510 if (!opt->jo_hidden) |
8db0345053b9
patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
13250
diff
changeset
|
511 { |
8db0345053b9
patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
13250
diff
changeset
|
512 ++curbuf->b_locked; |
8db0345053b9
patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
13250
diff
changeset
|
513 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); |
8db0345053b9
patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
13250
diff
changeset
|
514 --curbuf->b_locked; |
8db0345053b9
patch 8.0.1515: BufWinEnter event fired when opening hidden terminal
Christian Brabandt <cb@256bit.org>
parents:
13250
diff
changeset
|
515 } |
12509
1fd4594eb74a
Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents:
12502
diff
changeset
|
516 #endif |
1fd4594eb74a
Missing part of 8.0.1131.
Christian Brabandt <cb@256bit.org>
parents:
12502
diff
changeset
|
517 |
12502 | 518 if (old_curbuf != NULL) |
519 { | |
520 --curbuf->b_nwindows; | |
521 curbuf = old_curbuf; | |
522 curwin->w_buffer = curbuf; | |
523 ++curbuf->b_nwindows; | |
524 } | |
525 } | |
526 else | |
527 { | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
528 term_close_buffer(curbuf, old_curbuf); |
12502 | 529 return NULL; |
530 } | |
531 return newbuf; | |
532 } | |
533 | |
534 /* | |
535 * ":terminal": open a terminal window and execute a job in it. | |
536 */ | |
537 void | |
538 ex_terminal(exarg_T *eap) | |
539 { | |
540 typval_T argvar[2]; | |
541 jobopt_T opt; | |
542 char_u *cmd; | |
543 char_u *tofree = NULL; | |
544 | |
545 init_job_options(&opt); | |
546 | |
547 cmd = eap->arg; | |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
548 while (*cmd == '+' && *(cmd + 1) == '+') |
12502 | 549 { |
550 char_u *p, *ep; | |
551 | |
552 cmd += 2; | |
553 p = skiptowhite(cmd); | |
554 ep = vim_strchr(cmd, '='); | |
555 if (ep != NULL && ep < p) | |
556 p = ep; | |
557 | |
558 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0) | |
559 opt.jo_term_finish = 'c'; | |
560 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0) | |
561 opt.jo_term_finish = 'o'; | |
562 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0) | |
563 opt.jo_curwin = 1; | |
564 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0) | |
565 opt.jo_hidden = 1; | |
566 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "rows", 4) == 0 | |
567 && ep != NULL && isdigit(ep[1])) | |
568 { | |
569 opt.jo_set2 |= JO2_TERM_ROWS; | |
570 opt.jo_term_rows = atoi((char *)ep + 1); | |
571 p = skiptowhite(cmd); | |
572 } | |
573 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "cols", 4) == 0 | |
574 && ep != NULL && isdigit(ep[1])) | |
575 { | |
576 opt.jo_set2 |= JO2_TERM_COLS; | |
577 opt.jo_term_cols = atoi((char *)ep + 1); | |
578 p = skiptowhite(cmd); | |
579 } | |
580 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0 | |
581 && ep != NULL) | |
582 { | |
583 char_u *buf = NULL; | |
584 char_u *keys; | |
585 | |
586 p = skiptowhite(cmd); | |
587 *p = NUL; | |
588 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE); | |
589 opt.jo_set2 |= JO2_EOF_CHARS; | |
590 opt.jo_eof_chars = vim_strsave(keys); | |
591 vim_free(buf); | |
592 *p = ' '; | |
593 } | |
594 else | |
595 { | |
596 if (*p) | |
597 *p = NUL; | |
598 EMSG2(_("E181: Invalid attribute: %s"), cmd); | |
599 return; | |
600 } | |
601 cmd = skipwhite(p); | |
602 } | |
603 if (*cmd == NUL) | |
604 /* Make a copy of 'shell', an autocommand may change the option. */ | |
605 tofree = cmd = vim_strsave(p_sh); | |
606 | |
607 if (eap->addr_count > 0) | |
608 { | |
609 /* Write lines from current buffer to the job. */ | |
610 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; | |
611 opt.jo_io[PART_IN] = JIO_BUFFER; | |
612 opt.jo_io_buf[PART_IN] = curbuf->b_fnum; | |
613 opt.jo_in_top = eap->line1; | |
614 opt.jo_in_bot = eap->line2; | |
615 } | |
616 | |
617 argvar[0].v_type = VAR_STRING; | |
618 argvar[0].vval.v_string = cmd; | |
619 argvar[1].v_type = VAR_UNKNOWN; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
620 term_start(argvar, &opt, FALSE, eap->forceit); |
12502 | 621 vim_free(tofree); |
622 vim_free(opt.jo_eof_chars); | |
623 } | |
624 | |
625 /* | |
626 * Free the scrollback buffer for "term". | |
627 */ | |
628 static void | |
629 free_scrollback(term_T *term) | |
630 { | |
631 int i; | |
632 | |
633 for (i = 0; i < term->tl_scrollback.ga_len; ++i) | |
634 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); | |
635 ga_clear(&term->tl_scrollback); | |
636 } | |
637 | |
638 /* | |
639 * Free a terminal and everything it refers to. | |
640 * Kills the job if there is one. | |
641 * Called when wiping out a buffer. | |
642 */ | |
643 void | |
644 free_terminal(buf_T *buf) | |
645 { | |
646 term_T *term = buf->b_term; | |
647 term_T *tp; | |
648 | |
649 if (term == NULL) | |
650 return; | |
651 if (first_term == term) | |
652 first_term = term->tl_next; | |
653 else | |
654 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next) | |
655 if (tp->tl_next == term) | |
656 { | |
657 tp->tl_next = term->tl_next; | |
658 break; | |
659 } | |
660 | |
661 if (term->tl_job != NULL) | |
662 { | |
663 if (term->tl_job->jv_status != JOB_ENDED | |
664 && 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
|
665 && term->tl_job->jv_status != JOB_FAILED) |
12502 | 666 job_stop(term->tl_job, NULL, "kill"); |
667 job_unref(term->tl_job); | |
668 } | |
669 | |
670 free_scrollback(term); | |
671 | |
672 term_free_vterm(term); | |
673 vim_free(term->tl_title); | |
674 vim_free(term->tl_status_text); | |
675 vim_free(term->tl_opencmd); | |
676 vim_free(term->tl_eof_chars); | |
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
|
677 if (desired_cursor_color == term->tl_cursor_color) |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
678 desired_cursor_color = (char_u *)""; |
12502 | 679 vim_free(term->tl_cursor_color); |
680 vim_free(term); | |
681 buf->b_term = NULL; | |
682 if (in_terminal_loop == term) | |
683 in_terminal_loop = NULL; | |
684 } | |
685 | |
686 /* | |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
687 * 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
|
688 * 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
|
689 * 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
|
690 */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
691 static ch_part_T |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
692 get_tty_part(term_T *term) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
693 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
694 #ifdef UNIX |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
695 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
|
696 int i; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
697 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
698 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
|
699 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
700 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
|
701 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
702 if (isatty(fd)) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
703 return parts[i]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
704 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
705 #endif |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
706 return PART_IN; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
707 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
708 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
709 /* |
12502 | 710 * Write job output "msg[len]" to the vterm. |
711 */ | |
712 static void | |
713 term_write_job_output(term_T *term, char_u *msg, size_t len) | |
714 { | |
715 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
|
716 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
|
717 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
718 vterm_input_write(vterm, (char *)msg, len); |
12502 | 719 |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
720 /* flush vterm buffer when vterm responded to control sequence */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
721 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
|
722 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
723 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
|
724 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
|
725 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
726 if (curlen > 0) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
727 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
|
728 (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
|
729 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
730 |
12502 | 731 /* this invokes the damage callbacks */ |
732 vterm_screen_flush_damage(vterm_obtain_screen(vterm)); | |
733 } | |
734 | |
735 static void | |
736 update_cursor(term_T *term, int redraw) | |
737 { | |
738 if (term->tl_normal_mode) | |
739 return; | |
740 setcursor(); | |
741 if (redraw) | |
742 { | |
743 if (term->tl_buffer == curbuf && term->tl_cursor_visible) | |
744 cursor_on(); | |
745 out_flush(); | |
746 #ifdef FEAT_GUI | |
747 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
|
748 { |
12502 | 749 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
|
750 gui_mch_flush(); |
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
751 } |
12502 | 752 #endif |
753 } | |
754 } | |
755 | |
756 /* | |
757 * Invoked when "msg" output from a job was received. Write it to the terminal | |
758 * of "buffer". | |
759 */ | |
760 void | |
761 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel) | |
762 { | |
763 size_t len = STRLEN(msg); | |
764 term_T *term = buffer->b_term; | |
765 | |
766 if (term->tl_vterm == NULL) | |
767 { | |
768 ch_log(channel, "NOT writing %d bytes to terminal", (int)len); | |
769 return; | |
770 } | |
771 ch_log(channel, "writing %d bytes to terminal", (int)len); | |
772 term_write_job_output(term, msg, len); | |
773 | |
774 /* In Terminal-Normal mode we are displaying the buffer, not the terminal | |
775 * contents, thus no screen update is needed. */ | |
776 if (!term->tl_normal_mode) | |
777 { | |
778 /* TODO: only update once in a while. */ | |
779 ch_log(term->tl_job->jv_channel, "updating screen"); | |
780 if (buffer == curbuf) | |
781 { | |
782 update_screen(0); | |
783 update_cursor(term, TRUE); | |
784 } | |
785 else | |
786 redraw_after_callback(TRUE); | |
787 } | |
788 } | |
789 | |
790 /* | |
791 * Send a mouse position and click to the vterm | |
792 */ | |
793 static int | |
794 term_send_mouse(VTerm *vterm, int button, int pressed) | |
795 { | |
796 VTermModifier mod = VTERM_MOD_NONE; | |
797 | |
798 vterm_mouse_move(vterm, mouse_row - W_WINROW(curwin), | |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12509
diff
changeset
|
799 mouse_col - curwin->w_wincol, mod); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
800 if (button != 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
801 vterm_mouse_button(vterm, button, pressed, mod); |
12502 | 802 return TRUE; |
803 } | |
804 | |
805 /* | |
806 * Convert typed key "c" into bytes to send to the job. | |
807 * Return the number of bytes in "buf". | |
808 */ | |
809 static int | |
810 term_convert_key(term_T *term, int c, char *buf) | |
811 { | |
812 VTerm *vterm = term->tl_vterm; | |
813 VTermKey key = VTERM_KEY_NONE; | |
814 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
|
815 int other = FALSE; |
12502 | 816 |
817 switch (c) | |
818 { | |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
819 /* don't use VTERM_KEY_ENTER, it may do an unwanted conversion */ |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
820 |
12502 | 821 /* don't use VTERM_KEY_BACKSPACE, it always |
822 * becomes 0x7f DEL */ | |
823 case K_BS: c = term_backspace_char; break; | |
824 | |
825 case ESC: key = VTERM_KEY_ESCAPE; break; | |
826 case K_DEL: key = VTERM_KEY_DEL; break; | |
827 case K_DOWN: key = VTERM_KEY_DOWN; break; | |
828 case K_S_DOWN: mod = VTERM_MOD_SHIFT; | |
829 key = VTERM_KEY_DOWN; break; | |
830 case K_END: key = VTERM_KEY_END; break; | |
831 case K_S_END: mod = VTERM_MOD_SHIFT; | |
832 key = VTERM_KEY_END; break; | |
833 case K_C_END: mod = VTERM_MOD_CTRL; | |
834 key = VTERM_KEY_END; break; | |
835 case K_F10: key = VTERM_KEY_FUNCTION(10); break; | |
836 case K_F11: key = VTERM_KEY_FUNCTION(11); break; | |
837 case K_F12: key = VTERM_KEY_FUNCTION(12); break; | |
838 case K_F1: key = VTERM_KEY_FUNCTION(1); break; | |
839 case K_F2: key = VTERM_KEY_FUNCTION(2); break; | |
840 case K_F3: key = VTERM_KEY_FUNCTION(3); break; | |
841 case K_F4: key = VTERM_KEY_FUNCTION(4); break; | |
842 case K_F5: key = VTERM_KEY_FUNCTION(5); break; | |
843 case K_F6: key = VTERM_KEY_FUNCTION(6); break; | |
844 case K_F7: key = VTERM_KEY_FUNCTION(7); break; | |
845 case K_F8: key = VTERM_KEY_FUNCTION(8); break; | |
846 case K_F9: key = VTERM_KEY_FUNCTION(9); break; | |
847 case K_HOME: key = VTERM_KEY_HOME; break; | |
848 case K_S_HOME: mod = VTERM_MOD_SHIFT; | |
849 key = VTERM_KEY_HOME; break; | |
850 case K_C_HOME: mod = VTERM_MOD_CTRL; | |
851 key = VTERM_KEY_HOME; break; | |
852 case K_INS: key = VTERM_KEY_INS; break; | |
853 case K_K0: key = VTERM_KEY_KP_0; break; | |
854 case K_K1: key = VTERM_KEY_KP_1; break; | |
855 case K_K2: key = VTERM_KEY_KP_2; break; | |
856 case K_K3: key = VTERM_KEY_KP_3; break; | |
857 case K_K4: key = VTERM_KEY_KP_4; break; | |
858 case K_K5: key = VTERM_KEY_KP_5; break; | |
859 case K_K6: key = VTERM_KEY_KP_6; break; | |
860 case K_K7: key = VTERM_KEY_KP_7; break; | |
861 case K_K8: key = VTERM_KEY_KP_8; break; | |
862 case K_K9: key = VTERM_KEY_KP_9; break; | |
863 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */ | |
864 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break; | |
865 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */ | |
866 case K_KENTER: key = VTERM_KEY_KP_ENTER; break; | |
867 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */ | |
868 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */ | |
869 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break; | |
870 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break; | |
871 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */ | |
872 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */ | |
873 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break; | |
874 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break; | |
875 case K_LEFT: key = VTERM_KEY_LEFT; break; | |
876 case K_S_LEFT: mod = VTERM_MOD_SHIFT; | |
877 key = VTERM_KEY_LEFT; break; | |
878 case K_C_LEFT: mod = VTERM_MOD_CTRL; | |
879 key = VTERM_KEY_LEFT; break; | |
880 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break; | |
881 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break; | |
882 case K_RIGHT: key = VTERM_KEY_RIGHT; break; | |
883 case K_S_RIGHT: mod = VTERM_MOD_SHIFT; | |
884 key = VTERM_KEY_RIGHT; break; | |
885 case K_C_RIGHT: mod = VTERM_MOD_CTRL; | |
886 key = VTERM_KEY_RIGHT; break; | |
887 case K_UP: key = VTERM_KEY_UP; break; | |
888 case K_S_UP: mod = VTERM_MOD_SHIFT; | |
889 key = VTERM_KEY_UP; break; | |
890 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
|
891 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
|
892 key = VTERM_KEY_TAB; break; |
12502 | 893 |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
894 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
|
895 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break; |
12502 | 896 case K_MOUSELEFT: /* TODO */ return 0; |
897 case K_MOUSERIGHT: /* TODO */ return 0; | |
898 | |
899 case K_LEFTMOUSE: | |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
900 case K_LEFTMOUSE_NM: other = term_send_mouse(vterm, 1, 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
|
901 case K_LEFTDRAG: other = term_send_mouse(vterm, 1, 1); break; |
12502 | 902 case K_LEFTRELEASE: |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
903 case K_LEFTRELEASE_NM: other = term_send_mouse(vterm, 1, 0); break; |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
904 case K_MOUSEMOVE: other = term_send_mouse(vterm, 0, 0); break; |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
905 case K_MIDDLEMOUSE: other = term_send_mouse(vterm, 2, 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
|
906 case K_MIDDLEDRAG: other = term_send_mouse(vterm, 2, 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
|
907 case K_MIDDLERELEASE: other = term_send_mouse(vterm, 2, 0); break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
908 case K_RIGHTMOUSE: other = term_send_mouse(vterm, 3, 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
|
909 case K_RIGHTDRAG: other = term_send_mouse(vterm, 3, 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
|
910 case K_RIGHTRELEASE: other = term_send_mouse(vterm, 3, 0); break; |
12502 | 911 case K_X1MOUSE: /* TODO */ return 0; |
912 case K_X1DRAG: /* TODO */ return 0; | |
913 case K_X1RELEASE: /* TODO */ return 0; | |
914 case K_X2MOUSE: /* TODO */ return 0; | |
915 case K_X2DRAG: /* TODO */ return 0; | |
916 case K_X2RELEASE: /* TODO */ return 0; | |
917 | |
918 case K_IGNORE: return 0; | |
919 case K_NOP: return 0; | |
920 case K_UNDO: return 0; | |
921 case K_HELP: return 0; | |
922 case K_XF1: key = VTERM_KEY_FUNCTION(1); break; | |
923 case K_XF2: key = VTERM_KEY_FUNCTION(2); break; | |
924 case K_XF3: key = VTERM_KEY_FUNCTION(3); break; | |
925 case K_XF4: key = VTERM_KEY_FUNCTION(4); break; | |
926 case K_SELECT: return 0; | |
927 #ifdef FEAT_GUI | |
928 case K_VER_SCROLLBAR: return 0; | |
929 case K_HOR_SCROLLBAR: return 0; | |
930 #endif | |
931 #ifdef FEAT_GUI_TABLINE | |
932 case K_TABLINE: return 0; | |
933 case K_TABMENU: return 0; | |
934 #endif | |
935 #ifdef FEAT_NETBEANS_INTG | |
936 case K_F21: key = VTERM_KEY_FUNCTION(21); break; | |
937 #endif | |
938 #ifdef FEAT_DND | |
939 case K_DROP: return 0; | |
940 #endif | |
941 #ifdef FEAT_AUTOCMD | |
942 case K_CURSORHOLD: return 0; | |
943 #endif | |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
944 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
|
945 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
|
946 break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
947 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
|
948 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
|
949 break; |
12502 | 950 } |
951 | |
952 /* | |
953 * Convert special keys to vterm keys: | |
954 * - Write keys to vterm: vterm_keyboard_key() | |
955 * - Write output to channel. | |
956 * TODO: use mod_mask | |
957 */ | |
958 if (key != VTERM_KEY_NONE) | |
959 /* Special key, let vterm convert it. */ | |
960 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
|
961 else if (!other) |
12502 | 962 /* Normal character, let vterm convert it. */ |
963 vterm_keyboard_unichar(vterm, c, mod); | |
964 | |
965 /* Read back the converted escape sequence. */ | |
966 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); | |
967 } | |
968 | |
969 /* | |
970 * Return TRUE if the job for "term" is still running. | |
971 */ | |
972 int | |
973 term_job_running(term_T *term) | |
974 { | |
975 /* Also consider the job finished when the channel is closed, to avoid a | |
976 * race condition when updating the title. */ | |
977 return term != NULL | |
978 && term->tl_job != NULL | |
979 && channel_is_open(term->tl_job->jv_channel) | |
980 && (term->tl_job->jv_status == JOB_STARTED | |
981 || term->tl_job->jv_channel->ch_keep_open); | |
982 } | |
983 | |
984 /* | |
985 * Return TRUE if "term" has an active channel and used ":term NONE". | |
986 */ | |
987 int | |
988 term_none_open(term_T *term) | |
989 { | |
990 /* Also consider the job finished when the channel is closed, to avoid a | |
991 * race condition when updating the title. */ | |
992 return term != NULL | |
993 && term->tl_job != NULL | |
994 && channel_is_open(term->tl_job->jv_channel) | |
995 && term->tl_job->jv_channel->ch_keep_open; | |
996 } | |
997 | |
998 /* | |
999 * Add the last line of the scrollback buffer to the buffer in the window. | |
1000 */ | |
1001 static void | |
1002 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) | |
1003 { | |
1004 buf_T *buf = term->tl_buffer; | |
1005 int empty = (buf->b_ml.ml_flags & ML_EMPTY); | |
1006 linenr_T lnum = buf->b_ml.ml_line_count; | |
1007 | |
1008 #ifdef WIN3264 | |
1009 if (!enc_utf8 && enc_codepage > 0) | |
1010 { | |
1011 WCHAR *ret = NULL; | |
1012 int length = 0; | |
1013 | |
1014 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, | |
1015 &ret, &length); | |
1016 if (ret != NULL) | |
1017 { | |
1018 WideCharToMultiByte_alloc(enc_codepage, 0, | |
1019 ret, length, (char **)&text, &len, 0, 0); | |
1020 vim_free(ret); | |
1021 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); | |
1022 vim_free(text); | |
1023 } | |
1024 } | |
1025 else | |
1026 #endif | |
1027 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); | |
1028 if (empty) | |
1029 { | |
1030 /* Delete the empty line that was in the empty buffer. */ | |
1031 curbuf = buf; | |
1032 ml_delete(1, FALSE); | |
1033 curbuf = curwin->w_buffer; | |
1034 } | |
1035 } | |
1036 | |
1037 static void | |
1038 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr) | |
1039 { | |
1040 attr->width = cell->width; | |
1041 attr->attrs = cell->attrs; | |
1042 attr->fg = cell->fg; | |
1043 attr->bg = cell->bg; | |
1044 } | |
1045 | |
1046 static int | |
1047 equal_celattr(cellattr_T *a, cellattr_T *b) | |
1048 { | |
1049 /* Comparing the colors should be sufficient. */ | |
1050 return a->fg.red == b->fg.red | |
1051 && a->fg.green == b->fg.green | |
1052 && a->fg.blue == b->fg.blue | |
1053 && a->bg.red == b->bg.red | |
1054 && a->bg.green == b->bg.green | |
1055 && a->bg.blue == b->bg.blue; | |
1056 } | |
1057 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1058 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1059 * 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
|
1060 * 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
|
1061 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1062 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1063 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
|
1064 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1065 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
|
1066 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1067 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
|
1068 + 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
|
1069 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1070 if (lnum > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1071 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1072 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1073 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1074 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
|
1075 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1076 *line = *(line - 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1077 --line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1078 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1079 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1080 line->sb_cols = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1081 line->sb_cells = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1082 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
|
1083 ++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
|
1084 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1085 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1086 return FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1087 } |
12502 | 1088 |
1089 /* | |
1090 * Add the current lines of the terminal to scrollback and to the buffer. | |
1091 * Called after the job has ended and when switching to Terminal-Normal mode. | |
1092 */ | |
1093 static void | |
1094 move_terminal_to_buffer(term_T *term) | |
1095 { | |
1096 win_T *wp; | |
1097 int len; | |
1098 int lines_skipped = 0; | |
1099 VTermPos pos; | |
1100 VTermScreenCell cell; | |
1101 cellattr_T fill_attr, new_fill_attr; | |
1102 cellattr_T *p; | |
1103 VTermScreen *screen; | |
1104 | |
1105 if (term->tl_vterm == NULL) | |
1106 return; | |
1107 screen = vterm_obtain_screen(term->tl_vterm); | |
1108 fill_attr = new_fill_attr = term->tl_default_color; | |
1109 | |
1110 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row) | |
1111 { | |
1112 len = 0; | |
1113 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | |
1114 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | |
1115 && cell.chars[0] != NUL) | |
1116 { | |
1117 len = pos.col + 1; | |
1118 new_fill_attr = term->tl_default_color; | |
1119 } | |
1120 else | |
1121 /* Assume the last attr is the filler attr. */ | |
1122 cell2cellattr(&cell, &new_fill_attr); | |
1123 | |
1124 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr)) | |
1125 ++lines_skipped; | |
1126 else | |
1127 { | |
1128 while (lines_skipped > 0) | |
1129 { | |
1130 /* Line was skipped, add an empty line. */ | |
1131 --lines_skipped; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1132 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
12502 | 1133 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
1134 } | |
1135 | |
1136 if (len == 0) | |
1137 p = NULL; | |
1138 else | |
1139 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len); | |
1140 if ((p != NULL || len == 0) | |
1141 && ga_grow(&term->tl_scrollback, 1) == OK) | |
1142 { | |
1143 garray_T ga; | |
1144 int width; | |
1145 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | |
1146 + term->tl_scrollback.ga_len; | |
1147 | |
1148 ga_init2(&ga, 1, 100); | |
1149 for (pos.col = 0; pos.col < len; pos.col += width) | |
1150 { | |
1151 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
1152 { | |
1153 width = 1; | |
1154 vim_memset(p + pos.col, 0, sizeof(cellattr_T)); | |
1155 if (ga_grow(&ga, 1) == OK) | |
1156 ga.ga_len += utf_char2bytes(' ', | |
1157 (char_u *)ga.ga_data + ga.ga_len); | |
1158 } | |
1159 else | |
1160 { | |
1161 width = cell.width; | |
1162 | |
1163 cell2cellattr(&cell, &p[pos.col]); | |
1164 | |
1165 if (ga_grow(&ga, MB_MAXBYTES) == OK) | |
1166 { | |
1167 int i; | |
1168 int c; | |
1169 | |
1170 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) | |
1171 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
1172 (char_u *)ga.ga_data + ga.ga_len); | |
1173 } | |
1174 } | |
1175 } | |
1176 line->sb_cols = len; | |
1177 line->sb_cells = p; | |
1178 line->sb_fill_attr = new_fill_attr; | |
1179 fill_attr = new_fill_attr; | |
1180 ++term->tl_scrollback.ga_len; | |
1181 | |
1182 if (ga_grow(&ga, 1) == FAIL) | |
1183 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
1184 else | |
1185 { | |
1186 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
1187 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
1188 } | |
1189 ga_clear(&ga); | |
1190 } | |
1191 else | |
1192 vim_free(p); | |
1193 } | |
1194 } | |
1195 | |
1196 /* Obtain the current background color. */ | |
1197 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), | |
1198 &term->tl_default_color.fg, &term->tl_default_color.bg); | |
1199 | |
1200 FOR_ALL_WINDOWS(wp) | |
1201 { | |
1202 if (wp->w_buffer == term->tl_buffer) | |
1203 { | |
1204 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count; | |
1205 wp->w_cursor.col = 0; | |
1206 wp->w_valid = 0; | |
1207 if (wp->w_cursor.lnum >= wp->w_height) | |
1208 { | |
1209 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1; | |
1210 | |
1211 if (wp->w_topline < min_topline) | |
1212 wp->w_topline = min_topline; | |
1213 } | |
1214 redraw_win_later(wp, NOT_VALID); | |
1215 } | |
1216 } | |
1217 } | |
1218 | |
1219 static void | |
1220 set_terminal_mode(term_T *term, int normal_mode) | |
1221 { | |
1222 term->tl_normal_mode = normal_mode; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
1223 VIM_CLEAR(term->tl_status_text); |
12502 | 1224 if (term->tl_buffer == curbuf) |
1225 maketitle(); | |
1226 } | |
1227 | |
1228 /* | |
1229 * Called after the job if finished and Terminal mode is not active: | |
1230 * Move the vterm contents into the scrollback buffer and free the vterm. | |
1231 */ | |
1232 static void | |
1233 cleanup_vterm(term_T *term) | |
1234 { | |
1235 if (term->tl_finish != 'c') | |
1236 move_terminal_to_buffer(term); | |
1237 term_free_vterm(term); | |
1238 set_terminal_mode(term, FALSE); | |
1239 } | |
1240 | |
1241 /* | |
1242 * Switch from Terminal-Job mode to Terminal-Normal mode. | |
1243 * Suspends updating the terminal window. | |
1244 */ | |
1245 static void | |
1246 term_enter_normal_mode(void) | |
1247 { | |
1248 term_T *term = curbuf->b_term; | |
1249 | |
1250 /* Append the current terminal contents to the buffer. */ | |
1251 move_terminal_to_buffer(term); | |
1252 | |
1253 set_terminal_mode(term, TRUE); | |
1254 | |
1255 /* Move the window cursor to the position of the cursor in the | |
1256 * terminal. */ | |
1257 curwin->w_cursor.lnum = term->tl_scrollback_scrolled | |
1258 + term->tl_cursor_pos.row + 1; | |
1259 check_cursor(); | |
1260 coladvance(term->tl_cursor_pos.col); | |
1261 | |
1262 /* Display the same lines as in the terminal. */ | |
1263 curwin->w_topline = term->tl_scrollback_scrolled + 1; | |
1264 } | |
1265 | |
1266 /* | |
1267 * Returns TRUE if the current window contains a terminal and we are in | |
1268 * Terminal-Normal mode. | |
1269 */ | |
1270 int | |
1271 term_in_normal_mode(void) | |
1272 { | |
1273 term_T *term = curbuf->b_term; | |
1274 | |
1275 return term != NULL && term->tl_normal_mode; | |
1276 } | |
1277 | |
1278 /* | |
1279 * Switch from Terminal-Normal mode to Terminal-Job mode. | |
1280 * Restores updating the terminal window. | |
1281 */ | |
1282 void | |
1283 term_enter_job_mode() | |
1284 { | |
1285 term_T *term = curbuf->b_term; | |
1286 sb_line_T *line; | |
1287 garray_T *gap; | |
1288 | |
1289 /* Remove the terminal contents from the scrollback and the buffer. */ | |
1290 gap = &term->tl_scrollback; | |
1291 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled | |
1292 && gap->ga_len > 0) | |
1293 { | |
1294 ml_delete(curbuf->b_ml.ml_line_count, FALSE); | |
1295 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1; | |
1296 vim_free(line->sb_cells); | |
1297 --gap->ga_len; | |
1298 } | |
1299 check_cursor(); | |
1300 | |
1301 set_terminal_mode(term, FALSE); | |
1302 | |
1303 if (term->tl_channel_closed) | |
1304 cleanup_vterm(term); | |
1305 redraw_buf_and_status_later(curbuf, NOT_VALID); | |
1306 } | |
1307 | |
1308 /* | |
1309 * Get a key from the user without mapping. | |
1310 * Note: while waiting a terminal may be closed and freed if the channel is | |
1311 * closed and ++close was used. | |
1312 * Uses terminal mode mappings. | |
1313 */ | |
1314 static int | |
1315 term_vgetc() | |
1316 { | |
1317 int c; | |
1318 int save_State = State; | |
1319 | |
1320 State = TERMINAL; | |
1321 got_int = FALSE; | |
1322 #ifdef WIN3264 | |
1323 ctrl_break_was_pressed = FALSE; | |
1324 #endif | |
1325 c = vgetc(); | |
1326 got_int = FALSE; | |
1327 State = save_State; | |
1328 return c; | |
1329 } | |
1330 | |
1331 /* | |
1332 * Send keys to terminal. | |
1333 * Return FAIL when the key needs to be handled in Normal mode. | |
1334 * Return OK when the key was dropped or sent to the terminal. | |
1335 */ | |
1336 int | |
1337 send_keys_to_term(term_T *term, int c, int typed) | |
1338 { | |
1339 char msg[KEY_BUF_LEN]; | |
1340 size_t len; | |
1341 static int mouse_was_outside = FALSE; | |
1342 int dragging_outside = FALSE; | |
1343 | |
1344 /* Catch keys that need to be handled as in Normal mode. */ | |
1345 switch (c) | |
1346 { | |
1347 case NUL: | |
1348 case K_ZERO: | |
1349 if (typed) | |
1350 stuffcharReadbuff(c); | |
1351 return FAIL; | |
1352 | |
1353 case K_IGNORE: | |
1354 return FAIL; | |
1355 | |
1356 case K_LEFTDRAG: | |
1357 case K_MIDDLEDRAG: | |
1358 case K_RIGHTDRAG: | |
1359 case K_X1DRAG: | |
1360 case K_X2DRAG: | |
1361 dragging_outside = mouse_was_outside; | |
1362 /* FALLTHROUGH */ | |
1363 case K_LEFTMOUSE: | |
1364 case K_LEFTMOUSE_NM: | |
1365 case K_LEFTRELEASE: | |
1366 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
|
1367 case K_MOUSEMOVE: |
12502 | 1368 case K_MIDDLEMOUSE: |
1369 case K_MIDDLERELEASE: | |
1370 case K_RIGHTMOUSE: | |
1371 case K_RIGHTRELEASE: | |
1372 case K_X1MOUSE: | |
1373 case K_X1RELEASE: | |
1374 case K_X2MOUSE: | |
1375 case K_X2RELEASE: | |
1376 | |
1377 case K_MOUSEUP: | |
1378 case K_MOUSEDOWN: | |
1379 case K_MOUSELEFT: | |
1380 case K_MOUSERIGHT: | |
1381 if (mouse_row < W_WINROW(curwin) | |
12984
fc0d4a036654
patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1382 || mouse_row >= (W_WINROW(curwin) + curwin->w_height) |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12509
diff
changeset
|
1383 || mouse_col < curwin->w_wincol |
12984
fc0d4a036654
patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1384 || mouse_col >= W_ENDCOL(curwin) |
12502 | 1385 || dragging_outside) |
1386 { | |
12984
fc0d4a036654
patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1387 /* click or scroll outside the current window or on status line |
fc0d4a036654
patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1388 * or vertical separator */ |
12502 | 1389 if (typed) |
1390 { | |
1391 stuffcharReadbuff(c); | |
1392 mouse_was_outside = TRUE; | |
1393 } | |
1394 return FAIL; | |
1395 } | |
1396 } | |
1397 if (typed) | |
1398 mouse_was_outside = FALSE; | |
1399 | |
1400 /* Convert the typed key to a sequence of bytes for the job. */ | |
1401 len = term_convert_key(term, c, msg); | |
1402 if (len > 0) | |
1403 /* TODO: if FAIL is returned, stop? */ | |
1404 channel_send(term->tl_job->jv_channel, get_tty_part(term), | |
1405 (char_u *)msg, (int)len, NULL); | |
1406 | |
1407 return OK; | |
1408 } | |
1409 | |
1410 static void | |
1411 position_cursor(win_T *wp, VTermPos *pos) | |
1412 { | |
1413 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); | |
1414 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1)); | |
1415 wp->w_valid |= (VALID_WCOL|VALID_WROW); | |
1416 } | |
1417 | |
1418 /* | |
1419 * Handle CTRL-W "": send register contents to the job. | |
1420 */ | |
1421 static void | |
1422 term_paste_register(int prev_c UNUSED) | |
1423 { | |
1424 int c; | |
1425 list_T *l; | |
1426 listitem_T *item; | |
1427 long reglen = 0; | |
1428 int type; | |
1429 | |
1430 #ifdef FEAT_CMDL_INFO | |
1431 if (add_to_showcmd(prev_c)) | |
1432 if (add_to_showcmd('"')) | |
1433 out_flush(); | |
1434 #endif | |
1435 c = term_vgetc(); | |
1436 #ifdef FEAT_CMDL_INFO | |
1437 clear_showcmd(); | |
1438 #endif | |
1439 if (!term_use_loop()) | |
1440 /* job finished while waiting for a character */ | |
1441 return; | |
1442 | |
1443 /* CTRL-W "= prompt for expression to evaluate. */ | |
1444 if (c == '=' && get_expr_register() != '=') | |
1445 return; | |
1446 if (!term_use_loop()) | |
1447 /* job finished while waiting for a character */ | |
1448 return; | |
1449 | |
1450 l = (list_T *)get_reg_contents(c, GREG_LIST); | |
1451 if (l != NULL) | |
1452 { | |
1453 type = get_reg_type(c, ®len); | |
1454 for (item = l->lv_first; item != NULL; item = item->li_next) | |
1455 { | |
1456 char_u *s = get_tv_string(&item->li_tv); | |
1457 #ifdef WIN3264 | |
1458 char_u *tmp = s; | |
1459 | |
1460 if (!enc_utf8 && enc_codepage > 0) | |
1461 { | |
1462 WCHAR *ret = NULL; | |
1463 int length = 0; | |
1464 | |
1465 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s, | |
1466 (int)STRLEN(s), &ret, &length); | |
1467 if (ret != NULL) | |
1468 { | |
1469 WideCharToMultiByte_alloc(CP_UTF8, 0, | |
1470 ret, length, (char **)&s, &length, 0, 0); | |
1471 vim_free(ret); | |
1472 } | |
1473 } | |
1474 #endif | |
1475 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
1476 s, (int)STRLEN(s), NULL); | |
1477 #ifdef WIN3264 | |
1478 if (tmp != s) | |
1479 vim_free(s); | |
1480 #endif | |
1481 | |
1482 if (item->li_next != NULL || type == MLINE) | |
1483 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
1484 (char_u *)"\r", 1, NULL); | |
1485 } | |
1486 list_free(l); | |
1487 } | |
1488 } | |
1489 | |
1490 #if defined(FEAT_GUI) || defined(PROTO) | |
1491 /* | |
1492 * Return TRUE when the cursor of the terminal should be displayed. | |
1493 */ | |
1494 int | |
1495 terminal_is_active() | |
1496 { | |
1497 return in_terminal_loop != NULL; | |
1498 } | |
1499 | |
1500 cursorentry_T * | |
1501 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) | |
1502 { | |
1503 term_T *term = in_terminal_loop; | |
1504 static cursorentry_T entry; | |
1505 | |
1506 vim_memset(&entry, 0, sizeof(entry)); | |
1507 entry.shape = entry.mshape = | |
1508 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : | |
1509 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : | |
1510 SHAPE_BLOCK; | |
1511 entry.percentage = 20; | |
1512 if (term->tl_cursor_blink) | |
1513 { | |
1514 entry.blinkwait = 700; | |
1515 entry.blinkon = 400; | |
1516 entry.blinkoff = 250; | |
1517 } | |
1518 *fg = gui.back_pixel; | |
1519 if (term->tl_cursor_color == NULL) | |
1520 *bg = gui.norm_pixel; | |
1521 else | |
1522 *bg = color_name2handle(term->tl_cursor_color); | |
1523 entry.name = "n"; | |
1524 entry.used_for = SHAPE_CURSOR; | |
1525 | |
1526 return &entry; | |
1527 } | |
1528 #endif | |
1529 | |
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
|
1530 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
|
1531 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
|
1532 { |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1533 if (STRCMP(last_set_cursor_color, desired_cursor_color) != 0 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1534 || 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
|
1535 || 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
|
1536 { |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1537 last_set_cursor_color = desired_cursor_color; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1538 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
|
1539 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
|
1540 term_cursor_color(desired_cursor_color); |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1541 if (desired_cursor_shape == -1 || 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
|
1542 /* this will restore the initial cursor style, if possible */ |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1543 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
|
1544 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
|
1545 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
|
1546 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1547 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1548 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1549 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1550 * 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
|
1551 */ |
12502 | 1552 static void |
1553 may_set_cursor_props(term_T *term) | |
1554 { | |
1555 #ifdef FEAT_GUI | |
1556 /* For the GUI the cursor properties are obtained with | |
1557 * term_get_cursor_shape(). */ | |
1558 if (gui.in_use) | |
1559 return; | |
1560 #endif | |
1561 if (in_terminal_loop == term) | |
1562 { | |
1563 if (term->tl_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
|
1564 desired_cursor_color = term->tl_cursor_color; |
12502 | 1565 else |
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
|
1566 desired_cursor_color = (char_u *)""; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1567 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
|
1568 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
|
1569 may_output_cursor_props(); |
12502 | 1570 } |
1571 } | |
1572 | |
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
|
1573 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1574 * 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
|
1575 */ |
12502 | 1576 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
|
1577 prepare_restore_cursor_props(void) |
12502 | 1578 { |
1579 #ifdef FEAT_GUI | |
1580 if (gui.in_use) | |
1581 return; | |
1582 #endif | |
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
|
1583 desired_cursor_color = (char_u *)""; |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1584 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
|
1585 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
|
1586 may_output_cursor_props(); |
12502 | 1587 } |
1588 | |
1589 /* | |
1590 * Returns TRUE if the current window contains a terminal and we are sending | |
1591 * keys to the job. | |
1592 */ | |
1593 int | |
1594 term_use_loop(void) | |
1595 { | |
1596 term_T *term = curbuf->b_term; | |
1597 | |
1598 return term != NULL | |
1599 && !term->tl_normal_mode | |
1600 && term->tl_vterm != NULL | |
1601 && term_job_running(term); | |
1602 } | |
1603 | |
1604 /* | |
1605 * Wait for input and send it to the job. | |
1606 * When "blocking" is TRUE wait for a character to be typed. Otherwise return | |
1607 * when there is no more typahead. | |
1608 * Return when the start of a CTRL-W command is typed or anything else that | |
1609 * should be handled as a Normal mode command. | |
1610 * Returns OK if a typed character is to be handled in Normal mode, FAIL if | |
1611 * the terminal was closed. | |
1612 */ | |
1613 int | |
1614 terminal_loop(int blocking) | |
1615 { | |
1616 int c; | |
1617 int termkey = 0; | |
1618 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
|
1619 #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
|
1620 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
|
1621 ->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
|
1622 #endif |
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
|
1623 int restore_cursor; |
12502 | 1624 |
1625 /* Remember the terminal we are sending keys to. However, the terminal | |
1626 * might be closed while waiting for a character, e.g. typing "exit" in a | |
1627 * shell and ++close was used. Therefore use curbuf->b_term instead of a | |
1628 * stored reference. */ | |
1629 in_terminal_loop = curbuf->b_term; | |
1630 | |
1631 if (*curwin->w_p_tk != NUL) | |
1632 termkey = string_to_key(curwin->w_p_tk, TRUE); | |
1633 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos); | |
1634 may_set_cursor_props(curbuf->b_term); | |
1635 | |
1636 while (blocking || vpeekc() != NUL) | |
1637 { | |
1638 /* TODO: skip screen update when handling a sequence of keys. */ | |
1639 /* Repeat redrawing in case a message is received while redrawing. */ | |
1640 while (must_redraw != 0) | |
1641 if (update_screen(0) == FAIL) | |
1642 break; | |
1643 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
|
1644 restore_cursor = TRUE; |
12502 | 1645 |
1646 c = term_vgetc(); | |
1647 if (!term_use_loop()) | |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
1648 { |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1649 /* Job finished while waiting for a character. Push back the |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1650 * received character. */ |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
1651 if (c != K_IGNORE) |
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
1652 vungetc(c); |
12502 | 1653 break; |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
1654 } |
12502 | 1655 if (c == K_IGNORE) |
1656 continue; | |
1657 | |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1658 #ifdef UNIX |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1659 /* |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1660 * 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
|
1661 * 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
|
1662 * 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
|
1663 */ |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1664 if (isatty(tty_fd)) |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1665 { |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1666 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
|
1667 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1668 /* Get the current backspace character of the pty. */ |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1669 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
|
1670 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
|
1671 } |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1672 #endif |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1673 |
12502 | 1674 #ifdef WIN3264 |
1675 /* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT. | |
1676 * Use CTRL-BREAK to kill the job. */ | |
1677 if (ctrl_break_was_pressed) | |
1678 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
1679 #endif | |
1680 /* Was either CTRL-W (termkey) or CTRL-\ pressed? */ | |
1681 if (c == (termkey == 0 ? Ctrl_W : termkey) || c == Ctrl_BSL) | |
1682 { | |
1683 int prev_c = c; | |
1684 | |
1685 #ifdef FEAT_CMDL_INFO | |
1686 if (add_to_showcmd(c)) | |
1687 out_flush(); | |
1688 #endif | |
1689 c = term_vgetc(); | |
1690 #ifdef FEAT_CMDL_INFO | |
1691 clear_showcmd(); | |
1692 #endif | |
1693 if (!term_use_loop()) | |
1694 /* job finished while waiting for a character */ | |
1695 break; | |
1696 | |
1697 if (prev_c == Ctrl_BSL) | |
1698 { | |
1699 if (c == Ctrl_N) | |
1700 { | |
1701 /* CTRL-\ CTRL-N : go to Terminal-Normal mode. */ | |
1702 term_enter_normal_mode(); | |
1703 ret = FAIL; | |
1704 goto theend; | |
1705 } | |
1706 /* Send both keys to the terminal. */ | |
1707 send_keys_to_term(curbuf->b_term, prev_c, TRUE); | |
1708 } | |
1709 else if (c == Ctrl_C) | |
1710 { | |
1711 /* "CTRL-W CTRL-C" or 'termkey' CTRL-C: end the job */ | |
1712 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
1713 } | |
1714 else if (termkey == 0 && c == '.') | |
1715 { | |
1716 /* "CTRL-W .": send CTRL-W to the job */ | |
1717 c = Ctrl_W; | |
1718 } | |
1719 else if (c == 'N') | |
1720 { | |
1721 /* CTRL-W N : go to Terminal-Normal mode. */ | |
1722 term_enter_normal_mode(); | |
1723 ret = FAIL; | |
1724 goto theend; | |
1725 } | |
1726 else if (c == '"') | |
1727 { | |
1728 term_paste_register(prev_c); | |
1729 continue; | |
1730 } | |
1731 else if (termkey == 0 || c != termkey) | |
1732 { | |
1733 stuffcharReadbuff(Ctrl_W); | |
1734 stuffcharReadbuff(c); | |
1735 ret = OK; | |
1736 goto theend; | |
1737 } | |
1738 } | |
1739 # ifdef WIN3264 | |
1740 if (!enc_utf8 && has_mbyte && c >= 0x80) | |
1741 { | |
1742 WCHAR wc; | |
1743 char_u mb[3]; | |
1744 | |
1745 mb[0] = (unsigned)c >> 8; | |
1746 mb[1] = c; | |
1747 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0) | |
1748 c = wc; | |
1749 } | |
1750 # endif | |
1751 if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK) | |
1752 { | |
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
|
1753 if (c == K_MOUSEMOVE) |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1754 /* We are sure to come back here, don't reset the cursor color |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1755 * and shape to avoid flickering. */ |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
1756 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
|
1757 |
12502 | 1758 ret = OK; |
1759 goto theend; | |
1760 } | |
1761 } | |
1762 ret = FAIL; | |
1763 | |
1764 theend: | |
1765 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
|
1766 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
|
1767 prepare_restore_cursor_props(); |
12502 | 1768 return ret; |
1769 } | |
1770 | |
1771 /* | |
1772 * Called when a job has finished. | |
1773 * This updates the title and status, but does not close the vterm, because | |
1774 * there might still be pending output in the channel. | |
1775 */ | |
1776 void | |
1777 term_job_ended(job_T *job) | |
1778 { | |
1779 term_T *term; | |
1780 int did_one = FALSE; | |
1781 | |
1782 for (term = first_term; term != NULL; term = term->tl_next) | |
1783 if (term->tl_job == job) | |
1784 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
1785 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
|
1786 VIM_CLEAR(term->tl_status_text); |
12502 | 1787 redraw_buf_and_status_later(term->tl_buffer, VALID); |
1788 did_one = TRUE; | |
1789 } | |
1790 if (did_one) | |
1791 redraw_statuslines(); | |
1792 if (curbuf->b_term != NULL) | |
1793 { | |
1794 if (curbuf->b_term->tl_job == job) | |
1795 maketitle(); | |
1796 update_cursor(curbuf->b_term, TRUE); | |
1797 } | |
1798 } | |
1799 | |
1800 static void | |
1801 may_toggle_cursor(term_T *term) | |
1802 { | |
1803 if (in_terminal_loop == term) | |
1804 { | |
1805 if (term->tl_cursor_visible) | |
1806 cursor_on(); | |
1807 else | |
1808 cursor_off(); | |
1809 } | |
1810 } | |
1811 | |
1812 /* | |
1813 * 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
|
1814 * First color is 1. Return 0 if no match found (default color). |
12502 | 1815 */ |
1816 static int | |
1817 color2index(VTermColor *color, int fg, int *boldp) | |
1818 { | |
1819 int red = color->red; | |
1820 int blue = color->blue; | |
1821 int green = color->green; | |
1822 | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1823 if (color->ansi_index != VTERM_ANSI_INDEX_NONE) |
12502 | 1824 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1825 /* First 16 colors and default: use the ANSI index, because these |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1826 * colors can be redefined. */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1827 if (t_colors >= 16) |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1828 return color->ansi_index; |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1829 switch (color->ansi_index) |
12502 | 1830 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1831 case 0: return 0; |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1832 case 1: return lookup_color( 0, fg, boldp) + 1; |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1833 case 2: return lookup_color( 4, fg, boldp) + 1; /* dark red */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1834 case 3: return lookup_color( 2, fg, boldp) + 1; /* dark green */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1835 case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1836 case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue*/ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1837 case 6: return lookup_color( 5, fg, boldp) + 1; /* dark magenta */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1838 case 7: return lookup_color( 3, fg, boldp) + 1; /* dark cyan */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1839 case 8: return lookup_color( 8, fg, boldp) + 1; /* light grey */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1840 case 9: return lookup_color(12, fg, boldp) + 1; /* dark grey */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1841 case 10: return lookup_color(20, fg, boldp) + 1; /* red */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1842 case 11: return lookup_color(16, fg, boldp) + 1; /* green */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1843 case 12: return lookup_color(24, fg, boldp) + 1; /* yellow */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1844 case 13: return lookup_color(14, fg, boldp) + 1; /* blue */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1845 case 14: return lookup_color(22, fg, boldp) + 1; /* magenta */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1846 case 15: return lookup_color(18, fg, boldp) + 1; /* cyan */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1847 case 16: return lookup_color(26, fg, boldp) + 1; /* white */ |
12502 | 1848 } |
1849 } | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
1850 |
12502 | 1851 if (t_colors >= 256) |
1852 { | |
1853 if (red == blue && red == green) | |
1854 { | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1855 /* 24-color greyscale plus white and black */ |
12502 | 1856 static int cutoff[23] = { |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1857 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
|
1858 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
|
1859 0xD5, 0xDF, 0xE9}; |
12502 | 1860 int i; |
1861 | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1862 if (red < 5) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1863 return 17; /* 00/00/00 */ |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1864 if (red > 245) /* ff/ff/ff */ |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1865 return 232; |
12502 | 1866 for (i = 0; i < 23; ++i) |
1867 if (red < cutoff[i]) | |
1868 return i + 233; | |
1869 return 256; | |
1870 } | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1871 { |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1872 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
|
1873 int ri, gi, bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1874 |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1875 /* 216-color cube */ |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1876 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
|
1877 if (red < cutoff[ri]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1878 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1879 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
|
1880 if (green < cutoff[gi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1881 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1882 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
|
1883 if (blue < cutoff[bi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1884 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1885 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
|
1886 } |
12502 | 1887 } |
1888 return 0; | |
1889 } | |
1890 | |
1891 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1892 * Convert Vterm attributes to highlight flags. |
12502 | 1893 */ |
1894 static int | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1895 vtermAttr2hl(VTermScreenCellAttrs cellattrs) |
12502 | 1896 { |
1897 int attr = 0; | |
1898 | |
1899 if (cellattrs.bold) | |
1900 attr |= HL_BOLD; | |
1901 if (cellattrs.underline) | |
1902 attr |= HL_UNDERLINE; | |
1903 if (cellattrs.italic) | |
1904 attr |= HL_ITALIC; | |
1905 if (cellattrs.strike) | |
1906 attr |= HL_STRIKETHROUGH; | |
1907 if (cellattrs.reverse) | |
1908 attr |= HL_INVERSE; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1909 return attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1910 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1911 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1912 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1913 * 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
|
1914 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1915 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1916 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
|
1917 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1918 vim_memset(&cell->attrs, 0, sizeof(VTermScreenCellAttrs)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1919 if (attr & HL_BOLD) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1920 cell->attrs.bold = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1921 if (attr & HL_UNDERLINE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1922 cell->attrs.underline = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1923 if (attr & HL_ITALIC) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1924 cell->attrs.italic = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1925 if (attr & HL_STRIKETHROUGH) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1926 cell->attrs.strike = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1927 if (attr & HL_INVERSE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1928 cell->attrs.reverse = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1929 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1930 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1931 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1932 * 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
|
1933 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1934 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1935 cell2attr(VTermScreenCellAttrs cellattrs, VTermColor cellfg, VTermColor cellbg) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1936 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1937 int attr = vtermAttr2hl(cellattrs); |
12502 | 1938 |
1939 #ifdef FEAT_GUI | |
1940 if (gui.in_use) | |
1941 { | |
1942 guicolor_T fg, bg; | |
1943 | |
1944 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue); | |
1945 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue); | |
1946 return get_gui_attr_idx(attr, fg, bg); | |
1947 } | |
1948 else | |
1949 #endif | |
1950 #ifdef FEAT_TERMGUICOLORS | |
1951 if (p_tgc) | |
1952 { | |
1953 guicolor_T fg, bg; | |
1954 | |
1955 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue); | |
1956 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue); | |
1957 | |
1958 return get_tgc_attr_idx(attr, fg, bg); | |
1959 } | |
1960 else | |
1961 #endif | |
1962 { | |
1963 int bold = MAYBE; | |
1964 int fg = color2index(&cellfg, TRUE, &bold); | |
1965 int bg = color2index(&cellbg, FALSE, &bold); | |
1966 | |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
1967 /* Use the "Terminal" highlighting for the default colors. */ |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
1968 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
|
1969 { |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
1970 if (fg == 0 && term_default_cterm_fg >= 0) |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
1971 fg = 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
|
1972 if (bg == 0 && term_default_cterm_bg >= 0) |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
1973 bg = term_default_cterm_bg + 1; |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
1974 } |
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
1975 |
12502 | 1976 /* with 8 colors set the bold attribute to get a bright foreground */ |
1977 if (bold == TRUE) | |
1978 attr |= HL_BOLD; | |
1979 return get_cterm_attr_idx(attr, fg, bg); | |
1980 } | |
1981 return 0; | |
1982 } | |
1983 | |
1984 static int | |
1985 handle_damage(VTermRect rect, void *user) | |
1986 { | |
1987 term_T *term = (term_T *)user; | |
1988 | |
1989 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row); | |
1990 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row); | |
1991 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
1992 return 1; | |
1993 } | |
1994 | |
1995 static int | |
1996 handle_moverect(VTermRect dest, VTermRect src, void *user) | |
1997 { | |
1998 term_T *term = (term_T *)user; | |
1999 | |
2000 /* Scrolling up is done much more efficiently by deleting lines instead of | |
2001 * redrawing the text. */ | |
2002 if (dest.start_col == src.start_col | |
2003 && dest.end_col == src.end_col | |
2004 && dest.start_row < src.start_row) | |
2005 { | |
2006 win_T *wp; | |
2007 VTermColor fg, bg; | |
2008 VTermScreenCellAttrs attr; | |
2009 int clear_attr; | |
2010 | |
2011 /* Set the color to clear lines with. */ | |
2012 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), | |
2013 &fg, &bg); | |
2014 vim_memset(&attr, 0, sizeof(attr)); | |
2015 clear_attr = cell2attr(attr, fg, bg); | |
2016 | |
2017 FOR_ALL_WINDOWS(wp) | |
2018 { | |
2019 if (wp->w_buffer == term->tl_buffer) | |
2020 win_del_lines(wp, dest.start_row, | |
2021 src.start_row - dest.start_row, FALSE, FALSE, | |
2022 clear_attr); | |
2023 } | |
2024 } | |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2025 |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2026 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
|
2027 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row); |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2028 |
12502 | 2029 redraw_buf_later(term->tl_buffer, NOT_VALID); |
2030 return 1; | |
2031 } | |
2032 | |
2033 static int | |
2034 handle_movecursor( | |
2035 VTermPos pos, | |
2036 VTermPos oldpos UNUSED, | |
2037 int visible, | |
2038 void *user) | |
2039 { | |
2040 term_T *term = (term_T *)user; | |
2041 win_T *wp; | |
2042 | |
2043 term->tl_cursor_pos = pos; | |
2044 term->tl_cursor_visible = visible; | |
2045 | |
2046 FOR_ALL_WINDOWS(wp) | |
2047 { | |
2048 if (wp->w_buffer == term->tl_buffer) | |
2049 position_cursor(wp, &pos); | |
2050 } | |
2051 if (term->tl_buffer == curbuf && !term->tl_normal_mode) | |
2052 { | |
2053 may_toggle_cursor(term); | |
2054 update_cursor(term, term->tl_cursor_visible); | |
2055 } | |
2056 | |
2057 return 1; | |
2058 } | |
2059 | |
2060 static int | |
2061 handle_settermprop( | |
2062 VTermProp prop, | |
2063 VTermValue *value, | |
2064 void *user) | |
2065 { | |
2066 term_T *term = (term_T *)user; | |
2067 | |
2068 switch (prop) | |
2069 { | |
2070 case VTERM_PROP_TITLE: | |
2071 vim_free(term->tl_title); | |
2072 /* a blank title isn't useful, make it empty, so that "running" is | |
2073 * displayed */ | |
2074 if (*skipwhite((char_u *)value->string) == NUL) | |
2075 term->tl_title = NULL; | |
2076 #ifdef WIN3264 | |
2077 else if (!enc_utf8 && enc_codepage > 0) | |
2078 { | |
2079 WCHAR *ret = NULL; | |
2080 int length = 0; | |
2081 | |
2082 MultiByteToWideChar_alloc(CP_UTF8, 0, | |
2083 (char*)value->string, (int)STRLEN(value->string), | |
2084 &ret, &length); | |
2085 if (ret != NULL) | |
2086 { | |
2087 WideCharToMultiByte_alloc(enc_codepage, 0, | |
2088 ret, length, (char**)&term->tl_title, | |
2089 &length, 0, 0); | |
2090 vim_free(ret); | |
2091 } | |
2092 } | |
2093 #endif | |
2094 else | |
2095 term->tl_title = vim_strsave((char_u *)value->string); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
2096 VIM_CLEAR(term->tl_status_text); |
12502 | 2097 if (term == curbuf->b_term) |
2098 maketitle(); | |
2099 break; | |
2100 | |
2101 case VTERM_PROP_CURSORVISIBLE: | |
2102 term->tl_cursor_visible = value->boolean; | |
2103 may_toggle_cursor(term); | |
2104 out_flush(); | |
2105 break; | |
2106 | |
2107 case VTERM_PROP_CURSORBLINK: | |
2108 term->tl_cursor_blink = value->boolean; | |
2109 may_set_cursor_props(term); | |
2110 break; | |
2111 | |
2112 case VTERM_PROP_CURSORSHAPE: | |
2113 term->tl_cursor_shape = value->number; | |
2114 may_set_cursor_props(term); | |
2115 break; | |
2116 | |
2117 case VTERM_PROP_CURSORCOLOR: | |
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
|
2118 if (desired_cursor_color == term->tl_cursor_color) |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2119 desired_cursor_color = (char_u *)""; |
12502 | 2120 vim_free(term->tl_cursor_color); |
2121 if (*value->string == NUL) | |
2122 term->tl_cursor_color = NULL; | |
2123 else | |
2124 term->tl_cursor_color = vim_strsave((char_u *)value->string); | |
2125 may_set_cursor_props(term); | |
2126 break; | |
2127 | |
2128 case VTERM_PROP_ALTSCREEN: | |
2129 /* TODO: do anything else? */ | |
2130 term->tl_using_altscreen = value->boolean; | |
2131 break; | |
2132 | |
2133 default: | |
2134 break; | |
2135 } | |
2136 /* Always return 1, otherwise vterm doesn't store the value internally. */ | |
2137 return 1; | |
2138 } | |
2139 | |
2140 /* | |
2141 * The job running in the terminal resized the terminal. | |
2142 */ | |
2143 static int | |
2144 handle_resize(int rows, int cols, void *user) | |
2145 { | |
2146 term_T *term = (term_T *)user; | |
2147 win_T *wp; | |
2148 | |
2149 term->tl_rows = rows; | |
2150 term->tl_cols = cols; | |
2151 if (term->tl_vterm_size_changed) | |
2152 /* Size was set by vterm_set_size(), don't set the window size. */ | |
2153 term->tl_vterm_size_changed = FALSE; | |
2154 else | |
2155 { | |
2156 FOR_ALL_WINDOWS(wp) | |
2157 { | |
2158 if (wp->w_buffer == term->tl_buffer) | |
2159 { | |
2160 win_setheight_win(rows, wp); | |
2161 win_setwidth_win(cols, wp); | |
2162 } | |
2163 } | |
2164 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
2165 } | |
2166 return 1; | |
2167 } | |
2168 | |
2169 /* | |
2170 * Handle a line that is pushed off the top of the screen. | |
2171 */ | |
2172 static int | |
2173 handle_pushline(int cols, const VTermScreenCell *cells, void *user) | |
2174 { | |
2175 term_T *term = (term_T *)user; | |
2176 | |
2177 /* TODO: Limit the number of lines that are stored. */ | |
2178 if (ga_grow(&term->tl_scrollback, 1) == OK) | |
2179 { | |
2180 cellattr_T *p = NULL; | |
2181 int len = 0; | |
2182 int i; | |
2183 int c; | |
2184 int col; | |
2185 sb_line_T *line; | |
2186 garray_T ga; | |
2187 cellattr_T fill_attr = term->tl_default_color; | |
2188 | |
2189 /* do not store empty cells at the end */ | |
2190 for (i = 0; i < cols; ++i) | |
2191 if (cells[i].chars[0] != 0) | |
2192 len = i + 1; | |
2193 else | |
2194 cell2cellattr(&cells[i], &fill_attr); | |
2195 | |
2196 ga_init2(&ga, 1, 100); | |
2197 if (len > 0) | |
2198 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len); | |
2199 if (p != NULL) | |
2200 { | |
2201 for (col = 0; col < len; col += cells[col].width) | |
2202 { | |
2203 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | |
2204 { | |
2205 ga.ga_len = 0; | |
2206 break; | |
2207 } | |
2208 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i) | |
2209 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
2210 (char_u *)ga.ga_data + ga.ga_len); | |
2211 cell2cellattr(&cells[col], &p[col]); | |
2212 } | |
2213 } | |
2214 if (ga_grow(&ga, 1) == FAIL) | |
2215 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
2216 else | |
2217 { | |
2218 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
2219 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
2220 } | |
2221 ga_clear(&ga); | |
2222 | |
2223 line = (sb_line_T *)term->tl_scrollback.ga_data | |
2224 + term->tl_scrollback.ga_len; | |
2225 line->sb_cols = len; | |
2226 line->sb_cells = p; | |
2227 line->sb_fill_attr = fill_attr; | |
2228 ++term->tl_scrollback.ga_len; | |
2229 ++term->tl_scrollback_scrolled; | |
2230 } | |
2231 return 0; /* ignored */ | |
2232 } | |
2233 | |
2234 static VTermScreenCallbacks screen_callbacks = { | |
2235 handle_damage, /* damage */ | |
2236 handle_moverect, /* moverect */ | |
2237 handle_movecursor, /* movecursor */ | |
2238 handle_settermprop, /* settermprop */ | |
2239 NULL, /* bell */ | |
2240 handle_resize, /* resize */ | |
2241 handle_pushline, /* sb_pushline */ | |
2242 NULL /* sb_popline */ | |
2243 }; | |
2244 | |
2245 /* | |
2246 * Called when a channel has been closed. | |
2247 * If this was a channel for a terminal window then finish it up. | |
2248 */ | |
2249 void | |
2250 term_channel_closed(channel_T *ch) | |
2251 { | |
2252 term_T *term; | |
2253 int did_one = FALSE; | |
2254 | |
2255 for (term = first_term; term != NULL; term = term->tl_next) | |
2256 if (term->tl_job == ch->ch_job) | |
2257 { | |
2258 term->tl_channel_closed = TRUE; | |
2259 did_one = TRUE; | |
2260 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
2261 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
|
2262 VIM_CLEAR(term->tl_status_text); |
12502 | 2263 |
2264 /* Unless in Terminal-Normal mode: clear the vterm. */ | |
2265 if (!term->tl_normal_mode) | |
2266 { | |
2267 int fnum = term->tl_buffer->b_fnum; | |
2268 | |
2269 cleanup_vterm(term); | |
2270 | |
2271 if (term->tl_finish == 'c') | |
2272 { | |
12903
411a30bd7e8a
patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
2273 aco_save_T aco; |
411a30bd7e8a
patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
2274 |
12502 | 2275 /* ++close or term_finish == "close" */ |
2276 ch_log(NULL, "terminal job finished, closing window"); | |
12903
411a30bd7e8a
patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
2277 aucmd_prepbuf(&aco, term->tl_buffer); |
12502 | 2278 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE); |
12903
411a30bd7e8a
patch 8.0.1328: trouble when using ":term ++close" with autocmd
Christian Brabandt <cb@256bit.org>
parents:
12893
diff
changeset
|
2279 aucmd_restbuf(&aco); |
12502 | 2280 break; |
2281 } | |
2282 if (term->tl_finish == 'o' && term->tl_buffer->b_nwindows == 0) | |
2283 { | |
2284 char buf[50]; | |
2285 | |
2286 /* TODO: use term_opencmd */ | |
2287 ch_log(NULL, "terminal job finished, opening window"); | |
2288 vim_snprintf(buf, sizeof(buf), | |
2289 term->tl_opencmd == NULL | |
2290 ? "botright sbuf %d" | |
2291 : (char *)term->tl_opencmd, fnum); | |
2292 do_cmdline_cmd((char_u *)buf); | |
2293 } | |
2294 else | |
2295 ch_log(NULL, "terminal job finished"); | |
2296 } | |
2297 | |
2298 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID); | |
2299 } | |
2300 if (did_one) | |
2301 { | |
2302 redraw_statuslines(); | |
2303 | |
2304 /* Need to break out of vgetc(). */ | |
2305 ins_char_typebuf(K_IGNORE); | |
2306 typebuf_was_filled = TRUE; | |
2307 | |
2308 term = curbuf->b_term; | |
2309 if (term != NULL) | |
2310 { | |
2311 if (term->tl_job == ch->ch_job) | |
2312 maketitle(); | |
2313 update_cursor(term, term->tl_cursor_visible); | |
2314 } | |
2315 } | |
2316 } | |
2317 | |
2318 /* | |
2319 * Called to update a window that contains an active terminal. | |
2320 * Returns FAIL when there is no terminal running in this window or in | |
2321 * Terminal-Normal mode. | |
2322 */ | |
2323 int | |
2324 term_update_window(win_T *wp) | |
2325 { | |
2326 term_T *term = wp->w_buffer->b_term; | |
2327 VTerm *vterm; | |
2328 VTermScreen *screen; | |
2329 VTermState *state; | |
2330 VTermPos pos; | |
2331 | |
2332 if (term == NULL || term->tl_vterm == NULL || term->tl_normal_mode) | |
2333 return FAIL; | |
2334 | |
2335 vterm = term->tl_vterm; | |
2336 screen = vterm_obtain_screen(vterm); | |
2337 state = vterm_obtain_state(vterm); | |
2338 | |
12598
97a2f34962ee
patch 8.0.1177: in a terminal window the popup menu is not cleared
Christian Brabandt <cb@256bit.org>
parents:
12590
diff
changeset
|
2339 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
|
2340 { |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
2341 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
|
2342 term->tl_dirty_row_end = MAX_ROW; |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
2343 } |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
2344 |
12502 | 2345 /* |
2346 * If the window was resized a redraw will be triggered and we get here. | |
2347 * Adjust the size of the vterm unless 'termsize' specifies a fixed size. | |
2348 */ | |
2349 if ((!term->tl_rows_fixed && term->tl_rows != wp->w_height) | |
2350 || (!term->tl_cols_fixed && term->tl_cols != wp->w_width)) | |
2351 { | |
2352 int rows = term->tl_rows_fixed ? term->tl_rows : wp->w_height; | |
2353 int cols = term->tl_cols_fixed ? term->tl_cols : wp->w_width; | |
2354 win_T *twp; | |
2355 | |
2356 FOR_ALL_WINDOWS(twp) | |
2357 { | |
2358 /* When more than one window shows the same terminal, use the | |
2359 * smallest size. */ | |
2360 if (twp->w_buffer == term->tl_buffer) | |
2361 { | |
2362 if (!term->tl_rows_fixed && rows > twp->w_height) | |
2363 rows = twp->w_height; | |
2364 if (!term->tl_cols_fixed && cols > twp->w_width) | |
2365 cols = twp->w_width; | |
2366 } | |
2367 } | |
2368 | |
2369 term->tl_vterm_size_changed = TRUE; | |
2370 vterm_set_size(vterm, rows, cols); | |
2371 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines", | |
2372 rows); | |
2373 term_report_winsize(term, rows, cols); | |
2374 } | |
2375 | |
2376 /* The cursor may have been moved when resizing. */ | |
2377 vterm_state_get_cursorpos(state, &pos); | |
2378 position_cursor(wp, &pos); | |
2379 | |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2380 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
|
2381 && pos.row < wp->w_height; ++pos.row) |
12502 | 2382 { |
2383 int off = screen_get_current_line_off(); | |
2384 int max_col = MIN(wp->w_width, term->tl_cols); | |
2385 | |
2386 if (pos.row < term->tl_rows) | |
2387 { | |
2388 for (pos.col = 0; pos.col < max_col; ) | |
2389 { | |
2390 VTermScreenCell cell; | |
2391 int c; | |
2392 | |
2393 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
2394 vim_memset(&cell, 0, sizeof(cell)); | |
2395 | |
2396 c = cell.chars[0]; | |
2397 if (c == NUL) | |
2398 { | |
2399 ScreenLines[off] = ' '; | |
2400 if (enc_utf8) | |
2401 ScreenLinesUC[off] = NUL; | |
2402 } | |
2403 else | |
2404 { | |
2405 if (enc_utf8) | |
2406 { | |
12650
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2407 int i; |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2408 |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2409 /* composing chars */ |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2410 for (i = 0; i < Screen_mco |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2411 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i) |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2412 { |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2413 ScreenLinesC[i][off] = cell.chars[i + 1]; |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2414 if (cell.chars[i + 1] == 0) |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2415 break; |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2416 } |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2417 if (c >= 0x80 || (Screen_mco > 0 |
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
2418 && ScreenLinesC[0][off] != 0)) |
12502 | 2419 { |
2420 ScreenLines[off] = ' '; | |
2421 ScreenLinesUC[off] = c; | |
2422 } | |
2423 else | |
2424 { | |
2425 ScreenLines[off] = c; | |
2426 ScreenLinesUC[off] = NUL; | |
2427 } | |
2428 } | |
2429 #ifdef WIN3264 | |
2430 else if (has_mbyte && c >= 0x80) | |
2431 { | |
2432 char_u mb[MB_MAXBYTES+1]; | |
2433 WCHAR wc = c; | |
2434 | |
2435 if (WideCharToMultiByte(GetACP(), 0, &wc, 1, | |
2436 (char*)mb, 2, 0, 0) > 1) | |
2437 { | |
2438 ScreenLines[off] = mb[0]; | |
2439 ScreenLines[off + 1] = mb[1]; | |
2440 cell.width = mb_ptr2cells(mb); | |
2441 } | |
2442 else | |
2443 ScreenLines[off] = c; | |
2444 } | |
2445 #endif | |
2446 else | |
2447 ScreenLines[off] = c; | |
2448 } | |
2449 ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg); | |
2450 | |
2451 ++pos.col; | |
2452 ++off; | |
2453 if (cell.width == 2) | |
2454 { | |
2455 if (enc_utf8) | |
2456 ScreenLinesUC[off] = NUL; | |
2457 | |
2458 /* don't set the second byte to NUL for a DBCS encoding, it | |
2459 * has been set above */ | |
2460 if (enc_utf8 || !has_mbyte) | |
2461 ScreenLines[off] = NUL; | |
2462 | |
2463 ++pos.col; | |
2464 ++off; | |
2465 } | |
2466 } | |
2467 } | |
2468 else | |
2469 pos.col = 0; | |
2470 | |
13292
c42fe898b578
patch 8.0.1520: cursor in wrong line when using a WinBar in Terminal window
Christian Brabandt <cb@256bit.org>
parents:
13282
diff
changeset
|
2471 screen_line(wp->w_winrow + pos.row + winbar_height(wp), |
c42fe898b578
patch 8.0.1520: cursor in wrong line when using a WinBar in Terminal window
Christian Brabandt <cb@256bit.org>
parents:
13282
diff
changeset
|
2472 wp->w_wincol, pos.col, wp->w_width, FALSE); |
12502 | 2473 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2474 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
|
2475 term->tl_dirty_row_end = 0; |
12502 | 2476 |
2477 return OK; | |
2478 } | |
2479 | |
2480 /* | |
2481 * Return TRUE if "wp" is a terminal window where the job has finished. | |
2482 */ | |
2483 int | |
2484 term_is_finished(buf_T *buf) | |
2485 { | |
2486 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL; | |
2487 } | |
2488 | |
2489 /* | |
2490 * Return TRUE if "wp" is a terminal window where the job has finished or we | |
2491 * are in Terminal-Normal mode, thus we show the buffer contents. | |
2492 */ | |
2493 int | |
2494 term_show_buffer(buf_T *buf) | |
2495 { | |
2496 term_T *term = buf->b_term; | |
2497 | |
2498 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode); | |
2499 } | |
2500 | |
2501 /* | |
2502 * The current buffer is going to be changed. If there is terminal | |
2503 * highlighting remove it now. | |
2504 */ | |
2505 void | |
2506 term_change_in_curbuf(void) | |
2507 { | |
2508 term_T *term = curbuf->b_term; | |
2509 | |
2510 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) | |
2511 { | |
2512 free_scrollback(term); | |
2513 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
2514 | |
2515 /* The buffer is now like a normal buffer, it cannot be easily | |
2516 * abandoned when changed. */ | |
2517 set_string_option_direct((char_u *)"buftype", -1, | |
2518 (char_u *)"", OPT_FREE|OPT_LOCAL, 0); | |
2519 } | |
2520 } | |
2521 | |
2522 /* | |
2523 * Get the screen attribute for a position in the buffer. | |
2524 * Use a negative "col" to get the filler background color. | |
2525 */ | |
2526 int | |
2527 term_get_attr(buf_T *buf, linenr_T lnum, int col) | |
2528 { | |
2529 term_T *term = buf->b_term; | |
2530 sb_line_T *line; | |
2531 cellattr_T *cellattr; | |
2532 | |
2533 if (lnum > term->tl_scrollback.ga_len) | |
2534 cellattr = &term->tl_default_color; | |
2535 else | |
2536 { | |
2537 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1; | |
2538 if (col < 0 || col >= line->sb_cols) | |
2539 cellattr = &line->sb_fill_attr; | |
2540 else | |
2541 cellattr = line->sb_cells + col; | |
2542 } | |
2543 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); | |
2544 } | |
2545 | |
2546 static VTermColor ansi_table[16] = { | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2547 { 0, 0, 0, 1}, /* black */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2548 {224, 0, 0, 2}, /* dark red */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2549 { 0, 224, 0, 3}, /* dark green */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2550 {224, 224, 0, 4}, /* dark yellow / brown */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2551 { 0, 0, 224, 5}, /* dark blue */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2552 {224, 0, 224, 6}, /* dark magenta */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2553 { 0, 224, 224, 7}, /* dark cyan */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2554 {224, 224, 224, 8}, /* light grey */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2555 |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2556 {128, 128, 128, 9}, /* dark grey */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2557 {255, 64, 64, 10}, /* light red */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2558 { 64, 255, 64, 11}, /* light green */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2559 {255, 255, 64, 12}, /* yellow */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2560 { 64, 64, 255, 13}, /* light blue */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2561 {255, 64, 255, 14}, /* light magenta */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2562 { 64, 255, 255, 15}, /* light cyan */ |
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2563 {255, 255, 255, 16}, /* white */ |
12502 | 2564 }; |
2565 | |
2566 static int cube_value[] = { | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2567 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF |
12502 | 2568 }; |
2569 | |
2570 static int grey_ramp[] = { | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2571 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76, |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2572 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE |
12502 | 2573 }; |
2574 | |
2575 /* | |
2576 * 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
|
2577 * This is compatible with xterm. |
12502 | 2578 */ |
2579 static void | |
2580 cterm_color2rgb(int nr, VTermColor *rgb) | |
2581 { | |
2582 int idx; | |
2583 | |
2584 if (nr < 16) | |
2585 { | |
2586 *rgb = ansi_table[nr]; | |
2587 } | |
2588 else if (nr < 232) | |
2589 { | |
2590 /* 216 color cube */ | |
2591 idx = nr - 16; | |
2592 rgb->blue = cube_value[idx % 6]; | |
2593 rgb->green = cube_value[idx / 6 % 6]; | |
2594 rgb->red = cube_value[idx / 36 % 6]; | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2595 rgb->ansi_index = VTERM_ANSI_INDEX_NONE; |
12502 | 2596 } |
2597 else if (nr < 256) | |
2598 { | |
2599 /* 24 grey scale ramp */ | |
2600 idx = nr - 232; | |
2601 rgb->blue = grey_ramp[idx]; | |
2602 rgb->green = grey_ramp[idx]; | |
2603 rgb->red = grey_ramp[idx]; | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2604 rgb->ansi_index = VTERM_ANSI_INDEX_NONE; |
12502 | 2605 } |
2606 } | |
2607 | |
2608 /* | |
2609 * Create a new vterm and initialize it. | |
2610 */ | |
2611 static void | |
2612 create_vterm(term_T *term, int rows, int cols) | |
2613 { | |
2614 VTerm *vterm; | |
2615 VTermScreen *screen; | |
2616 VTermValue value; | |
2617 VTermColor *fg, *bg; | |
2618 int fgval, bgval; | |
2619 int id; | |
2620 | |
2621 vterm = vterm_new(rows, cols); | |
2622 term->tl_vterm = vterm; | |
2623 screen = vterm_obtain_screen(vterm); | |
2624 vterm_screen_set_callbacks(screen, &screen_callbacks, term); | |
2625 /* TODO: depends on 'encoding'. */ | |
2626 vterm_set_utf8(vterm, 1); | |
2627 | |
2628 vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs)); | |
2629 term->tl_default_color.width = 1; | |
2630 fg = &term->tl_default_color.fg; | |
2631 bg = &term->tl_default_color.bg; | |
2632 | |
2633 /* Vterm uses a default black background. Set it to white when | |
2634 * 'background' is "light". */ | |
2635 if (*p_bg == 'l') | |
2636 { | |
2637 fgval = 0; | |
2638 bgval = 255; | |
2639 } | |
2640 else | |
2641 { | |
2642 fgval = 255; | |
2643 bgval = 0; | |
2644 } | |
2645 fg->red = fg->green = fg->blue = fgval; | |
2646 bg->red = bg->green = bg->blue = bgval; | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2647 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT; |
12502 | 2648 |
2649 /* The "Terminal" highlight group overrules the defaults. */ | |
2650 id = syn_name2id((char_u *)"Terminal"); | |
2651 | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2652 /* Use the actual color for the GUI and when 'termguicolors' is set. */ |
12502 | 2653 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
2654 if (0 | |
2655 # ifdef FEAT_GUI | |
2656 || gui.in_use | |
2657 # endif | |
2658 # ifdef FEAT_TERMGUICOLORS | |
2659 || p_tgc | |
2660 # endif | |
2661 ) | |
2662 { | |
2663 guicolor_T fg_rgb = INVALCOLOR; | |
2664 guicolor_T bg_rgb = INVALCOLOR; | |
2665 | |
2666 if (id != 0) | |
2667 syn_id2colors(id, &fg_rgb, &bg_rgb); | |
2668 | |
2669 # ifdef FEAT_GUI | |
2670 if (gui.in_use) | |
2671 { | |
2672 if (fg_rgb == INVALCOLOR) | |
2673 fg_rgb = gui.norm_pixel; | |
2674 if (bg_rgb == INVALCOLOR) | |
2675 bg_rgb = gui.back_pixel; | |
2676 } | |
2677 # ifdef FEAT_TERMGUICOLORS | |
2678 else | |
2679 # endif | |
2680 # endif | |
2681 # ifdef FEAT_TERMGUICOLORS | |
2682 { | |
2683 if (fg_rgb == INVALCOLOR) | |
2684 fg_rgb = cterm_normal_fg_gui_color; | |
2685 if (bg_rgb == INVALCOLOR) | |
2686 bg_rgb = cterm_normal_bg_gui_color; | |
2687 } | |
2688 # endif | |
2689 if (fg_rgb != INVALCOLOR) | |
2690 { | |
2691 long_u rgb = GUI_MCH_GET_RGB(fg_rgb); | |
2692 | |
2693 fg->red = (unsigned)(rgb >> 16); | |
2694 fg->green = (unsigned)(rgb >> 8) & 255; | |
2695 fg->blue = (unsigned)rgb & 255; | |
2696 } | |
2697 if (bg_rgb != INVALCOLOR) | |
2698 { | |
2699 long_u rgb = GUI_MCH_GET_RGB(bg_rgb); | |
2700 | |
2701 bg->red = (unsigned)(rgb >> 16); | |
2702 bg->green = (unsigned)(rgb >> 8) & 255; | |
2703 bg->blue = (unsigned)rgb & 255; | |
2704 } | |
2705 } | |
2706 else | |
2707 #endif | |
2708 if (id != 0 && t_colors >= 16) | |
2709 { | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2710 if (term_default_cterm_fg >= 0) |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2711 cterm_color2rgb(term_default_cterm_fg, fg); |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2712 if (term_default_cterm_bg >= 0) |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2713 cterm_color2rgb(term_default_cterm_bg, bg); |
12502 | 2714 } |
2715 else | |
2716 { | |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
2717 #if defined(WIN3264) && !defined(FEAT_GUI_W32) |
12502 | 2718 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
|
2719 #endif |
12502 | 2720 |
2721 /* In an MS-Windows console we know the normal colors. */ | |
2722 if (cterm_normal_fg_color > 0) | |
2723 { | |
2724 cterm_color2rgb(cterm_normal_fg_color - 1, fg); | |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
2725 # if defined(WIN3264) && !defined(FEAT_GUI_W32) |
12502 | 2726 tmp = fg->red; |
2727 fg->red = fg->blue; | |
2728 fg->blue = 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
|
2729 # endif |
12502 | 2730 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
2731 # 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
|
2732 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
2733 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
|
2734 # 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
|
2735 |
12502 | 2736 if (cterm_normal_bg_color > 0) |
2737 { | |
2738 cterm_color2rgb(cterm_normal_bg_color - 1, bg); | |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
2739 # if defined(WIN3264) && !defined(FEAT_GUI_W32) |
12502 | 2740 tmp = bg->red; |
2741 bg->red = bg->blue; | |
2742 bg->blue = 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
|
2743 # endif |
12502 | 2744 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
2745 # 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
|
2746 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
2747 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
|
2748 # endif |
12502 | 2749 } |
2750 | |
2751 vterm_state_set_default_colors(vterm_obtain_state(vterm), fg, bg); | |
2752 | |
2753 /* Required to initialize most things. */ | |
2754 vterm_screen_reset(screen, 1 /* hard */); | |
2755 | |
2756 /* Allow using alternate screen. */ | |
2757 vterm_screen_enable_altscreen(screen, 1); | |
2758 | |
2759 /* For unix do not use a blinking cursor. In an xterm this causes the | |
2760 * cursor to blink if it's blinking in the xterm. | |
2761 * For Windows we respect the system wide setting. */ | |
2762 #ifdef WIN3264 | |
2763 if (GetCaretBlinkTime() == INFINITE) | |
2764 value.boolean = 0; | |
2765 else | |
2766 value.boolean = 1; | |
2767 #else | |
2768 value.boolean = 0; | |
2769 #endif | |
2770 vterm_state_set_termprop(vterm_obtain_state(vterm), | |
2771 VTERM_PROP_CURSORBLINK, &value); | |
2772 } | |
2773 | |
2774 /* | |
2775 * Return the text to show for the buffer name and status. | |
2776 */ | |
2777 char_u * | |
2778 term_get_status_text(term_T *term) | |
2779 { | |
2780 if (term->tl_status_text == NULL) | |
2781 { | |
2782 char_u *txt; | |
2783 size_t len; | |
2784 | |
2785 if (term->tl_normal_mode) | |
2786 { | |
2787 if (term_job_running(term)) | |
2788 txt = (char_u *)_("Terminal"); | |
2789 else | |
2790 txt = (char_u *)_("Terminal-finished"); | |
2791 } | |
2792 else if (term->tl_title != NULL) | |
2793 txt = term->tl_title; | |
2794 else if (term_none_open(term)) | |
2795 txt = (char_u *)_("active"); | |
2796 else if (term_job_running(term)) | |
2797 txt = (char_u *)_("running"); | |
2798 else | |
2799 txt = (char_u *)_("finished"); | |
2800 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt); | |
2801 term->tl_status_text = alloc((int)len); | |
2802 if (term->tl_status_text != NULL) | |
2803 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]", | |
2804 term->tl_buffer->b_fname, txt); | |
2805 } | |
2806 return term->tl_status_text; | |
2807 } | |
2808 | |
2809 /* | |
2810 * Mark references in jobs of terminals. | |
2811 */ | |
2812 int | |
2813 set_ref_in_term(int copyID) | |
2814 { | |
2815 int abort = FALSE; | |
2816 term_T *term; | |
2817 typval_T tv; | |
2818 | |
2819 for (term = first_term; term != NULL; term = term->tl_next) | |
2820 if (term->tl_job != NULL) | |
2821 { | |
2822 tv.v_type = VAR_JOB; | |
2823 tv.vval.v_job = term->tl_job; | |
2824 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); | |
2825 } | |
2826 return abort; | |
2827 } | |
2828 | |
2829 /* | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2830 * Cache "Terminal" highlight group colors. |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2831 */ |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2832 void |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2833 set_terminal_default_colors(int cterm_fg, int cterm_bg) |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2834 { |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2835 term_default_cterm_fg = 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
|
2836 term_default_cterm_bg = cterm_bg - 1; |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2837 } |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2838 |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2839 /* |
12502 | 2840 * Get the buffer from the first argument in "argvars". |
2841 * Returns NULL when the buffer is not for a terminal window. | |
2842 */ | |
2843 static buf_T * | |
2844 term_get_buf(typval_T *argvars) | |
2845 { | |
2846 buf_T *buf; | |
2847 | |
2848 (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */ | |
2849 ++emsg_off; | |
2850 buf = get_buf_tv(&argvars[0], FALSE); | |
2851 --emsg_off; | |
2852 if (buf == NULL || buf->b_term == NULL) | |
2853 return NULL; | |
2854 return buf; | |
2855 } | |
2856 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2857 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2858 same_color(VTermColor *a, VTermColor *b) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2859 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2860 return a->red == b->red |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2861 && a->green == b->green |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2862 && a->blue == b->blue |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2863 && a->ansi_index == b->ansi_index; |
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 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2867 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
|
2868 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2869 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
|
2870 (int)color->red, (int)color->green, (int)color->blue, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2871 (int)color->ansi_index); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2872 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2873 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2874 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2875 * "term_dumpwrite(buf, filename, max-height, max-width)" function |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2876 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2877 * 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
|
2878 * |{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
|
2879 * {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
|
2880 * 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
|
2881 * skipped. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2882 * {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
|
2883 * 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
|
2884 * {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
|
2885 * {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
|
2886 * {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
|
2887 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2888 * 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
|
2889 * |{characters} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2890 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2891 * 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
|
2892 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2893 * 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
|
2894 * @{count} |
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 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2897 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
|
2898 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2899 buf_T *buf = term_get_buf(argvars); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2900 term_T *term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2901 char_u *fname; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2902 int max_height = 99999; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2903 int max_width = 99999; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2904 stat_T st; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2905 FILE *fd; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2906 VTermPos pos; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2907 VTermScreen *screen; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2908 VTermScreenCell prev_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2909 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2910 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
|
2911 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2912 if (buf == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2913 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2914 term = buf->b_term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2915 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2916 fname = get_tv_string_chk(&argvars[1]); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2917 if (fname == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2918 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2919 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
|
2920 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2921 EMSG2(_("E953: File exists: %s"), fname); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2922 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2923 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2924 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2925 if (argvars[2].v_type != VAR_UNKNOWN) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2926 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2927 max_height = get_tv_number(&argvars[2]); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2928 if (argvars[3].v_type != VAR_UNKNOWN) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2929 max_width = get_tv_number(&argvars[3]); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2930 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2931 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2932 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
|
2933 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2934 EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2935 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2936 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2937 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2938 vim_memset(&prev_cell, 0, sizeof(prev_cell)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2939 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2940 screen = vterm_obtain_screen(term->tl_vterm); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2941 for (pos.row = 0; pos.row < max_height && pos.row < term->tl_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2942 ++pos.row) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2943 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2944 int repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2945 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2946 for (pos.col = 0; pos.col < max_width && pos.col < term->tl_cols; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2947 ++pos.col) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2948 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2949 VTermScreenCell cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2950 int same_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2951 int same_chars = TRUE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2952 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2953 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2954 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2955 vim_memset(&cell, 0, sizeof(cell)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2956 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2957 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
|
2958 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2959 if (cell.chars[i] != prev_cell.chars[i]) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2960 same_chars = FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2961 if (cell.chars[i] == NUL || prev_cell.chars[i] == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2962 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2963 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2964 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
|
2965 == vtermAttr2hl(prev_cell.attrs) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2966 && same_color(&cell.fg, &prev_cell.fg) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2967 && same_color(&cell.bg, &prev_cell.bg); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2968 if (same_chars && 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
|
2969 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2970 ++repeat; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2971 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2972 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2973 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2974 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2975 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2976 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2977 repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2978 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2979 fputs("|", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2980 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2981 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
|
2982 fputs(" ", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2983 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2984 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2985 char_u charbuf[10]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2986 int len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2987 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2988 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
|
2989 && 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
|
2990 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2991 len = utf_char2bytes(cell.chars[0], charbuf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2992 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
|
2993 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2994 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2995 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2996 /* When only the characters differ we don't write anything, the |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2997 * following "|", "@" or NL will indicate using the same |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2998 * attributes. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2999 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
|
3000 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3001 if (cell.width == 2) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3002 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3003 fputs("*", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3004 ++pos.col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3005 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3006 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3007 fputs("+", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3008 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3009 if (same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3010 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3011 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3012 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3013 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3014 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3015 fprintf(fd, "%d", vtermAttr2hl(cell.attrs)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3016 if (same_color(&cell.fg, &prev_cell.fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3017 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3018 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3019 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3020 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3021 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
|
3022 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3023 if (same_color(&cell.bg, &prev_cell.bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3024 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3025 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3026 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3027 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3028 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
|
3029 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3030 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3031 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3032 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3033 prev_cell = cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3034 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3035 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3036 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3037 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3038 fputs("\n", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3039 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3040 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3041 fclose(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3042 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3043 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3044 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3045 * 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
|
3046 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3047 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3048 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
|
3049 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3050 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
|
3051 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3052 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3053 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3054 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
|
3055 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3056 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
|
3057 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3058 *(((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
|
3059 ++gap->ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3060 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3061 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3062 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3063 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3064 * 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
|
3065 * 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
|
3066 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3067 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3068 read_dump_file(FILE *fd) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3069 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3070 int c; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3071 garray_T ga_text; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3072 garray_T ga_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3073 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
|
3074 int attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3075 cellattr_T cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3076 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
|
3077 int max_cells = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3078 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3079 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
|
3080 ga_init2(&ga_cell, sizeof(cellattr_T), 90); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3081 vim_memset(&cell, 0, sizeof(cell)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3082 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3083 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3084 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3085 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3086 if (c == EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3087 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3088 if (c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3089 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3090 /* End of a line: append it to the buffer. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3091 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
|
3092 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
|
3093 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
|
3094 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3095 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
|
3096 + 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
|
3097 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3098 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
|
3099 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
|
3100 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
|
3101 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
|
3102 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
|
3103 ++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
|
3104 ga_init(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3105 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3106 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
|
3107 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
|
3108 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
|
3109 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3110 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3111 ga_clear(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3112 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
|
3113 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3114 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3115 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3116 else if (c == '|') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3117 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3118 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
|
3119 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3120 /* normal character(s) followed by "+", "*", "|", "@" or NL */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3121 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3122 if (c != EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3123 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
|
3124 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3125 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3126 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3127 if (c == '+' || c == '*' || c == '|' || c == '@' |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3128 || c == EOF || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3129 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3130 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
|
3131 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3132 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3133 /* save the character for repeating it */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3134 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3135 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
|
3136 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
|
3137 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
|
3138 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3139 if (c == '@' || c == '|' || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3140 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3141 /* use all attributes from previous cell */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3142 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3143 else if (c == '+' || c == '*') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3144 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3145 int is_bg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3146 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3147 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
|
3148 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3149 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3150 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3151 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3152 /* use same attr as previous cell */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3153 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3154 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3155 else if (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3156 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3157 /* get the decimal attribute */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3158 attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3159 while (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3160 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3161 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
|
3162 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3163 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3164 hl2vtermAttr(attr, &cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3165 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3166 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3167 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
|
3168 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3169 /* is_bg == 0: fg, is_bg == 1: bg */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3170 for (is_bg = 0; is_bg <= 1; ++is_bg) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3171 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3172 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3173 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3174 /* use same color as previous cell */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3175 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3176 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3177 else if (c == '#') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3178 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3179 int red, green, blue, index = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3180 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3181 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3182 red = hex2nr(c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3183 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3184 red = (red << 4) + hex2nr(c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3185 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3186 green = hex2nr(c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3187 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3188 green = (green << 4) + hex2nr(c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3189 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3190 blue = hex2nr(c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3191 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3192 blue = (blue << 4) + hex2nr(c); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3193 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3194 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3195 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
|
3196 while (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3197 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3198 index = index * 10 + (c - '0'); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3199 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3200 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3201 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3202 if (is_bg) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3203 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3204 cell.bg.red = red; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3205 cell.bg.green = green; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3206 cell.bg.blue = blue; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3207 cell.bg.ansi_index = index; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3208 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3209 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3210 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3211 cell.fg.red = red; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3212 cell.fg.green = green; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3213 cell.fg.blue = blue; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3214 cell.fg.ansi_index = index; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3215 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3216 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3217 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3218 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
|
3219 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3220 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3221 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3222 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
|
3223 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3224 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
|
3225 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3226 else if (c == '@') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3227 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3228 if (prev_char == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3229 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
|
3230 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3231 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3232 int count = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3233 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3234 /* repeat previous character, get the count */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3235 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3236 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3237 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3238 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3239 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3240 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
|
3241 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3242 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3243 while (count-- > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3244 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3245 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
|
3246 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
|
3247 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3248 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3249 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3250 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3251 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3252 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
|
3253 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3254 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3255 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3256 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3257 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
|
3258 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3259 /* trailing characters after last NL */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3260 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
|
3261 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
|
3262 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
|
3263 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
|
3264 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3265 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3266 ga_clear(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3267 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3268 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3269 return max_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3270 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3271 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3272 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3273 * 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
|
3274 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3275 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3276 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
|
3277 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3278 jobopt_T opt; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3279 buf_T *buf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3280 char_u buf1[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3281 char_u buf2[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3282 char_u *fname1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
3283 char_u *fname2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3284 FILE *fd1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
3285 FILE *fd2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3286 char_u *textline = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3287 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3288 /* First open the files. If this fails bail out. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3289 fname1 = get_tv_string_buf_chk(&argvars[0], buf1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3290 if (do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3291 fname2 = get_tv_string_buf_chk(&argvars[1], buf2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3292 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
|
3293 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3294 EMSG(_(e_invarg)); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3295 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3296 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3297 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
|
3298 if (fd1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3299 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3300 EMSG2(_(e_notread), fname1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3301 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3302 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3303 if (do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3304 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3305 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
|
3306 if (fd2 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3307 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3308 fclose(fd1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3309 EMSG2(_(e_notread), fname2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3310 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3311 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3312 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3313 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3314 init_job_options(&opt); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3315 /* TODO: use the {options} argument */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3316 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3317 /* TODO: use the file name arguments for the buffer name */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3318 opt.jo_term_name = (char_u *)"dump diff"; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3319 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3320 buf = term_start(&argvars[0], &opt, TRUE, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3321 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
|
3322 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3323 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3324 linenr_T bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3325 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3326 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
|
3327 int width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3328 int width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3329 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3330 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
|
3331 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3332 /* read the files, fill the buffer with the diff */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3333 width = read_dump_file(fd1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3334 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3335 /* Delete the empty line that was in the empty buffer. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3336 ml_delete(1, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3337 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3338 /* For term_dumpload() we are done here. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3339 if (!do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3340 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3341 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3342 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
|
3343 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3344 textline = alloc(width + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3345 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3346 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3347 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
|
3348 textline[i] = '='; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3349 textline[width] = NUL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3350 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
|
3351 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3352 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
|
3353 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3354 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3355 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
|
3356 width2 = read_dump_file(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3357 if (width2 > width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3358 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3359 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3360 textline = alloc(width2 + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3361 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3362 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3363 width = width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3364 textline[width] = NUL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3365 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3366 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
|
3367 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3368 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
|
3369 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3370 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
|
3371 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3372 /* bottom part has fewer rows, fill with "-" */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3373 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
|
3374 textline[i] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3375 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3376 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3377 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3378 char_u *line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3379 char_u *line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3380 char_u *p1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3381 char_u *p2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3382 int col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3383 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
|
3384 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
|
3385 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
|
3386 ->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3387 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3388 /* Make a copy, getting the second line will invalidate it. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3389 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
|
3390 if (line1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3391 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3392 p1 = line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3393 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3394 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
|
3395 p2 = line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3396 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
|
3397 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3398 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
|
3399 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
|
3400 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3401 textline[col] = ' '; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3402 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3403 textline[col] = 'X'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3404 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
|
3405 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3406 if ((cellattr1 + col)->width |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3407 != (cellattr2 + col)->width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3408 textline[col] = 'w'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3409 else if (!same_color(&(cellattr1 + col)->fg, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3410 &(cellattr2 + col)->fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3411 textline[col] = 'f'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3412 else if (!same_color(&(cellattr1 + col)->bg, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3413 &(cellattr2 + col)->bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3414 textline[col] = 'b'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3415 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
|
3416 != vtermAttr2hl(((cellattr2 + col)->attrs))) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3417 textline[col] = 'a'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3418 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3419 p1 += len1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3420 p2 += len2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3421 /* TODO: handle different width */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3422 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3423 vim_free(line1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3424 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3425 while (col < width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3426 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3427 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
|
3428 textline[col] = '?'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3429 else if (*p1 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3430 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3431 textline[col] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3432 p2 += utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3433 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3434 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3435 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3436 textline[col] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3437 p1 += utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3438 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3439 ++col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3440 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3441 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3442 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
|
3443 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
|
3444 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
|
3445 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3446 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3447 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3448 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
|
3449 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3450 /* bottom part has more rows, fill with "+" */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3451 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
|
3452 textline[i] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3453 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
|
3454 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
|
3455 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
|
3456 ++lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3457 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3458 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3459 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3460 term->tl_cols = width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3461 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3462 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3463 theend: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3464 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3465 fclose(fd1); |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
3466 if (fd2 != NULL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3467 fclose(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3468 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3469 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3470 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3471 * 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
|
3472 * bottom files. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3473 * 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
|
3474 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3475 int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3476 term_swap_diff() |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3477 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3478 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
|
3479 linenr_T line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3480 linenr_T top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3481 linenr_T bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3482 linenr_T bot_start; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3483 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3484 char_u *p; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3485 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
|
3486 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3487 if (term == NULL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3488 || !term_is_finished(curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3489 || 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
|
3490 || 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
|
3491 return FAIL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3492 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3493 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
|
3494 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
|
3495 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
|
3496 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
|
3497 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
|
3498 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3499 /* move lines from top to above the bottom part */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3500 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
|
3501 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3502 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
|
3503 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3504 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3505 ml_append(bot_start, p, 0, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3506 ml_delete(1, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3507 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3508 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3509 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3510 /* move lines from bottom to the top */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3511 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
|
3512 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3513 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
|
3514 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3515 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3516 ml_delete(bot_start + lnum, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3517 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
|
3518 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3519 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3520 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3521 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
|
3522 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3523 /* rows counts are equal, can swap cell properties */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3524 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
|
3525 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3526 sb_line_T temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3527 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3528 temp = *(sb_line + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3529 *(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
|
3530 *(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
|
3531 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3532 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3533 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3534 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3535 size_t size = sizeof(sb_line_T) * 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
|
3536 sb_line_T *temp = (sb_line_T *)alloc((int)size); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3537 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3538 /* need to copy cell properties into temp memory */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3539 if (temp != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3540 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3541 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
|
3542 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
|
3543 temp + bot_start, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3544 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
|
3545 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
|
3546 temp + top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3547 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
|
3548 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
|
3549 + line_count - top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3550 temp, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3551 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
|
3552 vim_free(temp); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3553 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3554 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3555 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3556 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
|
3557 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
|
3558 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3559 update_screen(NOT_VALID); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3560 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3561 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3562 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3563 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3564 * "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
|
3565 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3566 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3567 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
|
3568 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3569 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
|
3570 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3571 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3572 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3573 * "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
|
3574 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3575 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3576 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
|
3577 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3578 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
|
3579 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3580 |
12502 | 3581 /* |
3582 * "term_getaltscreen(buf)" function | |
3583 */ | |
3584 void | |
3585 f_term_getaltscreen(typval_T *argvars, typval_T *rettv) | |
3586 { | |
3587 buf_T *buf = term_get_buf(argvars); | |
3588 | |
3589 if (buf == NULL) | |
3590 return; | |
3591 rettv->vval.v_number = buf->b_term->tl_using_altscreen; | |
3592 } | |
3593 | |
3594 /* | |
3595 * "term_getattr(attr, name)" function | |
3596 */ | |
3597 void | |
3598 f_term_getattr(typval_T *argvars, typval_T *rettv) | |
3599 { | |
3600 int attr; | |
3601 size_t i; | |
3602 char_u *name; | |
3603 | |
3604 static struct { | |
3605 char *name; | |
3606 int attr; | |
3607 } attrs[] = { | |
3608 {"bold", HL_BOLD}, | |
3609 {"italic", HL_ITALIC}, | |
3610 {"underline", HL_UNDERLINE}, | |
3611 {"strike", HL_STRIKETHROUGH}, | |
3612 {"reverse", HL_INVERSE}, | |
3613 }; | |
3614 | |
3615 attr = get_tv_number(&argvars[0]); | |
3616 name = get_tv_string_chk(&argvars[1]); | |
3617 if (name == NULL) | |
3618 return; | |
3619 | |
3620 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i) | |
3621 if (STRCMP(name, attrs[i].name) == 0) | |
3622 { | |
3623 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0; | |
3624 break; | |
3625 } | |
3626 } | |
3627 | |
3628 /* | |
3629 * "term_getcursor(buf)" function | |
3630 */ | |
3631 void | |
3632 f_term_getcursor(typval_T *argvars, typval_T *rettv) | |
3633 { | |
3634 buf_T *buf = term_get_buf(argvars); | |
3635 term_T *term; | |
3636 list_T *l; | |
3637 dict_T *d; | |
3638 | |
3639 if (rettv_list_alloc(rettv) == FAIL) | |
3640 return; | |
3641 if (buf == NULL) | |
3642 return; | |
3643 term = buf->b_term; | |
3644 | |
3645 l = rettv->vval.v_list; | |
3646 list_append_number(l, term->tl_cursor_pos.row + 1); | |
3647 list_append_number(l, term->tl_cursor_pos.col + 1); | |
3648 | |
3649 d = dict_alloc(); | |
3650 if (d != NULL) | |
3651 { | |
3652 dict_add_nr_str(d, "visible", term->tl_cursor_visible, NULL); | |
3653 dict_add_nr_str(d, "blink", blink_state_is_inverted() | |
3654 ? !term->tl_cursor_blink : term->tl_cursor_blink, NULL); | |
3655 dict_add_nr_str(d, "shape", term->tl_cursor_shape, NULL); | |
3656 dict_add_nr_str(d, "color", 0L, term->tl_cursor_color == NULL | |
3657 ? (char_u *)"" : term->tl_cursor_color); | |
3658 list_append_dict(l, d); | |
3659 } | |
3660 } | |
3661 | |
3662 /* | |
3663 * "term_getjob(buf)" function | |
3664 */ | |
3665 void | |
3666 f_term_getjob(typval_T *argvars, typval_T *rettv) | |
3667 { | |
3668 buf_T *buf = term_get_buf(argvars); | |
3669 | |
3670 rettv->v_type = VAR_JOB; | |
3671 rettv->vval.v_job = NULL; | |
3672 if (buf == NULL) | |
3673 return; | |
3674 | |
3675 rettv->vval.v_job = buf->b_term->tl_job; | |
3676 if (rettv->vval.v_job != NULL) | |
3677 ++rettv->vval.v_job->jv_refcount; | |
3678 } | |
3679 | |
3680 static int | |
3681 get_row_number(typval_T *tv, term_T *term) | |
3682 { | |
3683 if (tv->v_type == VAR_STRING | |
3684 && tv->vval.v_string != NULL | |
3685 && STRCMP(tv->vval.v_string, ".") == 0) | |
3686 return term->tl_cursor_pos.row; | |
3687 return (int)get_tv_number(tv) - 1; | |
3688 } | |
3689 | |
3690 /* | |
3691 * "term_getline(buf, row)" function | |
3692 */ | |
3693 void | |
3694 f_term_getline(typval_T *argvars, typval_T *rettv) | |
3695 { | |
3696 buf_T *buf = term_get_buf(argvars); | |
3697 term_T *term; | |
3698 int row; | |
3699 | |
3700 rettv->v_type = VAR_STRING; | |
3701 if (buf == NULL) | |
3702 return; | |
3703 term = buf->b_term; | |
3704 row = get_row_number(&argvars[1], term); | |
3705 | |
3706 if (term->tl_vterm == NULL) | |
3707 { | |
3708 linenr_T lnum = row + term->tl_scrollback_scrolled + 1; | |
3709 | |
3710 /* vterm is finished, get the text from the buffer */ | |
3711 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count) | |
3712 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE)); | |
3713 } | |
3714 else | |
3715 { | |
3716 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm); | |
3717 VTermRect rect; | |
3718 int len; | |
3719 char_u *p; | |
3720 | |
3721 if (row < 0 || row >= term->tl_rows) | |
3722 return; | |
3723 len = term->tl_cols * MB_MAXBYTES + 1; | |
3724 p = alloc(len); | |
3725 if (p == NULL) | |
3726 return; | |
3727 rettv->vval.v_string = p; | |
3728 | |
3729 rect.start_col = 0; | |
3730 rect.end_col = term->tl_cols; | |
3731 rect.start_row = row; | |
3732 rect.end_row = row + 1; | |
3733 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL; | |
3734 } | |
3735 } | |
3736 | |
3737 /* | |
3738 * "term_getscrolled(buf)" function | |
3739 */ | |
3740 void | |
3741 f_term_getscrolled(typval_T *argvars, typval_T *rettv) | |
3742 { | |
3743 buf_T *buf = term_get_buf(argvars); | |
3744 | |
3745 if (buf == NULL) | |
3746 return; | |
3747 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled; | |
3748 } | |
3749 | |
3750 /* | |
3751 * "term_getsize(buf)" function | |
3752 */ | |
3753 void | |
3754 f_term_getsize(typval_T *argvars, typval_T *rettv) | |
3755 { | |
3756 buf_T *buf = term_get_buf(argvars); | |
3757 list_T *l; | |
3758 | |
3759 if (rettv_list_alloc(rettv) == FAIL) | |
3760 return; | |
3761 if (buf == NULL) | |
3762 return; | |
3763 | |
3764 l = rettv->vval.v_list; | |
3765 list_append_number(l, buf->b_term->tl_rows); | |
3766 list_append_number(l, buf->b_term->tl_cols); | |
3767 } | |
3768 | |
3769 /* | |
3770 * "term_getstatus(buf)" function | |
3771 */ | |
3772 void | |
3773 f_term_getstatus(typval_T *argvars, typval_T *rettv) | |
3774 { | |
3775 buf_T *buf = term_get_buf(argvars); | |
3776 term_T *term; | |
3777 char_u val[100]; | |
3778 | |
3779 rettv->v_type = VAR_STRING; | |
3780 if (buf == NULL) | |
3781 return; | |
3782 term = buf->b_term; | |
3783 | |
3784 if (term_job_running(term)) | |
3785 STRCPY(val, "running"); | |
3786 else | |
3787 STRCPY(val, "finished"); | |
3788 if (term->tl_normal_mode) | |
3789 STRCAT(val, ",normal"); | |
3790 rettv->vval.v_string = vim_strsave(val); | |
3791 } | |
3792 | |
3793 /* | |
3794 * "term_gettitle(buf)" function | |
3795 */ | |
3796 void | |
3797 f_term_gettitle(typval_T *argvars, typval_T *rettv) | |
3798 { | |
3799 buf_T *buf = term_get_buf(argvars); | |
3800 | |
3801 rettv->v_type = VAR_STRING; | |
3802 if (buf == NULL) | |
3803 return; | |
3804 | |
3805 if (buf->b_term->tl_title != NULL) | |
3806 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title); | |
3807 } | |
3808 | |
3809 /* | |
3810 * "term_gettty(buf)" function | |
3811 */ | |
3812 void | |
3813 f_term_gettty(typval_T *argvars, typval_T *rettv) | |
3814 { | |
3815 buf_T *buf = term_get_buf(argvars); | |
3816 char_u *p; | |
3817 int num = 0; | |
3818 | |
3819 rettv->v_type = VAR_STRING; | |
3820 if (buf == NULL) | |
3821 return; | |
3822 if (argvars[1].v_type != VAR_UNKNOWN) | |
3823 num = get_tv_number(&argvars[1]); | |
3824 | |
3825 switch (num) | |
3826 { | |
3827 case 0: | |
3828 if (buf->b_term->tl_job != NULL) | |
3829 p = buf->b_term->tl_job->jv_tty_out; | |
3830 else | |
3831 p = buf->b_term->tl_tty_out; | |
3832 break; | |
3833 case 1: | |
3834 if (buf->b_term->tl_job != NULL) | |
3835 p = buf->b_term->tl_job->jv_tty_in; | |
3836 else | |
3837 p = buf->b_term->tl_tty_in; | |
3838 break; | |
3839 default: | |
3840 EMSG2(_(e_invarg2), get_tv_string(&argvars[1])); | |
3841 return; | |
3842 } | |
3843 if (p != NULL) | |
3844 rettv->vval.v_string = vim_strsave(p); | |
3845 } | |
3846 | |
3847 /* | |
3848 * "term_list()" function | |
3849 */ | |
3850 void | |
3851 f_term_list(typval_T *argvars UNUSED, typval_T *rettv) | |
3852 { | |
3853 term_T *tp; | |
3854 list_T *l; | |
3855 | |
3856 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL) | |
3857 return; | |
3858 | |
3859 l = rettv->vval.v_list; | |
3860 for (tp = first_term; tp != NULL; tp = tp->tl_next) | |
3861 if (tp != NULL && tp->tl_buffer != NULL) | |
3862 if (list_append_number(l, | |
3863 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL) | |
3864 return; | |
3865 } | |
3866 | |
3867 /* | |
3868 * "term_scrape(buf, row)" function | |
3869 */ | |
3870 void | |
3871 f_term_scrape(typval_T *argvars, typval_T *rettv) | |
3872 { | |
3873 buf_T *buf = term_get_buf(argvars); | |
3874 VTermScreen *screen = NULL; | |
3875 VTermPos pos; | |
3876 list_T *l; | |
3877 term_T *term; | |
3878 char_u *p; | |
3879 sb_line_T *line; | |
3880 | |
3881 if (rettv_list_alloc(rettv) == FAIL) | |
3882 return; | |
3883 if (buf == NULL) | |
3884 return; | |
3885 term = buf->b_term; | |
3886 | |
3887 l = rettv->vval.v_list; | |
3888 pos.row = get_row_number(&argvars[1], term); | |
3889 | |
3890 if (term->tl_vterm != NULL) | |
3891 { | |
3892 screen = vterm_obtain_screen(term->tl_vterm); | |
3893 p = NULL; | |
3894 line = NULL; | |
3895 } | |
3896 else | |
3897 { | |
3898 linenr_T lnum = pos.row + term->tl_scrollback_scrolled; | |
3899 | |
3900 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len) | |
3901 return; | |
3902 p = ml_get_buf(buf, lnum + 1, FALSE); | |
3903 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | |
3904 } | |
3905 | |
3906 for (pos.col = 0; pos.col < term->tl_cols; ) | |
3907 { | |
3908 dict_T *dcell; | |
3909 int width; | |
3910 VTermScreenCellAttrs attrs; | |
3911 VTermColor fg, bg; | |
3912 char_u rgb[8]; | |
3913 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1]; | |
3914 int off = 0; | |
3915 int i; | |
3916 | |
3917 if (screen == NULL) | |
3918 { | |
3919 cellattr_T *cellattr; | |
3920 int len; | |
3921 | |
3922 /* vterm has finished, get the cell from scrollback */ | |
3923 if (pos.col >= line->sb_cols) | |
3924 break; | |
3925 cellattr = line->sb_cells + pos.col; | |
3926 width = cellattr->width; | |
3927 attrs = cellattr->attrs; | |
3928 fg = cellattr->fg; | |
3929 bg = cellattr->bg; | |
3930 len = MB_PTR2LEN(p); | |
3931 mch_memmove(mbs, p, len); | |
3932 mbs[len] = NUL; | |
3933 p += len; | |
3934 } | |
3935 else | |
3936 { | |
3937 VTermScreenCell cell; | |
3938 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
3939 break; | |
3940 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | |
3941 { | |
3942 if (cell.chars[i] == 0) | |
3943 break; | |
3944 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off); | |
3945 } | |
3946 mbs[off] = NUL; | |
3947 width = cell.width; | |
3948 attrs = cell.attrs; | |
3949 fg = cell.fg; | |
3950 bg = cell.bg; | |
3951 } | |
3952 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
|
3953 if (dcell == NULL) |
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3954 break; |
12502 | 3955 list_append_dict(l, dcell); |
3956 | |
3957 dict_add_nr_str(dcell, "chars", 0, mbs); | |
3958 | |
3959 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
3960 fg.red, fg.green, fg.blue); | |
3961 dict_add_nr_str(dcell, "fg", 0, rgb); | |
3962 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
3963 bg.red, bg.green, bg.blue); | |
3964 dict_add_nr_str(dcell, "bg", 0, rgb); | |
3965 | |
3966 dict_add_nr_str(dcell, "attr", | |
3967 cell2attr(attrs, fg, bg), NULL); | |
3968 dict_add_nr_str(dcell, "width", width, NULL); | |
3969 | |
3970 ++pos.col; | |
3971 if (width == 2) | |
3972 ++pos.col; | |
3973 } | |
3974 } | |
3975 | |
3976 /* | |
3977 * "term_sendkeys(buf, keys)" function | |
3978 */ | |
3979 void | |
3980 f_term_sendkeys(typval_T *argvars, typval_T *rettv) | |
3981 { | |
3982 buf_T *buf = term_get_buf(argvars); | |
3983 char_u *msg; | |
3984 term_T *term; | |
3985 | |
3986 rettv->v_type = VAR_UNKNOWN; | |
3987 if (buf == NULL) | |
3988 return; | |
3989 | |
3990 msg = get_tv_string_chk(&argvars[1]); | |
3991 if (msg == NULL) | |
3992 return; | |
3993 term = buf->b_term; | |
3994 if (term->tl_vterm == NULL) | |
3995 return; | |
3996 | |
3997 while (*msg != NUL) | |
3998 { | |
3999 send_keys_to_term(term, PTR2CHAR(msg), FALSE); | |
12650
f58755eb453e
patch 8.0.1203: terminal window mistreats composing characters
Christian Brabandt <cb@256bit.org>
parents:
12634
diff
changeset
|
4000 msg += MB_CPTR2LEN(msg); |
12502 | 4001 } |
4002 } | |
4003 | |
4004 /* | |
4005 * "term_start(command, options)" function | |
4006 */ | |
4007 void | |
4008 f_term_start(typval_T *argvars, typval_T *rettv) | |
4009 { | |
4010 jobopt_T opt; | |
4011 buf_T *buf; | |
4012 | |
4013 init_job_options(&opt); | |
4014 if (argvars[1].v_type != VAR_UNKNOWN | |
4015 && get_job_options(&argvars[1], &opt, | |
4016 JO_TIMEOUT_ALL + JO_STOPONEXIT | |
4017 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK | |
4018 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO, | |
4019 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD | |
4020 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN | |
4021 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS) == FAIL) | |
4022 return; | |
4023 | |
4024 if (opt.jo_vertical) | |
4025 cmdmod.split = WSP_VERT; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4026 buf = term_start(&argvars[0], &opt, FALSE, FALSE); |
12502 | 4027 |
4028 if (buf != NULL && buf->b_term != NULL) | |
4029 rettv->vval.v_number = buf->b_fnum; | |
4030 } | |
4031 | |
4032 /* | |
4033 * "term_wait" function | |
4034 */ | |
4035 void | |
4036 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | |
4037 { | |
4038 buf_T *buf = term_get_buf(argvars); | |
4039 | |
4040 if (buf == NULL) | |
4041 { | |
4042 ch_log(NULL, "term_wait(): invalid argument"); | |
4043 return; | |
4044 } | |
4045 if (buf->b_term->tl_job == NULL) | |
4046 { | |
4047 ch_log(NULL, "term_wait(): no job to wait for"); | |
4048 return; | |
4049 } | |
4050 if (buf->b_term->tl_job->jv_channel == NULL) | |
4051 /* channel is closed, nothing to do */ | |
4052 return; | |
4053 | |
4054 /* 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
|
4055 if (!buf->b_term->tl_job->jv_channel->ch_keep_open |
12502 | 4056 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) |
4057 { | |
4058 /* The job is dead, keep reading channel I/O until the channel is | |
4059 * closed. buf->b_term may become NULL if the terminal was closed while | |
4060 * waiting. */ | |
4061 ch_log(NULL, "term_wait(): waiting for channel to close"); | |
4062 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) | |
4063 { | |
4064 mch_check_messages(); | |
4065 parse_queued_messages(); | |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
4066 if (!buf_valid(buf)) |
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
4067 /* If the terminal is closed when the channel is closed the |
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
4068 * buffer disappears. */ |
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
4069 break; |
12502 | 4070 ui_delay(10L, FALSE); |
4071 } | |
4072 mch_check_messages(); | |
4073 parse_queued_messages(); | |
4074 } | |
4075 else | |
4076 { | |
4077 long wait = 10L; | |
4078 | |
4079 mch_check_messages(); | |
4080 parse_queued_messages(); | |
4081 | |
4082 /* Wait for some time for any channel I/O. */ | |
4083 if (argvars[1].v_type != VAR_UNKNOWN) | |
4084 wait = get_tv_number(&argvars[1]); | |
4085 ui_delay(wait, TRUE); | |
4086 mch_check_messages(); | |
4087 | |
4088 /* Flushing messages on channels is hopefully sufficient. | |
4089 * TODO: is there a better way? */ | |
4090 parse_queued_messages(); | |
4091 } | |
4092 } | |
4093 | |
4094 /* | |
4095 * Called when a channel has sent all the lines to a terminal. | |
4096 * Send a CTRL-D to mark the end of the text. | |
4097 */ | |
4098 void | |
4099 term_send_eof(channel_T *ch) | |
4100 { | |
4101 term_T *term; | |
4102 | |
4103 for (term = first_term; term != NULL; term = term->tl_next) | |
4104 if (term->tl_job == ch->ch_job) | |
4105 { | |
4106 if (term->tl_eof_chars != NULL) | |
4107 { | |
4108 channel_send(ch, PART_IN, term->tl_eof_chars, | |
4109 (int)STRLEN(term->tl_eof_chars), NULL); | |
4110 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL); | |
4111 } | |
4112 # ifdef WIN3264 | |
4113 else | |
4114 /* Default: CTRL-D */ | |
4115 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL); | |
4116 # endif | |
4117 } | |
4118 } | |
4119 | |
4120 # if defined(WIN3264) || defined(PROTO) | |
4121 | |
4122 /************************************** | |
4123 * 2. MS-Windows implementation. | |
4124 */ | |
4125 | |
4126 # ifndef PROTO | |
4127 | |
4128 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul | |
4129 #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
|
4130 #define WINPTY_MOUSE_MODE_FORCE 2 |
12502 | 4131 |
4132 void* (*winpty_config_new)(UINT64, void*); | |
4133 void* (*winpty_open)(void*, void*); | |
4134 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*); | |
4135 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*); | |
4136 void (*winpty_config_set_mouse_mode)(void*, int); | |
4137 void (*winpty_config_set_initial_size)(void*, int, int); | |
4138 LPCWSTR (*winpty_conin_name)(void*); | |
4139 LPCWSTR (*winpty_conout_name)(void*); | |
4140 LPCWSTR (*winpty_conerr_name)(void*); | |
4141 void (*winpty_free)(void*); | |
4142 void (*winpty_config_free)(void*); | |
4143 void (*winpty_spawn_config_free)(void*); | |
4144 void (*winpty_error_free)(void*); | |
4145 LPCWSTR (*winpty_error_msg)(void*); | |
4146 BOOL (*winpty_set_size)(void*, int, int, void*); | |
4147 HANDLE (*winpty_agent_process)(void*); | |
4148 | |
4149 #define WINPTY_DLL "winpty.dll" | |
4150 | |
4151 static HINSTANCE hWinPtyDLL = NULL; | |
4152 # endif | |
4153 | |
4154 static int | |
4155 dyn_winpty_init(int verbose) | |
4156 { | |
4157 int i; | |
4158 static struct | |
4159 { | |
4160 char *name; | |
4161 FARPROC *ptr; | |
4162 } winpty_entry[] = | |
4163 { | |
4164 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name}, | |
4165 {"winpty_config_free", (FARPROC*)&winpty_config_free}, | |
4166 {"winpty_config_new", (FARPROC*)&winpty_config_new}, | |
4167 {"winpty_config_set_mouse_mode", | |
4168 (FARPROC*)&winpty_config_set_mouse_mode}, | |
4169 {"winpty_config_set_initial_size", | |
4170 (FARPROC*)&winpty_config_set_initial_size}, | |
4171 {"winpty_conin_name", (FARPROC*)&winpty_conin_name}, | |
4172 {"winpty_conout_name", (FARPROC*)&winpty_conout_name}, | |
4173 {"winpty_error_free", (FARPROC*)&winpty_error_free}, | |
4174 {"winpty_free", (FARPROC*)&winpty_free}, | |
4175 {"winpty_open", (FARPROC*)&winpty_open}, | |
4176 {"winpty_spawn", (FARPROC*)&winpty_spawn}, | |
4177 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free}, | |
4178 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new}, | |
4179 {"winpty_error_msg", (FARPROC*)&winpty_error_msg}, | |
4180 {"winpty_set_size", (FARPROC*)&winpty_set_size}, | |
4181 {"winpty_agent_process", (FARPROC*)&winpty_agent_process}, | |
4182 {NULL, NULL} | |
4183 }; | |
4184 | |
4185 /* No need to initialize twice. */ | |
4186 if (hWinPtyDLL) | |
4187 return OK; | |
4188 /* Load winpty.dll, prefer using the 'winptydll' option, fall back to just | |
4189 * winpty.dll. */ | |
4190 if (*p_winptydll != NUL) | |
4191 hWinPtyDLL = vimLoadLib((char *)p_winptydll); | |
4192 if (!hWinPtyDLL) | |
4193 hWinPtyDLL = vimLoadLib(WINPTY_DLL); | |
4194 if (!hWinPtyDLL) | |
4195 { | |
4196 if (verbose) | |
4197 EMSG2(_(e_loadlib), *p_winptydll != NUL ? p_winptydll | |
4198 : (char_u *)WINPTY_DLL); | |
4199 return FAIL; | |
4200 } | |
4201 for (i = 0; winpty_entry[i].name != NULL | |
4202 && winpty_entry[i].ptr != NULL; ++i) | |
4203 { | |
4204 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL, | |
4205 winpty_entry[i].name)) == NULL) | |
4206 { | |
4207 if (verbose) | |
4208 EMSG2(_(e_loadfunc), winpty_entry[i].name); | |
4209 return FAIL; | |
4210 } | |
4211 } | |
4212 | |
4213 return OK; | |
4214 } | |
4215 | |
4216 /* | |
4217 * Create a new terminal of "rows" by "cols" cells. | |
4218 * Store a reference in "term". | |
4219 * Return OK or FAIL. | |
4220 */ | |
4221 static int | |
4222 term_and_job_init( | |
4223 term_T *term, | |
4224 typval_T *argvar, | |
4225 jobopt_T *opt) | |
4226 { | |
4227 WCHAR *cmd_wchar = NULL; | |
4228 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
|
4229 WCHAR *env_wchar = NULL; |
12502 | 4230 channel_T *channel = NULL; |
4231 job_T *job = NULL; | |
4232 DWORD error; | |
4233 HANDLE jo = NULL; | |
4234 HANDLE child_process_handle; | |
4235 HANDLE child_thread_handle; | |
13111
149347fda678
patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents:
13109
diff
changeset
|
4236 void *winpty_err = NULL; |
12502 | 4237 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
|
4238 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
|
4239 char_u *cmd = NULL; |
12502 | 4240 |
4241 if (dyn_winpty_init(TRUE) == FAIL) | |
4242 return FAIL; | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4243 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
|
4244 ga_init2(&ga_env, (int)sizeof(char*), 20); |
12502 | 4245 |
4246 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
|
4247 { |
12502 | 4248 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
|
4249 } |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4250 else if (argvar->v_type == VAR_LIST) |
12502 | 4251 { |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
4252 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
12502 | 4253 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
|
4254 cmd = ga_cmd.ga_data; |
12502 | 4255 } |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4256 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
|
4257 { |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4258 EMSG(_(e_invarg)); |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4259 goto failed; |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4260 } |
12502 | 4261 |
4262 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
|
4263 ga_clear(&ga_cmd); |
12502 | 4264 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
|
4265 goto failed; |
12502 | 4266 if (opt->jo_cwd != NULL) |
4267 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
|
4268 |
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
|
4269 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
|
4270 env_wchar = ga_env.ga_data; |
12502 | 4271 |
4272 job = job_alloc(); | |
4273 if (job == NULL) | |
4274 goto failed; | |
4275 | |
4276 channel = add_channel(); | |
4277 if (channel == NULL) | |
4278 goto failed; | |
4279 | |
4280 term->tl_winpty_config = winpty_config_new(0, &winpty_err); | |
4281 if (term->tl_winpty_config == NULL) | |
4282 goto failed; | |
4283 | |
4284 winpty_config_set_mouse_mode(term->tl_winpty_config, | |
4285 WINPTY_MOUSE_MODE_FORCE); | |
4286 winpty_config_set_initial_size(term->tl_winpty_config, | |
4287 term->tl_cols, term->tl_rows); | |
4288 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err); | |
4289 if (term->tl_winpty == NULL) | |
4290 goto failed; | |
4291 | |
4292 spawn_config = winpty_spawn_config_new( | |
4293 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN | | |
4294 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN, | |
4295 NULL, | |
4296 cmd_wchar, | |
4297 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
|
4298 env_wchar, |
12502 | 4299 &winpty_err); |
4300 if (spawn_config == NULL) | |
4301 goto failed; | |
4302 | |
4303 channel = add_channel(); | |
4304 if (channel == NULL) | |
4305 goto failed; | |
4306 | |
4307 job = job_alloc(); | |
4308 if (job == NULL) | |
4309 goto failed; | |
4310 | |
4311 if (opt->jo_set & JO_IN_BUF) | |
4312 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); | |
4313 | |
4314 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle, | |
4315 &child_thread_handle, &error, &winpty_err)) | |
4316 goto failed; | |
4317 | |
4318 channel_set_pipes(channel, | |
4319 (sock_T)CreateFileW( | |
4320 winpty_conin_name(term->tl_winpty), | |
4321 GENERIC_WRITE, 0, NULL, | |
4322 OPEN_EXISTING, 0, NULL), | |
4323 (sock_T)CreateFileW( | |
4324 winpty_conout_name(term->tl_winpty), | |
4325 GENERIC_READ, 0, NULL, | |
4326 OPEN_EXISTING, 0, NULL), | |
4327 (sock_T)CreateFileW( | |
4328 winpty_conerr_name(term->tl_winpty), | |
4329 GENERIC_READ, 0, NULL, | |
4330 OPEN_EXISTING, 0, NULL)); | |
4331 | |
4332 /* Write lines with CR instead of NL. */ | |
4333 channel->ch_write_text_mode = TRUE; | |
4334 | |
4335 jo = CreateJobObject(NULL, NULL); | |
4336 if (jo == NULL) | |
4337 goto failed; | |
4338 | |
4339 if (!AssignProcessToJobObject(jo, child_process_handle)) | |
4340 { | |
4341 /* Failed, switch the way to terminate process with TerminateProcess. */ | |
4342 CloseHandle(jo); | |
4343 jo = NULL; | |
4344 } | |
4345 | |
4346 winpty_spawn_config_free(spawn_config); | |
4347 vim_free(cmd_wchar); | |
4348 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
|
4349 vim_free(env_wchar); |
12502 | 4350 |
4351 create_vterm(term, term->tl_rows, term->tl_cols); | |
4352 | |
4353 channel_set_job(channel, job, opt); | |
4354 job_set_options(job, opt); | |
4355 | |
4356 job->jv_channel = channel; | |
4357 job->jv_proc_info.hProcess = child_process_handle; | |
4358 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle); | |
4359 job->jv_job_object = jo; | |
4360 job->jv_status = JOB_STARTED; | |
4361 job->jv_tty_in = utf16_to_enc( | |
4362 (short_u*)winpty_conin_name(term->tl_winpty), NULL); | |
4363 job->jv_tty_out = utf16_to_enc( | |
4364 (short_u*)winpty_conout_name(term->tl_winpty), NULL); | |
4365 ++job->jv_refcount; | |
4366 term->tl_job = job; | |
4367 | |
4368 return OK; | |
4369 | |
4370 failed: | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
4371 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
|
4372 ga_clear(&ga_env); |
12502 | 4373 vim_free(cmd_wchar); |
4374 vim_free(cwd_wchar); | |
4375 if (spawn_config != NULL) | |
4376 winpty_spawn_config_free(spawn_config); | |
4377 if (channel != NULL) | |
4378 channel_clear(channel); | |
4379 if (job != NULL) | |
4380 { | |
4381 job->jv_channel = NULL; | |
4382 job_cleanup(job); | |
4383 } | |
4384 term->tl_job = NULL; | |
4385 if (jo != NULL) | |
4386 CloseHandle(jo); | |
4387 if (term->tl_winpty != NULL) | |
4388 winpty_free(term->tl_winpty); | |
4389 term->tl_winpty = NULL; | |
4390 if (term->tl_winpty_config != NULL) | |
4391 winpty_config_free(term->tl_winpty_config); | |
4392 term->tl_winpty_config = NULL; | |
4393 if (winpty_err != NULL) | |
4394 { | |
4395 char_u *msg = utf16_to_enc( | |
4396 (short_u *)winpty_error_msg(winpty_err), NULL); | |
4397 | |
4398 EMSG(msg); | |
4399 winpty_error_free(winpty_err); | |
4400 } | |
4401 return FAIL; | |
4402 } | |
4403 | |
4404 static int | |
4405 create_pty_only(term_T *term, jobopt_T *options) | |
4406 { | |
4407 HANDLE hPipeIn = INVALID_HANDLE_VALUE; | |
4408 HANDLE hPipeOut = INVALID_HANDLE_VALUE; | |
4409 char in_name[80], out_name[80]; | |
4410 channel_T *channel = NULL; | |
4411 | |
4412 create_vterm(term, term->tl_rows, term->tl_cols); | |
4413 | |
4414 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d", | |
4415 GetCurrentProcessId(), | |
4416 curbuf->b_fnum); | |
4417 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND, | |
4418 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
4419 PIPE_UNLIMITED_INSTANCES, | |
4420 0, 0, NMPWAIT_NOWAIT, NULL); | |
4421 if (hPipeIn == INVALID_HANDLE_VALUE) | |
4422 goto failed; | |
4423 | |
4424 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d", | |
4425 GetCurrentProcessId(), | |
4426 curbuf->b_fnum); | |
4427 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND, | |
4428 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
4429 PIPE_UNLIMITED_INSTANCES, | |
4430 0, 0, 0, NULL); | |
4431 if (hPipeOut == INVALID_HANDLE_VALUE) | |
4432 goto failed; | |
4433 | |
4434 ConnectNamedPipe(hPipeIn, NULL); | |
4435 ConnectNamedPipe(hPipeOut, NULL); | |
4436 | |
4437 term->tl_job = job_alloc(); | |
4438 if (term->tl_job == NULL) | |
4439 goto failed; | |
4440 ++term->tl_job->jv_refcount; | |
4441 | |
4442 /* behave like the job is already finished */ | |
4443 term->tl_job->jv_status = JOB_FINISHED; | |
4444 | |
4445 channel = add_channel(); | |
4446 if (channel == NULL) | |
4447 goto failed; | |
4448 term->tl_job->jv_channel = channel; | |
4449 channel->ch_keep_open = TRUE; | |
4450 channel->ch_named_pipe = TRUE; | |
4451 | |
4452 channel_set_pipes(channel, | |
4453 (sock_T)hPipeIn, | |
4454 (sock_T)hPipeOut, | |
4455 (sock_T)hPipeOut); | |
4456 channel_set_job(channel, term->tl_job, options); | |
4457 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name); | |
4458 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name); | |
4459 | |
4460 return OK; | |
4461 | |
4462 failed: | |
4463 if (hPipeIn != NULL) | |
4464 CloseHandle(hPipeIn); | |
4465 if (hPipeOut != NULL) | |
4466 CloseHandle(hPipeOut); | |
4467 return FAIL; | |
4468 } | |
4469 | |
4470 /* | |
4471 * Free the terminal emulator part of "term". | |
4472 */ | |
4473 static void | |
4474 term_free_vterm(term_T *term) | |
4475 { | |
4476 if (term->tl_winpty != NULL) | |
4477 winpty_free(term->tl_winpty); | |
4478 term->tl_winpty = NULL; | |
4479 if (term->tl_winpty_config != NULL) | |
4480 winpty_config_free(term->tl_winpty_config); | |
4481 term->tl_winpty_config = NULL; | |
4482 if (term->tl_vterm != NULL) | |
4483 vterm_free(term->tl_vterm); | |
4484 term->tl_vterm = NULL; | |
4485 } | |
4486 | |
4487 /* | |
4488 * Request size to terminal. | |
4489 */ | |
4490 static void | |
4491 term_report_winsize(term_T *term, int rows, int cols) | |
4492 { | |
4493 if (term->tl_winpty) | |
4494 winpty_set_size(term->tl_winpty, cols, rows, NULL); | |
4495 } | |
4496 | |
4497 int | |
4498 terminal_enabled(void) | |
4499 { | |
4500 return dyn_winpty_init(FALSE) == OK; | |
4501 } | |
4502 | |
4503 # else | |
4504 | |
4505 /************************************** | |
4506 * 3. Unix-like implementation. | |
4507 */ | |
4508 | |
4509 /* | |
4510 * Create a new terminal of "rows" by "cols" cells. | |
4511 * Start job for "cmd". | |
4512 * Store the pointers in "term". | |
4513 * Return OK or FAIL. | |
4514 */ | |
4515 static int | |
4516 term_and_job_init( | |
4517 term_T *term, | |
4518 typval_T *argvar, | |
4519 jobopt_T *opt) | |
4520 { | |
4521 create_vterm(term, term->tl_rows, term->tl_cols); | |
4522 | |
4523 term->tl_job = job_start(argvar, opt); | |
4524 if (term->tl_job != NULL) | |
4525 ++term->tl_job->jv_refcount; | |
4526 | |
4527 return term->tl_job != NULL | |
4528 && term->tl_job->jv_channel != NULL | |
4529 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL; | |
4530 } | |
4531 | |
4532 static int | |
4533 create_pty_only(term_T *term, jobopt_T *opt) | |
4534 { | |
4535 create_vterm(term, term->tl_rows, term->tl_cols); | |
4536 | |
4537 term->tl_job = job_alloc(); | |
4538 if (term->tl_job == NULL) | |
4539 return FAIL; | |
4540 ++term->tl_job->jv_refcount; | |
4541 | |
4542 /* behave like the job is already finished */ | |
4543 term->tl_job->jv_status = JOB_FINISHED; | |
4544 | |
4545 return mch_create_pty_channel(term->tl_job, opt); | |
4546 } | |
4547 | |
4548 /* | |
4549 * Free the terminal emulator part of "term". | |
4550 */ | |
4551 static void | |
4552 term_free_vterm(term_T *term) | |
4553 { | |
4554 if (term->tl_vterm != NULL) | |
4555 vterm_free(term->tl_vterm); | |
4556 term->tl_vterm = NULL; | |
4557 } | |
4558 | |
4559 /* | |
4560 * Request size to terminal. | |
4561 */ | |
4562 static void | |
4563 term_report_winsize(term_T *term, int rows, int cols) | |
4564 { | |
4565 /* Use an ioctl() to report the new window size to the job. */ | |
4566 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) | |
4567 { | |
4568 int fd = -1; | |
4569 int part; | |
4570 | |
4571 for (part = PART_OUT; part < PART_COUNT; ++part) | |
4572 { | |
4573 fd = term->tl_job->jv_channel->ch_part[part].ch_fd; | |
4574 if (isatty(fd)) | |
4575 break; | |
4576 } | |
4577 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) | |
4578 mch_signal_job(term->tl_job, (char_u *)"winch"); | |
4579 } | |
4580 } | |
4581 | |
4582 # endif | |
4583 | |
4584 #endif /* FEAT_TERMINAL */ |