Mercurial > vim
annotate src/terminal.c @ 15865:bf72955a2d0f
Added tag v8.1.0939 for changeset 9e0154efac3a3f9b55c6d966f4b8bc88640c233c
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 17 Feb 2019 15:00:06 +0100 |
parents | 63e71d195cee |
children | 7fad90423bd2 |
rev | line source |
---|---|
12502 | 1 /* vi:set ts=8 sts=4 sw=4 noet: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Terminal window support, see ":help :terminal". | |
12 * | |
13 * There are three parts: | |
14 * 1. Generic code for all systems. | |
15 * Uses libvterm for the terminal emulator. | |
16 * 2. The MS-Windows implementation. | |
17 * Uses winpty. | |
18 * 3. The Unix-like implementation. | |
19 * Uses pseudo-tty's (pty's). | |
20 * | |
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of | |
22 * this library is in the libvterm directory. | |
23 * | |
24 * When a terminal window is opened, a job is started that will be connected to | |
25 * the terminal emulator. | |
26 * | |
27 * If the terminal window has keyboard focus, typed keys are converted to the | |
28 * terminal encoding and writing to the job over a channel. | |
29 * | |
30 * If the job produces output, it is written to the terminal emulator. The | |
31 * terminal emulator invokes callbacks when its screen content changes. The | |
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a | |
33 * while, if the terminal window is visible, the screen contents is drawn. | |
34 * | |
35 * When the job ends the text is put in a buffer. Redrawing then happens from | |
36 * that buffer, attributes come from the scrollback buffer tl_scrollback. | |
37 * When the buffer is changed it is turned into a normal buffer, the attributes | |
38 * in tl_scrollback are no longer used. | |
39 */ | |
40 | |
41 #include "vim.h" | |
42 | |
43 #if defined(FEAT_TERMINAL) || defined(PROTO) | |
44 | |
45 #ifndef MIN | |
46 # define MIN(x,y) ((x) < (y) ? (x) : (y)) | |
47 #endif | |
48 #ifndef MAX | |
49 # define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
50 #endif | |
51 | |
52 #include "libvterm/include/vterm.h" | |
53 | |
54 /* This is VTermScreenCell without the characters, thus much smaller. */ | |
55 typedef struct { | |
56 VTermScreenCellAttrs attrs; | |
57 char width; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
58 VTermColor fg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
59 VTermColor bg; |
12502 | 60 } cellattr_T; |
61 | |
62 typedef struct sb_line_S { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
63 int sb_cols; // can differ per line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
64 cellattr_T *sb_cells; // allocated |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
65 cellattr_T sb_fill_attr; // for short line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
66 char_u *sb_text; // for tl_scrollback_postponed |
12502 | 67 } sb_line_T; |
68 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
69 #ifdef WIN3264 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
70 # ifndef HPCON |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
71 # define HPCON VOID* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
72 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
73 # ifndef EXTENDED_STARTUPINFO_PRESENT |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
74 # define EXTENDED_STARTUPINFO_PRESENT 0x00080000 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
75 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
76 # ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
77 # define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
78 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
79 typedef struct _DYN_STARTUPINFOEXW |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
80 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
81 STARTUPINFOW StartupInfo; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
82 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
83 } DYN_STARTUPINFOEXW, *PDYN_STARTUPINFOEXW; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
84 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
85 |
12502 | 86 /* typedef term_T in structs.h */ |
87 struct terminal_S { | |
88 term_T *tl_next; | |
89 | |
90 VTerm *tl_vterm; | |
91 job_T *tl_job; | |
92 buf_T *tl_buffer; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
93 #if defined(FEAT_GUI) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
94 int tl_system; /* when non-zero used for :!cmd output */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
95 int tl_toprow; /* row with first line of system terminal */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
96 #endif |
12502 | 97 |
98 /* Set when setting the size of a vterm, reset after redrawing. */ | |
99 int tl_vterm_size_changed; | |
100 | |
101 int tl_normal_mode; /* TRUE: Terminal-Normal mode */ | |
102 int tl_channel_closed; | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
103 int tl_channel_recently_closed; // still need to handle tl_finish |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
104 |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
105 int tl_finish; |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
106 #define TL_FINISH_UNSET NUL |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
107 #define TL_FINISH_CLOSE 'c' /* ++close or :terminal without argument */ |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
108 #define TL_FINISH_NOCLOSE 'n' /* ++noclose */ |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
109 #define TL_FINISH_OPEN 'o' /* ++open */ |
12502 | 110 char_u *tl_opencmd; |
111 char_u *tl_eof_chars; | |
112 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
113 char_u *tl_arg0_cmd; // To format the status bar |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
114 |
12502 | 115 #ifdef WIN3264 |
116 void *tl_winpty_config; | |
117 void *tl_winpty; | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
118 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
119 HPCON tl_conpty; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
120 DYN_STARTUPINFOEXW tl_siex; // Structure that always needs to be hold |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
121 |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
122 FILE *tl_out_fd; |
12502 | 123 #endif |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
124 #if defined(FEAT_SESSION) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
125 char_u *tl_command; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
126 #endif |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
127 char_u *tl_kill; |
12502 | 128 |
129 /* last known vterm size */ | |
130 int tl_rows; | |
131 int tl_cols; | |
132 | |
133 char_u *tl_title; /* NULL or allocated */ | |
134 char_u *tl_status_text; /* NULL or allocated */ | |
135 | |
136 /* 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
|
137 int tl_dirty_row_start; /* MAX_ROW if nothing dirty */ |
12502 | 138 int tl_dirty_row_end; /* row below last one to update */ |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
139 int tl_dirty_snapshot; /* text updated after making snapshot */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
140 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
141 int tl_timer_set; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
142 proftime_T tl_timer_due; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
143 #endif |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
144 int tl_postponed_scroll; /* to be scrolled up */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
145 |
12502 | 146 garray_T tl_scrollback; |
147 int tl_scrollback_scrolled; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
148 garray_T tl_scrollback_postponed; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
149 |
12502 | 150 cellattr_T tl_default_color; |
151 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
152 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
|
153 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
|
154 |
12502 | 155 VTermPos tl_cursor_pos; |
156 int tl_cursor_visible; | |
157 int tl_cursor_blink; | |
158 int tl_cursor_shape; /* 1: block, 2: underline, 3: bar */ | |
159 char_u *tl_cursor_color; /* NULL or allocated */ | |
160 | |
161 int tl_using_altscreen; | |
162 }; | |
163 | |
164 #define TMODE_ONCE 1 /* CTRL-\ CTRL-N used */ | |
165 #define TMODE_LOOP 2 /* CTRL-W N used */ | |
166 | |
167 /* | |
168 * List of all active terminals. | |
169 */ | |
170 static term_T *first_term = NULL; | |
171 | |
172 /* Terminal active in terminal_loop(). */ | |
173 static term_T *in_terminal_loop = NULL; | |
174 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
175 #ifdef WIN3264 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
176 static BOOL has_winpty = FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
177 static BOOL has_conpty = FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
178 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
179 |
12502 | 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 */ | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
186 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt); |
12502 | 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); | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
190 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
191 static void update_system_term(term_T *term); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
192 #endif |
12502 | 193 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
194 static void handle_postponed_scrollback(term_T *term); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
195 |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
196 /* 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
|
197 * backspace key. */ |
12502 | 198 static int term_backspace_char = BS; |
199 | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
200 /* "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
|
201 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
|
202 static int term_default_cterm_bg = -1; |
12502 | 203 |
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
|
204 /* 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
|
205 * them when needed. Doing it unnecessary may result in flicker. */ |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
206 static char_u *last_set_cursor_color = NULL; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
207 static char_u *desired_cursor_color = NULL; |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 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
|
212 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
213 |
12502 | 214 /************************************** |
215 * 1. Generic code for all systems. | |
216 */ | |
217 | |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
218 static int |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
219 cursor_color_equal(char_u *lhs_color, char_u *rhs_color) |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
220 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
221 if (lhs_color != NULL && rhs_color != NULL) |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
222 return STRCMP(lhs_color, rhs_color) == 0; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
223 return lhs_color == NULL && rhs_color == NULL; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
224 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
225 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
226 static void |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
227 cursor_color_copy(char_u **to_color, char_u *from_color) |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
228 { |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
229 // Avoid a free & alloc if the value is already right. |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
230 if (cursor_color_equal(*to_color, from_color)) |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
231 return; |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
232 vim_free(*to_color); |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
233 *to_color = (from_color == NULL) ? NULL : vim_strsave(from_color); |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
234 } |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
235 |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
236 static char_u * |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
237 cursor_color_get(char_u *color) |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
238 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
239 return (color == NULL) ? (char_u *)"" : color; |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
240 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
241 |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
242 |
12502 | 243 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
244 * Parse 'termwinsize' and set "rows" and "cols" for the terminal size in the |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
245 * current window. |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
246 * Sets "rows" and/or "cols" to zero when it should follow the window size. |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
247 * Return TRUE if the size is the minimum size: "24*80". |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
248 */ |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
249 static int |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
250 parse_termwinsize(win_T *wp, int *rows, int *cols) |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
251 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
252 int minsize = FALSE; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
253 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
254 *rows = 0; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
255 *cols = 0; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
256 |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
257 if (*wp->w_p_tws != NUL) |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
258 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
259 char_u *p = vim_strchr(wp->w_p_tws, 'x'); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
260 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
261 /* Syntax of value was already checked when it's set. */ |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
262 if (p == NULL) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
263 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
264 minsize = TRUE; |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
265 p = vim_strchr(wp->w_p_tws, '*'); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
266 } |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
267 *rows = atoi((char *)wp->w_p_tws); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
268 *cols = atoi((char *)p + 1); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
269 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
270 return minsize; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
271 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
272 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
273 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
274 * Determine the terminal size from 'termwinsize' and the current window. |
12502 | 275 */ |
276 static void | |
277 set_term_and_win_size(term_T *term) | |
278 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
279 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
280 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
281 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
282 /* Use the whole screen for the system command. However, it will start |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
283 * at the command line and scroll up as needed, using tl_toprow. */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
284 term->tl_rows = Rows; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
285 term->tl_cols = Columns; |
13624
429f0eb87d6f
patch 8.0.1684: ml_get errors when using terminal window for shell command
Christian Brabandt <cb@256bit.org>
parents:
13616
diff
changeset
|
286 return; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
287 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
288 #endif |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
289 if (parse_termwinsize(curwin, &term->tl_rows, &term->tl_cols)) |
12502 | 290 { |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
291 if (term->tl_rows != 0) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
292 term->tl_rows = MAX(term->tl_rows, curwin->w_height); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
293 if (term->tl_cols != 0) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
294 term->tl_cols = MAX(term->tl_cols, curwin->w_width); |
12502 | 295 } |
296 if (term->tl_rows == 0) | |
297 term->tl_rows = curwin->w_height; | |
298 else | |
299 win_setheight_win(term->tl_rows, curwin); | |
300 if (term->tl_cols == 0) | |
301 term->tl_cols = curwin->w_width; | |
302 else | |
303 win_setwidth_win(term->tl_cols, curwin); | |
304 } | |
305 | |
306 /* | |
307 * Initialize job options for a terminal job. | |
308 * Caller may overrule some of them. | |
309 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
310 void |
12502 | 311 init_job_options(jobopt_T *opt) |
312 { | |
313 clear_job_options(opt); | |
314 | |
315 opt->jo_mode = MODE_RAW; | |
316 opt->jo_out_mode = MODE_RAW; | |
317 opt->jo_err_mode = MODE_RAW; | |
318 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; | |
319 } | |
320 | |
321 /* | |
322 * Set job options mandatory for a terminal job. | |
323 */ | |
324 static void | |
325 setup_job_options(jobopt_T *opt, int rows, int cols) | |
326 { | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
327 #ifndef WIN3264 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
328 /* Win32: Redirecting the job output won't work, thus always connect stdout |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
329 * here. */ |
12502 | 330 if (!(opt->jo_set & JO_OUT_IO)) |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
331 #endif |
12502 | 332 { |
333 /* Connect stdout to the terminal. */ | |
334 opt->jo_io[PART_OUT] = JIO_BUFFER; | |
335 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; | |
336 opt->jo_modifiable[PART_OUT] = 0; | |
337 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE; | |
338 } | |
339 | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
340 #ifndef WIN3264 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
341 /* Win32: Redirecting the job output won't work, thus always connect stderr |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
342 * here. */ |
12502 | 343 if (!(opt->jo_set & JO_ERR_IO)) |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
344 #endif |
12502 | 345 { |
346 /* Connect stderr to the terminal. */ | |
347 opt->jo_io[PART_ERR] = JIO_BUFFER; | |
348 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; | |
349 opt->jo_modifiable[PART_ERR] = 0; | |
350 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE; | |
351 } | |
352 | |
353 opt->jo_pty = TRUE; | |
354 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0) | |
355 opt->jo_term_rows = rows; | |
356 if ((opt->jo_set2 & JO2_TERM_COLS) == 0) | |
357 opt->jo_term_cols = cols; | |
358 } | |
359 | |
360 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
361 * 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
|
362 * fails. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
363 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
364 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
365 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
|
366 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
367 free_terminal(buf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
368 if (old_curbuf != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
369 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
370 --curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
371 curbuf = old_curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
372 curwin->w_buffer = curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
373 ++curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
374 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
375 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
376 /* 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
|
377 * free_terminal(). */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
378 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
|
379 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
380 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
381 /* |
12502 | 382 * Start a terminal window and return its buffer. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
383 * Use either "argvar" or "argv", the other must be NULL. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
384 * When "flags" has TERM_START_NOJOB only create the buffer, b_term and open |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
385 * the window. |
12502 | 386 * Returns NULL when failed. |
387 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
388 buf_T * |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
389 term_start( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
390 typval_T *argvar, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
391 char **argv, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
392 jobopt_T *opt, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
393 int flags) |
12502 | 394 { |
395 exarg_T split_ea; | |
396 win_T *old_curwin = curwin; | |
397 term_T *term; | |
398 buf_T *old_curbuf = NULL; | |
399 int res; | |
400 buf_T *newbuf; | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
401 int vertical = opt->jo_vertical || (cmdmod.split & WSP_VERT); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
402 jobopt_T orig_opt; // only partly filled |
12502 | 403 |
404 if (check_restricted() || check_secure()) | |
405 return NULL; | |
406 | |
407 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)) | |
408 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO) | |
409 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF)) | |
410 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF))) | |
411 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
412 emsg(_(e_invarg)); |
12502 | 413 return NULL; |
414 } | |
415 | |
416 term = (term_T *)alloc_clear(sizeof(term_T)); | |
417 if (term == NULL) | |
418 return NULL; | |
419 term->tl_dirty_row_end = MAX_ROW; | |
420 term->tl_cursor_visible = TRUE; | |
421 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | |
422 term->tl_finish = opt->jo_term_finish; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
423 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
424 term->tl_system = (flags & TERM_START_SYSTEM); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
425 #endif |
12502 | 426 ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300); |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
427 ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300); |
12502 | 428 |
429 vim_memset(&split_ea, 0, sizeof(split_ea)); | |
430 if (opt->jo_curwin) | |
431 { | |
432 /* Create a new buffer in the current window. */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
433 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT)) |
12502 | 434 { |
435 no_write_message(); | |
436 vim_free(term); | |
437 return NULL; | |
438 } | |
439 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE, | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
440 ECMD_HIDE |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
441 + ((flags & TERM_START_FORCEIT) ? ECMD_FORCEIT : 0), |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
442 curwin) == FAIL) |
12502 | 443 { |
444 vim_free(term); | |
445 return NULL; | |
446 } | |
447 } | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
448 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM)) |
12502 | 449 { |
450 buf_T *buf; | |
451 | |
452 /* Create a new buffer without a window. Make it the current buffer for | |
453 * a moment to be able to do the initialisations. */ | |
454 buf = buflist_new((char_u *)"", NULL, (linenr_T)0, | |
455 BLN_NEW | BLN_LISTED); | |
456 if (buf == NULL || ml_open(buf) == FAIL) | |
457 { | |
458 vim_free(term); | |
459 return NULL; | |
460 } | |
461 old_curbuf = curbuf; | |
462 --curbuf->b_nwindows; | |
463 curbuf = buf; | |
464 curwin->w_buffer = buf; | |
465 ++curbuf->b_nwindows; | |
466 } | |
467 else | |
468 { | |
469 /* Open a new window or tab. */ | |
470 split_ea.cmdidx = CMD_new; | |
471 split_ea.cmd = (char_u *)"new"; | |
472 split_ea.arg = (char_u *)""; | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
473 if (opt->jo_term_rows > 0 && !vertical) |
12502 | 474 { |
475 split_ea.line2 = opt->jo_term_rows; | |
476 split_ea.addr_count = 1; | |
477 } | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
478 if (opt->jo_term_cols > 0 && vertical) |
12502 | 479 { |
480 split_ea.line2 = opt->jo_term_cols; | |
481 split_ea.addr_count = 1; | |
482 } | |
483 | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
484 if (vertical) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
485 cmdmod.split |= WSP_VERT; |
12502 | 486 ex_splitview(&split_ea); |
487 if (curwin == old_curwin) | |
488 { | |
489 /* split failed */ | |
490 vim_free(term); | |
491 return NULL; | |
492 } | |
493 } | |
494 term->tl_buffer = curbuf; | |
495 curbuf->b_term = term; | |
496 | |
497 if (!opt->jo_hidden) | |
498 { | |
13304
013c44d9dc09
patch 8.0.1526: no test using a screen dump yet
Christian Brabandt <cb@256bit.org>
parents:
13300
diff
changeset
|
499 /* 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
|
500 * "curwin" both need to be done. */ |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
501 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical)) |
12502 | 502 win_setheight(opt->jo_term_rows); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
503 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical)) |
12502 | 504 win_setwidth(opt->jo_term_cols); |
505 } | |
506 | |
507 /* Link the new terminal in the list of active terminals. */ | |
508 term->tl_next = first_term; | |
509 first_term = term; | |
510 | |
511 if (opt->jo_term_name != NULL) | |
512 curbuf->b_ffname = vim_strsave(opt->jo_term_name); | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
513 else if (argv != NULL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
514 curbuf->b_ffname = vim_strsave((char_u *)"!system"); |
12502 | 515 else |
516 { | |
517 int i; | |
518 size_t len; | |
519 char_u *cmd, *p; | |
520 | |
521 if (argvar->v_type == VAR_STRING) | |
522 { | |
523 cmd = argvar->vval.v_string; | |
524 if (cmd == NULL) | |
525 cmd = (char_u *)""; | |
526 else if (STRCMP(cmd, "NONE") == 0) | |
527 cmd = (char_u *)"pty"; | |
528 } | |
529 else if (argvar->v_type != VAR_LIST | |
530 || argvar->vval.v_list == NULL | |
531 || argvar->vval.v_list->lv_len < 1 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
532 || (cmd = tv_get_string_chk( |
12502 | 533 &argvar->vval.v_list->lv_first->li_tv)) == NULL) |
534 cmd = (char_u*)""; | |
535 | |
536 len = STRLEN(cmd) + 10; | |
537 p = alloc((int)len); | |
538 | |
539 for (i = 0; p != NULL; ++i) | |
540 { | |
541 /* Prepend a ! to the command name to avoid the buffer name equals | |
542 * the executable, otherwise ":w!" would overwrite it. */ | |
543 if (i == 0) | |
544 vim_snprintf((char *)p, len, "!%s", cmd); | |
545 else | |
546 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i); | |
547 if (buflist_findname(p) == NULL) | |
548 { | |
549 vim_free(curbuf->b_ffname); | |
550 curbuf->b_ffname = p; | |
551 break; | |
552 } | |
553 } | |
554 } | |
555 curbuf->b_fname = curbuf->b_ffname; | |
556 | |
557 if (opt->jo_term_opencmd != NULL) | |
558 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); | |
559 | |
560 if (opt->jo_eof_chars != NULL) | |
561 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); | |
562 | |
563 set_string_option_direct((char_u *)"buftype", -1, | |
564 (char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0); | |
14449
5faab0545f3c
patch 8.1.0238: 'buftype' is cleared when using ":term ++hidden cat"
Christian Brabandt <cb@256bit.org>
parents:
14311
diff
changeset
|
565 // Avoid that 'buftype' is reset when this buffer is entered. |
5faab0545f3c
patch 8.1.0238: 'buftype' is cleared when using ":term ++hidden cat"
Christian Brabandt <cb@256bit.org>
parents:
14311
diff
changeset
|
566 curbuf->b_p_initialized = TRUE; |
12502 | 567 |
568 /* Mark the buffer as not modifiable. It can only be made modifiable after | |
569 * the job finished. */ | |
570 curbuf->b_p_ma = FALSE; | |
571 | |
572 set_term_and_win_size(term); | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
573 #ifdef WIN3264 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
574 mch_memmove(orig_opt.jo_io, opt->jo_io, sizeof(orig_opt.jo_io)); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
575 #endif |
12502 | 576 setup_job_options(opt, term->tl_rows, term->tl_cols); |
577 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
578 if (flags & TERM_START_NOJOB) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
579 return curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
580 |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
581 #if defined(FEAT_SESSION) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
582 /* Remember the command for the session file. */ |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
583 if (opt->jo_term_norestore || argv != NULL) |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
584 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
585 term->tl_command = vim_strsave((char_u *)"NONE"); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
586 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
587 else if (argvar->v_type == VAR_STRING) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
588 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
589 char_u *cmd = argvar->vval.v_string; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
590 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
591 if (cmd != NULL && STRCMP(cmd, p_sh) != 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
592 term->tl_command = vim_strsave(cmd); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
593 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
594 else if (argvar->v_type == VAR_LIST |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
595 && argvar->vval.v_list != NULL |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
596 && argvar->vval.v_list->lv_len > 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
597 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
598 garray_T ga; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
599 listitem_T *item; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
600 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
601 ga_init2(&ga, 1, 100); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
602 for (item = argvar->vval.v_list->lv_first; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
603 item != NULL; item = item->li_next) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
604 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
605 char_u *s = tv_get_string_chk(&item->li_tv); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
606 char_u *p; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
607 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
608 if (s == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
609 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
610 p = vim_strsave_fnameescape(s, FALSE); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
611 if (p == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
612 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
613 ga_concat(&ga, p); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
614 vim_free(p); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
615 ga_append(&ga, ' '); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
616 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
617 if (item == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
618 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
619 ga_append(&ga, NUL); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
620 term->tl_command = ga.ga_data; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
621 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
622 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
623 ga_clear(&ga); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
624 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
625 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
626 |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
627 if (opt->jo_term_kill != NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
628 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
629 char_u *p = skiptowhite(opt->jo_term_kill); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
630 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
631 term->tl_kill = vim_strnsave(opt->jo_term_kill, p - opt->jo_term_kill); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
632 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
633 |
12502 | 634 /* System dependent: setup the vterm and maybe start the job in it. */ |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
635 if (argv == NULL |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
636 && argvar->v_type == VAR_STRING |
12502 | 637 && argvar->vval.v_string != NULL |
638 && STRCMP(argvar->vval.v_string, "NONE") == 0) | |
639 res = create_pty_only(term, opt); | |
640 else | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
641 res = term_and_job_init(term, argvar, argv, opt, &orig_opt); |
12502 | 642 |
643 newbuf = curbuf; | |
644 if (res == OK) | |
645 { | |
646 /* Get and remember the size we ended up with. Update the pty. */ | |
647 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); | |
648 term_report_winsize(term, term->tl_rows, term->tl_cols); | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
649 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
650 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
651 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
652 /* display first line below typed command */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
653 term->tl_toprow = msg_row + 1; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
654 term->tl_dirty_row_end = 0; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
655 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
656 #endif |
12502 | 657 |
658 /* Make sure we don't get stuck on sending keys to the job, it leads to | |
659 * a deadlock if the job is waiting for Vim to read. */ | |
660 channel_set_nonblock(term->tl_job->jv_channel, PART_IN); | |
661 | |
13835
8e583c52eb44
patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13829
diff
changeset
|
662 if (old_curbuf != NULL) |
12502 | 663 { |
664 --curbuf->b_nwindows; | |
665 curbuf = old_curbuf; | |
666 curwin->w_buffer = curbuf; | |
667 ++curbuf->b_nwindows; | |
668 } | |
669 } | |
670 else | |
671 { | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
672 term_close_buffer(curbuf, old_curbuf); |
12502 | 673 return NULL; |
674 } | |
13444
9f06f7aca74c
patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
675 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
676 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf); |
12502 | 677 return newbuf; |
678 } | |
679 | |
680 /* | |
681 * ":terminal": open a terminal window and execute a job in it. | |
682 */ | |
683 void | |
684 ex_terminal(exarg_T *eap) | |
685 { | |
686 typval_T argvar[2]; | |
687 jobopt_T opt; | |
688 char_u *cmd; | |
689 char_u *tofree = NULL; | |
690 | |
691 init_job_options(&opt); | |
692 | |
693 cmd = eap->arg; | |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
694 while (*cmd == '+' && *(cmd + 1) == '+') |
12502 | 695 { |
696 char_u *p, *ep; | |
697 | |
698 cmd += 2; | |
699 p = skiptowhite(cmd); | |
700 ep = vim_strchr(cmd, '='); | |
701 if (ep != NULL && ep < p) | |
702 p = ep; | |
703 | |
704 if ((int)(p - cmd) == 5 && STRNICMP(cmd, "close", 5) == 0) | |
705 opt.jo_term_finish = 'c'; | |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
706 else if ((int)(p - cmd) == 7 && STRNICMP(cmd, "noclose", 7) == 0) |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
707 opt.jo_term_finish = 'n'; |
12502 | 708 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0) |
709 opt.jo_term_finish = 'o'; | |
710 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0) | |
711 opt.jo_curwin = 1; | |
712 else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "hidden", 6) == 0) | |
713 opt.jo_hidden = 1; | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
714 else if ((int)(p - cmd) == 9 && STRNICMP(cmd, "norestore", 9) == 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
715 opt.jo_term_norestore = 1; |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
716 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "kill", 4) == 0 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
717 && ep != NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
718 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
719 opt.jo_set2 |= JO2_TERM_KILL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
720 opt.jo_term_kill = ep + 1; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
721 p = skiptowhite(cmd); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
722 } |
12502 | 723 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "rows", 4) == 0 |
724 && ep != NULL && isdigit(ep[1])) | |
725 { | |
726 opt.jo_set2 |= JO2_TERM_ROWS; | |
727 opt.jo_term_rows = atoi((char *)ep + 1); | |
728 p = skiptowhite(cmd); | |
729 } | |
730 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "cols", 4) == 0 | |
731 && ep != NULL && isdigit(ep[1])) | |
732 { | |
733 opt.jo_set2 |= JO2_TERM_COLS; | |
734 opt.jo_term_cols = atoi((char *)ep + 1); | |
735 p = skiptowhite(cmd); | |
736 } | |
737 else if ((int)(p - cmd) == 3 && STRNICMP(cmd, "eof", 3) == 0 | |
738 && ep != NULL) | |
739 { | |
740 char_u *buf = NULL; | |
741 char_u *keys; | |
742 | |
743 p = skiptowhite(cmd); | |
744 *p = NUL; | |
745 keys = replace_termcodes(ep + 1, &buf, TRUE, TRUE, TRUE); | |
746 opt.jo_set2 |= JO2_EOF_CHARS; | |
747 opt.jo_eof_chars = vim_strsave(keys); | |
748 vim_free(buf); | |
749 *p = ' '; | |
750 } | |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
751 #ifdef WIN3264 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
752 else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "type", 4) == 0 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
753 && ep != NULL) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
754 { |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
755 int tty_type = NUL; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
756 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
757 p = skiptowhite(cmd); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
758 if (STRNICMP(ep + 1, "winpty", p - (ep + 1)) == 0) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
759 tty_type = 'w'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
760 else if (STRNICMP(ep + 1, "conpty", p - (ep + 1)) == 0) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
761 tty_type = 'c'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
762 else |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
763 { |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
764 semsg(e_invargval, "type"); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
765 goto theend; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
766 } |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
767 opt.jo_set2 |= JO2_TTY_TYPE; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
768 opt.jo_tty_type = tty_type; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
769 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
770 #endif |
12502 | 771 else |
772 { | |
773 if (*p) | |
774 *p = NUL; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
775 semsg(_("E181: Invalid attribute: %s"), cmd); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
776 goto theend; |
12502 | 777 } |
778 cmd = skipwhite(p); | |
779 } | |
780 if (*cmd == NUL) | |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
781 { |
12502 | 782 /* Make a copy of 'shell', an autocommand may change the option. */ |
783 tofree = cmd = vim_strsave(p_sh); | |
784 | |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
785 /* default to close when the shell exits */ |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
786 if (opt.jo_term_finish == NUL) |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
787 opt.jo_term_finish = 'c'; |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
788 } |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
789 |
12502 | 790 if (eap->addr_count > 0) |
791 { | |
792 /* Write lines from current buffer to the job. */ | |
793 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; | |
794 opt.jo_io[PART_IN] = JIO_BUFFER; | |
795 opt.jo_io_buf[PART_IN] = curbuf->b_fnum; | |
796 opt.jo_in_top = eap->line1; | |
797 opt.jo_in_bot = eap->line2; | |
798 } | |
799 | |
800 argvar[0].v_type = VAR_STRING; | |
801 argvar[0].vval.v_string = cmd; | |
802 argvar[1].v_type = VAR_UNKNOWN; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
803 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0); |
12502 | 804 vim_free(tofree); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
805 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
806 theend: |
12502 | 807 vim_free(opt.jo_eof_chars); |
808 } | |
809 | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
810 #if defined(FEAT_SESSION) || defined(PROTO) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
811 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
812 * Write a :terminal command to the session file to restore the terminal in |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
813 * window "wp". |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
814 * Return FAIL if writing fails. |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
815 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
816 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
817 term_write_session(FILE *fd, win_T *wp) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
818 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
819 term_T *term = wp->w_buffer->b_term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
820 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
821 /* Create the terminal and run the command. This is not without |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
822 * risk, but let's assume the user only creates a session when this |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
823 * will be OK. */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
824 if (fprintf(fd, "terminal ++curwin ++cols=%d ++rows=%d ", |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
825 term->tl_cols, term->tl_rows) < 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
826 return FAIL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
827 #ifdef WIN3264 |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
828 if (fprintf(fd, "++type=%s ", term->tl_job->jv_tty_type) < 0) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
829 return FAIL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
830 #endif |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
831 if (term->tl_command != NULL && fputs((char *)term->tl_command, fd) < 0) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
832 return FAIL; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
833 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
834 return put_eol(fd); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
835 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
836 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
837 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
838 * Return TRUE if "buf" has a terminal that should be restored. |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
839 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
840 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
841 term_should_restore(buf_T *buf) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
842 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
843 term_T *term = buf->b_term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
844 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
845 return term != NULL && (term->tl_command == NULL |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
846 || STRCMP(term->tl_command, "NONE") != 0); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
847 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
848 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
849 |
12502 | 850 /* |
851 * Free the scrollback buffer for "term". | |
852 */ | |
853 static void | |
854 free_scrollback(term_T *term) | |
855 { | |
856 int i; | |
857 | |
858 for (i = 0; i < term->tl_scrollback.ga_len; ++i) | |
859 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); | |
860 ga_clear(&term->tl_scrollback); | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
861 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
862 vim_free(((sb_line_T *)term->tl_scrollback_postponed.ga_data + i)->sb_cells); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
863 ga_clear(&term->tl_scrollback_postponed); |
12502 | 864 } |
865 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
866 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
867 // Terminals that need to be freed soon. |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
868 term_T *terminals_to_free = NULL; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
869 |
12502 | 870 /* |
871 * Free a terminal and everything it refers to. | |
872 * Kills the job if there is one. | |
873 * Called when wiping out a buffer. | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
874 * The actual terminal structure is freed later in free_unused_terminals(), |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
875 * because callbacks may wipe out a buffer while the terminal is still |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
876 * referenced. |
12502 | 877 */ |
878 void | |
879 free_terminal(buf_T *buf) | |
880 { | |
881 term_T *term = buf->b_term; | |
882 term_T *tp; | |
883 | |
884 if (term == NULL) | |
885 return; | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
886 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
887 // Unlink the terminal form the list of terminals. |
12502 | 888 if (first_term == term) |
889 first_term = term->tl_next; | |
890 else | |
891 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next) | |
892 if (tp->tl_next == term) | |
893 { | |
894 tp->tl_next = term->tl_next; | |
895 break; | |
896 } | |
897 | |
898 if (term->tl_job != NULL) | |
899 { | |
900 if (term->tl_job->jv_status != JOB_ENDED | |
901 && 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
|
902 && term->tl_job->jv_status != JOB_FAILED) |
12502 | 903 job_stop(term->tl_job, NULL, "kill"); |
904 job_unref(term->tl_job); | |
905 } | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
906 term->tl_next = terminals_to_free; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
907 terminals_to_free = term; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
908 |
12502 | 909 buf->b_term = NULL; |
910 if (in_terminal_loop == term) | |
911 in_terminal_loop = NULL; | |
912 } | |
913 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
914 void |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
915 free_unused_terminals() |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
916 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
917 while (terminals_to_free != NULL) |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
918 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
919 term_T *term = terminals_to_free; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
920 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
921 terminals_to_free = term->tl_next; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
922 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
923 free_scrollback(term); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
924 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
925 term_free_vterm(term); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
926 vim_free(term->tl_title); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
927 #ifdef FEAT_SESSION |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
928 vim_free(term->tl_command); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
929 #endif |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
930 vim_free(term->tl_kill); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
931 vim_free(term->tl_status_text); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
932 vim_free(term->tl_opencmd); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
933 vim_free(term->tl_eof_chars); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
934 vim_free(term->tl_arg0_cmd); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
935 #ifdef WIN3264 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
936 if (term->tl_out_fd != NULL) |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
937 fclose(term->tl_out_fd); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
938 #endif |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
939 vim_free(term->tl_cursor_color); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
940 vim_free(term); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
941 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
942 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
943 |
12502 | 944 /* |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
945 * 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
|
946 * 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
|
947 * 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
|
948 */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
949 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
|
950 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
|
951 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
952 #ifdef UNIX |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
953 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
|
954 int i; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
955 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
956 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
|
957 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
958 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
|
959 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
960 if (mch_isatty(fd)) |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
961 return parts[i]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
962 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
963 #endif |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
964 return PART_IN; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
965 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
966 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
967 /* |
12502 | 968 * Write job output "msg[len]" to the vterm. |
969 */ | |
970 static void | |
971 term_write_job_output(term_T *term, char_u *msg, size_t len) | |
972 { | |
973 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
|
974 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
|
975 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
976 vterm_input_write(vterm, (char *)msg, len); |
12502 | 977 |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
978 /* 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
|
979 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
|
980 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
981 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
|
982 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
|
983 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
984 if (curlen > 0) |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
985 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
|
986 (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
|
987 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
988 |
12502 | 989 /* this invokes the damage callbacks */ |
990 vterm_screen_flush_damage(vterm_obtain_screen(vterm)); | |
991 } | |
992 | |
993 static void | |
994 update_cursor(term_T *term, int redraw) | |
995 { | |
996 if (term->tl_normal_mode) | |
997 return; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
998 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
999 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1000 windgoto(term->tl_cursor_pos.row + term->tl_toprow, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1001 term->tl_cursor_pos.col); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1002 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1003 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1004 setcursor(); |
12502 | 1005 if (redraw) |
1006 { | |
1007 if (term->tl_buffer == curbuf && term->tl_cursor_visible) | |
1008 cursor_on(); | |
1009 out_flush(); | |
1010 #ifdef FEAT_GUI | |
1011 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
|
1012 { |
12502 | 1013 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
|
1014 gui_mch_flush(); |
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1015 } |
12502 | 1016 #endif |
1017 } | |
1018 } | |
1019 | |
1020 /* | |
1021 * Invoked when "msg" output from a job was received. Write it to the terminal | |
1022 * of "buffer". | |
1023 */ | |
1024 void | |
1025 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel) | |
1026 { | |
1027 size_t len = STRLEN(msg); | |
1028 term_T *term = buffer->b_term; | |
1029 | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1030 #ifdef WIN3264 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1031 /* Win32: Cannot redirect output of the job, intercept it here and write to |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1032 * the file. */ |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1033 if (term->tl_out_fd != NULL) |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1034 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1035 ch_log(channel, "Writing %d bytes to output file", (int)len); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1036 fwrite(msg, len, 1, term->tl_out_fd); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1037 return; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1038 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1039 #endif |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1040 |
12502 | 1041 if (term->tl_vterm == NULL) |
1042 { | |
1043 ch_log(channel, "NOT writing %d bytes to terminal", (int)len); | |
1044 return; | |
1045 } | |
1046 ch_log(channel, "writing %d bytes to terminal", (int)len); | |
1047 term_write_job_output(term, msg, len); | |
1048 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1049 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1050 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1051 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1052 /* show system output, scrolling up the screen as needed */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1053 update_system_term(term); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1054 update_cursor(term, TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1055 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1056 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1057 #endif |
12502 | 1058 /* In Terminal-Normal mode we are displaying the buffer, not the terminal |
1059 * contents, thus no screen update is needed. */ | |
1060 if (!term->tl_normal_mode) | |
1061 { | |
14117
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1062 // Don't use update_screen() when editing the command line, it gets |
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1063 // cleared. |
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1064 // TODO: only update once in a while. |
12502 | 1065 ch_log(term->tl_job->jv_channel, "updating screen"); |
14117
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1066 if (buffer == curbuf && (State & CMDLINE) == 0) |
12502 | 1067 { |
14117
08b0b6d6cbe7
patch 8.1.0076: command getting cleared with CTRL-W : in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14109
diff
changeset
|
1068 update_screen(VALID_NO_UPDATE); |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1069 /* update_screen() can be slow, check the terminal wasn't closed |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1070 * already */ |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1071 if (buffer == curbuf && curbuf->b_term != NULL) |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1072 update_cursor(curbuf->b_term, TRUE); |
12502 | 1073 } |
1074 else | |
1075 redraw_after_callback(TRUE); | |
1076 } | |
1077 } | |
1078 | |
1079 /* | |
1080 * Send a mouse position and click to the vterm | |
1081 */ | |
1082 static int | |
1083 term_send_mouse(VTerm *vterm, int button, int pressed) | |
1084 { | |
1085 VTermModifier mod = VTERM_MOD_NONE; | |
1086 | |
1087 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
|
1088 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
|
1089 if (button != 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1090 vterm_mouse_button(vterm, button, pressed, mod); |
12502 | 1091 return TRUE; |
1092 } | |
1093 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1094 static int enter_mouse_col = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1095 static int enter_mouse_row = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1096 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1097 /* |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1098 * Handle a mouse click, drag or release. |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1099 * Return TRUE when a mouse event is sent to the terminal. |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1100 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1101 static int |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1102 term_mouse_click(VTerm *vterm, int key) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1103 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1104 #if defined(FEAT_CLIPBOARD) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1105 /* For modeless selection mouse drag and release events are ignored, unless |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1106 * they are preceded with a mouse down event */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1107 static int ignore_drag_release = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1108 VTermMouseState mouse_state; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1109 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1110 vterm_state_get_mousestate(vterm_obtain_state(vterm), &mouse_state); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1111 if (mouse_state.flags == 0) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1112 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1113 /* Terminal is not using the mouse, use modeless selection. */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1114 switch (key) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1115 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1116 case K_LEFTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1117 case K_LEFTRELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1118 case K_RIGHTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1119 case K_RIGHTRELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1120 /* Ignore drag and release events when the button-down wasn't |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1121 * seen before. */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1122 if (ignore_drag_release) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1123 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1124 int save_mouse_col, save_mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1125 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1126 if (enter_mouse_col < 0) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1127 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1128 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1129 /* mouse click in the window gave us focus, handle that |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1130 * click now */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1131 save_mouse_col = mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1132 save_mouse_row = mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1133 mouse_col = enter_mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1134 mouse_row = enter_mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1135 clip_modeless(MOUSE_LEFT, TRUE, FALSE); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1136 mouse_col = save_mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1137 mouse_row = save_mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1138 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1139 /* FALLTHROUGH */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1140 case K_LEFTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1141 case K_RIGHTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1142 if (key == K_LEFTRELEASE || key == K_RIGHTRELEASE) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1143 ignore_drag_release = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1144 else |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1145 ignore_drag_release = FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1146 /* Should we call mouse_has() here? */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1147 if (clip_star.available) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1148 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1149 int button, is_click, is_drag; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1150 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1151 button = get_mouse_button(KEY2TERMCAP1(key), |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1152 &is_click, &is_drag); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1153 if (mouse_model_popup() && button == MOUSE_LEFT |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1154 && (mod_mask & MOD_MASK_SHIFT)) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1155 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1156 /* Translate shift-left to right button. */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1157 button = MOUSE_RIGHT; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1158 mod_mask &= ~MOD_MASK_SHIFT; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1159 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1160 clip_modeless(button, is_click, is_drag); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1161 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1162 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1163 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1164 case K_MIDDLEMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1165 if (clip_star.available) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1166 insert_reg('*', TRUE); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1167 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1168 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1169 enter_mouse_col = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1170 return FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1171 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1172 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1173 enter_mouse_col = -1; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1174 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1175 switch (key) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1176 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1177 case K_LEFTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1178 case K_LEFTMOUSE_NM: term_send_mouse(vterm, 1, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1179 case K_LEFTDRAG: term_send_mouse(vterm, 1, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1180 case K_LEFTRELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1181 case K_LEFTRELEASE_NM: term_send_mouse(vterm, 1, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1182 case K_MOUSEMOVE: term_send_mouse(vterm, 0, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1183 case K_MIDDLEMOUSE: term_send_mouse(vterm, 2, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1184 case K_MIDDLEDRAG: term_send_mouse(vterm, 2, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1185 case K_MIDDLERELEASE: term_send_mouse(vterm, 2, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1186 case K_RIGHTMOUSE: term_send_mouse(vterm, 3, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1187 case K_RIGHTDRAG: term_send_mouse(vterm, 3, 1); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1188 case K_RIGHTRELEASE: term_send_mouse(vterm, 3, 0); break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1189 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1190 return TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1191 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1192 |
12502 | 1193 /* |
1194 * Convert typed key "c" into bytes to send to the job. | |
1195 * Return the number of bytes in "buf". | |
1196 */ | |
1197 static int | |
1198 term_convert_key(term_T *term, int c, char *buf) | |
1199 { | |
1200 VTerm *vterm = term->tl_vterm; | |
1201 VTermKey key = VTERM_KEY_NONE; | |
1202 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
|
1203 int other = FALSE; |
12502 | 1204 |
1205 switch (c) | |
1206 { | |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1207 /* 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
|
1208 |
12502 | 1209 /* don't use VTERM_KEY_BACKSPACE, it always |
1210 * becomes 0x7f DEL */ | |
1211 case K_BS: c = term_backspace_char; break; | |
1212 | |
1213 case ESC: key = VTERM_KEY_ESCAPE; break; | |
1214 case K_DEL: key = VTERM_KEY_DEL; break; | |
1215 case K_DOWN: key = VTERM_KEY_DOWN; break; | |
1216 case K_S_DOWN: mod = VTERM_MOD_SHIFT; | |
1217 key = VTERM_KEY_DOWN; break; | |
1218 case K_END: key = VTERM_KEY_END; break; | |
1219 case K_S_END: mod = VTERM_MOD_SHIFT; | |
1220 key = VTERM_KEY_END; break; | |
1221 case K_C_END: mod = VTERM_MOD_CTRL; | |
1222 key = VTERM_KEY_END; break; | |
1223 case K_F10: key = VTERM_KEY_FUNCTION(10); break; | |
1224 case K_F11: key = VTERM_KEY_FUNCTION(11); break; | |
1225 case K_F12: key = VTERM_KEY_FUNCTION(12); break; | |
1226 case K_F1: key = VTERM_KEY_FUNCTION(1); break; | |
1227 case K_F2: key = VTERM_KEY_FUNCTION(2); break; | |
1228 case K_F3: key = VTERM_KEY_FUNCTION(3); break; | |
1229 case K_F4: key = VTERM_KEY_FUNCTION(4); break; | |
1230 case K_F5: key = VTERM_KEY_FUNCTION(5); break; | |
1231 case K_F6: key = VTERM_KEY_FUNCTION(6); break; | |
1232 case K_F7: key = VTERM_KEY_FUNCTION(7); break; | |
1233 case K_F8: key = VTERM_KEY_FUNCTION(8); break; | |
1234 case K_F9: key = VTERM_KEY_FUNCTION(9); break; | |
1235 case K_HOME: key = VTERM_KEY_HOME; break; | |
1236 case K_S_HOME: mod = VTERM_MOD_SHIFT; | |
1237 key = VTERM_KEY_HOME; break; | |
1238 case K_C_HOME: mod = VTERM_MOD_CTRL; | |
1239 key = VTERM_KEY_HOME; break; | |
1240 case K_INS: key = VTERM_KEY_INS; break; | |
1241 case K_K0: key = VTERM_KEY_KP_0; break; | |
1242 case K_K1: key = VTERM_KEY_KP_1; break; | |
1243 case K_K2: key = VTERM_KEY_KP_2; break; | |
1244 case K_K3: key = VTERM_KEY_KP_3; break; | |
1245 case K_K4: key = VTERM_KEY_KP_4; break; | |
1246 case K_K5: key = VTERM_KEY_KP_5; break; | |
1247 case K_K6: key = VTERM_KEY_KP_6; break; | |
1248 case K_K7: key = VTERM_KEY_KP_7; break; | |
1249 case K_K8: key = VTERM_KEY_KP_8; break; | |
1250 case K_K9: key = VTERM_KEY_KP_9; break; | |
1251 case K_KDEL: key = VTERM_KEY_DEL; break; /* TODO */ | |
1252 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break; | |
1253 case K_KEND: key = VTERM_KEY_KP_1; break; /* TODO */ | |
1254 case K_KENTER: key = VTERM_KEY_KP_ENTER; break; | |
1255 case K_KHOME: key = VTERM_KEY_KP_7; break; /* TODO */ | |
1256 case K_KINS: key = VTERM_KEY_KP_0; break; /* TODO */ | |
1257 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break; | |
1258 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break; | |
1259 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; /* TODO */ | |
1260 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; /* TODO */ | |
1261 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break; | |
1262 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break; | |
1263 case K_LEFT: key = VTERM_KEY_LEFT; break; | |
1264 case K_S_LEFT: mod = VTERM_MOD_SHIFT; | |
1265 key = VTERM_KEY_LEFT; break; | |
1266 case K_C_LEFT: mod = VTERM_MOD_CTRL; | |
1267 key = VTERM_KEY_LEFT; break; | |
1268 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break; | |
1269 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break; | |
1270 case K_RIGHT: key = VTERM_KEY_RIGHT; break; | |
1271 case K_S_RIGHT: mod = VTERM_MOD_SHIFT; | |
1272 key = VTERM_KEY_RIGHT; break; | |
1273 case K_C_RIGHT: mod = VTERM_MOD_CTRL; | |
1274 key = VTERM_KEY_RIGHT; break; | |
1275 case K_UP: key = VTERM_KEY_UP; break; | |
1276 case K_S_UP: mod = VTERM_MOD_SHIFT; | |
1277 key = VTERM_KEY_UP; break; | |
1278 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
|
1279 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
|
1280 key = VTERM_KEY_TAB; break; |
12502 | 1281 |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1282 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
|
1283 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break; |
12502 | 1284 case K_MOUSELEFT: /* TODO */ return 0; |
1285 case K_MOUSERIGHT: /* TODO */ return 0; | |
1286 | |
1287 case K_LEFTMOUSE: | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1288 case K_LEFTMOUSE_NM: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1289 case K_LEFTDRAG: |
12502 | 1290 case K_LEFTRELEASE: |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1291 case K_LEFTRELEASE_NM: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1292 case K_MOUSEMOVE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1293 case K_MIDDLEMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1294 case K_MIDDLEDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1295 case K_MIDDLERELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1296 case K_RIGHTMOUSE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1297 case K_RIGHTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1298 case K_RIGHTRELEASE: if (!term_mouse_click(vterm, c)) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1299 return 0; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1300 other = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1301 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1302 |
12502 | 1303 case K_X1MOUSE: /* TODO */ return 0; |
1304 case K_X1DRAG: /* TODO */ return 0; | |
1305 case K_X1RELEASE: /* TODO */ return 0; | |
1306 case K_X2MOUSE: /* TODO */ return 0; | |
1307 case K_X2DRAG: /* TODO */ return 0; | |
1308 case K_X2RELEASE: /* TODO */ return 0; | |
1309 | |
1310 case K_IGNORE: return 0; | |
1311 case K_NOP: return 0; | |
1312 case K_UNDO: return 0; | |
1313 case K_HELP: return 0; | |
1314 case K_XF1: key = VTERM_KEY_FUNCTION(1); break; | |
1315 case K_XF2: key = VTERM_KEY_FUNCTION(2); break; | |
1316 case K_XF3: key = VTERM_KEY_FUNCTION(3); break; | |
1317 case K_XF4: key = VTERM_KEY_FUNCTION(4); break; | |
1318 case K_SELECT: return 0; | |
1319 #ifdef FEAT_GUI | |
1320 case K_VER_SCROLLBAR: return 0; | |
1321 case K_HOR_SCROLLBAR: return 0; | |
1322 #endif | |
1323 #ifdef FEAT_GUI_TABLINE | |
1324 case K_TABLINE: return 0; | |
1325 case K_TABMENU: return 0; | |
1326 #endif | |
1327 #ifdef FEAT_NETBEANS_INTG | |
1328 case K_F21: key = VTERM_KEY_FUNCTION(21); break; | |
1329 #endif | |
1330 #ifdef FEAT_DND | |
1331 case K_DROP: return 0; | |
1332 #endif | |
1333 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
|
1334 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
|
1335 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
|
1336 break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1337 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
|
1338 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
|
1339 break; |
12502 | 1340 } |
1341 | |
1342 /* | |
1343 * Convert special keys to vterm keys: | |
1344 * - Write keys to vterm: vterm_keyboard_key() | |
1345 * - Write output to channel. | |
1346 * TODO: use mod_mask | |
1347 */ | |
1348 if (key != VTERM_KEY_NONE) | |
1349 /* Special key, let vterm convert it. */ | |
1350 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
|
1351 else if (!other) |
12502 | 1352 /* Normal character, let vterm convert it. */ |
1353 vterm_keyboard_unichar(vterm, c, mod); | |
1354 | |
1355 /* Read back the converted escape sequence. */ | |
1356 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); | |
1357 } | |
1358 | |
1359 /* | |
1360 * Return TRUE if the job for "term" is still running. | |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1361 * If "check_job_status" is TRUE update the job status. |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1362 * NOTE: "term" may be freed by callbacks. |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1363 */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1364 static int |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1365 term_job_running_check(term_T *term, int check_job_status) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1366 { |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1367 /* Also consider the job finished when the channel is closed, to avoid a |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1368 * race condition when updating the title. */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1369 if (term != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1370 && term->tl_job != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1371 && channel_is_open(term->tl_job->jv_channel)) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1372 { |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1373 job_T *job = term->tl_job; |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1374 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1375 // Careful: Checking the job status may invoked callbacks, which close |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1376 // the buffer and terminate "term". However, "job" will not be freed |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1377 // yet. |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1378 if (check_job_status) |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1379 job_status(job); |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1380 return (job->jv_status == JOB_STARTED |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1381 || (job->jv_channel != NULL && job->jv_channel->ch_keep_open)); |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1382 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1383 return FALSE; |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1384 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1385 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1386 /* |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1387 * Return TRUE if the job for "term" is still running. |
12502 | 1388 */ |
1389 int | |
1390 term_job_running(term_T *term) | |
1391 { | |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1392 return term_job_running_check(term, FALSE); |
12502 | 1393 } |
1394 | |
1395 /* | |
1396 * Return TRUE if "term" has an active channel and used ":term NONE". | |
1397 */ | |
1398 int | |
1399 term_none_open(term_T *term) | |
1400 { | |
1401 /* Also consider the job finished when the channel is closed, to avoid a | |
1402 * race condition when updating the title. */ | |
1403 return term != NULL | |
1404 && term->tl_job != NULL | |
1405 && channel_is_open(term->tl_job->jv_channel) | |
1406 && term->tl_job->jv_channel->ch_keep_open; | |
1407 } | |
1408 | |
1409 /* | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1410 * Used when exiting: kill the job in "buf" if so desired. |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1411 * Return OK when the job finished. |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1412 * Return FAIL when the job is still running. |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1413 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1414 int |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1415 term_try_stop_job(buf_T *buf) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1416 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1417 int count; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1418 char *how = (char *)buf->b_term->tl_kill; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1419 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1420 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1421 if ((how == NULL || *how == NUL) && (p_confirm || cmdmod.confirm)) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1422 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1423 char_u buff[DIALOG_MSG_SIZE]; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1424 int ret; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1425 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1426 dialog_msg(buff, _("Kill job in \"%s\"?"), buf->b_fname); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1427 ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1428 if (ret == VIM_YES) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1429 how = "kill"; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1430 else if (ret == VIM_CANCEL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1431 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1432 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1433 #endif |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1434 if (how == NULL || *how == NUL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1435 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1436 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1437 job_stop(buf->b_term->tl_job, NULL, how); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1438 |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1439 // wait for up to a second for the job to die |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1440 for (count = 0; count < 100; ++count) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1441 { |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1442 job_T *job; |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1443 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1444 // buffer, terminal and job may be cleaned up while waiting |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1445 if (!buf_valid(buf) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1446 || buf->b_term == NULL |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1447 || buf->b_term->tl_job == NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1448 return OK; |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1449 job = buf->b_term->tl_job; |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1450 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1451 // Call job_status() to update jv_status. It may cause the job to be |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1452 // cleaned up but it won't be freed. |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1453 job_status(job); |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1454 if (job->jv_status >= JOB_ENDED) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1455 return OK; |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1456 |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1457 ui_delay(10L, FALSE); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1458 mch_check_messages(); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1459 parse_queued_messages(); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1460 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1461 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1462 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1463 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1464 /* |
12502 | 1465 * Add the last line of the scrollback buffer to the buffer in the window. |
1466 */ | |
1467 static void | |
1468 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) | |
1469 { | |
1470 buf_T *buf = term->tl_buffer; | |
1471 int empty = (buf->b_ml.ml_flags & ML_EMPTY); | |
1472 linenr_T lnum = buf->b_ml.ml_line_count; | |
1473 | |
1474 #ifdef WIN3264 | |
1475 if (!enc_utf8 && enc_codepage > 0) | |
1476 { | |
1477 WCHAR *ret = NULL; | |
1478 int length = 0; | |
1479 | |
1480 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, | |
1481 &ret, &length); | |
1482 if (ret != NULL) | |
1483 { | |
1484 WideCharToMultiByte_alloc(enc_codepage, 0, | |
1485 ret, length, (char **)&text, &len, 0, 0); | |
1486 vim_free(ret); | |
1487 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); | |
1488 vim_free(text); | |
1489 } | |
1490 } | |
1491 else | |
1492 #endif | |
1493 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); | |
1494 if (empty) | |
1495 { | |
1496 /* Delete the empty line that was in the empty buffer. */ | |
1497 curbuf = buf; | |
1498 ml_delete(1, FALSE); | |
1499 curbuf = curwin->w_buffer; | |
1500 } | |
1501 } | |
1502 | |
1503 static void | |
1504 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr) | |
1505 { | |
1506 attr->width = cell->width; | |
1507 attr->attrs = cell->attrs; | |
1508 attr->fg = cell->fg; | |
1509 attr->bg = cell->bg; | |
1510 } | |
1511 | |
1512 static int | |
1513 equal_celattr(cellattr_T *a, cellattr_T *b) | |
1514 { | |
1515 /* Comparing the colors should be sufficient. */ | |
1516 return a->fg.red == b->fg.red | |
1517 && a->fg.green == b->fg.green | |
1518 && a->fg.blue == b->fg.blue | |
1519 && a->bg.red == b->bg.red | |
1520 && a->bg.green == b->bg.green | |
1521 && a->bg.blue == b->bg.blue; | |
1522 } | |
1523 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1524 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1525 * 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
|
1526 * 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
|
1527 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1528 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1529 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
|
1530 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1531 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
|
1532 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1533 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
|
1534 + 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
|
1535 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1536 if (lnum > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1537 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1538 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1539 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1540 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
|
1541 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1542 *line = *(line - 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1543 --line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1544 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1545 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1546 line->sb_cols = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1547 line->sb_cells = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1548 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
|
1549 ++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
|
1550 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1551 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1552 return FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1553 } |
12502 | 1554 |
1555 /* | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1556 * Remove the terminal contents from the scrollback and the buffer. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1557 * Used before adding a new scrollback line or updating the buffer for lines |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1558 * displayed in the terminal. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1559 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1560 static void |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1561 cleanup_scrollback(term_T *term) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1562 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1563 sb_line_T *line; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1564 garray_T *gap; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1565 |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1566 curbuf = term->tl_buffer; |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1567 gap = &term->tl_scrollback; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1568 while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1569 && gap->ga_len > 0) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1570 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1571 ml_delete(curbuf->b_ml.ml_line_count, FALSE); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1572 line = (sb_line_T *)gap->ga_data + gap->ga_len - 1; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1573 vim_free(line->sb_cells); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1574 --gap->ga_len; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1575 } |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1576 curbuf = curwin->w_buffer; |
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1577 if (curbuf == term->tl_buffer) |
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1578 check_cursor(); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1579 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1580 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1581 /* |
12502 | 1582 * Add the current lines of the terminal to scrollback and to the buffer. |
1583 */ | |
1584 static void | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1585 update_snapshot(term_T *term) |
12502 | 1586 { |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1587 VTermScreen *screen; |
12502 | 1588 int len; |
1589 int lines_skipped = 0; | |
1590 VTermPos pos; | |
1591 VTermScreenCell cell; | |
1592 cellattr_T fill_attr, new_fill_attr; | |
1593 cellattr_T *p; | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1594 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1595 ch_log(term->tl_job == NULL ? NULL : term->tl_job->jv_channel, |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1596 "Adding terminal window snapshot to buffer"); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1597 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1598 /* First remove the lines that were appended before, they might be |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1599 * outdated. */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1600 cleanup_scrollback(term); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1601 |
12502 | 1602 screen = vterm_obtain_screen(term->tl_vterm); |
1603 fill_attr = new_fill_attr = term->tl_default_color; | |
1604 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row) | |
1605 { | |
1606 len = 0; | |
1607 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | |
1608 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | |
1609 && cell.chars[0] != NUL) | |
1610 { | |
1611 len = pos.col + 1; | |
1612 new_fill_attr = term->tl_default_color; | |
1613 } | |
1614 else | |
1615 /* Assume the last attr is the filler attr. */ | |
1616 cell2cellattr(&cell, &new_fill_attr); | |
1617 | |
1618 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr)) | |
1619 ++lines_skipped; | |
1620 else | |
1621 { | |
1622 while (lines_skipped > 0) | |
1623 { | |
1624 /* Line was skipped, add an empty line. */ | |
1625 --lines_skipped; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1626 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
12502 | 1627 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
1628 } | |
1629 | |
1630 if (len == 0) | |
1631 p = NULL; | |
1632 else | |
1633 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len); | |
1634 if ((p != NULL || len == 0) | |
1635 && ga_grow(&term->tl_scrollback, 1) == OK) | |
1636 { | |
1637 garray_T ga; | |
1638 int width; | |
1639 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | |
1640 + term->tl_scrollback.ga_len; | |
1641 | |
1642 ga_init2(&ga, 1, 100); | |
1643 for (pos.col = 0; pos.col < len; pos.col += width) | |
1644 { | |
1645 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
1646 { | |
1647 width = 1; | |
1648 vim_memset(p + pos.col, 0, sizeof(cellattr_T)); | |
1649 if (ga_grow(&ga, 1) == OK) | |
1650 ga.ga_len += utf_char2bytes(' ', | |
1651 (char_u *)ga.ga_data + ga.ga_len); | |
1652 } | |
1653 else | |
1654 { | |
1655 width = cell.width; | |
1656 | |
1657 cell2cellattr(&cell, &p[pos.col]); | |
1658 | |
15203
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1659 // Each character can be up to 6 bytes. |
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1660 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK) |
12502 | 1661 { |
1662 int i; | |
1663 int c; | |
1664 | |
1665 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) | |
1666 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
1667 (char_u *)ga.ga_data + ga.ga_len); | |
1668 } | |
1669 } | |
1670 } | |
1671 line->sb_cols = len; | |
1672 line->sb_cells = p; | |
1673 line->sb_fill_attr = new_fill_attr; | |
1674 fill_attr = new_fill_attr; | |
1675 ++term->tl_scrollback.ga_len; | |
1676 | |
1677 if (ga_grow(&ga, 1) == FAIL) | |
1678 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
1679 else | |
1680 { | |
1681 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
1682 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
1683 } | |
1684 ga_clear(&ga); | |
1685 } | |
1686 else | |
1687 vim_free(p); | |
1688 } | |
1689 } | |
1690 | |
15022
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1691 // Add trailing empty lines. |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1692 for (pos.row = term->tl_scrollback.ga_len; |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1693 pos.row < term->tl_scrollback_scrolled + term->tl_cursor_pos.row; |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1694 ++pos.row) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1695 { |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1696 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1697 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1698 } |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1699 |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1700 term->tl_dirty_snapshot = FALSE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1701 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1702 term->tl_timer_set = FALSE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1703 #endif |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1704 } |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1705 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1706 /* |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1707 * If needed, add the current lines of the terminal to scrollback and to the |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1708 * buffer. Called after the job has ended and when switching to |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1709 * Terminal-Normal mode. |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1710 * When "redraw" is TRUE redraw the windows that show the terminal. |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1711 */ |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1712 static void |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1713 may_move_terminal_to_buffer(term_T *term, int redraw) |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1714 { |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1715 win_T *wp; |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1716 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1717 if (term->tl_vterm == NULL) |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1718 return; |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1719 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1720 /* Update the snapshot only if something changes or the buffer does not |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1721 * have all the lines. */ |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1722 if (term->tl_dirty_snapshot || term->tl_buffer->b_ml.ml_line_count |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1723 <= term->tl_scrollback_scrolled) |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1724 update_snapshot(term); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1725 |
12502 | 1726 /* Obtain the current background color. */ |
1727 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), | |
1728 &term->tl_default_color.fg, &term->tl_default_color.bg); | |
1729 | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1730 if (redraw) |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1731 FOR_ALL_WINDOWS(wp) |
12502 | 1732 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1733 if (wp->w_buffer == term->tl_buffer) |
12502 | 1734 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1735 wp->w_cursor.lnum = term->tl_buffer->b_ml.ml_line_count; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1736 wp->w_cursor.col = 0; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1737 wp->w_valid = 0; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1738 if (wp->w_cursor.lnum >= wp->w_height) |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1739 { |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1740 linenr_T min_topline = wp->w_cursor.lnum - wp->w_height + 1; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1741 |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1742 if (wp->w_topline < min_topline) |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1743 wp->w_topline = min_topline; |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1744 } |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1745 redraw_win_later(wp, NOT_VALID); |
12502 | 1746 } |
1747 } | |
1748 } | |
1749 | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1750 #if defined(FEAT_TIMERS) || defined(PROTO) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1751 /* |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1752 * Check if any terminal timer expired. If so, copy text from the terminal to |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1753 * the buffer. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1754 * Return the time until the next timer will expire. |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1755 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1756 int |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1757 term_check_timers(int next_due_arg, proftime_T *now) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1758 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1759 term_T *term; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1760 int next_due = next_due_arg; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1761 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1762 for (term = first_term; term != NULL; term = term->tl_next) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1763 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1764 if (term->tl_timer_set && !term->tl_normal_mode) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1765 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1766 long this_due = proftime_time_left(&term->tl_timer_due, now); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1767 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1768 if (this_due <= 1) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1769 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1770 term->tl_timer_set = FALSE; |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1771 may_move_terminal_to_buffer(term, FALSE); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1772 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1773 else if (next_due == -1 || next_due > this_due) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1774 next_due = this_due; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1775 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1776 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1777 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1778 return next_due; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1779 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1780 #endif |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1781 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1782 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1783 * When "normal_mode" is TRUE set the terminal to Terminal-Normal mode, |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1784 * otherwise end it. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1785 */ |
12502 | 1786 static void |
1787 set_terminal_mode(term_T *term, int normal_mode) | |
1788 { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1789 ch_log(NULL, "set_terminal_mode(): %d", normal_mode); |
12502 | 1790 term->tl_normal_mode = normal_mode; |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1791 if (!normal_mode) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1792 handle_postponed_scrollback(term); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
1793 VIM_CLEAR(term->tl_status_text); |
12502 | 1794 if (term->tl_buffer == curbuf) |
1795 maketitle(); | |
1796 } | |
1797 | |
1798 /* | |
1799 * Called after the job if finished and Terminal mode is not active: | |
1800 * Move the vterm contents into the scrollback buffer and free the vterm. | |
1801 */ | |
1802 static void | |
1803 cleanup_vterm(term_T *term) | |
1804 { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
1805 set_terminal_mode(term, FALSE); |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
1806 if (term->tl_finish != TL_FINISH_CLOSE) |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1807 may_move_terminal_to_buffer(term, TRUE); |
12502 | 1808 term_free_vterm(term); |
1809 } | |
1810 | |
1811 /* | |
1812 * Switch from Terminal-Job mode to Terminal-Normal mode. | |
1813 * Suspends updating the terminal window. | |
1814 */ | |
1815 static void | |
1816 term_enter_normal_mode(void) | |
1817 { | |
1818 term_T *term = curbuf->b_term; | |
1819 | |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1820 set_terminal_mode(term, TRUE); |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1821 |
12502 | 1822 /* Append the current terminal contents to the buffer. */ |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1823 may_move_terminal_to_buffer(term, TRUE); |
12502 | 1824 |
1825 /* Move the window cursor to the position of the cursor in the | |
1826 * terminal. */ | |
1827 curwin->w_cursor.lnum = term->tl_scrollback_scrolled | |
1828 + term->tl_cursor_pos.row + 1; | |
1829 check_cursor(); | |
13935
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
1830 if (coladvance(term->tl_cursor_pos.col) == FAIL) |
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
1831 coladvance(MAXCOL); |
12502 | 1832 |
1833 /* Display the same lines as in the terminal. */ | |
1834 curwin->w_topline = term->tl_scrollback_scrolled + 1; | |
1835 } | |
1836 | |
1837 /* | |
1838 * Returns TRUE if the current window contains a terminal and we are in | |
1839 * Terminal-Normal mode. | |
1840 */ | |
1841 int | |
1842 term_in_normal_mode(void) | |
1843 { | |
1844 term_T *term = curbuf->b_term; | |
1845 | |
1846 return term != NULL && term->tl_normal_mode; | |
1847 } | |
1848 | |
1849 /* | |
1850 * Switch from Terminal-Normal mode to Terminal-Job mode. | |
1851 * Restores updating the terminal window. | |
1852 */ | |
1853 void | |
1854 term_enter_job_mode() | |
1855 { | |
1856 term_T *term = curbuf->b_term; | |
1857 | |
1858 set_terminal_mode(term, FALSE); | |
1859 | |
1860 if (term->tl_channel_closed) | |
1861 cleanup_vterm(term); | |
1862 redraw_buf_and_status_later(curbuf, NOT_VALID); | |
1863 } | |
1864 | |
1865 /* | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
1866 * Get a key from the user with terminal mode mappings. |
12502 | 1867 * Note: while waiting a terminal may be closed and freed if the channel is |
1868 * closed and ++close was used. | |
1869 */ | |
1870 static int | |
1871 term_vgetc() | |
1872 { | |
1873 int c; | |
1874 int save_State = State; | |
1875 | |
1876 State = TERMINAL; | |
1877 got_int = FALSE; | |
1878 #ifdef WIN3264 | |
1879 ctrl_break_was_pressed = FALSE; | |
1880 #endif | |
1881 c = vgetc(); | |
1882 got_int = FALSE; | |
1883 State = save_State; | |
1884 return c; | |
1885 } | |
1886 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1887 static int mouse_was_outside = FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1888 |
12502 | 1889 /* |
1890 * Send keys to terminal. | |
1891 * Return FAIL when the key needs to be handled in Normal mode. | |
1892 * Return OK when the key was dropped or sent to the terminal. | |
1893 */ | |
1894 int | |
1895 send_keys_to_term(term_T *term, int c, int typed) | |
1896 { | |
1897 char msg[KEY_BUF_LEN]; | |
1898 size_t len; | |
1899 int dragging_outside = FALSE; | |
1900 | |
1901 /* Catch keys that need to be handled as in Normal mode. */ | |
1902 switch (c) | |
1903 { | |
1904 case NUL: | |
1905 case K_ZERO: | |
1906 if (typed) | |
1907 stuffcharReadbuff(c); | |
1908 return FAIL; | |
1909 | |
13849
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
1910 case K_TABLINE: |
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
1911 stuffcharReadbuff(c); |
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
1912 return FAIL; |
58b6982ca049
patch 8.0.1796: GUI: click on tab fails when the focus is in a terminal
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
1913 |
12502 | 1914 case K_IGNORE: |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
1915 case K_CANCEL: // used for :normal when running out of chars |
12502 | 1916 return FAIL; |
1917 | |
1918 case K_LEFTDRAG: | |
1919 case K_MIDDLEDRAG: | |
1920 case K_RIGHTDRAG: | |
1921 case K_X1DRAG: | |
1922 case K_X2DRAG: | |
1923 dragging_outside = mouse_was_outside; | |
1924 /* FALLTHROUGH */ | |
1925 case K_LEFTMOUSE: | |
1926 case K_LEFTMOUSE_NM: | |
1927 case K_LEFTRELEASE: | |
1928 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
|
1929 case K_MOUSEMOVE: |
12502 | 1930 case K_MIDDLEMOUSE: |
1931 case K_MIDDLERELEASE: | |
1932 case K_RIGHTMOUSE: | |
1933 case K_RIGHTRELEASE: | |
1934 case K_X1MOUSE: | |
1935 case K_X1RELEASE: | |
1936 case K_X2MOUSE: | |
1937 case K_X2RELEASE: | |
1938 | |
1939 case K_MOUSEUP: | |
1940 case K_MOUSEDOWN: | |
1941 case K_MOUSELEFT: | |
1942 case K_MOUSERIGHT: | |
1943 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
|
1944 || 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
|
1945 || 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
|
1946 || mouse_col >= W_ENDCOL(curwin) |
12502 | 1947 || dragging_outside) |
1948 { | |
12984
fc0d4a036654
patch 8.0.1368: cannot drag status or separator of new terminal window
Christian Brabandt <cb@256bit.org>
parents:
12973
diff
changeset
|
1949 /* 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
|
1950 * or vertical separator */ |
12502 | 1951 if (typed) |
1952 { | |
1953 stuffcharReadbuff(c); | |
1954 mouse_was_outside = TRUE; | |
1955 } | |
1956 return FAIL; | |
1957 } | |
1958 } | |
1959 if (typed) | |
1960 mouse_was_outside = FALSE; | |
1961 | |
1962 /* Convert the typed key to a sequence of bytes for the job. */ | |
1963 len = term_convert_key(term, c, msg); | |
1964 if (len > 0) | |
1965 /* TODO: if FAIL is returned, stop? */ | |
1966 channel_send(term->tl_job->jv_channel, get_tty_part(term), | |
1967 (char_u *)msg, (int)len, NULL); | |
1968 | |
1969 return OK; | |
1970 } | |
1971 | |
1972 static void | |
1973 position_cursor(win_T *wp, VTermPos *pos) | |
1974 { | |
1975 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); | |
1976 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1)); | |
1977 wp->w_valid |= (VALID_WCOL|VALID_WROW); | |
1978 } | |
1979 | |
1980 /* | |
1981 * Handle CTRL-W "": send register contents to the job. | |
1982 */ | |
1983 static void | |
1984 term_paste_register(int prev_c UNUSED) | |
1985 { | |
1986 int c; | |
1987 list_T *l; | |
1988 listitem_T *item; | |
1989 long reglen = 0; | |
1990 int type; | |
1991 | |
1992 #ifdef FEAT_CMDL_INFO | |
1993 if (add_to_showcmd(prev_c)) | |
1994 if (add_to_showcmd('"')) | |
1995 out_flush(); | |
1996 #endif | |
1997 c = term_vgetc(); | |
1998 #ifdef FEAT_CMDL_INFO | |
1999 clear_showcmd(); | |
2000 #endif | |
2001 if (!term_use_loop()) | |
2002 /* job finished while waiting for a character */ | |
2003 return; | |
2004 | |
2005 /* CTRL-W "= prompt for expression to evaluate. */ | |
2006 if (c == '=' && get_expr_register() != '=') | |
2007 return; | |
2008 if (!term_use_loop()) | |
2009 /* job finished while waiting for a character */ | |
2010 return; | |
2011 | |
2012 l = (list_T *)get_reg_contents(c, GREG_LIST); | |
2013 if (l != NULL) | |
2014 { | |
2015 type = get_reg_type(c, ®len); | |
2016 for (item = l->lv_first; item != NULL; item = item->li_next) | |
2017 { | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
2018 char_u *s = tv_get_string(&item->li_tv); |
12502 | 2019 #ifdef WIN3264 |
2020 char_u *tmp = s; | |
2021 | |
2022 if (!enc_utf8 && enc_codepage > 0) | |
2023 { | |
2024 WCHAR *ret = NULL; | |
2025 int length = 0; | |
2026 | |
2027 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s, | |
2028 (int)STRLEN(s), &ret, &length); | |
2029 if (ret != NULL) | |
2030 { | |
2031 WideCharToMultiByte_alloc(CP_UTF8, 0, | |
2032 ret, length, (char **)&s, &length, 0, 0); | |
2033 vim_free(ret); | |
2034 } | |
2035 } | |
2036 #endif | |
2037 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2038 s, (int)STRLEN(s), NULL); | |
2039 #ifdef WIN3264 | |
2040 if (tmp != s) | |
2041 vim_free(s); | |
2042 #endif | |
2043 | |
2044 if (item->li_next != NULL || type == MLINE) | |
2045 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2046 (char_u *)"\r", 1, NULL); | |
2047 } | |
2048 list_free(l); | |
2049 } | |
2050 } | |
2051 | |
2052 /* | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2053 * Return TRUE when waiting for a character in the terminal, the cursor of the |
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2054 * terminal should be displayed. |
12502 | 2055 */ |
2056 int | |
2057 terminal_is_active() | |
2058 { | |
2059 return in_terminal_loop != NULL; | |
2060 } | |
2061 | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2062 #if defined(FEAT_GUI) || defined(PROTO) |
12502 | 2063 cursorentry_T * |
2064 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) | |
2065 { | |
2066 term_T *term = in_terminal_loop; | |
2067 static cursorentry_T entry; | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2068 int id; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2069 guicolor_T term_fg, term_bg; |
12502 | 2070 |
2071 vim_memset(&entry, 0, sizeof(entry)); | |
2072 entry.shape = entry.mshape = | |
2073 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : | |
2074 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : | |
2075 SHAPE_BLOCK; | |
2076 entry.percentage = 20; | |
2077 if (term->tl_cursor_blink) | |
2078 { | |
2079 entry.blinkwait = 700; | |
2080 entry.blinkon = 400; | |
2081 entry.blinkoff = 250; | |
2082 } | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2083 |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2084 /* The "Terminal" highlight group overrules the defaults. */ |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2085 id = syn_name2id((char_u *)"Terminal"); |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2086 if (id != 0) |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2087 { |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2088 syn_id2colors(id, &term_fg, &term_bg); |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2089 *fg = term_bg; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2090 } |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2091 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2092 *fg = gui.back_pixel; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2093 |
12502 | 2094 if (term->tl_cursor_color == NULL) |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2095 { |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2096 if (id != 0) |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2097 *bg = term_fg; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2098 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2099 *bg = gui.norm_pixel; |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2100 } |
12502 | 2101 else |
2102 *bg = color_name2handle(term->tl_cursor_color); | |
2103 entry.name = "n"; | |
2104 entry.used_for = SHAPE_CURSOR; | |
2105 | |
2106 return &entry; | |
2107 } | |
2108 #endif | |
2109 | |
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
|
2110 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
|
2111 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
|
2112 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2113 if (!cursor_color_equal(last_set_cursor_color, desired_cursor_color) |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2114 || 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
|
2115 || 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
|
2116 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2117 cursor_color_copy(&last_set_cursor_color, desired_cursor_color); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2118 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
|
2119 last_set_cursor_blink = desired_cursor_blink; |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2120 term_cursor_color(cursor_color_get(desired_cursor_color)); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2121 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
|
2122 /* 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
|
2123 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
|
2124 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
|
2125 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
|
2126 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2127 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2128 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2129 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2130 * 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
|
2131 */ |
12502 | 2132 static void |
2133 may_set_cursor_props(term_T *term) | |
2134 { | |
2135 #ifdef FEAT_GUI | |
2136 /* For the GUI the cursor properties are obtained with | |
2137 * term_get_cursor_shape(). */ | |
2138 if (gui.in_use) | |
2139 return; | |
2140 #endif | |
2141 if (in_terminal_loop == term) | |
2142 { | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2143 cursor_color_copy(&desired_cursor_color, term->tl_cursor_color); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2144 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
|
2145 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
|
2146 may_output_cursor_props(); |
12502 | 2147 } |
2148 } | |
2149 | |
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
|
2150 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2151 * 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
|
2152 */ |
12502 | 2153 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
|
2154 prepare_restore_cursor_props(void) |
12502 | 2155 { |
2156 #ifdef FEAT_GUI | |
2157 if (gui.in_use) | |
2158 return; | |
2159 #endif | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2160 cursor_color_copy(&desired_cursor_color, NULL); |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2161 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
|
2162 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
|
2163 may_output_cursor_props(); |
12502 | 2164 } |
2165 | |
2166 /* | |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2167 * Returns TRUE if the current window contains a terminal and we are sending |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2168 * keys to the job. |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2169 * If "check_job_status" is TRUE update the job status. |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2170 */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2171 static int |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2172 term_use_loop_check(int check_job_status) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2173 { |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2174 term_T *term = curbuf->b_term; |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2175 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2176 return term != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2177 && !term->tl_normal_mode |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2178 && term->tl_vterm != NULL |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2179 && term_job_running_check(term, check_job_status); |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2180 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2181 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2182 /* |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2183 * Returns TRUE if the current window contains a terminal and we are sending |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2184 * keys to the job. |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2185 */ |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2186 int |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2187 term_use_loop(void) |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2188 { |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2189 return term_use_loop_check(FALSE); |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2190 } |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2191 |
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2192 /* |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2193 * Called when entering a window with the mouse. If this is a terminal window |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2194 * we may want to change state. |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2195 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2196 void |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2197 term_win_entered() |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2198 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2199 term_T *term = curbuf->b_term; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2200 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2201 if (term != NULL) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2202 { |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
2203 if (term_use_loop_check(TRUE)) |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2204 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2205 reset_VIsual_and_resel(); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2206 if (State & INSERT) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2207 stop_insert_mode = TRUE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2208 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2209 mouse_was_outside = FALSE; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2210 enter_mouse_col = mouse_col; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2211 enter_mouse_row = mouse_row; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2212 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2213 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2214 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2215 /* |
12502 | 2216 * Wait for input and send it to the job. |
2217 * When "blocking" is TRUE wait for a character to be typed. Otherwise return | |
2218 * when there is no more typahead. | |
2219 * Return when the start of a CTRL-W command is typed or anything else that | |
2220 * should be handled as a Normal mode command. | |
2221 * Returns OK if a typed character is to be handled in Normal mode, FAIL if | |
2222 * the terminal was closed. | |
2223 */ | |
2224 int | |
2225 terminal_loop(int blocking) | |
2226 { | |
2227 int c; | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2228 int termwinkey = 0; |
12502 | 2229 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
|
2230 #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
|
2231 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
|
2232 ->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
|
2233 #endif |
13906
0ae89b121c58
patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents:
13900
diff
changeset
|
2234 int restore_cursor = FALSE; |
12502 | 2235 |
2236 /* Remember the terminal we are sending keys to. However, the terminal | |
2237 * might be closed while waiting for a character, e.g. typing "exit" in a | |
2238 * shell and ++close was used. Therefore use curbuf->b_term instead of a | |
2239 * stored reference. */ | |
2240 in_terminal_loop = curbuf->b_term; | |
2241 | |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2242 if (*curwin->w_p_twk != NUL) |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2243 { |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2244 termwinkey = string_to_key(curwin->w_p_twk, TRUE); |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2245 if (termwinkey == Ctrl_W) |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2246 termwinkey = 0; |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2247 } |
12502 | 2248 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos); |
2249 may_set_cursor_props(curbuf->b_term); | |
2250 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2251 while (blocking || vpeekc_nomap() != NUL) |
12502 | 2252 { |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2253 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2254 if (!curbuf->b_term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2255 #endif |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2256 // TODO: skip screen update when handling a sequence of keys. |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2257 // Repeat redrawing in case a message is received while redrawing. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2258 while (must_redraw != 0) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2259 if (update_screen(0) == FAIL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2260 break; |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2261 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term) |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2262 /* job finished while redrawing */ |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2263 break; |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2264 |
12502 | 2265 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
|
2266 restore_cursor = TRUE; |
12502 | 2267 |
2268 c = term_vgetc(); | |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2269 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term) |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2270 { |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2271 /* 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
|
2272 * 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
|
2273 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
|
2274 vungetc(c); |
12502 | 2275 break; |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2276 } |
12502 | 2277 if (c == K_IGNORE) |
2278 continue; | |
2279 | |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2280 #ifdef UNIX |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2281 /* |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2282 * 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
|
2283 * 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
|
2284 * 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
|
2285 */ |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2286 if (mch_isatty(tty_fd)) |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2287 { |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2288 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
|
2289 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2290 /* 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
|
2291 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
|
2292 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
|
2293 } |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2294 #endif |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2295 |
12502 | 2296 #ifdef WIN3264 |
2297 /* On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT. | |
2298 * Use CTRL-BREAK to kill the job. */ | |
2299 if (ctrl_break_was_pressed) | |
2300 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
2301 #endif | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2302 /* Was either CTRL-W (termwinkey) or CTRL-\ pressed? |
13474
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2303 * Not in a system terminal. */ |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2304 if ((c == (termwinkey == 0 ? Ctrl_W : termwinkey) || c == Ctrl_BSL) |
13474
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2305 #ifdef FEAT_GUI |
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2306 && !curbuf->b_term->tl_system |
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2307 #endif |
8a8daeb057d1
patch 8.0.1611: CTRL-W in system terminal does not go to job
Christian Brabandt <cb@256bit.org>
parents:
13472
diff
changeset
|
2308 ) |
12502 | 2309 { |
2310 int prev_c = c; | |
2311 | |
2312 #ifdef FEAT_CMDL_INFO | |
2313 if (add_to_showcmd(c)) | |
2314 out_flush(); | |
2315 #endif | |
2316 c = term_vgetc(); | |
2317 #ifdef FEAT_CMDL_INFO | |
2318 clear_showcmd(); | |
2319 #endif | |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2320 if (!term_use_loop_check(TRUE) |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2321 || in_terminal_loop != curbuf->b_term) |
12502 | 2322 /* job finished while waiting for a character */ |
2323 break; | |
2324 | |
2325 if (prev_c == Ctrl_BSL) | |
2326 { | |
2327 if (c == Ctrl_N) | |
2328 { | |
2329 /* CTRL-\ CTRL-N : go to Terminal-Normal mode. */ | |
2330 term_enter_normal_mode(); | |
2331 ret = FAIL; | |
2332 goto theend; | |
2333 } | |
2334 /* Send both keys to the terminal. */ | |
2335 send_keys_to_term(curbuf->b_term, prev_c, TRUE); | |
2336 } | |
2337 else if (c == Ctrl_C) | |
2338 { | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2339 /* "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job */ |
12502 | 2340 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); |
2341 } | |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2342 else if (c == '.') |
12502 | 2343 { |
2344 /* "CTRL-W .": send CTRL-W to the job */ | |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2345 /* "'termwinkey' .": send 'termwinkey' to the job */ |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2346 c = termwinkey == 0 ? Ctrl_W : termwinkey; |
12502 | 2347 } |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2348 else if (c == Ctrl_BSL) |
13668
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2349 { |
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2350 /* "CTRL-W CTRL-\": send CTRL-\ to the job */ |
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2351 c = Ctrl_BSL; |
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2352 } |
12502 | 2353 else if (c == 'N') |
2354 { | |
2355 /* CTRL-W N : go to Terminal-Normal mode. */ | |
2356 term_enter_normal_mode(); | |
2357 ret = FAIL; | |
2358 goto theend; | |
2359 } | |
2360 else if (c == '"') | |
2361 { | |
2362 term_paste_register(prev_c); | |
2363 continue; | |
2364 } | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2365 else if (termwinkey == 0 || c != termwinkey) |
12502 | 2366 { |
2367 stuffcharReadbuff(Ctrl_W); | |
2368 stuffcharReadbuff(c); | |
2369 ret = OK; | |
2370 goto theend; | |
2371 } | |
2372 } | |
2373 # ifdef WIN3264 | |
2374 if (!enc_utf8 && has_mbyte && c >= 0x80) | |
2375 { | |
2376 WCHAR wc; | |
2377 char_u mb[3]; | |
2378 | |
2379 mb[0] = (unsigned)c >> 8; | |
2380 mb[1] = c; | |
2381 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0) | |
2382 c = wc; | |
2383 } | |
2384 # endif | |
2385 if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK) | |
2386 { | |
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
|
2387 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
|
2388 /* 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
|
2389 * 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
|
2390 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
|
2391 |
12502 | 2392 ret = OK; |
2393 goto theend; | |
2394 } | |
2395 } | |
2396 ret = FAIL; | |
2397 | |
2398 theend: | |
2399 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
|
2400 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
|
2401 prepare_restore_cursor_props(); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2402 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2403 /* Move a snapshot of the screen contents to the buffer, so that completion |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2404 * works in other buffers. */ |
13935
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
2405 if (curbuf->b_term != NULL && !curbuf->b_term->tl_normal_mode) |
cc25795aeec6
patch 8.0.1838: cursor in wrong pos when switching to Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13919
diff
changeset
|
2406 may_move_terminal_to_buffer(curbuf->b_term, FALSE); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2407 |
12502 | 2408 return ret; |
2409 } | |
2410 | |
2411 static void | |
2412 may_toggle_cursor(term_T *term) | |
2413 { | |
2414 if (in_terminal_loop == term) | |
2415 { | |
2416 if (term->tl_cursor_visible) | |
2417 cursor_on(); | |
2418 else | |
2419 cursor_off(); | |
2420 } | |
2421 } | |
2422 | |
2423 /* | |
2424 * 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
|
2425 * First color is 1. Return 0 if no match found (default color). |
12502 | 2426 */ |
2427 static int | |
2428 color2index(VTermColor *color, int fg, int *boldp) | |
2429 { | |
2430 int red = color->red; | |
2431 int blue = color->blue; | |
2432 int green = color->green; | |
2433 | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2434 if (color->ansi_index != VTERM_ANSI_INDEX_NONE) |
12502 | 2435 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2436 /* 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
|
2437 * 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
|
2438 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
|
2439 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
|
2440 switch (color->ansi_index) |
12502 | 2441 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2442 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
|
2443 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
|
2444 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
|
2445 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
|
2446 case 4: return lookup_color( 6, fg, boldp) + 1; /* brown */ |
13668
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2447 case 5: return lookup_color( 1, fg, boldp) + 1; /* dark blue */ |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2448 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
|
2449 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
|
2450 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
|
2451 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
|
2452 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
|
2453 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
|
2454 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
|
2455 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
|
2456 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
|
2457 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
|
2458 case 16: return lookup_color(26, fg, boldp) + 1; /* white */ |
12502 | 2459 } |
2460 } | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2461 |
12502 | 2462 if (t_colors >= 256) |
2463 { | |
2464 if (red == blue && red == green) | |
2465 { | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2466 /* 24-color greyscale plus white and black */ |
12502 | 2467 static int cutoff[23] = { |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2468 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
|
2469 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
|
2470 0xD5, 0xDF, 0xE9}; |
12502 | 2471 int i; |
2472 | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2473 if (red < 5) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2474 return 17; /* 00/00/00 */ |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2475 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
|
2476 return 232; |
12502 | 2477 for (i = 0; i < 23; ++i) |
2478 if (red < cutoff[i]) | |
2479 return i + 233; | |
2480 return 256; | |
2481 } | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2482 { |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2483 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
|
2484 int ri, gi, bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2485 |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2486 /* 216-color cube */ |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2487 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
|
2488 if (red < cutoff[ri]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2489 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2490 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
|
2491 if (green < cutoff[gi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2492 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2493 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
|
2494 if (blue < cutoff[bi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2495 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2496 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
|
2497 } |
12502 | 2498 } |
2499 return 0; | |
2500 } | |
2501 | |
2502 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2503 * Convert Vterm attributes to highlight flags. |
12502 | 2504 */ |
2505 static int | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2506 vtermAttr2hl(VTermScreenCellAttrs cellattrs) |
12502 | 2507 { |
2508 int attr = 0; | |
2509 | |
2510 if (cellattrs.bold) | |
2511 attr |= HL_BOLD; | |
2512 if (cellattrs.underline) | |
2513 attr |= HL_UNDERLINE; | |
2514 if (cellattrs.italic) | |
2515 attr |= HL_ITALIC; | |
2516 if (cellattrs.strike) | |
2517 attr |= HL_STRIKETHROUGH; | |
2518 if (cellattrs.reverse) | |
2519 attr |= HL_INVERSE; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2520 return attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2521 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2522 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2523 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2524 * 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
|
2525 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2526 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2527 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
|
2528 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2529 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
|
2530 if (attr & HL_BOLD) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2531 cell->attrs.bold = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2532 if (attr & HL_UNDERLINE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2533 cell->attrs.underline = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2534 if (attr & HL_ITALIC) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2535 cell->attrs.italic = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2536 if (attr & HL_STRIKETHROUGH) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2537 cell->attrs.strike = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2538 if (attr & HL_INVERSE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2539 cell->attrs.reverse = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2540 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2541 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2542 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2543 * 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
|
2544 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2545 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2546 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
|
2547 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2548 int attr = vtermAttr2hl(cellattrs); |
12502 | 2549 |
2550 #ifdef FEAT_GUI | |
2551 if (gui.in_use) | |
2552 { | |
2553 guicolor_T fg, bg; | |
2554 | |
2555 fg = gui_mch_get_rgb_color(cellfg.red, cellfg.green, cellfg.blue); | |
2556 bg = gui_mch_get_rgb_color(cellbg.red, cellbg.green, cellbg.blue); | |
2557 return get_gui_attr_idx(attr, fg, bg); | |
2558 } | |
2559 else | |
2560 #endif | |
2561 #ifdef FEAT_TERMGUICOLORS | |
2562 if (p_tgc) | |
2563 { | |
2564 guicolor_T fg, bg; | |
2565 | |
2566 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue); | |
2567 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue); | |
2568 | |
2569 return get_tgc_attr_idx(attr, fg, bg); | |
2570 } | |
2571 else | |
2572 #endif | |
2573 { | |
2574 int bold = MAYBE; | |
2575 int fg = color2index(&cellfg, TRUE, &bold); | |
2576 int bg = color2index(&cellbg, FALSE, &bold); | |
2577 | |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2578 /* 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
|
2579 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
|
2580 { |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
2581 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
|
2582 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
|
2583 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
|
2584 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
|
2585 } |
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2586 |
12502 | 2587 /* with 8 colors set the bold attribute to get a bright foreground */ |
2588 if (bold == TRUE) | |
2589 attr |= HL_BOLD; | |
2590 return get_cterm_attr_idx(attr, fg, bg); | |
2591 } | |
2592 return 0; | |
2593 } | |
2594 | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2595 static void |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2596 set_dirty_snapshot(term_T *term) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2597 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2598 term->tl_dirty_snapshot = TRUE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2599 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2600 if (!term->tl_normal_mode) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2601 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2602 /* Update the snapshot after 100 msec of not getting updates. */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2603 profile_setlimit(100L, &term->tl_timer_due); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2604 term->tl_timer_set = TRUE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2605 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2606 #endif |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2607 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2608 |
12502 | 2609 static int |
2610 handle_damage(VTermRect rect, void *user) | |
2611 { | |
2612 term_T *term = (term_T *)user; | |
2613 | |
2614 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row); | |
2615 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row); | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2616 set_dirty_snapshot(term); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2617 redraw_buf_later(term->tl_buffer, SOME_VALID); |
12502 | 2618 return 1; |
2619 } | |
2620 | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2621 static void |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2622 term_scroll_up(term_T *term, int start_row, int count) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2623 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2624 win_T *wp; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2625 VTermColor fg, bg; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2626 VTermScreenCellAttrs attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2627 int clear_attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2628 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2629 /* Set the color to clear lines with. */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2630 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2631 &fg, &bg); |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2632 vim_memset(&attr, 0, sizeof(attr)); |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2633 clear_attr = cell2attr(attr, fg, bg); |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2634 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2635 FOR_ALL_WINDOWS(wp) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2636 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2637 if (wp->w_buffer == term->tl_buffer) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2638 win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr); |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2639 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2640 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2641 |
12502 | 2642 static int |
2643 handle_moverect(VTermRect dest, VTermRect src, void *user) | |
2644 { | |
2645 term_T *term = (term_T *)user; | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2646 int count = src.start_row - dest.start_row; |
12502 | 2647 |
2648 /* Scrolling up is done much more efficiently by deleting lines instead of | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2649 * redrawing the text. But avoid doing this multiple times, postpone until |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2650 * the redraw happens. */ |
12502 | 2651 if (dest.start_col == src.start_col |
2652 && dest.end_col == src.end_col | |
2653 && dest.start_row < src.start_row) | |
2654 { | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2655 if (dest.start_row == 0) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2656 term->tl_postponed_scroll += count; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2657 else |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2658 term_scroll_up(term, dest.start_row, count); |
12502 | 2659 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2660 |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2661 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
|
2662 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2663 set_dirty_snapshot(term); |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
2664 |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2665 /* Note sure if the scrolling will work correctly, let's do a complete |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2666 * redraw later. */ |
12502 | 2667 redraw_buf_later(term->tl_buffer, NOT_VALID); |
2668 return 1; | |
2669 } | |
2670 | |
2671 static int | |
2672 handle_movecursor( | |
2673 VTermPos pos, | |
2674 VTermPos oldpos UNUSED, | |
2675 int visible, | |
2676 void *user) | |
2677 { | |
2678 term_T *term = (term_T *)user; | |
2679 win_T *wp; | |
2680 | |
2681 term->tl_cursor_pos = pos; | |
2682 term->tl_cursor_visible = visible; | |
2683 | |
2684 FOR_ALL_WINDOWS(wp) | |
2685 { | |
2686 if (wp->w_buffer == term->tl_buffer) | |
2687 position_cursor(wp, &pos); | |
2688 } | |
2689 if (term->tl_buffer == curbuf && !term->tl_normal_mode) | |
2690 { | |
2691 may_toggle_cursor(term); | |
2692 update_cursor(term, term->tl_cursor_visible); | |
2693 } | |
2694 | |
2695 return 1; | |
2696 } | |
2697 | |
2698 static int | |
2699 handle_settermprop( | |
2700 VTermProp prop, | |
2701 VTermValue *value, | |
2702 void *user) | |
2703 { | |
2704 term_T *term = (term_T *)user; | |
2705 | |
2706 switch (prop) | |
2707 { | |
2708 case VTERM_PROP_TITLE: | |
2709 vim_free(term->tl_title); | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2710 // a blank title isn't useful, make it empty, so that "running" is |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2711 // displayed |
12502 | 2712 if (*skipwhite((char_u *)value->string) == NUL) |
2713 term->tl_title = NULL; | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2714 // Same as blank |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2715 else if (term->tl_arg0_cmd != NULL |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2716 && STRNCMP(term->tl_arg0_cmd, (char_u *)value->string, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2717 (int)STRLEN(term->tl_arg0_cmd)) == 0) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2718 term->tl_title = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2719 // Empty corrupted data of winpty |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2720 else if (STRNCMP(" - ", (char_u *)value->string, 4) == 0) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
2721 term->tl_title = NULL; |
12502 | 2722 #ifdef WIN3264 |
2723 else if (!enc_utf8 && enc_codepage > 0) | |
2724 { | |
2725 WCHAR *ret = NULL; | |
2726 int length = 0; | |
2727 | |
2728 MultiByteToWideChar_alloc(CP_UTF8, 0, | |
2729 (char*)value->string, (int)STRLEN(value->string), | |
2730 &ret, &length); | |
2731 if (ret != NULL) | |
2732 { | |
2733 WideCharToMultiByte_alloc(enc_codepage, 0, | |
2734 ret, length, (char**)&term->tl_title, | |
2735 &length, 0, 0); | |
2736 vim_free(ret); | |
2737 } | |
2738 } | |
2739 #endif | |
2740 else | |
2741 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
|
2742 VIM_CLEAR(term->tl_status_text); |
12502 | 2743 if (term == curbuf->b_term) |
2744 maketitle(); | |
2745 break; | |
2746 | |
2747 case VTERM_PROP_CURSORVISIBLE: | |
2748 term->tl_cursor_visible = value->boolean; | |
2749 may_toggle_cursor(term); | |
2750 out_flush(); | |
2751 break; | |
2752 | |
2753 case VTERM_PROP_CURSORBLINK: | |
2754 term->tl_cursor_blink = value->boolean; | |
2755 may_set_cursor_props(term); | |
2756 break; | |
2757 | |
2758 case VTERM_PROP_CURSORSHAPE: | |
2759 term->tl_cursor_shape = value->number; | |
2760 may_set_cursor_props(term); | |
2761 break; | |
2762 | |
2763 case VTERM_PROP_CURSORCOLOR: | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2764 cursor_color_copy(&term->tl_cursor_color, (char_u*)value->string); |
12502 | 2765 may_set_cursor_props(term); |
2766 break; | |
2767 | |
2768 case VTERM_PROP_ALTSCREEN: | |
2769 /* TODO: do anything else? */ | |
2770 term->tl_using_altscreen = value->boolean; | |
2771 break; | |
2772 | |
2773 default: | |
2774 break; | |
2775 } | |
2776 /* Always return 1, otherwise vterm doesn't store the value internally. */ | |
2777 return 1; | |
2778 } | |
2779 | |
2780 /* | |
2781 * The job running in the terminal resized the terminal. | |
2782 */ | |
2783 static int | |
2784 handle_resize(int rows, int cols, void *user) | |
2785 { | |
2786 term_T *term = (term_T *)user; | |
2787 win_T *wp; | |
2788 | |
2789 term->tl_rows = rows; | |
2790 term->tl_cols = cols; | |
2791 if (term->tl_vterm_size_changed) | |
2792 /* Size was set by vterm_set_size(), don't set the window size. */ | |
2793 term->tl_vterm_size_changed = FALSE; | |
2794 else | |
2795 { | |
2796 FOR_ALL_WINDOWS(wp) | |
2797 { | |
2798 if (wp->w_buffer == term->tl_buffer) | |
2799 { | |
2800 win_setheight_win(rows, wp); | |
2801 win_setwidth_win(cols, wp); | |
2802 } | |
2803 } | |
2804 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
2805 } | |
2806 return 1; | |
2807 } | |
2808 | |
2809 /* | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2810 * If the number of lines that are stored goes over 'termscrollback' then |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2811 * delete the first 10%. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2812 * "gap" points to tl_scrollback or tl_scrollback_postponed. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2813 * "update_buffer" is TRUE when the buffer should be updated. |
12502 | 2814 */ |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2815 static void |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2816 limit_scrollback(term_T *term, garray_T *gap, int update_buffer) |
12502 | 2817 { |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2818 if (gap->ga_len >= term->tl_buffer->b_p_twsl) |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2819 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2820 int todo = term->tl_buffer->b_p_twsl / 10; |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2821 int i; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2822 |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2823 curbuf = term->tl_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2824 for (i = 0; i < todo; ++i) |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2825 { |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2826 vim_free(((sb_line_T *)gap->ga_data + i)->sb_cells); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2827 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2828 ml_delete(1, FALSE); |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2829 } |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2830 curbuf = curwin->w_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
2831 |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2832 gap->ga_len -= todo; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2833 mch_memmove(gap->ga_data, |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2834 (sb_line_T *)gap->ga_data + todo, |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2835 sizeof(sb_line_T) * gap->ga_len); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2836 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2837 term->tl_scrollback_scrolled -= todo; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2838 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2839 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2840 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2841 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2842 * Handle a line that is pushed off the top of the screen. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2843 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2844 static int |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2845 handle_pushline(int cols, const VTermScreenCell *cells, void *user) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2846 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2847 term_T *term = (term_T *)user; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2848 garray_T *gap; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2849 int update_buffer; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2850 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2851 if (term->tl_normal_mode) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2852 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2853 // In Terminal-Normal mode the user interacts with the buffer, thus we |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2854 // must not change it. Postpone adding the scrollback lines. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2855 gap = &term->tl_scrollback_postponed; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2856 update_buffer = FALSE; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2857 ch_log(NULL, "handle_pushline(): add to postponed"); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2858 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2859 else |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2860 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2861 // First remove the lines that were appended before, the pushed line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2862 // goes above it. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2863 cleanup_scrollback(term); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2864 gap = &term->tl_scrollback; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2865 update_buffer = TRUE; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2866 ch_log(NULL, "handle_pushline(): add to window"); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2867 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2868 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2869 limit_scrollback(term, gap, update_buffer); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2870 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2871 if (ga_grow(gap, 1) == OK) |
12502 | 2872 { |
2873 cellattr_T *p = NULL; | |
2874 int len = 0; | |
2875 int i; | |
2876 int c; | |
2877 int col; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2878 int text_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2879 char_u *text; |
12502 | 2880 sb_line_T *line; |
2881 garray_T ga; | |
2882 cellattr_T fill_attr = term->tl_default_color; | |
2883 | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2884 // do not store empty cells at the end |
12502 | 2885 for (i = 0; i < cols; ++i) |
2886 if (cells[i].chars[0] != 0) | |
2887 len = i + 1; | |
2888 else | |
2889 cell2cellattr(&cells[i], &fill_attr); | |
2890 | |
2891 ga_init2(&ga, 1, 100); | |
2892 if (len > 0) | |
2893 p = (cellattr_T *)alloc((int)sizeof(cellattr_T) * len); | |
2894 if (p != NULL) | |
2895 { | |
2896 for (col = 0; col < len; col += cells[col].width) | |
2897 { | |
2898 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | |
2899 { | |
2900 ga.ga_len = 0; | |
2901 break; | |
2902 } | |
2903 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i) | |
2904 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
2905 (char_u *)ga.ga_data + ga.ga_len); | |
2906 cell2cellattr(&cells[col], &p[col]); | |
2907 } | |
2908 } | |
2909 if (ga_grow(&ga, 1) == FAIL) | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2910 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2911 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2912 text = (char_u *)""; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2913 else |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2914 text = vim_strsave((char_u *)""); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2915 text_len = 0; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2916 } |
12502 | 2917 else |
2918 { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2919 text = ga.ga_data; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2920 text_len = ga.ga_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2921 *(text + text_len) = NUL; |
12502 | 2922 } |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2923 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2924 add_scrollback_line_to_buffer(term, text, text_len); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2925 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2926 line = (sb_line_T *)gap->ga_data + gap->ga_len; |
12502 | 2927 line->sb_cols = len; |
2928 line->sb_cells = p; | |
2929 line->sb_fill_attr = fill_attr; | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2930 if (update_buffer) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2931 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2932 line->sb_text = NULL; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2933 ++term->tl_scrollback_scrolled; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2934 ga_clear(&ga); // free the text |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2935 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2936 else |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2937 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2938 line->sb_text = text; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2939 ga_init(&ga); // text is kept in tl_scrollback_postponed |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2940 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2941 ++gap->ga_len; |
12502 | 2942 } |
2943 return 0; /* ignored */ | |
2944 } | |
2945 | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2946 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2947 * Called when leaving Terminal-Normal mode: deal with any scrollback that was |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2948 * received and stored in tl_scrollback_postponed. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2949 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2950 static void |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2951 handle_postponed_scrollback(term_T *term) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2952 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2953 int i; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2954 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2955 ch_log(NULL, "Moving postponed scrollback to scrollback"); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2956 // First remove the lines that were appended before, the pushed lines go |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2957 // above it. |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2958 cleanup_scrollback(term); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2959 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2960 for (i = 0; i < term->tl_scrollback_postponed.ga_len; ++i) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2961 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2962 char_u *text; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2963 sb_line_T *pp_line; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2964 sb_line_T *line; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2965 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2966 if (ga_grow(&term->tl_scrollback, 1) == FAIL) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2967 break; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2968 pp_line = (sb_line_T *)term->tl_scrollback_postponed.ga_data + i; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2969 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2970 text = pp_line->sb_text; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2971 if (text == NULL) |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2972 text = (char_u *)""; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2973 add_scrollback_line_to_buffer(term, text, (int)STRLEN(text)); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2974 vim_free(pp_line->sb_text); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2975 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2976 line = (sb_line_T *)term->tl_scrollback.ga_data |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2977 + term->tl_scrollback.ga_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2978 line->sb_cols = pp_line->sb_cols; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2979 line->sb_cells = pp_line->sb_cells; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2980 line->sb_fill_attr = pp_line->sb_fill_attr; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2981 line->sb_text = NULL; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2982 ++term->tl_scrollback_scrolled; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2983 ++term->tl_scrollback.ga_len; |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2984 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2985 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2986 ga_clear(&term->tl_scrollback_postponed); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2987 limit_scrollback(term, &term->tl_scrollback, TRUE); |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2988 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2989 |
12502 | 2990 static VTermScreenCallbacks screen_callbacks = { |
2991 handle_damage, /* damage */ | |
2992 handle_moverect, /* moverect */ | |
2993 handle_movecursor, /* movecursor */ | |
2994 handle_settermprop, /* settermprop */ | |
2995 NULL, /* bell */ | |
2996 handle_resize, /* resize */ | |
2997 handle_pushline, /* sb_pushline */ | |
2998 NULL /* sb_popline */ | |
2999 }; | |
3000 | |
3001 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3002 * Do the work after the channel of a terminal was closed. |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3003 * Must be called only when updating_screen is FALSE. |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3004 * Returns TRUE when a buffer was closed (list of terminals may have changed). |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3005 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3006 static int |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3007 term_after_channel_closed(term_T *term) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3008 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3009 /* Unless in Terminal-Normal mode: clear the vterm. */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3010 if (!term->tl_normal_mode) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3011 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3012 int fnum = term->tl_buffer->b_fnum; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3013 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3014 cleanup_vterm(term); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3015 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3016 if (term->tl_finish == TL_FINISH_CLOSE) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3017 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3018 aco_save_T aco; |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3019 int do_set_w_closing = term->tl_buffer->b_nwindows == 0; |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3020 |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3021 // ++close or term_finish == "close" |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3022 ch_log(NULL, "terminal job finished, closing window"); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3023 aucmd_prepbuf(&aco, term->tl_buffer); |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3024 // Avoid closing the window if we temporarily use it. |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3025 if (do_set_w_closing) |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3026 curwin->w_closing = TRUE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3027 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE); |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3028 if (do_set_w_closing) |
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3029 curwin->w_closing = FALSE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3030 aucmd_restbuf(&aco); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3031 return TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3032 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3033 if (term->tl_finish == TL_FINISH_OPEN |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3034 && term->tl_buffer->b_nwindows == 0) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3035 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3036 char buf[50]; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3037 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3038 /* TODO: use term_opencmd */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3039 ch_log(NULL, "terminal job finished, opening window"); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3040 vim_snprintf(buf, sizeof(buf), |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3041 term->tl_opencmd == NULL |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3042 ? "botright sbuf %d" |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3043 : (char *)term->tl_opencmd, fnum); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3044 do_cmdline_cmd((char_u *)buf); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3045 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3046 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3047 ch_log(NULL, "terminal job finished"); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3048 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3049 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3050 redraw_buf_and_status_later(term->tl_buffer, NOT_VALID); |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3051 return FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3052 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3053 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3054 /* |
12502 | 3055 * Called when a channel has been closed. |
3056 * If this was a channel for a terminal window then finish it up. | |
3057 */ | |
3058 void | |
3059 term_channel_closed(channel_T *ch) | |
3060 { | |
3061 term_T *term; | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3062 term_T *next_term; |
12502 | 3063 int did_one = FALSE; |
3064 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3065 for (term = first_term; term != NULL; term = next_term) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3066 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3067 next_term = term->tl_next; |
12502 | 3068 if (term->tl_job == ch->ch_job) |
3069 { | |
3070 term->tl_channel_closed = TRUE; | |
3071 did_one = TRUE; | |
3072 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3073 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
|
3074 VIM_CLEAR(term->tl_status_text); |
13862
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3075 #ifdef WIN3264 |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3076 if (term->tl_out_fd != NULL) |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3077 { |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3078 fclose(term->tl_out_fd); |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3079 term->tl_out_fd = NULL; |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3080 } |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3081 #endif |
12502 | 3082 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3083 if (updating_screen) |
12502 | 3084 { |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3085 /* Cannot open or close windows now. Can happen when |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3086 * 'lazyredraw' is set. */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3087 term->tl_channel_recently_closed = TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3088 continue; |
12502 | 3089 } |
3090 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3091 if (term_after_channel_closed(term)) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3092 next_term = first_term; |
12502 | 3093 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3094 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3095 |
12502 | 3096 if (did_one) |
3097 { | |
3098 redraw_statuslines(); | |
3099 | |
3100 /* Need to break out of vgetc(). */ | |
3101 ins_char_typebuf(K_IGNORE); | |
3102 typebuf_was_filled = TRUE; | |
3103 | |
3104 term = curbuf->b_term; | |
3105 if (term != NULL) | |
3106 { | |
3107 if (term->tl_job == ch->ch_job) | |
3108 maketitle(); | |
3109 update_cursor(term, term->tl_cursor_visible); | |
3110 } | |
3111 } | |
3112 } | |
3113 | |
3114 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3115 * To be called after resetting updating_screen: handle any terminal where the |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3116 * channel was closed. |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3117 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3118 void |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3119 term_check_channel_closed_recently() |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3120 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3121 term_T *term; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3122 term_T *next_term; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3123 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3124 for (term = first_term; term != NULL; term = next_term) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3125 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3126 next_term = term->tl_next; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3127 if (term->tl_channel_recently_closed) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3128 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3129 term->tl_channel_recently_closed = FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3130 if (term_after_channel_closed(term)) |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3131 // start over, the list may have changed |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3132 next_term = first_term; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3133 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3134 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3135 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3136 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3137 /* |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3138 * Fill one screen line from a line of the terminal. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3139 * Advances "pos" to past the last column. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3140 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3141 static void |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3142 term_line2screenline(VTermScreen *screen, VTermPos *pos, int max_col) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3143 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3144 int off = screen_get_current_line_off(); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3145 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3146 for (pos->col = 0; pos->col < max_col; ) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3147 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3148 VTermScreenCell cell; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3149 int c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3150 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3151 if (vterm_screen_get_cell(screen, *pos, &cell) == 0) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3152 vim_memset(&cell, 0, sizeof(cell)); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3153 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3154 c = cell.chars[0]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3155 if (c == NUL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3156 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3157 ScreenLines[off] = ' '; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3158 if (enc_utf8) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3159 ScreenLinesUC[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3160 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3161 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3162 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3163 if (enc_utf8) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3164 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3165 int i; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3166 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3167 /* composing chars */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3168 for (i = 0; i < Screen_mco |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3169 && i + 1 < VTERM_MAX_CHARS_PER_CELL; ++i) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3170 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3171 ScreenLinesC[i][off] = cell.chars[i + 1]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3172 if (cell.chars[i + 1] == 0) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3173 break; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3174 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3175 if (c >= 0x80 || (Screen_mco > 0 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3176 && ScreenLinesC[0][off] != 0)) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3177 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3178 ScreenLines[off] = ' '; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3179 ScreenLinesUC[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3180 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3181 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3182 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3183 ScreenLines[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3184 ScreenLinesUC[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3185 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3186 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3187 #ifdef WIN3264 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3188 else if (has_mbyte && c >= 0x80) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3189 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3190 char_u mb[MB_MAXBYTES+1]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3191 WCHAR wc = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3192 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3193 if (WideCharToMultiByte(GetACP(), 0, &wc, 1, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3194 (char*)mb, 2, 0, 0) > 1) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3195 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3196 ScreenLines[off] = mb[0]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3197 ScreenLines[off + 1] = mb[1]; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3198 cell.width = mb_ptr2cells(mb); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3199 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3200 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3201 ScreenLines[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3202 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3203 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3204 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3205 ScreenLines[off] = c; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3206 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3207 ScreenAttrs[off] = cell2attr(cell.attrs, cell.fg, cell.bg); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3208 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3209 ++pos->col; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3210 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3211 if (cell.width == 2) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3212 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3213 if (enc_utf8) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3214 ScreenLinesUC[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3215 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3216 /* don't set the second byte to NUL for a DBCS encoding, it |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3217 * has been set above */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3218 if (enc_utf8 || !has_mbyte) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3219 ScreenLines[off] = NUL; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3220 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3221 ++pos->col; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3222 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3223 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3224 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3225 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3226 |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3227 #if defined(FEAT_GUI) |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3228 static void |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3229 update_system_term(term_T *term) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3230 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3231 VTermPos pos; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3232 VTermScreen *screen; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3233 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3234 if (term->tl_vterm == NULL) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3235 return; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3236 screen = vterm_obtain_screen(term->tl_vterm); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3237 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3238 /* Scroll up to make more room for terminal lines if needed. */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3239 while (term->tl_toprow > 0 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3240 && (Rows - term->tl_toprow) < term->tl_dirty_row_end) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3241 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3242 int save_p_more = p_more; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3243 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3244 p_more = FALSE; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3245 msg_row = Rows - 1; |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
3246 msg_puts("\n"); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3247 p_more = save_p_more; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3248 --term->tl_toprow; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3249 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3250 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3251 for (pos.row = term->tl_dirty_row_start; pos.row < term->tl_dirty_row_end |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3252 && pos.row < Rows; ++pos.row) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3253 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3254 if (pos.row < term->tl_rows) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3255 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3256 int max_col = MIN(Columns, term->tl_cols); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3257 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3258 term_line2screenline(screen, &pos, max_col); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3259 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3260 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3261 pos.col = 0; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3262 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3263 screen_line(term->tl_toprow + pos.row, 0, pos.col, Columns, FALSE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3264 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3265 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3266 term->tl_dirty_row_start = MAX_ROW; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3267 term->tl_dirty_row_end = 0; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3268 update_cursor(term, TRUE); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3269 } |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3270 #endif |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3271 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3272 /* |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3273 * Return TRUE if window "wp" is to be redrawn with term_update_window(). |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3274 * Returns FALSE when there is no terminal running in this window or it is in |
12502 | 3275 * Terminal-Normal mode. |
3276 */ | |
3277 int | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3278 term_do_update_window(win_T *wp) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3279 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3280 term_T *term = wp->w_buffer->b_term; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3281 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3282 return term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3283 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3284 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3285 /* |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3286 * Called to update a window that contains an active terminal. |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3287 */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3288 void |
12502 | 3289 term_update_window(win_T *wp) |
3290 { | |
3291 term_T *term = wp->w_buffer->b_term; | |
3292 VTerm *vterm; | |
3293 VTermScreen *screen; | |
3294 VTermState *state; | |
3295 VTermPos pos; | |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3296 int rows, cols; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3297 int newrows, newcols; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3298 int minsize; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3299 win_T *twp; |
12502 | 3300 |
3301 vterm = term->tl_vterm; | |
3302 screen = vterm_obtain_screen(vterm); | |
3303 state = vterm_obtain_state(vterm); | |
3304 | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3305 /* We use NOT_VALID on a resize or scroll, redraw everything then. With |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3306 * SOME_VALID only redraw what was marked dirty. */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3307 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
|
3308 { |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3309 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
|
3310 term->tl_dirty_row_end = MAX_ROW; |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3311 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3312 if (term->tl_postponed_scroll > 0 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3313 && term->tl_postponed_scroll < term->tl_rows / 3) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3314 /* Scrolling is usually faster than redrawing, when there are only |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3315 * a few lines to scroll. */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3316 term_scroll_up(term, 0, term->tl_postponed_scroll); |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3317 term->tl_postponed_scroll = 0; |
12590
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3318 } |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3319 |
12502 | 3320 /* |
3321 * If the window was resized a redraw will be triggered and we get here. | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3322 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size. |
12502 | 3323 */ |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3324 minsize = parse_termwinsize(wp, &rows, &cols); |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3325 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3326 newrows = 99999; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3327 newcols = 99999; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3328 FOR_ALL_WINDOWS(twp) |
12502 | 3329 { |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3330 /* When more than one window shows the same terminal, use the |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3331 * smallest size. */ |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3332 if (twp->w_buffer == term->tl_buffer) |
12502 | 3333 { |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3334 newrows = MIN(newrows, twp->w_height); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3335 newcols = MIN(newcols, twp->w_width); |
12502 | 3336 } |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3337 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3338 newrows = rows == 0 ? newrows : minsize ? MAX(rows, newrows) : rows; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3339 newcols = cols == 0 ? newcols : minsize ? MAX(cols, newcols) : cols; |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3340 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3341 if (term->tl_rows != newrows || term->tl_cols != newcols) |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3342 { |
12502 | 3343 term->tl_vterm_size_changed = TRUE; |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3344 vterm_set_size(vterm, newrows, newcols); |
12502 | 3345 ch_log(term->tl_job->jv_channel, "Resizing terminal to %d lines", |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3346 newrows); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3347 term_report_winsize(term, newrows, newcols); |
14311
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3348 |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3349 // Updating the terminal size will cause the snapshot to be cleared. |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3350 // When not in terminal_loop() we need to restore it. |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3351 if (term != in_terminal_loop) |
83b870d9ac4b
patch 8.1.0171: typing CTRL-W n in a terminal window causes ml_get error
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
3352 may_move_terminal_to_buffer(term, FALSE); |
12502 | 3353 } |
3354 | |
3355 /* The cursor may have been moved when resizing. */ | |
3356 vterm_state_get_cursorpos(state, &pos); | |
3357 position_cursor(wp, &pos); | |
3358 | |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3359 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
|
3360 && pos.row < wp->w_height; ++pos.row) |
12502 | 3361 { |
3362 if (pos.row < term->tl_rows) | |
3363 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3364 int max_col = MIN(wp->w_width, term->tl_cols); |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3365 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3366 term_line2screenline(screen, &pos, max_col); |
12502 | 3367 } |
3368 else | |
3369 pos.col = 0; | |
3370 | |
13458
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3371 screen_line(wp->w_winrow + pos.row |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3372 #ifdef FEAT_MENU |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3373 + winbar_height(wp) |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3374 #endif |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3375 , wp->w_wincol, pos.col, wp->w_width, FALSE); |
12502 | 3376 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3377 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
|
3378 term->tl_dirty_row_end = 0; |
12502 | 3379 } |
3380 | |
3381 /* | |
3382 * Return TRUE if "wp" is a terminal window where the job has finished. | |
3383 */ | |
3384 int | |
3385 term_is_finished(buf_T *buf) | |
3386 { | |
3387 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL; | |
3388 } | |
3389 | |
3390 /* | |
3391 * Return TRUE if "wp" is a terminal window where the job has finished or we | |
3392 * are in Terminal-Normal mode, thus we show the buffer contents. | |
3393 */ | |
3394 int | |
3395 term_show_buffer(buf_T *buf) | |
3396 { | |
3397 term_T *term = buf->b_term; | |
3398 | |
3399 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode); | |
3400 } | |
3401 | |
3402 /* | |
3403 * The current buffer is going to be changed. If there is terminal | |
3404 * highlighting remove it now. | |
3405 */ | |
3406 void | |
3407 term_change_in_curbuf(void) | |
3408 { | |
3409 term_T *term = curbuf->b_term; | |
3410 | |
3411 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) | |
3412 { | |
3413 free_scrollback(term); | |
3414 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3415 | |
3416 /* The buffer is now like a normal buffer, it cannot be easily | |
3417 * abandoned when changed. */ | |
3418 set_string_option_direct((char_u *)"buftype", -1, | |
3419 (char_u *)"", OPT_FREE|OPT_LOCAL, 0); | |
3420 } | |
3421 } | |
3422 | |
3423 /* | |
3424 * Get the screen attribute for a position in the buffer. | |
3425 * Use a negative "col" to get the filler background color. | |
3426 */ | |
3427 int | |
3428 term_get_attr(buf_T *buf, linenr_T lnum, int col) | |
3429 { | |
3430 term_T *term = buf->b_term; | |
3431 sb_line_T *line; | |
3432 cellattr_T *cellattr; | |
3433 | |
3434 if (lnum > term->tl_scrollback.ga_len) | |
3435 cellattr = &term->tl_default_color; | |
3436 else | |
3437 { | |
3438 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1; | |
3439 if (col < 0 || col >= line->sb_cols) | |
3440 cellattr = &line->sb_fill_attr; | |
3441 else | |
3442 cellattr = line->sb_cells + col; | |
3443 } | |
3444 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); | |
3445 } | |
3446 | |
3447 /* | |
3448 * 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
|
3449 * This is compatible with xterm. |
12502 | 3450 */ |
3451 static void | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3452 cterm_color2vterm(int nr, VTermColor *rgb) |
12502 | 3453 { |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3454 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->ansi_index); |
12502 | 3455 } |
3456 | |
3457 /* | |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3458 * Initialize term->tl_default_color from the environment. |
12502 | 3459 */ |
3460 static void | |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3461 init_default_colors(term_T *term) |
12502 | 3462 { |
3463 VTermColor *fg, *bg; | |
3464 int fgval, bgval; | |
3465 int id; | |
3466 | |
3467 vim_memset(&term->tl_default_color.attrs, 0, sizeof(VTermScreenCellAttrs)); | |
3468 term->tl_default_color.width = 1; | |
3469 fg = &term->tl_default_color.fg; | |
3470 bg = &term->tl_default_color.bg; | |
3471 | |
3472 /* Vterm uses a default black background. Set it to white when | |
3473 * 'background' is "light". */ | |
3474 if (*p_bg == 'l') | |
3475 { | |
3476 fgval = 0; | |
3477 bgval = 255; | |
3478 } | |
3479 else | |
3480 { | |
3481 fgval = 255; | |
3482 bgval = 0; | |
3483 } | |
3484 fg->red = fg->green = fg->blue = fgval; | |
3485 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
|
3486 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT; |
12502 | 3487 |
3488 /* The "Terminal" highlight group overrules the defaults. */ | |
3489 id = syn_name2id((char_u *)"Terminal"); | |
3490 | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
3491 /* Use the actual color for the GUI and when 'termguicolors' is set. */ |
12502 | 3492 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
3493 if (0 | |
3494 # ifdef FEAT_GUI | |
3495 || gui.in_use | |
3496 # endif | |
3497 # ifdef FEAT_TERMGUICOLORS | |
3498 || p_tgc | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3499 # ifdef FEAT_VTP |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3500 /* Finally get INVALCOLOR on this execution path */ |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3501 || (!p_tgc && t_colors >= 256) |
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3502 # endif |
12502 | 3503 # endif |
3504 ) | |
3505 { | |
3506 guicolor_T fg_rgb = INVALCOLOR; | |
3507 guicolor_T bg_rgb = INVALCOLOR; | |
3508 | |
3509 if (id != 0) | |
3510 syn_id2colors(id, &fg_rgb, &bg_rgb); | |
3511 | |
3512 # ifdef FEAT_GUI | |
3513 if (gui.in_use) | |
3514 { | |
3515 if (fg_rgb == INVALCOLOR) | |
3516 fg_rgb = gui.norm_pixel; | |
3517 if (bg_rgb == INVALCOLOR) | |
3518 bg_rgb = gui.back_pixel; | |
3519 } | |
3520 # ifdef FEAT_TERMGUICOLORS | |
3521 else | |
3522 # endif | |
3523 # endif | |
3524 # ifdef FEAT_TERMGUICOLORS | |
3525 { | |
3526 if (fg_rgb == INVALCOLOR) | |
3527 fg_rgb = cterm_normal_fg_gui_color; | |
3528 if (bg_rgb == INVALCOLOR) | |
3529 bg_rgb = cterm_normal_bg_gui_color; | |
3530 } | |
3531 # endif | |
3532 if (fg_rgb != INVALCOLOR) | |
3533 { | |
3534 long_u rgb = GUI_MCH_GET_RGB(fg_rgb); | |
3535 | |
3536 fg->red = (unsigned)(rgb >> 16); | |
3537 fg->green = (unsigned)(rgb >> 8) & 255; | |
3538 fg->blue = (unsigned)rgb & 255; | |
3539 } | |
3540 if (bg_rgb != INVALCOLOR) | |
3541 { | |
3542 long_u rgb = GUI_MCH_GET_RGB(bg_rgb); | |
3543 | |
3544 bg->red = (unsigned)(rgb >> 16); | |
3545 bg->green = (unsigned)(rgb >> 8) & 255; | |
3546 bg->blue = (unsigned)rgb & 255; | |
3547 } | |
3548 } | |
3549 else | |
3550 #endif | |
3551 if (id != 0 && t_colors >= 16) | |
3552 { | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
3553 if (term_default_cterm_fg >= 0) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3554 cterm_color2vterm(term_default_cterm_fg, fg); |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
3555 if (term_default_cterm_bg >= 0) |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3556 cterm_color2vterm(term_default_cterm_bg, bg); |
12502 | 3557 } |
3558 else | |
3559 { | |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3560 #if defined(WIN3264) && !defined(FEAT_GUI_W32) |
12502 | 3561 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
|
3562 #endif |
12502 | 3563 |
3564 /* In an MS-Windows console we know the normal colors. */ | |
3565 if (cterm_normal_fg_color > 0) | |
3566 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3567 cterm_color2vterm(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
|
3568 # if defined(WIN3264) && !defined(FEAT_GUI_W32) |
12502 | 3569 tmp = fg->red; |
3570 fg->red = fg->blue; | |
3571 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
|
3572 # endif |
12502 | 3573 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
3574 # 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
|
3575 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3576 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
|
3577 # 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
|
3578 |
12502 | 3579 if (cterm_normal_bg_color > 0) |
3580 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
3581 cterm_color2vterm(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
|
3582 # if defined(WIN3264) && !defined(FEAT_GUI_W32) |
12502 | 3583 tmp = bg->red; |
3584 bg->red = bg->blue; | |
3585 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
|
3586 # endif |
12502 | 3587 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
3588 # 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
|
3589 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
3590 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
|
3591 # endif |
12502 | 3592 } |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3593 } |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3594 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3595 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3596 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3597 * Set the 16 ANSI colors from array of RGB values |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3598 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3599 static void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3600 set_vterm_palette(VTerm *vterm, long_u *rgb) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3601 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3602 int index = 0; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3603 VTermState *state = vterm_obtain_state(vterm); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3604 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3605 for (; index < 16; index++) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3606 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3607 VTermColor color; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3608 color.red = (unsigned)(rgb[index] >> 16); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3609 color.green = (unsigned)(rgb[index] >> 8) & 255; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3610 color.blue = (unsigned)rgb[index] & 255; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3611 vterm_state_set_palette_color(state, index, &color); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3612 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3613 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3614 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3615 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3616 * Set the ANSI color palette from a list of colors |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3617 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3618 static int |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3619 set_ansi_colors_list(VTerm *vterm, list_T *list) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3620 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3621 int n = 0; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3622 long_u rgb[16]; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3623 listitem_T *li = list->lv_first; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3624 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3625 for (; li != NULL && n < 16; li = li->li_next, n++) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3626 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3627 char_u *color_name; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3628 guicolor_T guicolor; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3629 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
3630 color_name = tv_get_string_chk(&li->li_tv); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3631 if (color_name == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3632 return FAIL; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3633 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3634 guicolor = GUI_GET_COLOR(color_name); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3635 if (guicolor == INVALCOLOR) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3636 return FAIL; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3637 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3638 rgb[n] = GUI_MCH_GET_RGB(guicolor); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3639 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3640 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3641 if (n != 16 || li != NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3642 return FAIL; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3643 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3644 set_vterm_palette(vterm, rgb); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3645 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3646 return OK; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3647 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3648 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3649 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3650 * Initialize the ANSI color palette from g:terminal_ansi_colors[0:15] |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3651 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3652 static void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3653 init_vterm_ansi_colors(VTerm *vterm) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3654 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3655 dictitem_T *var = find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3656 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3657 if (var != NULL |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3658 && (var->di_tv.v_type != VAR_LIST |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3659 || var->di_tv.vval.v_list == NULL |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3660 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
3661 semsg(_(e_invarg2), "g:terminal_ansi_colors"); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3662 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3663 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3664 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3665 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3666 * Handles a "drop" command from the job in the terminal. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3667 * "item" is the file name, "item->li_next" may have options. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3668 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3669 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3670 handle_drop_command(listitem_T *item) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3671 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
3672 char_u *fname = tv_get_string(&item->li_tv); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3673 listitem_T *opt_item = item->li_next; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3674 int bufnr; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3675 win_T *wp; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3676 tabpage_T *tp; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3677 exarg_T ea; |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3678 char_u *tofree = NULL; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3679 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3680 bufnr = buflist_add(fname, BLN_LISTED | BLN_NOOPT); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3681 FOR_ALL_TAB_WINDOWS(tp, wp) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3682 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3683 if (wp->w_buffer->b_fnum == bufnr) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3684 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3685 /* buffer is in a window already, go there */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3686 goto_tabpage_win(tp, wp); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3687 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3688 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3689 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3690 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3691 vim_memset(&ea, 0, sizeof(ea)); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3692 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3693 if (opt_item != NULL && opt_item->li_tv.v_type == VAR_DICT |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3694 && opt_item->li_tv.vval.v_dict != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3695 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3696 dict_T *dict = opt_item->li_tv.vval.v_dict; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3697 char_u *p; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3698 |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
3699 p = dict_get_string(dict, (char_u *)"ff", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3700 if (p == NULL) |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
3701 p = dict_get_string(dict, (char_u *)"fileformat", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3702 if (p != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3703 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3704 if (check_ff_value(p) == FAIL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3705 ch_log(NULL, "Invalid ff argument to drop: %s", p); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3706 else |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3707 ea.force_ff = *p; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3708 } |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
3709 p = dict_get_string(dict, (char_u *)"enc", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3710 if (p == NULL) |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
3711 p = dict_get_string(dict, (char_u *)"encoding", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3712 if (p != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3713 { |
13583
200ef826e7dd
patch 8.0.1664: test failure because of not allocating enough space
Christian Brabandt <cb@256bit.org>
parents:
13579
diff
changeset
|
3714 ea.cmd = alloc((int)STRLEN(p) + 12); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3715 if (ea.cmd != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3716 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3717 sprintf((char *)ea.cmd, "sbuf ++enc=%s", p); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3718 ea.force_enc = 11; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3719 tofree = ea.cmd; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3720 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3721 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3722 |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
3723 p = dict_get_string(dict, (char_u *)"bad", FALSE); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3724 if (p != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3725 get_bad_opt(p, &ea); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3726 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3727 if (dict_find(dict, (char_u *)"bin", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3728 ea.force_bin = FORCE_BIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3729 if (dict_find(dict, (char_u *)"binary", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3730 ea.force_bin = FORCE_BIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3731 if (dict_find(dict, (char_u *)"nobin", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3732 ea.force_bin = FORCE_NOBIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3733 if (dict_find(dict, (char_u *)"nobinary", -1) != NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3734 ea.force_bin = FORCE_NOBIN; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3735 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3736 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3737 /* open in new window, like ":split fname" */ |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3738 if (ea.cmd == NULL) |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3739 ea.cmd = (char_u *)"split"; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3740 ea.arg = fname; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3741 ea.cmdidx = CMD_split; |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3742 ex_splitview(&ea); |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3743 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
3744 vim_free(tofree); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3745 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3746 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3747 /* |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3748 * Handles a function call from the job running in a terminal. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3749 * "item" is the function name, "item->li_next" has the arguments. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3750 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3751 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3752 handle_call_command(term_T *term, channel_T *channel, listitem_T *item) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3753 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3754 char_u *func; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3755 typval_T argvars[2]; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3756 typval_T rettv; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3757 int doesrange; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3758 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3759 if (item->li_next == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3760 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3761 ch_log(channel, "Missing function arguments for call"); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3762 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3763 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
3764 func = tv_get_string(&item->li_tv); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3765 |
13547
87a9c1be0ae3
patch 8.0.1647: terminal API may call any user function
Christian Brabandt <cb@256bit.org>
parents:
13535
diff
changeset
|
3766 if (STRNCMP(func, "Tapi_", 5) != 0) |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3767 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3768 ch_log(channel, "Invalid function name: %s", func); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3769 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3770 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3771 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3772 argvars[0].v_type = VAR_NUMBER; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3773 argvars[0].vval.v_number = term->tl_buffer->b_fnum; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3774 argvars[1] = item->li_next->li_tv; |
13577
4cb743db55b3
patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents:
13575
diff
changeset
|
3775 if (call_func(func, (int)STRLEN(func), &rettv, |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3776 2, argvars, /* argv_func */ NULL, |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3777 /* firstline */ 1, /* lastline */ 1, |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3778 &doesrange, /* evaluate */ TRUE, |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3779 /* partial */ NULL, /* selfdict */ NULL) == OK) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3780 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3781 clear_tv(&rettv); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3782 ch_log(channel, "Function %s called", func); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3783 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3784 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3785 ch_log(channel, "Calling function %s failed", func); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3786 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3787 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3788 /* |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3789 * Called by libvterm when it cannot recognize an OSC sequence. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3790 * We recognize a terminal API command. |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3791 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3792 static int |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3793 parse_osc(const char *command, size_t cmdlen, void *user) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3794 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3795 term_T *term = (term_T *)user; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3796 js_read_T reader; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3797 typval_T tv; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3798 channel_T *channel = term->tl_job == NULL ? NULL |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3799 : term->tl_job->jv_channel; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3800 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3801 /* We recognize only OSC 5 1 ; {command} */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3802 if (cmdlen < 3 || STRNCMP(command, "51;", 3) != 0) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3803 return 0; /* not handled */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3804 |
13577
4cb743db55b3
patch 8.0.1661: warnings from 64 bit compiler
Christian Brabandt <cb@256bit.org>
parents:
13575
diff
changeset
|
3805 reader.js_buf = vim_strnsave((char_u *)command + 3, (int)(cmdlen - 3)); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3806 if (reader.js_buf == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3807 return 1; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3808 reader.js_fill = NULL; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3809 reader.js_used = 0; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3810 if (json_decode(&reader, &tv, 0) == OK |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3811 && tv.v_type == VAR_LIST |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3812 && tv.vval.v_list != NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3813 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3814 listitem_T *item = tv.vval.v_list->lv_first; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3815 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3816 if (item == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3817 ch_log(channel, "Missing command"); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3818 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3819 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
3820 char_u *cmd = tv_get_string(&item->li_tv); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3821 |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
3822 /* Make sure an invoked command doesn't delete the buffer (and the |
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
3823 * terminal) under our fingers. */ |
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
3824 ++term->tl_buffer->b_locked; |
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
3825 |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3826 item = item->li_next; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3827 if (item == NULL) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3828 ch_log(channel, "Missing argument for %s", cmd); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3829 else if (STRCMP(cmd, "drop") == 0) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3830 handle_drop_command(item); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3831 else if (STRCMP(cmd, "call") == 0) |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3832 handle_call_command(term, channel, item); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3833 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3834 ch_log(channel, "Invalid command received: %s", cmd); |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
3835 --term->tl_buffer->b_locked; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3836 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3837 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3838 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3839 ch_log(channel, "Invalid JSON received"); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3840 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3841 vim_free(reader.js_buf); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3842 clear_tv(&tv); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3843 return 1; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3844 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3845 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3846 static VTermParserCallbacks parser_fallbacks = { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3847 NULL, /* text */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3848 NULL, /* control */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3849 NULL, /* escape */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3850 NULL, /* csi */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3851 parse_osc, /* osc */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3852 NULL, /* dcs */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3853 NULL /* resize */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3854 }; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3855 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3856 /* |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3857 * Use Vim's allocation functions for vterm so profiling works. |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3858 */ |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3859 static void * |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3860 vterm_malloc(size_t size, void *data UNUSED) |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3861 { |
13630
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
3862 return alloc_clear((unsigned) size); |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3863 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3864 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3865 static void |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3866 vterm_memfree(void *ptr, void *data UNUSED) |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3867 { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3868 vim_free(ptr); |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3869 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3870 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3871 static VTermAllocatorFunctions vterm_allocator = { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3872 &vterm_malloc, |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3873 &vterm_memfree |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3874 }; |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3875 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3876 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3877 * Create a new vterm and initialize it. |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3878 * Return FAIL when out of memory. |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3879 */ |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3880 static int |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3881 create_vterm(term_T *term, int rows, int cols) |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3882 { |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3883 VTerm *vterm; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3884 VTermScreen *screen; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3885 VTermState *state; |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3886 VTermValue value; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3887 |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
3888 vterm = vterm_new_with_allocator(rows, cols, &vterm_allocator, NULL); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3889 term->tl_vterm = vterm; |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3890 if (vterm == NULL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3891 return FAIL; |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3892 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3893 // Allocate screen and state here, so we can bail out if that fails. |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3894 state = vterm_obtain_state(vterm); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3895 screen = vterm_obtain_screen(vterm); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3896 if (state == NULL || screen == NULL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3897 { |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3898 vterm_free(vterm); |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3899 return FAIL; |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3900 } |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3901 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3902 vterm_screen_set_callbacks(screen, &screen_callbacks, term); |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3903 /* TODO: depends on 'encoding'. */ |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3904 vterm_set_utf8(vterm, 1); |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3905 |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3906 init_default_colors(term); |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3907 |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3908 vterm_state_set_default_colors( |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3909 state, |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3910 &term->tl_default_color.fg, |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
3911 &term->tl_default_color.bg); |
12502 | 3912 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3913 if (t_colors >= 16) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3914 vterm_state_set_bold_highbright(vterm_obtain_state(vterm), 1); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
3915 |
12502 | 3916 /* Required to initialize most things. */ |
3917 vterm_screen_reset(screen, 1 /* hard */); | |
3918 | |
3919 /* Allow using alternate screen. */ | |
3920 vterm_screen_enable_altscreen(screen, 1); | |
3921 | |
3922 /* For unix do not use a blinking cursor. In an xterm this causes the | |
3923 * cursor to blink if it's blinking in the xterm. | |
3924 * For Windows we respect the system wide setting. */ | |
3925 #ifdef WIN3264 | |
3926 if (GetCaretBlinkTime() == INFINITE) | |
3927 value.boolean = 0; | |
3928 else | |
3929 value.boolean = 1; | |
3930 #else | |
3931 value.boolean = 0; | |
3932 #endif | |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3933 vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value); |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
3934 vterm_state_set_unrecognised_fallbacks(state, &parser_fallbacks, term); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3935 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
3936 return OK; |
12502 | 3937 } |
3938 | |
3939 /* | |
3940 * Return the text to show for the buffer name and status. | |
3941 */ | |
3942 char_u * | |
3943 term_get_status_text(term_T *term) | |
3944 { | |
3945 if (term->tl_status_text == NULL) | |
3946 { | |
3947 char_u *txt; | |
3948 size_t len; | |
3949 | |
3950 if (term->tl_normal_mode) | |
3951 { | |
3952 if (term_job_running(term)) | |
3953 txt = (char_u *)_("Terminal"); | |
3954 else | |
3955 txt = (char_u *)_("Terminal-finished"); | |
3956 } | |
3957 else if (term->tl_title != NULL) | |
3958 txt = term->tl_title; | |
3959 else if (term_none_open(term)) | |
3960 txt = (char_u *)_("active"); | |
3961 else if (term_job_running(term)) | |
3962 txt = (char_u *)_("running"); | |
3963 else | |
3964 txt = (char_u *)_("finished"); | |
3965 len = 9 + STRLEN(term->tl_buffer->b_fname) + STRLEN(txt); | |
3966 term->tl_status_text = alloc((int)len); | |
3967 if (term->tl_status_text != NULL) | |
3968 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]", | |
3969 term->tl_buffer->b_fname, txt); | |
3970 } | |
3971 return term->tl_status_text; | |
3972 } | |
3973 | |
3974 /* | |
3975 * Mark references in jobs of terminals. | |
3976 */ | |
3977 int | |
3978 set_ref_in_term(int copyID) | |
3979 { | |
3980 int abort = FALSE; | |
3981 term_T *term; | |
3982 typval_T tv; | |
3983 | |
3984 for (term = first_term; term != NULL; term = term->tl_next) | |
3985 if (term->tl_job != NULL) | |
3986 { | |
3987 tv.v_type = VAR_JOB; | |
3988 tv.vval.v_job = term->tl_job; | |
3989 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); | |
3990 } | |
3991 return abort; | |
3992 } | |
3993 | |
3994 /* | |
12973
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
3995 * 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
|
3996 */ |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
3997 void |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
3998 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
|
3999 { |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
4000 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
|
4001 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
|
4002 } |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
4003 |
418941f0df08
patch 8.0.1362: terminal window colors wrong when using Terminal highlighting
Christian Brabandt <cb@256bit.org>
parents:
12969
diff
changeset
|
4004 /* |
12502 | 4005 * Get the buffer from the first argument in "argvars". |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4006 * Returns NULL when the buffer is not for a terminal window and logs a message |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4007 * with "where". |
12502 | 4008 */ |
4009 static buf_T * | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4010 term_get_buf(typval_T *argvars, char *where) |
12502 | 4011 { |
4012 buf_T *buf; | |
4013 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4014 (void)tv_get_number(&argvars[0]); /* issue errmsg if type error */ |
12502 | 4015 ++emsg_off; |
15355
73b153ed5af8
patch 8.1.0685: get_buf_tv() is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
15273
diff
changeset
|
4016 buf = tv_get_buf(&argvars[0], FALSE); |
12502 | 4017 --emsg_off; |
4018 if (buf == NULL || buf->b_term == NULL) | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4019 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4020 ch_log(NULL, "%s: invalid buffer argument", where); |
12502 | 4021 return NULL; |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4022 } |
12502 | 4023 return buf; |
4024 } | |
4025 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4026 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4027 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
|
4028 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4029 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
|
4030 && a->green == b->green |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4031 && a->blue == b->blue |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4032 && 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
|
4033 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4034 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4035 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4036 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
|
4037 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4038 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
|
4039 (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
|
4040 (int)color->ansi_index); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4041 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4042 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4043 /* |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4044 * "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
|
4045 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4046 * 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
|
4047 * |{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
|
4048 * {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
|
4049 * 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
|
4050 * skipped. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4051 * {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
|
4052 * 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
|
4053 * {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
|
4054 * {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
|
4055 * {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
|
4056 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4057 * 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
|
4058 * |{characters} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4059 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4060 * 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
|
4061 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4062 * 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
|
4063 * @{count} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4064 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4065 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4066 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
|
4067 { |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4068 buf_T *buf = term_get_buf(argvars, "term_dumpwrite()"); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4069 term_T *term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4070 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
|
4071 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
|
4072 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
|
4073 stat_T st; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4074 FILE *fd; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4075 VTermPos pos; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4076 VTermScreen *screen; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4077 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
|
4078 VTermState *state; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4079 VTermPos cursor_pos; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4080 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4081 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
|
4082 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4083 if (buf == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4084 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4085 term = buf->b_term; |
14691
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4086 if (term->tl_vterm == NULL) |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4087 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4088 emsg(_("E958: Job already finished")); |
14691
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4089 return; |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4090 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4091 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4092 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
|
4093 { |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4094 dict_T *d; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4095 |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4096 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
|
4097 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4098 emsg(_(e_dictreq)); |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4099 return; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4100 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4101 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
|
4102 if (d != NULL) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4103 { |
15146
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4104 max_height = dict_get_number(d, (char_u *)"rows"); |
7903dce131d4
patch 8.1.0583: using illogical name for get_dict_number()/get_dict_string()
Bram Moolenaar <Bram@vim.org>
parents:
15022
diff
changeset
|
4105 max_width = dict_get_number(d, (char_u *)"columns"); |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4106 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4107 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4108 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4109 fname = tv_get_string_chk(&argvars[1]); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4110 if (fname == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4111 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4112 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
|
4113 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4114 semsg(_("E953: File exists: %s"), fname); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4115 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4116 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4117 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4118 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
|
4119 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4120 semsg(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4121 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4122 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4123 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4124 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
|
4125 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4126 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
|
4127 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
|
4128 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
|
4129 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4130 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
|
4131 && 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
|
4132 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4133 int repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4134 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4135 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
|
4136 && 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
|
4137 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4138 VTermScreenCell cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4139 int same_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4140 int same_chars = TRUE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4141 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
|
4142 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
|
4143 && 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
|
4144 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4145 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
|
4146 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
|
4147 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4148 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
|
4149 { |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4150 int c = cell.chars[i]; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4151 int pc = prev_cell.chars[i]; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4152 |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4153 /* For the first character NUL is the same as space. */ |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4154 if (i == 0) |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4155 { |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4156 c = (c == NUL) ? ' ' : c; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4157 pc = (pc == NUL) ? ' ' : pc; |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4158 } |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
4159 if (c != pc) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4160 same_chars = FALSE; |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
4161 if (c == NUL || pc == NUL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4162 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4163 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4164 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
|
4165 == vtermAttr2hl(prev_cell.attrs) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4166 && 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
|
4167 && 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
|
4168 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
|
4169 && !is_cursor_pos) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4170 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4171 ++repeat; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4172 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4173 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4174 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4175 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4176 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4177 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4178 repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4179 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4180 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
|
4181 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4182 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
|
4183 fputs(" ", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4184 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4185 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4186 char_u charbuf[10]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4187 int len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4188 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4189 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
|
4190 && 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
|
4191 { |
13557
4911058c43eb
patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents:
13547
diff
changeset
|
4192 len = utf_char2bytes(cell.chars[i], charbuf); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4193 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
|
4194 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4195 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4196 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4197 /* 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
|
4198 * 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
|
4199 * attributes. */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4200 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
|
4201 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4202 if (cell.width == 2) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4203 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4204 fputs("*", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4205 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4206 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4207 fputs("+", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4208 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4209 if (same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4210 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4211 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4212 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4213 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4214 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4215 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
|
4216 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
|
4217 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4218 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4219 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4220 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4221 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
|
4222 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4223 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
|
4224 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4225 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4226 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4227 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4228 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
|
4229 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4230 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4231 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4232 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4233 prev_cell = cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4234 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4235 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4236 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4237 ++pos.col; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4238 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4239 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4240 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4241 fputs("\n", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4242 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4243 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4244 fclose(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4245 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4246 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4247 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4248 * 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
|
4249 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4250 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4251 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
|
4252 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4253 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
|
4254 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4255 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4256 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4257 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
|
4258 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4259 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
|
4260 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4261 *(((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
|
4262 ++gap->ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4263 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4264 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4265 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4266 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4267 * 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
|
4268 * 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
|
4269 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4270 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
|
4271 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
|
4272 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4273 int c; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4274 garray_T ga_text; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4275 garray_T ga_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4276 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
|
4277 int attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4278 cellattr_T cell; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4279 cellattr_T empty_cell; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4280 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
|
4281 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
|
4282 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
|
4283 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4284 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
|
4285 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
|
4286 vim_memset(&cell, 0, sizeof(cell)); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4287 vim_memset(&empty_cell, 0, sizeof(empty_cell)); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4288 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
|
4289 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
|
4290 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4291 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4292 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4293 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4294 if (c == EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4295 break; |
14960
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4296 if (c == '\r') |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4297 { |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4298 // DOS line endings? Ignore. |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4299 c = fgetc(fd); |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4300 } |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
4301 else if (c == '\n') |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4302 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4303 /* 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
|
4304 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
|
4305 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
|
4306 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
|
4307 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4308 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
|
4309 + 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
|
4310 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4311 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
|
4312 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
|
4313 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
|
4314 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
|
4315 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
|
4316 ++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
|
4317 ga_init(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4318 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4319 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
|
4320 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
|
4321 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
|
4322 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4323 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4324 ga_clear(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4325 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
|
4326 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4327 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4328 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4329 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
|
4330 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4331 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
|
4332 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4333 if (c == '>') |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4334 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4335 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
|
4336 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
|
4337 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
|
4338 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
|
4339 } |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4340 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4341 /* 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
|
4342 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4343 if (c != EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4344 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
|
4345 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4346 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4347 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
|
4348 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
|
4349 || c == EOF || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4350 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4351 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
|
4352 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4353 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4354 /* 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
|
4355 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4356 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
|
4357 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
|
4358 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
|
4359 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4360 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
|
4361 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4362 /* 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
|
4363 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4364 else if (c == '+' || c == '*') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4365 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4366 int is_bg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4367 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4368 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
|
4369 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4370 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4371 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4372 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4373 /* 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
|
4374 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4375 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4376 else if (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4377 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4378 /* get the decimal attribute */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4379 attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4380 while (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4381 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4382 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
|
4383 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4384 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4385 hl2vtermAttr(attr, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4386 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4387 /* is_bg == 0: fg, is_bg == 1: bg */ |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4388 for (is_bg = 0; is_bg <= 1; ++is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4389 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4390 if (c == '&') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4391 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4392 /* use same color as previous cell */ |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4393 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4394 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4395 else if (c == '#') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4396 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4397 int red, green, blue, index = 0; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4398 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4399 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4400 red = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4401 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4402 red = (red << 4) + hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4403 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4404 green = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4405 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4406 green = (green << 4) + hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4407 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4408 blue = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4409 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4410 blue = (blue << 4) + hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4411 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4412 if (!isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4413 dump_is_corrupt(&ga_text); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4414 while (isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4415 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4416 index = index * 10 + (c - '0'); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4417 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4418 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4419 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4420 if (is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4421 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4422 cell.bg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4423 cell.bg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4424 cell.bg.blue = blue; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4425 cell.bg.ansi_index = index; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4426 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4427 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4428 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4429 cell.fg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4430 cell.fg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4431 cell.fg.blue = blue; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4432 cell.fg.ansi_index = index; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4433 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4434 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4435 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4436 dump_is_corrupt(&ga_text); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4437 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4438 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4439 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4440 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
|
4441 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4442 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4443 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
|
4444 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4445 append_cell(&ga_cell, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4446 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4447 append_cell(&ga_cell, &empty_cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4448 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4449 else if (c == '@') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4450 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4451 if (prev_char == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4452 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
|
4453 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4454 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4455 int count = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4456 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4457 /* 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
|
4458 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4459 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4460 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4461 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4462 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4463 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
|
4464 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4465 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4466 while (count-- > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4467 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4468 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
|
4469 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
|
4470 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4471 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4472 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4473 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4474 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4475 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
|
4476 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4477 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4478 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4479 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4480 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
|
4481 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4482 /* 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
|
4483 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
|
4484 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
|
4485 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
|
4486 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
|
4487 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4488 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4489 ga_clear(&ga_text); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4490 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4491 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4492 return max_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4493 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4494 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4495 /* |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4496 * Return an allocated string with at least "text_width" "=" characters and |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4497 * "fname" inserted in the middle. |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4498 */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4499 static char_u * |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4500 get_separator(int text_width, char_u *fname) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4501 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4502 int width = MAX(text_width, curwin->w_width); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4503 char_u *textline; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4504 int fname_size; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4505 char_u *p = fname; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4506 int i; |
13630
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
4507 size_t off; |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
4508 |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
4509 textline = alloc(width + (int)STRLEN(fname) + 1); |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4510 if (textline == NULL) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4511 return NULL; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4512 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4513 fname_size = vim_strsize(fname); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4514 if (fname_size < width - 8) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4515 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4516 /* enough room, don't use the full window width */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4517 width = MAX(text_width, fname_size + 8); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4518 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4519 else if (fname_size > width - 8) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4520 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4521 /* full name doesn't fit, use only the tail */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4522 p = gettail(fname); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4523 fname_size = vim_strsize(p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4524 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4525 /* skip characters until the name fits */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4526 while (fname_size > width - 8) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4527 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4528 p += (*mb_ptr2len)(p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4529 fname_size = vim_strsize(p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4530 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4531 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4532 for (i = 0; i < (width - fname_size) / 2 - 1; ++i) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4533 textline[i] = '='; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4534 textline[i++] = ' '; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4535 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4536 STRCPY(textline + i, p); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4537 off = STRLEN(textline); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4538 textline[off] = ' '; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4539 for (i = 1; i < (width - fname_size) / 2; ++i) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4540 textline[off + i] = '='; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4541 textline[off + i] = NUL; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4542 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4543 return textline; |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4544 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4545 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4546 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4547 * 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
|
4548 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4549 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4550 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
|
4551 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4552 jobopt_T opt; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4553 buf_T *buf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4554 char_u buf1[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4555 char_u buf2[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4556 char_u *fname1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
4557 char_u *fname2 = NULL; |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4558 char_u *fname_tofree = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4559 FILE *fd1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
4560 FILE *fd2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4561 char_u *textline = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4562 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4563 /* First open the files. If this fails bail out. */ |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4564 fname1 = tv_get_string_buf_chk(&argvars[0], buf1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4565 if (do_diff) |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4566 fname2 = tv_get_string_buf_chk(&argvars[1], buf2); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4567 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
|
4568 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4569 emsg(_(e_invarg)); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4570 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4571 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4572 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
|
4573 if (fd1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4574 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4575 semsg(_(e_notread), fname1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4576 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4577 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4578 if (do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4579 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4580 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
|
4581 if (fd2 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4582 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4583 fclose(fd1); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
4584 semsg(_(e_notread), fname2); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4585 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4586 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4587 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4588 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4589 init_job_options(&opt); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4590 if (argvars[do_diff ? 2 : 1].v_type != VAR_UNKNOWN |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4591 && get_job_options(&argvars[do_diff ? 2 : 1], &opt, 0, |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4592 JO2_TERM_NAME + JO2_TERM_COLS + JO2_TERM_ROWS |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4593 + JO2_VERTICAL + JO2_CURWIN + JO2_NORESTORE) == FAIL) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4594 goto theend; |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4595 |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4596 if (opt.jo_term_name == NULL) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4597 { |
13505
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
4598 size_t len = STRLEN(fname1) + 12; |
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
4599 |
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
4600 fname_tofree = alloc((int)len); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4601 if (fname_tofree != NULL) |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4602 { |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4603 vim_snprintf((char *)fname_tofree, len, "dump diff %s", fname1); |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4604 opt.jo_term_name = fname_tofree; |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4605 } |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4606 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4607 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
4608 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4609 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
|
4610 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4611 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4612 linenr_T bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4613 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4614 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
|
4615 int width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4616 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
|
4617 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
|
4618 VTermPos cursor_pos2; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4619 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4620 init_default_colors(term); |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4621 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4622 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
|
4623 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4624 /* 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
|
4625 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
|
4626 |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4627 /* 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
|
4628 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
|
4629 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4630 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
|
4631 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
|
4632 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4633 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4634 /* 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
|
4635 ml_delete(1, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4636 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4637 /* 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
|
4638 if (!do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4639 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4640 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4641 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
|
4642 |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4643 textline = get_separator(width, fname1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4644 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4645 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4646 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
|
4647 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE); |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4648 vim_free(textline); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4649 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4650 textline = get_separator(width, fname2); |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4651 if (textline == NULL) |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4652 goto theend; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4653 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
|
4654 ml_append(curbuf->b_ml.ml_line_count, textline, 0, FALSE); |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4655 textline[width] = NUL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4656 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4657 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
|
4658 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
|
4659 if (width2 > width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4660 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4661 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4662 textline = alloc(width2 + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4663 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4664 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4665 width = width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4666 textline[width] = NUL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4667 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4668 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
|
4669 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4670 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
|
4671 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4672 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
|
4673 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4674 /* 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
|
4675 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
|
4676 textline[i] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4677 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4678 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4679 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4680 char_u *line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4681 char_u *line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4682 char_u *p1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4683 char_u *p2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4684 int col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4685 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
|
4686 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
|
4687 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
|
4688 ->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4689 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4690 /* 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
|
4691 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
|
4692 if (line1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4693 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4694 p1 = line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4695 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4696 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
|
4697 p2 = line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4698 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
|
4699 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4700 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
|
4701 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
|
4702 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4703 textline[col] = ' '; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4704 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
|
4705 /* text differs */ |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4706 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
|
4707 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
|
4708 && 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
|
4709 && (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
|
4710 || 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
|
4711 /* 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
|
4712 textline[col] = '>'; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4713 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
|
4714 && 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
|
4715 && (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
|
4716 || 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
|
4717 /* 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
|
4718 textline[col] = '<'; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4719 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
|
4720 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4721 if ((cellattr1 + col)->width |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4722 != (cellattr2 + col)->width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4723 textline[col] = 'w'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4724 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
|
4725 &(cellattr2 + col)->fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4726 textline[col] = 'f'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4727 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
|
4728 &(cellattr2 + col)->bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4729 textline[col] = 'b'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4730 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
|
4731 != vtermAttr2hl(((cellattr2 + col)->attrs))) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4732 textline[col] = 'a'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4733 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4734 p1 += len1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4735 p2 += len2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4736 /* TODO: handle different width */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4737 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4738 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4739 while (col < width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4740 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4741 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
|
4742 textline[col] = '?'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4743 else if (*p1 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4744 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4745 textline[col] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4746 p2 += utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4747 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4748 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4749 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4750 textline[col] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4751 p1 += utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4752 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4753 ++col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4754 } |
15828
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
4755 |
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
4756 vim_free(line1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4757 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4758 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
|
4759 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
|
4760 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
|
4761 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4762 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4763 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4764 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
|
4765 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4766 /* 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
|
4767 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
|
4768 textline[i] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4769 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
|
4770 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
|
4771 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
|
4772 ++lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4773 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4774 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4775 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4776 term->tl_cols = width; |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4777 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4778 /* looks better without wrapping */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
4779 curwin->w_p_wrap = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4780 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4781 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4782 theend: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4783 vim_free(textline); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
4784 vim_free(fname_tofree); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4785 fclose(fd1); |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
4786 if (fd2 != NULL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4787 fclose(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4788 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4789 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4790 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4791 * 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
|
4792 * bottom files. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4793 * 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
|
4794 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4795 int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4796 term_swap_diff() |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4797 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4798 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
|
4799 linenr_T line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4800 linenr_T top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4801 linenr_T bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4802 linenr_T bot_start; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4803 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4804 char_u *p; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4805 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
|
4806 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4807 if (term == NULL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4808 || !term_is_finished(curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4809 || 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
|
4810 || 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
|
4811 return FAIL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4812 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4813 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
|
4814 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
|
4815 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
|
4816 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
|
4817 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
|
4818 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4819 // move lines from top to above the bottom part |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4820 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
|
4821 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4822 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
|
4823 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4824 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4825 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
|
4826 ml_delete(1, FALSE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4827 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4828 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4829 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4830 // move lines from bottom to the top |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4831 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
|
4832 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4833 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
|
4834 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4835 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4836 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
|
4837 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
|
4838 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4839 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4840 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4841 // move top title to bottom |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4842 p = vim_strsave(ml_get(bot_rows + 1)); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4843 if (p == NULL) |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4844 return OK; |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4845 ml_append(line_count - top_rows - 1, p, 0, FALSE); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4846 ml_delete(bot_rows + 1, FALSE); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4847 vim_free(p); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4848 |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4849 // move bottom title to top |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4850 p = vim_strsave(ml_get(line_count - top_rows)); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4851 if (p == NULL) |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4852 return OK; |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4853 ml_delete(line_count - top_rows, FALSE); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4854 ml_append(bot_rows, p, 0, FALSE); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4855 vim_free(p); |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
4856 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4857 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
|
4858 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4859 /* 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
|
4860 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
|
4861 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4862 sb_line_T temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4863 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4864 temp = *(sb_line + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4865 *(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
|
4866 *(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
|
4867 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4868 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4869 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4870 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4871 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
|
4872 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
|
4873 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4874 /* 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
|
4875 if (temp != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4876 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4877 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
|
4878 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
|
4879 temp + bot_start, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4880 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
|
4881 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
|
4882 temp + top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4883 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
|
4884 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
|
4885 + line_count - top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4886 temp, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4887 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
|
4888 vim_free(temp); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4889 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4890 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4891 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4892 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
|
4893 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
|
4894 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4895 update_screen(NOT_VALID); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4896 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4897 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4898 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4899 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4900 * "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
|
4901 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4902 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4903 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
|
4904 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4905 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
|
4906 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4907 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4908 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4909 * "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
|
4910 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4911 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4912 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
|
4913 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4914 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
|
4915 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4916 |
12502 | 4917 /* |
4918 * "term_getaltscreen(buf)" function | |
4919 */ | |
4920 void | |
4921 f_term_getaltscreen(typval_T *argvars, typval_T *rettv) | |
4922 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4923 buf_T *buf = term_get_buf(argvars, "term_getaltscreen()"); |
12502 | 4924 |
4925 if (buf == NULL) | |
4926 return; | |
4927 rettv->vval.v_number = buf->b_term->tl_using_altscreen; | |
4928 } | |
4929 | |
4930 /* | |
4931 * "term_getattr(attr, name)" function | |
4932 */ | |
4933 void | |
4934 f_term_getattr(typval_T *argvars, typval_T *rettv) | |
4935 { | |
4936 int attr; | |
4937 size_t i; | |
4938 char_u *name; | |
4939 | |
4940 static struct { | |
4941 char *name; | |
4942 int attr; | |
4943 } attrs[] = { | |
4944 {"bold", HL_BOLD}, | |
4945 {"italic", HL_ITALIC}, | |
4946 {"underline", HL_UNDERLINE}, | |
4947 {"strike", HL_STRIKETHROUGH}, | |
4948 {"reverse", HL_INVERSE}, | |
4949 }; | |
4950 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4951 attr = tv_get_number(&argvars[0]); |
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4952 name = tv_get_string_chk(&argvars[1]); |
12502 | 4953 if (name == NULL) |
4954 return; | |
4955 | |
4956 for (i = 0; i < sizeof(attrs)/sizeof(attrs[0]); ++i) | |
4957 if (STRCMP(name, attrs[i].name) == 0) | |
4958 { | |
4959 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0; | |
4960 break; | |
4961 } | |
4962 } | |
4963 | |
4964 /* | |
4965 * "term_getcursor(buf)" function | |
4966 */ | |
4967 void | |
4968 f_term_getcursor(typval_T *argvars, typval_T *rettv) | |
4969 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4970 buf_T *buf = term_get_buf(argvars, "term_getcursor()"); |
12502 | 4971 term_T *term; |
4972 list_T *l; | |
4973 dict_T *d; | |
4974 | |
4975 if (rettv_list_alloc(rettv) == FAIL) | |
4976 return; | |
4977 if (buf == NULL) | |
4978 return; | |
4979 term = buf->b_term; | |
4980 | |
4981 l = rettv->vval.v_list; | |
4982 list_append_number(l, term->tl_cursor_pos.row + 1); | |
4983 list_append_number(l, term->tl_cursor_pos.col + 1); | |
4984 | |
4985 d = dict_alloc(); | |
4986 if (d != NULL) | |
4987 { | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4988 dict_add_number(d, "visible", term->tl_cursor_visible); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4989 dict_add_number(d, "blink", blink_state_is_inverted() |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4990 ? !term->tl_cursor_blink : term->tl_cursor_blink); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4991 dict_add_number(d, "shape", term->tl_cursor_shape); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
4992 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color)); |
12502 | 4993 list_append_dict(l, d); |
4994 } | |
4995 } | |
4996 | |
4997 /* | |
4998 * "term_getjob(buf)" function | |
4999 */ | |
5000 void | |
5001 f_term_getjob(typval_T *argvars, typval_T *rettv) | |
5002 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5003 buf_T *buf = term_get_buf(argvars, "term_getjob()"); |
12502 | 5004 |
15217
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5005 if (buf == NULL) |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5006 { |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5007 rettv->v_type = VAR_SPECIAL; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5008 rettv->vval.v_number = VVAL_NULL; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5009 return; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5010 } |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5011 |
12502 | 5012 rettv->v_type = VAR_JOB; |
5013 rettv->vval.v_job = buf->b_term->tl_job; | |
5014 if (rettv->vval.v_job != NULL) | |
5015 ++rettv->vval.v_job->jv_refcount; | |
5016 } | |
5017 | |
5018 static int | |
5019 get_row_number(typval_T *tv, term_T *term) | |
5020 { | |
5021 if (tv->v_type == VAR_STRING | |
5022 && tv->vval.v_string != NULL | |
5023 && STRCMP(tv->vval.v_string, ".") == 0) | |
5024 return term->tl_cursor_pos.row; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5025 return (int)tv_get_number(tv) - 1; |
12502 | 5026 } |
5027 | |
5028 /* | |
5029 * "term_getline(buf, row)" function | |
5030 */ | |
5031 void | |
5032 f_term_getline(typval_T *argvars, typval_T *rettv) | |
5033 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5034 buf_T *buf = term_get_buf(argvars, "term_getline()"); |
12502 | 5035 term_T *term; |
5036 int row; | |
5037 | |
5038 rettv->v_type = VAR_STRING; | |
5039 if (buf == NULL) | |
5040 return; | |
5041 term = buf->b_term; | |
5042 row = get_row_number(&argvars[1], term); | |
5043 | |
5044 if (term->tl_vterm == NULL) | |
5045 { | |
5046 linenr_T lnum = row + term->tl_scrollback_scrolled + 1; | |
5047 | |
5048 /* vterm is finished, get the text from the buffer */ | |
5049 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count) | |
5050 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE)); | |
5051 } | |
5052 else | |
5053 { | |
5054 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm); | |
5055 VTermRect rect; | |
5056 int len; | |
5057 char_u *p; | |
5058 | |
5059 if (row < 0 || row >= term->tl_rows) | |
5060 return; | |
5061 len = term->tl_cols * MB_MAXBYTES + 1; | |
5062 p = alloc(len); | |
5063 if (p == NULL) | |
5064 return; | |
5065 rettv->vval.v_string = p; | |
5066 | |
5067 rect.start_col = 0; | |
5068 rect.end_col = term->tl_cols; | |
5069 rect.start_row = row; | |
5070 rect.end_row = row + 1; | |
5071 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL; | |
5072 } | |
5073 } | |
5074 | |
5075 /* | |
5076 * "term_getscrolled(buf)" function | |
5077 */ | |
5078 void | |
5079 f_term_getscrolled(typval_T *argvars, typval_T *rettv) | |
5080 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5081 buf_T *buf = term_get_buf(argvars, "term_getscrolled()"); |
12502 | 5082 |
5083 if (buf == NULL) | |
5084 return; | |
5085 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled; | |
5086 } | |
5087 | |
5088 /* | |
5089 * "term_getsize(buf)" function | |
5090 */ | |
5091 void | |
5092 f_term_getsize(typval_T *argvars, typval_T *rettv) | |
5093 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5094 buf_T *buf = term_get_buf(argvars, "term_getsize()"); |
12502 | 5095 list_T *l; |
5096 | |
5097 if (rettv_list_alloc(rettv) == FAIL) | |
5098 return; | |
5099 if (buf == NULL) | |
5100 return; | |
5101 | |
5102 l = rettv->vval.v_list; | |
5103 list_append_number(l, buf->b_term->tl_rows); | |
5104 list_append_number(l, buf->b_term->tl_cols); | |
5105 } | |
5106 | |
5107 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5108 * "term_setsize(buf, rows, cols)" function |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5109 */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5110 void |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5111 f_term_setsize(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5112 { |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5113 buf_T *buf = term_get_buf(argvars, "term_setsize()"); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5114 term_T *term; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5115 varnumber_T rows, cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5116 |
13684
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5117 if (buf == NULL) |
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5118 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5119 emsg(_("E955: Not a terminal buffer")); |
13684
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5120 return; |
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5121 } |
1651a4c5c27a
patch 8.0.1714: term_setsize() does not give an error in a normal buffer
Christian Brabandt <cb@256bit.org>
parents:
13680
diff
changeset
|
5122 if (buf->b_term->tl_vterm == NULL) |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5123 return; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5124 term = buf->b_term; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5125 rows = tv_get_number(&argvars[1]); |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5126 rows = rows <= 0 ? term->tl_rows : rows; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5127 cols = tv_get_number(&argvars[2]); |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5128 cols = cols <= 0 ? term->tl_cols : cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5129 vterm_set_size(term->tl_vterm, rows, cols); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5130 /* handle_resize() will resize the windows */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5131 |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5132 /* Get and remember the size we ended up with. Update the pty. */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5133 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5134 term_report_winsize(term, term->tl_rows, term->tl_cols); |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5135 } |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5136 |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5137 /* |
12502 | 5138 * "term_getstatus(buf)" function |
5139 */ | |
5140 void | |
5141 f_term_getstatus(typval_T *argvars, typval_T *rettv) | |
5142 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5143 buf_T *buf = term_get_buf(argvars, "term_getstatus()"); |
12502 | 5144 term_T *term; |
5145 char_u val[100]; | |
5146 | |
5147 rettv->v_type = VAR_STRING; | |
5148 if (buf == NULL) | |
5149 return; | |
5150 term = buf->b_term; | |
5151 | |
5152 if (term_job_running(term)) | |
5153 STRCPY(val, "running"); | |
5154 else | |
5155 STRCPY(val, "finished"); | |
5156 if (term->tl_normal_mode) | |
5157 STRCAT(val, ",normal"); | |
5158 rettv->vval.v_string = vim_strsave(val); | |
5159 } | |
5160 | |
5161 /* | |
5162 * "term_gettitle(buf)" function | |
5163 */ | |
5164 void | |
5165 f_term_gettitle(typval_T *argvars, typval_T *rettv) | |
5166 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5167 buf_T *buf = term_get_buf(argvars, "term_gettitle()"); |
12502 | 5168 |
5169 rettv->v_type = VAR_STRING; | |
5170 if (buf == NULL) | |
5171 return; | |
5172 | |
5173 if (buf->b_term->tl_title != NULL) | |
5174 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title); | |
5175 } | |
5176 | |
5177 /* | |
5178 * "term_gettty(buf)" function | |
5179 */ | |
5180 void | |
5181 f_term_gettty(typval_T *argvars, typval_T *rettv) | |
5182 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5183 buf_T *buf = term_get_buf(argvars, "term_gettty()"); |
13864
de8455bd2d05
patch 8.0.1803: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13862
diff
changeset
|
5184 char_u *p = NULL; |
12502 | 5185 int num = 0; |
5186 | |
5187 rettv->v_type = VAR_STRING; | |
5188 if (buf == NULL) | |
5189 return; | |
5190 if (argvars[1].v_type != VAR_UNKNOWN) | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5191 num = tv_get_number(&argvars[1]); |
12502 | 5192 |
5193 switch (num) | |
5194 { | |
5195 case 0: | |
5196 if (buf->b_term->tl_job != NULL) | |
5197 p = buf->b_term->tl_job->jv_tty_out; | |
5198 break; | |
5199 case 1: | |
5200 if (buf->b_term->tl_job != NULL) | |
5201 p = buf->b_term->tl_job->jv_tty_in; | |
5202 break; | |
5203 default: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5204 semsg(_(e_invarg2), tv_get_string(&argvars[1])); |
12502 | 5205 return; |
5206 } | |
5207 if (p != NULL) | |
5208 rettv->vval.v_string = vim_strsave(p); | |
5209 } | |
5210 | |
5211 /* | |
5212 * "term_list()" function | |
5213 */ | |
5214 void | |
5215 f_term_list(typval_T *argvars UNUSED, typval_T *rettv) | |
5216 { | |
5217 term_T *tp; | |
5218 list_T *l; | |
5219 | |
5220 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL) | |
5221 return; | |
5222 | |
5223 l = rettv->vval.v_list; | |
5224 for (tp = first_term; tp != NULL; tp = tp->tl_next) | |
5225 if (tp != NULL && tp->tl_buffer != NULL) | |
5226 if (list_append_number(l, | |
5227 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL) | |
5228 return; | |
5229 } | |
5230 | |
5231 /* | |
5232 * "term_scrape(buf, row)" function | |
5233 */ | |
5234 void | |
5235 f_term_scrape(typval_T *argvars, typval_T *rettv) | |
5236 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5237 buf_T *buf = term_get_buf(argvars, "term_scrape()"); |
12502 | 5238 VTermScreen *screen = NULL; |
5239 VTermPos pos; | |
5240 list_T *l; | |
5241 term_T *term; | |
5242 char_u *p; | |
5243 sb_line_T *line; | |
5244 | |
5245 if (rettv_list_alloc(rettv) == FAIL) | |
5246 return; | |
5247 if (buf == NULL) | |
5248 return; | |
5249 term = buf->b_term; | |
5250 | |
5251 l = rettv->vval.v_list; | |
5252 pos.row = get_row_number(&argvars[1], term); | |
5253 | |
5254 if (term->tl_vterm != NULL) | |
5255 { | |
5256 screen = vterm_obtain_screen(term->tl_vterm); | |
15273
19272aa12962
patch 8.1.0645: Coverity warns for possible use of NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
15249
diff
changeset
|
5257 if (screen == NULL) // can't really happen |
19272aa12962
patch 8.1.0645: Coverity warns for possible use of NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
15249
diff
changeset
|
5258 return; |
12502 | 5259 p = NULL; |
5260 line = NULL; | |
5261 } | |
5262 else | |
5263 { | |
5264 linenr_T lnum = pos.row + term->tl_scrollback_scrolled; | |
5265 | |
5266 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len) | |
5267 return; | |
5268 p = ml_get_buf(buf, lnum + 1, FALSE); | |
5269 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | |
5270 } | |
5271 | |
5272 for (pos.col = 0; pos.col < term->tl_cols; ) | |
5273 { | |
5274 dict_T *dcell; | |
5275 int width; | |
5276 VTermScreenCellAttrs attrs; | |
5277 VTermColor fg, bg; | |
5278 char_u rgb[8]; | |
5279 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1]; | |
5280 int off = 0; | |
5281 int i; | |
5282 | |
5283 if (screen == NULL) | |
5284 { | |
5285 cellattr_T *cellattr; | |
5286 int len; | |
5287 | |
5288 /* vterm has finished, get the cell from scrollback */ | |
5289 if (pos.col >= line->sb_cols) | |
5290 break; | |
5291 cellattr = line->sb_cells + pos.col; | |
5292 width = cellattr->width; | |
5293 attrs = cellattr->attrs; | |
5294 fg = cellattr->fg; | |
5295 bg = cellattr->bg; | |
5296 len = MB_PTR2LEN(p); | |
5297 mch_memmove(mbs, p, len); | |
5298 mbs[len] = NUL; | |
5299 p += len; | |
5300 } | |
5301 else | |
5302 { | |
5303 VTermScreenCell cell; | |
5304 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
5305 break; | |
5306 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | |
5307 { | |
5308 if (cell.chars[i] == 0) | |
5309 break; | |
5310 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off); | |
5311 } | |
5312 mbs[off] = NUL; | |
5313 width = cell.width; | |
5314 attrs = cell.attrs; | |
5315 fg = cell.fg; | |
5316 bg = cell.bg; | |
5317 } | |
5318 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
|
5319 if (dcell == NULL) |
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5320 break; |
12502 | 5321 list_append_dict(l, dcell); |
5322 | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5323 dict_add_string(dcell, "chars", mbs); |
12502 | 5324 |
5325 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
5326 fg.red, fg.green, fg.blue); | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5327 dict_add_string(dcell, "fg", rgb); |
12502 | 5328 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", |
5329 bg.red, bg.green, bg.blue); | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5330 dict_add_string(dcell, "bg", rgb); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5331 |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5332 dict_add_number(dcell, "attr", cell2attr(attrs, fg, bg)); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5333 dict_add_number(dcell, "width", width); |
12502 | 5334 |
5335 ++pos.col; | |
5336 if (width == 2) | |
5337 ++pos.col; | |
5338 } | |
5339 } | |
5340 | |
5341 /* | |
5342 * "term_sendkeys(buf, keys)" function | |
5343 */ | |
5344 void | |
5345 f_term_sendkeys(typval_T *argvars, typval_T *rettv) | |
5346 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5347 buf_T *buf = term_get_buf(argvars, "term_sendkeys()"); |
12502 | 5348 char_u *msg; |
5349 term_T *term; | |
5350 | |
5351 rettv->v_type = VAR_UNKNOWN; | |
5352 if (buf == NULL) | |
5353 return; | |
5354 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5355 msg = tv_get_string_chk(&argvars[1]); |
12502 | 5356 if (msg == NULL) |
5357 return; | |
5358 term = buf->b_term; | |
5359 if (term->tl_vterm == NULL) | |
5360 return; | |
5361 | |
5362 while (*msg != NUL) | |
5363 { | |
14029
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5364 int c; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5365 |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5366 if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL) |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5367 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5368 c = TO_SPECIAL(msg[1], msg[2]); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5369 msg += 3; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5370 } |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5371 else |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5372 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5373 c = PTR2CHAR(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5374 msg += MB_CPTR2LEN(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5375 } |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
5376 send_keys_to_term(term, c, FALSE); |
12502 | 5377 } |
5378 } | |
5379 | |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5380 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) || defined(PROTO) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5381 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5382 * "term_getansicolors(buf)" function |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5383 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5384 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5385 f_term_getansicolors(typval_T *argvars, typval_T *rettv) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5386 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5387 buf_T *buf = term_get_buf(argvars, "term_getansicolors()"); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5388 term_T *term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5389 VTermState *state; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5390 VTermColor color; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5391 char_u hexbuf[10]; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5392 int index; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5393 list_T *list; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5394 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5395 if (rettv_list_alloc(rettv) == FAIL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5396 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5397 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5398 if (buf == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5399 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5400 term = buf->b_term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5401 if (term->tl_vterm == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5402 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5403 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5404 list = rettv->vval.v_list; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5405 state = vterm_obtain_state(term->tl_vterm); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5406 for (index = 0; index < 16; index++) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5407 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5408 vterm_state_get_palette_color(state, index, &color); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5409 sprintf((char *)hexbuf, "#%02x%02x%02x", |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5410 color.red, color.green, color.blue); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5411 if (list_append_string(list, hexbuf, 7) == FAIL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5412 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5413 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5414 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5415 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5416 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5417 * "term_setansicolors(buf, list)" function |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5418 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5419 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5420 f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5421 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5422 buf_T *buf = term_get_buf(argvars, "term_setansicolors()"); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5423 term_T *term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5424 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5425 if (buf == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5426 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5427 term = buf->b_term; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5428 if (term->tl_vterm == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5429 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5430 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5431 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5432 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5433 emsg(_(e_listreq)); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5434 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5435 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5436 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5437 if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
5438 emsg(_(e_invarg)); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5439 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5440 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5441 |
12502 | 5442 /* |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5443 * "term_setrestore(buf, command)" function |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5444 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5445 void |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5446 f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5447 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5448 #if defined(FEAT_SESSION) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5449 buf_T *buf = term_get_buf(argvars, "term_setrestore()"); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5450 term_T *term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5451 char_u *cmd; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5452 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5453 if (buf == NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5454 return; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5455 term = buf->b_term; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5456 vim_free(term->tl_command); |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5457 cmd = tv_get_string_chk(&argvars[1]); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5458 if (cmd != NULL) |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5459 term->tl_command = vim_strsave(cmd); |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5460 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5461 term->tl_command = NULL; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5462 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5463 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5464 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5465 /* |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5466 * "term_setkill(buf, how)" function |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5467 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5468 void |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5469 f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5470 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5471 buf_T *buf = term_get_buf(argvars, "term_setkill()"); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5472 term_T *term; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5473 char_u *how; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5474 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5475 if (buf == NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5476 return; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5477 term = buf->b_term; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5478 vim_free(term->tl_kill); |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5479 how = tv_get_string_chk(&argvars[1]); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5480 if (how != NULL) |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5481 term->tl_kill = vim_strsave(how); |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5482 else |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5483 term->tl_kill = NULL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5484 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5485 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5486 /* |
12502 | 5487 * "term_start(command, options)" function |
5488 */ | |
5489 void | |
5490 f_term_start(typval_T *argvars, typval_T *rettv) | |
5491 { | |
5492 jobopt_T opt; | |
5493 buf_T *buf; | |
5494 | |
5495 init_job_options(&opt); | |
5496 if (argvars[1].v_type != VAR_UNKNOWN | |
5497 && get_job_options(&argvars[1], &opt, | |
5498 JO_TIMEOUT_ALL + JO_STOPONEXIT | |
5499 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK | |
5500 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO, | |
5501 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD | |
5502 + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
5503 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
5504 + JO2_NORESTORE + JO2_TERM_KILL |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
5505 + JO2_ANSI_COLORS + JO2_TTY_TYPE) == FAIL) |
12502 | 5506 return; |
5507 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
5508 buf = term_start(&argvars[0], NULL, &opt, 0); |
12502 | 5509 |
5510 if (buf != NULL && buf->b_term != NULL) | |
5511 rettv->vval.v_number = buf->b_fnum; | |
5512 } | |
5513 | |
5514 /* | |
5515 * "term_wait" function | |
5516 */ | |
5517 void | |
5518 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | |
5519 { | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
5520 buf_T *buf = term_get_buf(argvars, "term_wait()"); |
12502 | 5521 |
5522 if (buf == NULL) | |
5523 return; | |
5524 if (buf->b_term->tl_job == NULL) | |
5525 { | |
5526 ch_log(NULL, "term_wait(): no job to wait for"); | |
5527 return; | |
5528 } | |
5529 if (buf->b_term->tl_job->jv_channel == NULL) | |
5530 /* channel is closed, nothing to do */ | |
5531 return; | |
5532 | |
5533 /* 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
|
5534 if (!buf->b_term->tl_job->jv_channel->ch_keep_open |
12502 | 5535 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) |
5536 { | |
5537 /* The job is dead, keep reading channel I/O until the channel is | |
5538 * closed. buf->b_term may become NULL if the terminal was closed while | |
5539 * waiting. */ | |
5540 ch_log(NULL, "term_wait(): waiting for channel to close"); | |
5541 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) | |
5542 { | |
5543 mch_check_messages(); | |
5544 parse_queued_messages(); | |
13996
59121ffd7fce
patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
13994
diff
changeset
|
5545 ui_delay(10L, FALSE); |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
5546 if (!buf_valid(buf)) |
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
5547 /* 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
|
5548 * buffer disappears. */ |
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
5549 break; |
12502 | 5550 } |
5551 mch_check_messages(); | |
5552 parse_queued_messages(); | |
5553 } | |
5554 else | |
5555 { | |
5556 long wait = 10L; | |
5557 | |
5558 mch_check_messages(); | |
5559 parse_queued_messages(); | |
5560 | |
5561 /* Wait for some time for any channel I/O. */ | |
5562 if (argvars[1].v_type != VAR_UNKNOWN) | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5563 wait = tv_get_number(&argvars[1]); |
12502 | 5564 ui_delay(wait, TRUE); |
5565 mch_check_messages(); | |
5566 | |
5567 /* Flushing messages on channels is hopefully sufficient. | |
5568 * TODO: is there a better way? */ | |
5569 parse_queued_messages(); | |
5570 } | |
5571 } | |
5572 | |
5573 /* | |
5574 * Called when a channel has sent all the lines to a terminal. | |
5575 * Send a CTRL-D to mark the end of the text. | |
5576 */ | |
5577 void | |
5578 term_send_eof(channel_T *ch) | |
5579 { | |
5580 term_T *term; | |
5581 | |
5582 for (term = first_term; term != NULL; term = term->tl_next) | |
5583 if (term->tl_job == ch->ch_job) | |
5584 { | |
5585 if (term->tl_eof_chars != NULL) | |
5586 { | |
5587 channel_send(ch, PART_IN, term->tl_eof_chars, | |
5588 (int)STRLEN(term->tl_eof_chars), NULL); | |
5589 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL); | |
5590 } | |
5591 # ifdef WIN3264 | |
5592 else | |
5593 /* Default: CTRL-D */ | |
5594 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL); | |
5595 # endif | |
5596 } | |
5597 } | |
5598 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
5599 #if defined(FEAT_GUI) || defined(PROTO) |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
5600 job_T * |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
5601 term_getjob(term_T *term) |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
5602 { |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
5603 return term != NULL ? term->tl_job : NULL; |
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
5604 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
5605 #endif |
14139
4d3f6bf86bec
patch 8.1.0087: v:shell_error is always zero when using terminal for "!cmd"
Christian Brabandt <cb@256bit.org>
parents:
14117
diff
changeset
|
5606 |
12502 | 5607 # if defined(WIN3264) || defined(PROTO) |
5608 | |
5609 /************************************** | |
5610 * 2. MS-Windows implementation. | |
5611 */ | |
5612 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5613 HRESULT (WINAPI *pCreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON*); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5614 HRESULT (WINAPI *pResizePseudoConsole)(HPCON, COORD); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5615 HRESULT (WINAPI *pClosePseudoConsole)(HPCON); |
15786
ec39beb7e61f
patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
5616 BOOL (WINAPI *pInitializeProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T); |
ec39beb7e61f
patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
5617 BOOL (WINAPI *pUpdateProcThreadAttribute)(LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T); |
ec39beb7e61f
patch 8.1.0900: ConPTY many crash with 32-bit build
Bram Moolenaar <Bram@vim.org>
parents:
15746
diff
changeset
|
5618 void (WINAPI *pDeleteProcThreadAttributeList)(LPPROC_THREAD_ATTRIBUTE_LIST); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5619 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5620 static int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5621 dyn_conpty_init(int verbose) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5622 { |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5623 static HMODULE hKerneldll = NULL; |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5624 int i; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5625 static struct |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5626 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5627 char *name; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5628 FARPROC *ptr; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5629 } conpty_entry[] = |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5630 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5631 {"CreatePseudoConsole", (FARPROC*)&pCreatePseudoConsole}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5632 {"ResizePseudoConsole", (FARPROC*)&pResizePseudoConsole}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5633 {"ClosePseudoConsole", (FARPROC*)&pClosePseudoConsole}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5634 {"InitializeProcThreadAttributeList", |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5635 (FARPROC*)&pInitializeProcThreadAttributeList}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5636 {"UpdateProcThreadAttribute", |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5637 (FARPROC*)&pUpdateProcThreadAttribute}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5638 {"DeleteProcThreadAttributeList", |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5639 (FARPROC*)&pDeleteProcThreadAttributeList}, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5640 {NULL, NULL} |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5641 }; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5642 |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15786
diff
changeset
|
5643 if (!has_conpty_working()) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5644 { |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5645 if (verbose) |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5646 emsg(_("E982: ConPTY is not available")); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5647 return FAIL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5648 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5649 |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5650 // No need to initialize twice. |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5651 if (hKerneldll) |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5652 return OK; |
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5653 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5654 hKerneldll = vimLoadLib("kernel32.dll"); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5655 for (i = 0; conpty_entry[i].name != NULL |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5656 && conpty_entry[i].ptr != NULL; ++i) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5657 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5658 if ((*conpty_entry[i].ptr = (FARPROC)GetProcAddress(hKerneldll, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5659 conpty_entry[i].name)) == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5660 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5661 if (verbose) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5662 semsg(_(e_loadfunc), conpty_entry[i].name); |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
5663 hKerneldll = NULL; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5664 return FAIL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5665 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5666 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5667 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5668 return OK; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5669 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5670 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5671 static int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5672 conpty_term_and_job_init( |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5673 term_T *term, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5674 typval_T *argvar, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5675 char **argv, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5676 jobopt_T *opt, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5677 jobopt_T *orig_opt) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5678 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5679 WCHAR *cmd_wchar = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5680 WCHAR *cmd_wchar_copy = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5681 WCHAR *cwd_wchar = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5682 WCHAR *env_wchar = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5683 channel_T *channel = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5684 job_T *job = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5685 HANDLE jo = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5686 garray_T ga_cmd, ga_env; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5687 char_u *cmd = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5688 HRESULT hr; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5689 COORD consize; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5690 SIZE_T breq; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5691 PROCESS_INFORMATION proc_info; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5692 HANDLE i_theirs = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5693 HANDLE o_theirs = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5694 HANDLE i_ours = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5695 HANDLE o_ours = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5696 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5697 ga_init2(&ga_cmd, (int)sizeof(char*), 20); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5698 ga_init2(&ga_env, (int)sizeof(char*), 20); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5699 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5700 if (argvar->v_type == VAR_STRING) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5701 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5702 cmd = argvar->vval.v_string; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5703 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5704 else if (argvar->v_type == VAR_LIST) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5705 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5706 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5707 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5708 cmd = ga_cmd.ga_data; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5709 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5710 if (cmd == NULL || *cmd == NUL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5711 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5712 emsg(_(e_invarg)); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5713 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5714 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5715 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5716 term->tl_arg0_cmd = vim_strsave(cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5717 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5718 cmd_wchar = enc_to_utf16(cmd, NULL); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5719 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5720 if (cmd_wchar != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5721 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5722 /* Request by CreateProcessW */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5723 breq = wcslen(cmd_wchar) + 1 + 1; /* Addition of NUL by API */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5724 cmd_wchar_copy = (PWSTR)alloc((int)(breq * sizeof(WCHAR))); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5725 wcsncpy(cmd_wchar_copy, cmd_wchar, breq - 1); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5726 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5727 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5728 ga_clear(&ga_cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5729 if (cmd_wchar == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5730 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5731 if (opt->jo_cwd != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5732 cwd_wchar = enc_to_utf16(opt->jo_cwd, NULL); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5733 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5734 win32_build_env(opt->jo_env, &ga_env, TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5735 env_wchar = ga_env.ga_data; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5736 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5737 if (!CreatePipe(&i_theirs, &i_ours, NULL, 0)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5738 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5739 if (!CreatePipe(&o_ours, &o_theirs, NULL, 0)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5740 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5741 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5742 consize.X = term->tl_cols; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5743 consize.Y = term->tl_rows; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5744 hr = pCreatePseudoConsole(consize, i_theirs, o_theirs, 0, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5745 &term->tl_conpty); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5746 if (FAILED(hr)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5747 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5748 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5749 term->tl_siex.StartupInfo.cb = sizeof(term->tl_siex); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5750 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5751 /* Set up pipe inheritance safely: Vista or later. */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5752 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5753 term->tl_siex.lpAttributeList = |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5754 (PPROC_THREAD_ATTRIBUTE_LIST)alloc((int)breq); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5755 if (!term->tl_siex.lpAttributeList) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5756 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5757 if (!pInitializeProcThreadAttributeList(term->tl_siex.lpAttributeList, 1, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5758 0, &breq)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5759 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5760 if (!pUpdateProcThreadAttribute( |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5761 term->tl_siex.lpAttributeList, 0, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5762 PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, term->tl_conpty, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5763 sizeof(HPCON), NULL, NULL)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5764 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5765 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5766 channel = add_channel(); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5767 if (channel == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5768 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5769 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5770 job = job_alloc(); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5771 if (job == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5772 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5773 if (argvar->v_type == VAR_STRING) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5774 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5775 int argc; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5776 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5777 build_argv_from_string(cmd, &job->jv_argv, &argc); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5778 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5779 else |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5780 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5781 int argc; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5782 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5783 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5784 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5785 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5786 if (opt->jo_set & JO_IN_BUF) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5787 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5788 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5789 if (!CreateProcessW(NULL, cmd_wchar_copy, NULL, NULL, FALSE, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5790 EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5791 | CREATE_SUSPENDED | CREATE_NEW_PROCESS_GROUP |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5792 | CREATE_DEFAULT_ERROR_MODE, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5793 env_wchar, cwd_wchar, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5794 &term->tl_siex.StartupInfo, &proc_info)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5795 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5796 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5797 CloseHandle(i_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5798 CloseHandle(o_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5799 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5800 channel_set_pipes(channel, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5801 (sock_T)i_ours, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5802 (sock_T)o_ours, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5803 (sock_T)o_ours); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5804 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5805 /* Write lines with CR instead of NL. */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5806 channel->ch_write_text_mode = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5807 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5808 /* Use to explicitly delete anonymous pipe handle. */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5809 channel->ch_anonymous_pipe = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5810 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5811 jo = CreateJobObject(NULL, NULL); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5812 if (jo == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5813 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5814 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5815 if (!AssignProcessToJobObject(jo, proc_info.hProcess)) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5816 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5817 /* Failed, switch the way to terminate process with TerminateProcess. */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5818 CloseHandle(jo); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5819 jo = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5820 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5821 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5822 ResumeThread(proc_info.hThread); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5823 CloseHandle(proc_info.hThread); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5824 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5825 vim_free(cmd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5826 vim_free(cmd_wchar_copy); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5827 vim_free(cwd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5828 vim_free(env_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5829 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5830 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5831 goto failed; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5832 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5833 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5834 if (opt->jo_set2 & JO2_ANSI_COLORS) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5835 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5836 else |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5837 init_vterm_ansi_colors(term->tl_vterm); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5838 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5839 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5840 channel_set_job(channel, job, opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5841 job_set_options(job, opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5842 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5843 job->jv_channel = channel; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5844 job->jv_proc_info = proc_info; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5845 job->jv_job_object = jo; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5846 job->jv_status = JOB_STARTED; |
15810
5523665fdf80
patch 8.1.0912: MS-Windows: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
5847 job->jv_tty_type = vim_strsave((char_u *)"conpty"); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5848 ++job->jv_refcount; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5849 term->tl_job = job; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5850 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5851 /* Redirecting stdout and stderr doesn't work at the job level. Instead |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5852 * open the file here and handle it in. opt->jo_io was changed in |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5853 * setup_job_options(), use the original flags here. */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5854 if (orig_opt->jo_io[PART_OUT] == JIO_FILE) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5855 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5856 char_u *fname = opt->jo_io_name[PART_OUT]; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5857 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5858 ch_log(channel, "Opening output file %s", fname); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5859 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5860 if (term->tl_out_fd == NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5861 semsg(_(e_notopen), fname); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5862 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5863 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5864 return OK; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5865 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5866 failed: |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5867 ga_clear(&ga_cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5868 ga_clear(&ga_env); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5869 vim_free(cmd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5870 vim_free(cmd_wchar_copy); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5871 vim_free(cwd_wchar); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5872 if (channel != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5873 channel_clear(channel); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5874 if (job != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5875 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5876 job->jv_channel = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5877 job_cleanup(job); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5878 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5879 term->tl_job = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5880 if (jo != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5881 CloseHandle(jo); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5882 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5883 if (term->tl_siex.lpAttributeList != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5884 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5885 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5886 vim_free(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5887 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5888 term->tl_siex.lpAttributeList = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5889 if (o_theirs != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5890 CloseHandle(o_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5891 if (o_ours != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5892 CloseHandle(o_ours); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5893 if (i_ours != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5894 CloseHandle(i_ours); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5895 if (i_theirs != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5896 CloseHandle(i_theirs); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5897 if (term->tl_conpty != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5898 pClosePseudoConsole(term->tl_conpty); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5899 term->tl_conpty = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5900 return FAIL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5901 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5902 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5903 static void |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5904 conpty_term_report_winsize(term_T *term, int rows, int cols) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5905 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5906 COORD consize; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5907 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5908 consize.X = cols; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5909 consize.Y = rows; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5910 pResizePseudoConsole(term->tl_conpty, consize); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5911 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5912 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5913 void |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5914 term_free_conpty(term_T *term) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5915 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5916 if (term->tl_siex.lpAttributeList != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5917 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5918 pDeleteProcThreadAttributeList(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5919 vim_free(term->tl_siex.lpAttributeList); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5920 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5921 term->tl_siex.lpAttributeList = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5922 if (term->tl_conpty != NULL) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5923 pClosePseudoConsole(term->tl_conpty); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5924 term->tl_conpty = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5925 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5926 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5927 int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5928 use_conpty(void) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5929 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5930 return has_conpty; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5931 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
5932 |
12502 | 5933 # ifndef PROTO |
5934 | |
5935 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul | |
5936 #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
|
5937 #define WINPTY_MOUSE_MODE_FORCE 2 |
12502 | 5938 |
5939 void* (*winpty_config_new)(UINT64, void*); | |
5940 void* (*winpty_open)(void*, void*); | |
5941 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*); | |
5942 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*); | |
5943 void (*winpty_config_set_mouse_mode)(void*, int); | |
5944 void (*winpty_config_set_initial_size)(void*, int, int); | |
5945 LPCWSTR (*winpty_conin_name)(void*); | |
5946 LPCWSTR (*winpty_conout_name)(void*); | |
5947 LPCWSTR (*winpty_conerr_name)(void*); | |
5948 void (*winpty_free)(void*); | |
5949 void (*winpty_config_free)(void*); | |
5950 void (*winpty_spawn_config_free)(void*); | |
5951 void (*winpty_error_free)(void*); | |
5952 LPCWSTR (*winpty_error_msg)(void*); | |
5953 BOOL (*winpty_set_size)(void*, int, int, void*); | |
5954 HANDLE (*winpty_agent_process)(void*); | |
5955 | |
5956 #define WINPTY_DLL "winpty.dll" | |
5957 | |
5958 static HINSTANCE hWinPtyDLL = NULL; | |
5959 # endif | |
5960 | |
5961 static int | |
5962 dyn_winpty_init(int verbose) | |
5963 { | |
5964 int i; | |
5965 static struct | |
5966 { | |
5967 char *name; | |
5968 FARPROC *ptr; | |
5969 } winpty_entry[] = | |
5970 { | |
5971 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name}, | |
5972 {"winpty_config_free", (FARPROC*)&winpty_config_free}, | |
5973 {"winpty_config_new", (FARPROC*)&winpty_config_new}, | |
5974 {"winpty_config_set_mouse_mode", | |
5975 (FARPROC*)&winpty_config_set_mouse_mode}, | |
5976 {"winpty_config_set_initial_size", | |
5977 (FARPROC*)&winpty_config_set_initial_size}, | |
5978 {"winpty_conin_name", (FARPROC*)&winpty_conin_name}, | |
5979 {"winpty_conout_name", (FARPROC*)&winpty_conout_name}, | |
5980 {"winpty_error_free", (FARPROC*)&winpty_error_free}, | |
5981 {"winpty_free", (FARPROC*)&winpty_free}, | |
5982 {"winpty_open", (FARPROC*)&winpty_open}, | |
5983 {"winpty_spawn", (FARPROC*)&winpty_spawn}, | |
5984 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free}, | |
5985 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new}, | |
5986 {"winpty_error_msg", (FARPROC*)&winpty_error_msg}, | |
5987 {"winpty_set_size", (FARPROC*)&winpty_set_size}, | |
5988 {"winpty_agent_process", (FARPROC*)&winpty_agent_process}, | |
5989 {NULL, NULL} | |
5990 }; | |
5991 | |
5992 /* No need to initialize twice. */ | |
5993 if (hWinPtyDLL) | |
5994 return OK; | |
5995 /* Load winpty.dll, prefer using the 'winptydll' option, fall back to just | |
5996 * winpty.dll. */ | |
5997 if (*p_winptydll != NUL) | |
5998 hWinPtyDLL = vimLoadLib((char *)p_winptydll); | |
5999 if (!hWinPtyDLL) | |
6000 hWinPtyDLL = vimLoadLib(WINPTY_DLL); | |
6001 if (!hWinPtyDLL) | |
6002 { | |
6003 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6004 semsg(_(e_loadlib), *p_winptydll != NUL ? p_winptydll |
12502 | 6005 : (char_u *)WINPTY_DLL); |
6006 return FAIL; | |
6007 } | |
6008 for (i = 0; winpty_entry[i].name != NULL | |
6009 && winpty_entry[i].ptr != NULL; ++i) | |
6010 { | |
6011 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL, | |
6012 winpty_entry[i].name)) == NULL) | |
6013 { | |
6014 if (verbose) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6015 semsg(_(e_loadfunc), winpty_entry[i].name); |
15844
63e71d195cee
patch 8.1.0929: no error when requesting ConPTY but it's not available
Bram Moolenaar <Bram@vim.org>
parents:
15832
diff
changeset
|
6016 hWinPtyDLL = NULL; |
12502 | 6017 return FAIL; |
6018 } | |
6019 } | |
6020 | |
6021 return OK; | |
6022 } | |
6023 | |
6024 static int | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6025 winpty_term_and_job_init( |
12502 | 6026 term_T *term, |
6027 typval_T *argvar, | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6028 char **argv, |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6029 jobopt_T *opt, |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6030 jobopt_T *orig_opt) |
12502 | 6031 { |
6032 WCHAR *cmd_wchar = NULL; | |
6033 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
|
6034 WCHAR *env_wchar = NULL; |
12502 | 6035 channel_T *channel = NULL; |
6036 job_T *job = NULL; | |
6037 DWORD error; | |
6038 HANDLE jo = NULL; | |
6039 HANDLE child_process_handle; | |
6040 HANDLE child_thread_handle; | |
13111
149347fda678
patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents:
13109
diff
changeset
|
6041 void *winpty_err = NULL; |
12502 | 6042 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
|
6043 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
|
6044 char_u *cmd = NULL; |
12502 | 6045 |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6046 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
|
6047 ga_init2(&ga_env, (int)sizeof(char*), 20); |
12502 | 6048 |
6049 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
|
6050 { |
12502 | 6051 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
|
6052 } |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6053 else if (argvar->v_type == VAR_LIST) |
12502 | 6054 { |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
6055 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
12502 | 6056 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
|
6057 cmd = ga_cmd.ga_data; |
12502 | 6058 } |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6059 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
|
6060 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6061 emsg(_(e_invarg)); |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6062 goto failed; |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6063 } |
12502 | 6064 |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6065 term->tl_arg0_cmd = vim_strsave(cmd); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6066 |
12502 | 6067 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
|
6068 ga_clear(&ga_cmd); |
12502 | 6069 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
|
6070 goto failed; |
12502 | 6071 if (opt->jo_cwd != NULL) |
6072 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
|
6073 |
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
|
6074 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
|
6075 env_wchar = ga_env.ga_data; |
12502 | 6076 |
6077 term->tl_winpty_config = winpty_config_new(0, &winpty_err); | |
6078 if (term->tl_winpty_config == NULL) | |
6079 goto failed; | |
6080 | |
6081 winpty_config_set_mouse_mode(term->tl_winpty_config, | |
6082 WINPTY_MOUSE_MODE_FORCE); | |
6083 winpty_config_set_initial_size(term->tl_winpty_config, | |
6084 term->tl_cols, term->tl_rows); | |
6085 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err); | |
6086 if (term->tl_winpty == NULL) | |
6087 goto failed; | |
6088 | |
6089 spawn_config = winpty_spawn_config_new( | |
6090 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN | | |
6091 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN, | |
6092 NULL, | |
6093 cmd_wchar, | |
6094 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
|
6095 env_wchar, |
12502 | 6096 &winpty_err); |
6097 if (spawn_config == NULL) | |
6098 goto failed; | |
6099 | |
6100 channel = add_channel(); | |
6101 if (channel == NULL) | |
6102 goto failed; | |
6103 | |
6104 job = job_alloc(); | |
6105 if (job == NULL) | |
6106 goto failed; | |
13750
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6107 if (argvar->v_type == VAR_STRING) |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6108 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6109 int argc; |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6110 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6111 build_argv_from_string(cmd, &job->jv_argv, &argc); |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6112 } |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6113 else |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6114 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6115 int argc; |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6116 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6117 build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc); |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
6118 } |
12502 | 6119 |
6120 if (opt->jo_set & JO_IN_BUF) | |
6121 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); | |
6122 | |
6123 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle, | |
6124 &child_thread_handle, &error, &winpty_err)) | |
6125 goto failed; | |
6126 | |
6127 channel_set_pipes(channel, | |
6128 (sock_T)CreateFileW( | |
6129 winpty_conin_name(term->tl_winpty), | |
6130 GENERIC_WRITE, 0, NULL, | |
6131 OPEN_EXISTING, 0, NULL), | |
6132 (sock_T)CreateFileW( | |
6133 winpty_conout_name(term->tl_winpty), | |
6134 GENERIC_READ, 0, NULL, | |
6135 OPEN_EXISTING, 0, NULL), | |
6136 (sock_T)CreateFileW( | |
6137 winpty_conerr_name(term->tl_winpty), | |
6138 GENERIC_READ, 0, NULL, | |
6139 OPEN_EXISTING, 0, NULL)); | |
6140 | |
6141 /* Write lines with CR instead of NL. */ | |
6142 channel->ch_write_text_mode = TRUE; | |
6143 | |
6144 jo = CreateJobObject(NULL, NULL); | |
6145 if (jo == NULL) | |
6146 goto failed; | |
6147 | |
6148 if (!AssignProcessToJobObject(jo, child_process_handle)) | |
6149 { | |
6150 /* Failed, switch the way to terminate process with TerminateProcess. */ | |
6151 CloseHandle(jo); | |
6152 jo = NULL; | |
6153 } | |
6154 | |
6155 winpty_spawn_config_free(spawn_config); | |
6156 vim_free(cmd_wchar); | |
6157 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
|
6158 vim_free(env_wchar); |
12502 | 6159 |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6160 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6161 goto failed; |
12502 | 6162 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6163 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6164 if (opt->jo_set2 & JO2_ANSI_COLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6165 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6166 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6167 init_vterm_ansi_colors(term->tl_vterm); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6168 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6169 |
12502 | 6170 channel_set_job(channel, job, opt); |
6171 job_set_options(job, opt); | |
6172 | |
6173 job->jv_channel = channel; | |
6174 job->jv_proc_info.hProcess = child_process_handle; | |
6175 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle); | |
6176 job->jv_job_object = jo; | |
6177 job->jv_status = JOB_STARTED; | |
6178 job->jv_tty_in = utf16_to_enc( | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6179 (short_u *)winpty_conin_name(term->tl_winpty), NULL); |
12502 | 6180 job->jv_tty_out = utf16_to_enc( |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6181 (short_u *)winpty_conout_name(term->tl_winpty), NULL); |
15810
5523665fdf80
patch 8.1.0912: MS-Windows: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15804
diff
changeset
|
6182 job->jv_tty_type = vim_strsave((char_u *)"winpty"); |
12502 | 6183 ++job->jv_refcount; |
6184 term->tl_job = job; | |
6185 | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6186 /* Redirecting stdout and stderr doesn't work at the job level. Instead |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6187 * open the file here and handle it in. opt->jo_io was changed in |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6188 * setup_job_options(), use the original flags here. */ |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6189 if (orig_opt->jo_io[PART_OUT] == JIO_FILE) |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6190 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6191 char_u *fname = opt->jo_io_name[PART_OUT]; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6192 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6193 ch_log(channel, "Opening output file %s", fname); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6194 term->tl_out_fd = mch_fopen((char *)fname, WRITEBIN); |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6195 if (term->tl_out_fd == NULL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6196 semsg(_(e_notopen), fname); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6197 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6198 |
12502 | 6199 return OK; |
6200 | |
6201 failed: | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
6202 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
|
6203 ga_clear(&ga_env); |
12502 | 6204 vim_free(cmd_wchar); |
6205 vim_free(cwd_wchar); | |
6206 if (spawn_config != NULL) | |
6207 winpty_spawn_config_free(spawn_config); | |
6208 if (channel != NULL) | |
6209 channel_clear(channel); | |
6210 if (job != NULL) | |
6211 { | |
6212 job->jv_channel = NULL; | |
6213 job_cleanup(job); | |
6214 } | |
6215 term->tl_job = NULL; | |
6216 if (jo != NULL) | |
6217 CloseHandle(jo); | |
6218 if (term->tl_winpty != NULL) | |
6219 winpty_free(term->tl_winpty); | |
6220 term->tl_winpty = NULL; | |
6221 if (term->tl_winpty_config != NULL) | |
6222 winpty_config_free(term->tl_winpty_config); | |
6223 term->tl_winpty_config = NULL; | |
6224 if (winpty_err != NULL) | |
6225 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6226 char *msg = (char *)utf16_to_enc( |
12502 | 6227 (short_u *)winpty_error_msg(winpty_err), NULL); |
6228 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
6229 emsg(msg); |
12502 | 6230 winpty_error_free(winpty_err); |
6231 } | |
6232 return FAIL; | |
6233 } | |
6234 | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6235 /* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6236 * Create a new terminal of "rows" by "cols" cells. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6237 * Store a reference in "term". |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6238 * Return OK or FAIL. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6239 */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6240 static int |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6241 term_and_job_init( |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6242 term_T *term, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6243 typval_T *argvar, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6244 char **argv UNUSED, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6245 jobopt_T *opt, |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6246 jobopt_T *orig_opt) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6247 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6248 int use_winpty = FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6249 int use_conpty = FALSE; |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6250 int tty_type = *p_twt; |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6251 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6252 has_winpty = dyn_winpty_init(FALSE) != FAIL ? TRUE : FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6253 has_conpty = dyn_conpty_init(FALSE) != FAIL ? TRUE : FALSE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6254 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6255 if (!has_winpty && !has_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6256 // If neither is available give the errors for winpty, since when |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6257 // conpty is not available it can't be installed either. |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6258 return dyn_winpty_init(TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6259 |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6260 if (opt->jo_tty_type != NUL) |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6261 tty_type = opt->jo_tty_type; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6262 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6263 if (tty_type == NUL) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6264 { |
15804
864ec0dd71b9
patch 8.1.0909: MS-Windows: using ConPTY even though it is not stable
Bram Moolenaar <Bram@vim.org>
parents:
15786
diff
changeset
|
6265 if (has_conpty && (is_conpty_stable() || !has_winpty)) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6266 use_conpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6267 else if (has_winpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6268 use_winpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6269 // else: error |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6270 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6271 else if (tty_type == 'w') // winpty |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6272 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6273 if (has_winpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6274 use_winpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6275 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
6276 else if (tty_type == 'c') // conpty |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6277 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6278 if (has_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6279 use_conpty = TRUE; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6280 else |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6281 return dyn_conpty_init(TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6282 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6283 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6284 if (use_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6285 return conpty_term_and_job_init(term, argvar, argv, opt, orig_opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6286 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6287 if (use_winpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6288 return winpty_term_and_job_init(term, argvar, argv, opt, orig_opt); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6289 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6290 // error |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6291 return dyn_winpty_init(TRUE); |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6292 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6293 |
12502 | 6294 static int |
6295 create_pty_only(term_T *term, jobopt_T *options) | |
6296 { | |
6297 HANDLE hPipeIn = INVALID_HANDLE_VALUE; | |
6298 HANDLE hPipeOut = INVALID_HANDLE_VALUE; | |
6299 char in_name[80], out_name[80]; | |
6300 channel_T *channel = NULL; | |
6301 | |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6302 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6303 return FAIL; |
12502 | 6304 |
6305 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d", | |
6306 GetCurrentProcessId(), | |
6307 curbuf->b_fnum); | |
6308 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND, | |
6309 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
6310 PIPE_UNLIMITED_INSTANCES, | |
6311 0, 0, NMPWAIT_NOWAIT, NULL); | |
6312 if (hPipeIn == INVALID_HANDLE_VALUE) | |
6313 goto failed; | |
6314 | |
6315 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d", | |
6316 GetCurrentProcessId(), | |
6317 curbuf->b_fnum); | |
6318 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND, | |
6319 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
6320 PIPE_UNLIMITED_INSTANCES, | |
6321 0, 0, 0, NULL); | |
6322 if (hPipeOut == INVALID_HANDLE_VALUE) | |
6323 goto failed; | |
6324 | |
6325 ConnectNamedPipe(hPipeIn, NULL); | |
6326 ConnectNamedPipe(hPipeOut, NULL); | |
6327 | |
6328 term->tl_job = job_alloc(); | |
6329 if (term->tl_job == NULL) | |
6330 goto failed; | |
6331 ++term->tl_job->jv_refcount; | |
6332 | |
6333 /* behave like the job is already finished */ | |
6334 term->tl_job->jv_status = JOB_FINISHED; | |
6335 | |
6336 channel = add_channel(); | |
6337 if (channel == NULL) | |
6338 goto failed; | |
6339 term->tl_job->jv_channel = channel; | |
6340 channel->ch_keep_open = TRUE; | |
6341 channel->ch_named_pipe = TRUE; | |
6342 | |
6343 channel_set_pipes(channel, | |
6344 (sock_T)hPipeIn, | |
6345 (sock_T)hPipeOut, | |
6346 (sock_T)hPipeOut); | |
6347 channel_set_job(channel, term->tl_job, options); | |
6348 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name); | |
6349 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name); | |
6350 | |
6351 return OK; | |
6352 | |
6353 failed: | |
6354 if (hPipeIn != NULL) | |
6355 CloseHandle(hPipeIn); | |
6356 if (hPipeOut != NULL) | |
6357 CloseHandle(hPipeOut); | |
6358 return FAIL; | |
6359 } | |
6360 | |
6361 /* | |
6362 * Free the terminal emulator part of "term". | |
6363 */ | |
6364 static void | |
6365 term_free_vterm(term_T *term) | |
6366 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6367 term_free_conpty(term); |
12502 | 6368 if (term->tl_winpty != NULL) |
6369 winpty_free(term->tl_winpty); | |
6370 term->tl_winpty = NULL; | |
6371 if (term->tl_winpty_config != NULL) | |
6372 winpty_config_free(term->tl_winpty_config); | |
6373 term->tl_winpty_config = NULL; | |
6374 if (term->tl_vterm != NULL) | |
6375 vterm_free(term->tl_vterm); | |
6376 term->tl_vterm = NULL; | |
6377 } | |
6378 | |
6379 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6380 * Report the size to the terminal. |
12502 | 6381 */ |
6382 static void | |
6383 term_report_winsize(term_T *term, int rows, int cols) | |
6384 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6385 if (term->tl_conpty) |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6386 conpty_term_report_winsize(term, rows, cols); |
12502 | 6387 if (term->tl_winpty) |
6388 winpty_set_size(term->tl_winpty, cols, rows, NULL); | |
6389 } | |
6390 | |
6391 int | |
6392 terminal_enabled(void) | |
6393 { | |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6394 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK; |
12502 | 6395 } |
6396 | |
6397 # else | |
6398 | |
6399 /************************************** | |
6400 * 3. Unix-like implementation. | |
6401 */ | |
6402 | |
6403 /* | |
6404 * Create a new terminal of "rows" by "cols" cells. | |
6405 * Start job for "cmd". | |
6406 * Store the pointers in "term". | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6407 * When "argv" is not NULL then "argvar" is not used. |
12502 | 6408 * Return OK or FAIL. |
6409 */ | |
6410 static int | |
6411 term_and_job_init( | |
6412 term_T *term, | |
6413 typval_T *argvar, | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6414 char **argv, |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6415 jobopt_T *opt, |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
6416 jobopt_T *orig_opt UNUSED) |
12502 | 6417 { |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6418 term->tl_arg0_cmd = NULL; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6419 |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6420 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6421 return FAIL; |
12502 | 6422 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6423 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6424 if (opt->jo_set2 & JO2_ANSI_COLORS) |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6425 set_vterm_palette(term->tl_vterm, opt->jo_ansi_colors); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6426 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6427 init_vterm_ansi_colors(term->tl_vterm); |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6428 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6429 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6430 /* This may change a string in "argvar". */ |
14065
e271ca6f32f9
patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
14029
diff
changeset
|
6431 term->tl_job = job_start(argvar, argv, opt, TRUE); |
12502 | 6432 if (term->tl_job != NULL) |
6433 ++term->tl_job->jv_refcount; | |
6434 | |
6435 return term->tl_job != NULL | |
6436 && term->tl_job->jv_channel != NULL | |
6437 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL; | |
6438 } | |
6439 | |
6440 static int | |
6441 create_pty_only(term_T *term, jobopt_T *opt) | |
6442 { | |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6443 if (create_vterm(term, term->tl_rows, term->tl_cols) == FAIL) |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
6444 return FAIL; |
12502 | 6445 |
6446 term->tl_job = job_alloc(); | |
6447 if (term->tl_job == NULL) | |
6448 return FAIL; | |
6449 ++term->tl_job->jv_refcount; | |
6450 | |
6451 /* behave like the job is already finished */ | |
6452 term->tl_job->jv_status = JOB_FINISHED; | |
6453 | |
6454 return mch_create_pty_channel(term->tl_job, opt); | |
6455 } | |
6456 | |
6457 /* | |
6458 * Free the terminal emulator part of "term". | |
6459 */ | |
6460 static void | |
6461 term_free_vterm(term_T *term) | |
6462 { | |
6463 if (term->tl_vterm != NULL) | |
6464 vterm_free(term->tl_vterm); | |
6465 term->tl_vterm = NULL; | |
6466 } | |
6467 | |
6468 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6469 * Report the size to the terminal. |
12502 | 6470 */ |
6471 static void | |
6472 term_report_winsize(term_T *term, int rows, int cols) | |
6473 { | |
6474 /* Use an ioctl() to report the new window size to the job. */ | |
6475 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) | |
6476 { | |
6477 int fd = -1; | |
6478 int part; | |
6479 | |
6480 for (part = PART_OUT; part < PART_COUNT; ++part) | |
6481 { | |
6482 fd = term->tl_job->jv_channel->ch_part[part].ch_fd; | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
6483 if (mch_isatty(fd)) |
12502 | 6484 break; |
6485 } | |
6486 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) | |
6487 mch_signal_job(term->tl_job, (char_u *)"winch"); | |
6488 } | |
6489 } | |
6490 | |
6491 # endif | |
6492 | |
6493 #endif /* FEAT_TERMINAL */ |