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