Mercurial > vim
annotate src/terminal.c @ 28037:12a256140887 v8.2.4543
patch 8.2.4543: Coverity warning for refactored tag search code
Commit: https://github.com/vim/vim/commit/20fb28b1dcc092787e1a7b22dcfcfe1e46e29813
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Mar 11 12:05:18 2022 +0000
patch 8.2.4543: Coverity warning for refactored tag search code
Problem: Coverity warning for refactored tag search code.
Solution: Avoid the warnings. Update comments. Add one more test case.
(Yegappan Lakshmanan, closes #9928)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 11 Mar 2022 13:15:04 +0100 |
parents | dd804c17e7e3 |
children | 62cc3b60493b |
rev | line source |
---|---|
12502 | 1 /* vi:set ts=8 sts=4 sw=4 noet: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * Terminal window support, see ":help :terminal". | |
12 * | |
13 * There are three parts: | |
14 * 1. Generic code for all systems. | |
15 * Uses libvterm for the terminal emulator. | |
16 * 2. The MS-Windows implementation. | |
17 * Uses winpty. | |
18 * 3. The Unix-like implementation. | |
19 * Uses pseudo-tty's (pty's). | |
20 * | |
21 * For each terminal one VTerm is constructed. This uses libvterm. A copy of | |
22 * this library is in the libvterm directory. | |
23 * | |
24 * When a terminal window is opened, a job is started that will be connected to | |
25 * the terminal emulator. | |
26 * | |
27 * If the terminal window has keyboard focus, typed keys are converted to the | |
28 * terminal encoding and writing to the job over a channel. | |
29 * | |
30 * If the job produces output, it is written to the terminal emulator. The | |
31 * terminal emulator invokes callbacks when its screen content changes. The | |
32 * line range is stored in tl_dirty_row_start and tl_dirty_row_end. Once in a | |
33 * while, if the terminal window is visible, the screen contents is drawn. | |
34 * | |
35 * When the job ends the text is put in a buffer. Redrawing then happens from | |
36 * that buffer, attributes come from the scrollback buffer tl_scrollback. | |
37 * When the buffer is changed it is turned into a normal buffer, the attributes | |
38 * in tl_scrollback are no longer used. | |
39 */ | |
40 | |
41 #include "vim.h" | |
42 | |
43 #if defined(FEAT_TERMINAL) || defined(PROTO) | |
44 | |
45 #ifndef MIN | |
46 # define MIN(x,y) ((x) < (y) ? (x) : (y)) | |
47 #endif | |
48 #ifndef MAX | |
49 # define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
50 #endif | |
51 | |
52 #include "libvterm/include/vterm.h" | |
53 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
54 // This is VTermScreenCell without the characters, thus much smaller. |
12502 | 55 typedef struct { |
56 VTermScreenCellAttrs attrs; | |
57 char width; | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
58 VTermColor fg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
59 VTermColor bg; |
12502 | 60 } cellattr_T; |
61 | |
62 typedef struct sb_line_S { | |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
63 int sb_cols; // can differ per line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
64 cellattr_T *sb_cells; // allocated |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
65 cellattr_T sb_fill_attr; // for short line |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
66 char_u *sb_text; // for tl_scrollback_postponed |
12502 | 67 } sb_line_T; |
68 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
69 #ifdef MSWIN |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
70 # ifndef HPCON |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
71 # define HPCON VOID* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
72 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
73 # ifndef EXTENDED_STARTUPINFO_PRESENT |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
74 # define EXTENDED_STARTUPINFO_PRESENT 0x00080000 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
75 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
76 # ifndef PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
77 # define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
78 # endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
79 typedef struct _DYN_STARTUPINFOEXW |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
80 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
81 STARTUPINFOW StartupInfo; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
82 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
83 } DYN_STARTUPINFOEXW, *PDYN_STARTUPINFOEXW; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
84 #endif |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
85 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
86 // typedef term_T in structs.h |
12502 | 87 struct terminal_S { |
88 term_T *tl_next; | |
89 | |
90 VTerm *tl_vterm; | |
91 job_T *tl_job; | |
92 buf_T *tl_buffer; | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
93 #if defined(FEAT_GUI) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
94 int tl_system; // when non-zero used for :!cmd output |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
95 int tl_toprow; // row with first line of system terminal |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
96 #endif |
12502 | 97 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
98 // Set when setting the size of a vterm, reset after redrawing. |
12502 | 99 int tl_vterm_size_changed; |
100 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
101 int tl_normal_mode; // TRUE: Terminal-Normal mode |
26217
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
102 int tl_channel_closing; |
12502 | 103 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
|
104 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
|
105 |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
106 int tl_finish; |
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_UNSET NUL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
108 #define TL_FINISH_CLOSE 'c' // ++close or :terminal without argument |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
109 #define TL_FINISH_NOCLOSE 'n' // ++noclose |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
110 #define TL_FINISH_OPEN 'o' // ++open |
12502 | 111 char_u *tl_opencmd; |
112 char_u *tl_eof_chars; | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
113 char_u *tl_api; // prefix for terminal API function |
12502 | 114 |
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
|
115 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
|
116 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
117 #ifdef MSWIN |
12502 | 118 void *tl_winpty_config; |
119 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
|
120 |
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
|
121 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
|
122 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
|
123 |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
124 FILE *tl_out_fd; |
12502 | 125 #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
|
126 #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
|
127 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
|
128 #endif |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
129 char_u *tl_kill; |
12502 | 130 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
131 // last known vterm size |
12502 | 132 int tl_rows; |
133 int tl_cols; | |
134 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
135 char_u *tl_title; // NULL or allocated |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
136 char_u *tl_status_text; // NULL or allocated |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
137 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
138 // Range of screen rows to update. Zero based. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
139 int tl_dirty_row_start; // MAX_ROW if nothing dirty |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
140 int tl_dirty_row_end; // row below last one to update |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
141 int tl_dirty_snapshot; // text updated after making snapshot |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
142 #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
|
143 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
|
144 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
|
145 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
146 int tl_postponed_scroll; // to be scrolled up |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
147 |
12502 | 148 garray_T tl_scrollback; |
149 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
|
150 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
|
151 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
152 char_u *tl_highlight_name; // replaces "Terminal"; allocated |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
153 |
12502 | 154 cellattr_T tl_default_color; |
155 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
156 linenr_T tl_top_diff_rows; // rows of top diff file or zero |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
157 linenr_T tl_bot_diff_rows; // rows of bottom diff file |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
158 |
12502 | 159 VTermPos tl_cursor_pos; |
160 int tl_cursor_visible; | |
161 int tl_cursor_blink; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
162 int tl_cursor_shape; // 1: block, 2: underline, 3: bar |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
163 char_u *tl_cursor_color; // NULL or allocated |
12502 | 164 |
165 int tl_using_altscreen; | |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
166 garray_T tl_osc_buf; // incomplete OSC string |
12502 | 167 }; |
168 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
169 #define TMODE_ONCE 1 // CTRL-\ CTRL-N used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
170 #define TMODE_LOOP 2 // CTRL-W N used |
12502 | 171 |
172 /* | |
173 * List of all active terminals. | |
174 */ | |
175 static term_T *first_term = NULL; | |
176 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
177 // Terminal active in terminal_loop(). |
12502 | 178 static term_T *in_terminal_loop = NULL; |
179 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
180 #ifdef MSWIN |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
181 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
|
182 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
|
183 #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
|
184 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
185 #define MAX_ROW 999999 // used for tl_dirty_row_end to update all rows |
12502 | 186 #define KEY_BUF_LEN 200 |
187 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
188 #define FOR_ALL_TERMS(term) \ |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
189 for ((term) = first_term; (term) != NULL; (term) = (term)->tl_next) |
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
190 |
12502 | 191 /* |
192 * Functions with separate implementation for MS-Windows and Unix-like systems. | |
193 */ | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
194 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt); |
12502 | 195 static int create_pty_only(term_T *term, jobopt_T *opt); |
196 static void term_report_winsize(term_T *term, int rows, int cols); | |
197 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
|
198 #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
|
199 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
|
200 #endif |
12502 | 201 |
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
|
202 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
|
203 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
204 // The character that we know (or assume) that the terminal expects for the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
205 // backspace key. |
12502 | 206 static int term_backspace_char = BS; |
207 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
208 // Store the last set and the desired cursor properties, so that we only update |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
209 // 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
217 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
218 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
219 // 1. Generic code for all systems. |
12502 | 220 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
221 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
|
222 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
|
223 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
228 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
229 static void |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
230 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
|
231 { |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
232 // 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
|
233 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
|
234 return; |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
235 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
|
236 *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
|
237 } |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
238 |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
239 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
|
240 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
|
241 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
242 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
|
243 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
244 |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
245 |
12502 | 246 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
247 * 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
|
248 * 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
|
249 * 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
|
250 * 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
|
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 static int |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
253 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
|
254 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
255 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
|
256 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
257 *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
|
258 *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
|
259 |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
260 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
|
261 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
262 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
|
263 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
264 // Syntax of value was already checked when it's set. |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
265 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
|
266 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
267 minsize = TRUE; |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
268 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
|
269 } |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
270 *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
|
271 *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
|
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 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
|
274 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
275 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
276 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
277 * Determine the terminal size from 'termwinsize' and the current window. |
12502 | 278 */ |
279 static void | |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
280 set_term_and_win_size(term_T *term, jobopt_T *opt) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
281 { |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
282 int rows, cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
283 int minsize; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
284 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
285 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
286 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
287 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
288 // Use the whole screen for the system command. However, it will start |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
289 // at the command line and scroll up as needed, using tl_toprow. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
290 term->tl_rows = Rows; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
291 term->tl_cols = Columns; |
13624
429f0eb87d6f
patch 8.0.1684: ml_get errors when using terminal window for shell command
Christian Brabandt <cb@256bit.org>
parents:
13616
diff
changeset
|
292 return; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
293 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
294 #endif |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
295 term->tl_rows = curwin->w_height; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
296 term->tl_cols = curwin->w_width; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
297 |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
298 minsize = parse_termwinsize(curwin, &rows, &cols); |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
299 if (minsize) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
300 { |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
301 if (term->tl_rows < rows) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
302 term->tl_rows = rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
303 if (term->tl_cols < cols) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
304 term->tl_cols = cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
305 } |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
306 if ((opt->jo_set2 & JO2_TERM_ROWS)) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
307 term->tl_rows = opt->jo_term_rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
308 else if (rows != 0) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
309 term->tl_rows = rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
310 if ((opt->jo_set2 & JO2_TERM_COLS)) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
311 term->tl_cols = opt->jo_term_cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
312 else if (cols != 0) |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
313 term->tl_cols = cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
314 |
22097
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
315 if (!opt->jo_hidden) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
316 { |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
317 if (term->tl_rows != curwin->w_height) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
318 win_setheight_win(term->tl_rows, curwin); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
319 if (term->tl_cols != curwin->w_width) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
320 win_setwidth_win(term->tl_cols, curwin); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
321 |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
322 // Set 'winsize' now to avoid a resize at the next redraw. |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
323 if (!minsize && *curwin->w_p_tws != NUL) |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
324 { |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
325 char_u buf[100]; |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
326 |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
327 vim_snprintf((char *)buf, 100, "%dx%d", |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
328 term->tl_rows, term->tl_cols); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
329 set_option_value((char_u *)"termwinsize", 0L, buf, OPT_LOCAL); |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
330 } |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
331 } |
12502 | 332 } |
333 | |
334 /* | |
335 * Initialize job options for a terminal job. | |
336 * Caller may overrule some of them. | |
337 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
338 void |
12502 | 339 init_job_options(jobopt_T *opt) |
340 { | |
341 clear_job_options(opt); | |
342 | |
343 opt->jo_mode = MODE_RAW; | |
344 opt->jo_out_mode = MODE_RAW; | |
345 opt->jo_err_mode = MODE_RAW; | |
346 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; | |
347 } | |
348 | |
349 /* | |
350 * Set job options mandatory for a terminal job. | |
351 */ | |
352 static void | |
353 setup_job_options(jobopt_T *opt, int rows, int cols) | |
354 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
355 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
356 // Win32: Redirecting the job output won't work, thus always connect stdout |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
357 // here. |
12502 | 358 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
|
359 #endif |
12502 | 360 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
361 // Connect stdout to the terminal. |
12502 | 362 opt->jo_io[PART_OUT] = JIO_BUFFER; |
363 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; | |
364 opt->jo_modifiable[PART_OUT] = 0; | |
365 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE; | |
366 } | |
367 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
368 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
369 // Win32: Redirecting the job output won't work, thus always connect stderr |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
370 // here. |
12502 | 371 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
|
372 #endif |
12502 | 373 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
374 // Connect stderr to the terminal. |
12502 | 375 opt->jo_io[PART_ERR] = JIO_BUFFER; |
376 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; | |
377 opt->jo_modifiable[PART_ERR] = 0; | |
378 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE; | |
379 } | |
380 | |
381 opt->jo_pty = TRUE; | |
382 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0) | |
383 opt->jo_term_rows = rows; | |
384 if ((opt->jo_set2 & JO2_TERM_COLS) == 0) | |
385 opt->jo_term_cols = cols; | |
386 } | |
387 | |
388 /* | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
389 * Flush messages on channels. |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
390 */ |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
391 static void |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
392 term_flush_messages() |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
393 { |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
394 mch_check_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
395 parse_queued_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
396 } |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
397 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
398 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
399 * 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
|
400 * fails. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
401 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
402 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
403 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
|
404 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
405 free_terminal(buf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
406 if (old_curbuf != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
407 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
408 --curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
409 curbuf = old_curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
410 curwin->w_buffer = curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
411 ++curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
412 } |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19542
diff
changeset
|
413 CHECK_CURBUF; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
414 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
415 // Wiping out the buffer will also close the window and call |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
416 // free_terminal(). |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
417 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
|
418 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
419 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
420 /* |
12502 | 421 * 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
|
422 * 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
|
423 * 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
|
424 * the window. |
12502 | 425 * Returns NULL when failed. |
426 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 int flags) |
12502 | 433 { |
434 exarg_T split_ea; | |
435 win_T *old_curwin = curwin; | |
436 term_T *term; | |
437 buf_T *old_curbuf = NULL; | |
438 int res; | |
439 buf_T *newbuf; | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
440 int vertical = opt->jo_vertical || (cmdmod.cmod_split & WSP_VERT); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
441 jobopt_T orig_opt; // only partly filled |
12502 | 442 |
443 if (check_restricted() || check_secure()) | |
444 return NULL; | |
24739
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
445 #ifdef FEAT_CMDWIN |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
446 if (cmdwin_type != 0) |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
447 { |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
448 emsg(_(e_cannot_open_terminal_from_command_line_window)); |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
449 return NULL; |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
450 } |
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
451 #endif |
12502 | 452 |
453 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)) | |
454 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO) | |
455 || (!(opt->jo_set & JO_OUT_IO) && (opt->jo_set & JO_OUT_BUF)) | |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
456 || (!(opt->jo_set & JO_ERR_IO) && (opt->jo_set & JO_ERR_BUF)) |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
457 || (argvar != NULL |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
458 && argvar->v_type == VAR_LIST |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
459 && argvar->vval.v_list != NULL |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
460 && argvar->vval.v_list->lv_first == &range_list_item)) |
12502 | 461 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
462 emsg(_(e_invalid_argument)); |
12502 | 463 return NULL; |
464 } | |
465 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
466 term = ALLOC_CLEAR_ONE(term_T); |
12502 | 467 if (term == NULL) |
468 return NULL; | |
469 term->tl_dirty_row_end = MAX_ROW; | |
470 term->tl_cursor_visible = TRUE; | |
471 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | |
472 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
|
473 #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
|
474 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
|
475 #endif |
12502 | 476 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
|
477 ga_init2(&term->tl_scrollback_postponed, sizeof(sb_line_T), 300); |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
478 ga_init2(&term->tl_osc_buf, sizeof(char), 300); |
12502 | 479 |
24557
7a4cc4d3a40a
patch 8.2.2818: no jump added when opening terminal in current window
Bram Moolenaar <Bram@vim.org>
parents:
24268
diff
changeset
|
480 setpcmark(); |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
481 CLEAR_FIELD(split_ea); |
12502 | 482 if (opt->jo_curwin) |
483 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
484 // 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
|
485 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT)) |
12502 | 486 { |
487 no_write_message(); | |
488 vim_free(term); | |
489 return NULL; | |
490 } | |
491 if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE, | |
20617
c81f61e3b508
patch 8.2.0862: ":term ++curwin" makes the current buffer hidden
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
492 (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0) |
c81f61e3b508
patch 8.2.0862: ":term ++curwin" makes the current buffer hidden
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
493 + ((flags & TERM_START_FORCEIT) ? ECMD_FORCEIT : 0), |
c81f61e3b508
patch 8.2.0862: ":term ++curwin" makes the current buffer hidden
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
494 curwin) == FAIL) |
12502 | 495 { |
496 vim_free(term); | |
497 return NULL; | |
498 } | |
499 } | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
500 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM)) |
12502 | 501 { |
502 buf_T *buf; | |
503 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
504 // Create a new buffer without a window. Make it the current buffer for |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
505 // a moment to be able to do the initializations. |
12502 | 506 buf = buflist_new((char_u *)"", NULL, (linenr_T)0, |
507 BLN_NEW | BLN_LISTED); | |
508 if (buf == NULL || ml_open(buf) == FAIL) | |
509 { | |
510 vim_free(term); | |
511 return NULL; | |
512 } | |
513 old_curbuf = curbuf; | |
514 --curbuf->b_nwindows; | |
515 curbuf = buf; | |
516 curwin->w_buffer = buf; | |
517 ++curbuf->b_nwindows; | |
518 } | |
519 else | |
520 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
521 // Open a new window or tab. |
12502 | 522 split_ea.cmdidx = CMD_new; |
523 split_ea.cmd = (char_u *)"new"; | |
524 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
|
525 if (opt->jo_term_rows > 0 && !vertical) |
12502 | 526 { |
527 split_ea.line2 = opt->jo_term_rows; | |
528 split_ea.addr_count = 1; | |
529 } | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
530 if (opt->jo_term_cols > 0 && vertical) |
12502 | 531 { |
532 split_ea.line2 = opt->jo_term_cols; | |
533 split_ea.addr_count = 1; | |
534 } | |
535 | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
536 if (vertical) |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
537 cmdmod.cmod_split |= WSP_VERT; |
12502 | 538 ex_splitview(&split_ea); |
539 if (curwin == old_curwin) | |
540 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
541 // split failed |
12502 | 542 vim_free(term); |
543 return NULL; | |
544 } | |
545 } | |
546 term->tl_buffer = curbuf; | |
547 curbuf->b_term = term; | |
548 | |
549 if (!opt->jo_hidden) | |
550 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
551 // Only one size was taken care of with :new, do the other one. With |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
552 // "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
|
553 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical)) |
12502 | 554 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
|
555 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical)) |
12502 | 556 win_setwidth(opt->jo_term_cols); |
557 } | |
558 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
559 // Link the new terminal in the list of active terminals. |
12502 | 560 term->tl_next = first_term; |
561 first_term = term; | |
562 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
563 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); |
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
564 |
12502 | 565 if (opt->jo_term_name != NULL) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
566 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
567 vim_free(curbuf->b_ffname); |
12502 | 568 curbuf->b_ffname = vim_strsave(opt->jo_term_name); |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
569 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
570 else if (argv != NULL) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
571 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
572 vim_free(curbuf->b_ffname); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
573 curbuf->b_ffname = vim_strsave((char_u *)"!system"); |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
574 } |
12502 | 575 else |
576 { | |
577 int i; | |
578 size_t len; | |
579 char_u *cmd, *p; | |
580 | |
581 if (argvar->v_type == VAR_STRING) | |
582 { | |
583 cmd = argvar->vval.v_string; | |
584 if (cmd == NULL) | |
585 cmd = (char_u *)""; | |
586 else if (STRCMP(cmd, "NONE") == 0) | |
587 cmd = (char_u *)"pty"; | |
588 } | |
589 else if (argvar->v_type != VAR_LIST | |
590 || argvar->vval.v_list == NULL | |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
591 || argvar->vval.v_list->lv_len == 0 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
592 || (cmd = tv_get_string_chk( |
12502 | 593 &argvar->vval.v_list->lv_first->li_tv)) == NULL) |
594 cmd = (char_u*)""; | |
595 | |
596 len = STRLEN(cmd) + 10; | |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
597 p = alloc(len); |
12502 | 598 |
599 for (i = 0; p != NULL; ++i) | |
600 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
601 // Prepend a ! to the command name to avoid the buffer name equals |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
602 // the executable, otherwise ":w!" would overwrite it. |
12502 | 603 if (i == 0) |
604 vim_snprintf((char *)p, len, "!%s", cmd); | |
605 else | |
606 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i); | |
607 if (buflist_findname(p) == NULL) | |
608 { | |
609 vim_free(curbuf->b_ffname); | |
610 curbuf->b_ffname = p; | |
611 break; | |
612 } | |
613 } | |
614 } | |
19513
274052873790
patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
19358
diff
changeset
|
615 vim_free(curbuf->b_sfname); |
274052873790
patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
19358
diff
changeset
|
616 curbuf->b_sfname = vim_strsave(curbuf->b_ffname); |
12502 | 617 curbuf->b_fname = curbuf->b_ffname; |
618 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
619 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
620 |
12502 | 621 if (opt->jo_term_opencmd != NULL) |
622 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); | |
623 | |
624 if (opt->jo_eof_chars != NULL) | |
625 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); | |
626 | |
627 set_string_option_direct((char_u *)"buftype", -1, | |
628 (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
|
629 // 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
|
630 curbuf->b_p_initialized = TRUE; |
12502 | 631 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
632 // Mark the buffer as not modifiable. It can only be made modifiable after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
633 // the job finished. |
12502 | 634 curbuf->b_p_ma = FALSE; |
635 | |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
636 set_term_and_win_size(term, opt); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
637 #ifdef MSWIN |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
638 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
|
639 #endif |
12502 | 640 setup_job_options(opt, term->tl_rows, term->tl_cols); |
641 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
642 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
|
643 return curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
644 |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
645 #if defined(FEAT_SESSION) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
646 // 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
|
647 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
|
648 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
|
649 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
|
650 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
651 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
|
652 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
653 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
|
654 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
|
655 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
656 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
|
657 && 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
|
658 && 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
|
659 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
660 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
|
661 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
|
662 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
663 ga_init2(&ga, 1, 100); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
664 FOR_ALL_LIST_ITEMS(argvar->vval.v_list, item) |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
665 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
666 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
|
667 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
|
668 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
669 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
|
670 break; |
25994
e8873138ffbb
patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents:
25965
diff
changeset
|
671 p = vim_strsave_fnameescape(s, VSE_NONE); |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
672 if (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
|
673 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
674 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
|
675 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
|
676 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
|
677 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
678 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
|
679 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
680 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
|
681 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
|
682 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
683 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
684 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
|
685 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
686 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
687 |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
688 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
|
689 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
690 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
|
691 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
692 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
|
693 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
694 |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
695 if (opt->jo_term_api != NULL) |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
696 { |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
697 char_u *p = skiptowhite(opt->jo_term_api); |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
698 |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
699 term->tl_api = vim_strnsave(opt->jo_term_api, p - opt->jo_term_api); |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
700 } |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
701 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
702 term->tl_api = vim_strsave((char_u *)"Tapi_"); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
703 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
704 if (opt->jo_set2 & JO2_TERM_HIGHLIGHT) |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
705 term->tl_highlight_name = vim_strsave(opt->jo_term_highlight); |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
706 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
707 // 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
|
708 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
|
709 && argvar->v_type == VAR_STRING |
12502 | 710 && argvar->vval.v_string != NULL |
711 && STRCMP(argvar->vval.v_string, "NONE") == 0) | |
712 res = create_pty_only(term, opt); | |
713 else | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
714 res = term_and_job_init(term, argvar, argv, opt, &orig_opt); |
12502 | 715 |
716 newbuf = curbuf; | |
717 if (res == OK) | |
718 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
719 // Get and remember the size we ended up with. Update the pty. |
12502 | 720 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); |
721 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
|
722 #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
|
723 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
|
724 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
725 // display first line below typed command |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
726 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
|
727 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
|
728 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
729 #endif |
12502 | 730 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
731 // Make sure we don't get stuck on sending keys to the job, it leads to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
732 // a deadlock if the job is waiting for Vim to read. |
12502 | 733 channel_set_nonblock(term->tl_job->jv_channel, PART_IN); |
734 | |
13835
8e583c52eb44
patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13829
diff
changeset
|
735 if (old_curbuf != NULL) |
12502 | 736 { |
737 --curbuf->b_nwindows; | |
738 curbuf = old_curbuf; | |
739 curwin->w_buffer = curbuf; | |
740 ++curbuf->b_nwindows; | |
741 } | |
26598
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
742 else if (vgetc_busy |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
743 #ifdef FEAT_TIMERS |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
744 || timer_busy |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
745 #endif |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
746 || input_busy) |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
747 { |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
748 char_u ignore[4]; |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
749 |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
750 // When waiting for input need to return and possibly end up in |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
751 // terminal_loop() instead. |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
752 ignore[0] = K_SPECIAL; |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
753 ignore[1] = KS_EXTRA; |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
754 ignore[2] = KE_IGNORE; |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
755 ignore[3] = NUL; |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
756 ins_typebuf(ignore, REMAP_NONE, 0, TRUE, FALSE); |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
757 typebuf_was_filled = TRUE; |
b3ac5a4dc158
patch 8.2.3828: when opening a terminal from a timer first typed char is lost
Bram Moolenaar <Bram@vim.org>
parents:
26548
diff
changeset
|
758 } |
12502 | 759 } |
760 else | |
761 { | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
762 term_close_buffer(curbuf, old_curbuf); |
12502 | 763 return NULL; |
764 } | |
13444
9f06f7aca74c
patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
765 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
766 apply_autocmds(EVENT_TERMINALOPEN, NULL, NULL, FALSE, newbuf); |
18450
507348b211b4
patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents:
18420
diff
changeset
|
767 if (!opt->jo_hidden && !(flags & TERM_START_SYSTEM)) |
507348b211b4
patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents:
18420
diff
changeset
|
768 apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf); |
12502 | 769 return newbuf; |
770 } | |
771 | |
772 /* | |
773 * ":terminal": open a terminal window and execute a job in it. | |
774 */ | |
775 void | |
776 ex_terminal(exarg_T *eap) | |
777 { | |
778 typval_T argvar[2]; | |
779 jobopt_T opt; | |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
780 int opt_shell = FALSE; |
12502 | 781 char_u *cmd; |
782 char_u *tofree = NULL; | |
783 | |
784 init_job_options(&opt); | |
785 | |
786 cmd = eap->arg; | |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
787 while (*cmd == '+' && *(cmd + 1) == '+') |
12502 | 788 { |
789 char_u *p, *ep; | |
790 | |
791 cmd += 2; | |
792 p = skiptowhite(cmd); | |
793 ep = vim_strchr(cmd, '='); | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
794 if (ep != NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
795 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
796 if (ep < p) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
797 p = ep; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
798 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
799 ep = NULL; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
800 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
801 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
802 # define OPTARG_HAS(name) ((int)(p - cmd) == sizeof(name) - 1 \ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
803 && STRNICMP(cmd, name, sizeof(name) - 1) == 0) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
804 if (OPTARG_HAS("close")) |
12502 | 805 opt.jo_term_finish = 'c'; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
806 else if (OPTARG_HAS("noclose")) |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
807 opt.jo_term_finish = 'n'; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
808 else if (OPTARG_HAS("open")) |
12502 | 809 opt.jo_term_finish = 'o'; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
810 else if (OPTARG_HAS("curwin")) |
12502 | 811 opt.jo_curwin = 1; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
812 else if (OPTARG_HAS("hidden")) |
12502 | 813 opt.jo_hidden = 1; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
814 else if (OPTARG_HAS("norestore")) |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
815 opt.jo_term_norestore = 1; |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
816 else if (OPTARG_HAS("shell")) |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
817 opt_shell = TRUE; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
818 else if (OPTARG_HAS("kill") && ep != NULL) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
819 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
820 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
|
821 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
|
822 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
|
823 } |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
824 else if (OPTARG_HAS("api")) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
825 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
826 opt.jo_set2 |= JO2_TERM_API; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
827 if (ep != NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
828 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
829 opt.jo_term_api = ep + 1; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
830 p = skiptowhite(cmd); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
831 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
832 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
833 opt.jo_term_api = NULL; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
834 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
835 else if (OPTARG_HAS("rows") && ep != NULL && isdigit(ep[1])) |
12502 | 836 { |
837 opt.jo_set2 |= JO2_TERM_ROWS; | |
838 opt.jo_term_rows = atoi((char *)ep + 1); | |
839 p = skiptowhite(cmd); | |
840 } | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
841 else if (OPTARG_HAS("cols") && ep != NULL && isdigit(ep[1])) |
12502 | 842 { |
843 opt.jo_set2 |= JO2_TERM_COLS; | |
844 opt.jo_term_cols = atoi((char *)ep + 1); | |
845 p = skiptowhite(cmd); | |
846 } | |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
847 else if (OPTARG_HAS("eof") && ep != NULL) |
12502 | 848 { |
849 char_u *buf = NULL; | |
850 char_u *keys; | |
851 | |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
852 vim_free(opt.jo_eof_chars); |
12502 | 853 p = skiptowhite(cmd); |
854 *p = NUL; | |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
855 keys = replace_termcodes(ep + 1, &buf, |
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
856 REPTERM_FROM_PART | REPTERM_DO_LT | REPTERM_SPECIAL, NULL); |
12502 | 857 opt.jo_set2 |= JO2_EOF_CHARS; |
858 opt.jo_eof_chars = vim_strsave(keys); | |
859 vim_free(buf); | |
860 *p = ' '; | |
861 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
862 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
863 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
|
864 && 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
|
865 { |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
866 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
|
867 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
868 p = skiptowhite(cmd); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
869 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
|
870 tty_type = 'w'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
871 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
|
872 tty_type = 'c'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
873 else |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
874 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
875 semsg(e_invalid_value_for_argument_str, "type"); |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
876 goto theend; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
877 } |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
878 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
|
879 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
|
880 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
881 #endif |
12502 | 882 else |
883 { | |
884 if (*p) | |
885 *p = NUL; | |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
886 semsg(_(e_invalid_attribute_str), cmd); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
887 goto theend; |
12502 | 888 } |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
889 # undef OPTARG_HAS |
12502 | 890 cmd = skipwhite(p); |
891 } | |
892 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
|
893 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
894 // Make a copy of 'shell', an autocommand may change the option. |
12502 | 895 tofree = cmd = vim_strsave(p_sh); |
896 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
897 // default to close when the shell exits |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
898 if (opt.jo_term_finish == NUL) |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
899 opt.jo_term_finish = TL_FINISH_CLOSE; |
13476
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
900 } |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
901 |
12502 | 902 if (eap->addr_count > 0) |
903 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
904 // Write lines from current buffer to the job. |
12502 | 905 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; |
906 opt.jo_io[PART_IN] = JIO_BUFFER; | |
907 opt.jo_io_buf[PART_IN] = curbuf->b_fnum; | |
908 opt.jo_in_top = eap->line1; | |
909 opt.jo_in_bot = eap->line2; | |
910 } | |
911 | |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
912 if (opt_shell && tofree == NULL) |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
913 { |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
914 #ifdef UNIX |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
915 char **argv = NULL; |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
916 char_u *tofree1 = NULL; |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
917 char_u *tofree2 = NULL; |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
918 |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
919 // :term ++shell command |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
920 if (unix_build_argv(cmd, &argv, &tofree1, &tofree2) == OK) |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
921 term_start(NULL, argv, &opt, eap->forceit ? TERM_START_FORCEIT : 0); |
18595
517bfb2998aa
patch 8.1.2291: memory leak when executing command in a terminal
Bram Moolenaar <Bram@vim.org>
parents:
18522
diff
changeset
|
922 vim_free(argv); |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
923 vim_free(tofree1); |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
924 vim_free(tofree2); |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
925 goto theend; |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
926 #else |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
927 # ifdef MSWIN |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
928 long_u cmdlen = STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
929 char_u *newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
930 |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
931 newcmd = alloc(cmdlen); |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
932 if (newcmd == NULL) |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
933 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
934 tofree = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
935 vim_snprintf((char *)newcmd, cmdlen, "%s %s %s", p_sh, p_shcf, cmd); |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
936 cmd = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
937 # else |
26897
d02d40f0261c
patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
938 emsg(_(e_sorry_plusplusshell_not_supported_on_this_system)); |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
939 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
940 # endif |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
941 #endif |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
942 } |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
943 argvar[0].v_type = VAR_STRING; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
944 argvar[0].vval.v_string = cmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
945 argvar[1].v_type = VAR_UNKNOWN; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
946 term_start(argvar, NULL, &opt, eap->forceit ? TERM_START_FORCEIT : 0); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
947 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
948 theend: |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
949 vim_free(tofree); |
12502 | 950 vim_free(opt.jo_eof_chars); |
951 } | |
952 | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
953 #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
|
954 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
955 * 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
|
956 * 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
|
957 * 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
|
958 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
959 int |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
960 term_write_session(FILE *fd, win_T *wp, hashtab_T *terminal_bufs) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
961 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
962 const int bufnr = wp->w_buffer->b_fnum; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
963 term_T *term = wp->w_buffer->b_term; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
964 |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
965 if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
966 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
967 // There are multiple views into this terminal buffer. We don't want to |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
968 // create the terminal multiple times. If it's the first time, create, |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
969 // otherwise link to the first buffer. |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
970 char id_as_str[NUMBUFLEN]; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
971 hashitem_T *entry; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
972 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
973 vim_snprintf(id_as_str, sizeof(id_as_str), "%d", bufnr); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
974 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
975 entry = hash_find(terminal_bufs, (char_u *)id_as_str); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
976 if (!HASHITEM_EMPTY(entry)) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
977 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
978 // we've already opened this terminal buffer |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
979 if (fprintf(fd, "execute 'buffer ' . s:term_buf_%d", bufnr) < 0) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
980 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
981 return put_eol(fd); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
982 } |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
983 } |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
984 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
985 // Create the terminal and run the command. This is not without |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
986 // risk, but let's assume the user only creates a session when this |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
987 // will be OK. |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
988 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
|
989 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
|
990 return FAIL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
991 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
992 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
|
993 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
|
994 #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
|
995 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
|
996 return FAIL; |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
997 if (put_eol(fd) != OK) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
998 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
999 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1000 if (fprintf(fd, "let s:term_buf_%d = bufnr()", bufnr) < 0) |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1001 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1002 |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
1003 if (terminal_bufs != NULL && wp->w_buffer->b_nwindows > 1) |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1004 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1005 char *hash_key = alloc(NUMBUFLEN); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1006 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1007 vim_snprintf(hash_key, NUMBUFLEN, "%d", bufnr); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1008 hash_add(terminal_bufs, (char_u *)hash_key); |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1009 } |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1010 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1011 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
|
1012 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1013 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1014 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1015 * 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
|
1016 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1017 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1018 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
|
1019 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1020 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
|
1021 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1022 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
|
1023 || 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
|
1024 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1025 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1026 |
12502 | 1027 /* |
1028 * Free the scrollback buffer for "term". | |
1029 */ | |
1030 static void | |
1031 free_scrollback(term_T *term) | |
1032 { | |
1033 int i; | |
1034 | |
1035 for (i = 0; i < term->tl_scrollback.ga_len; ++i) | |
1036 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); | |
1037 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
|
1038 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
|
1039 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
|
1040 ga_clear(&term->tl_scrollback_postponed); |
12502 | 1041 } |
1042 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1043 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1044 // Terminals that need to be freed soon. |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
18033
diff
changeset
|
1045 static term_T *terminals_to_free = NULL; |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1046 |
12502 | 1047 /* |
1048 * Free a terminal and everything it refers to. | |
1049 * Kills the job if there is one. | |
1050 * 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
|
1051 * 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
|
1052 * 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
|
1053 * referenced. |
12502 | 1054 */ |
1055 void | |
1056 free_terminal(buf_T *buf) | |
1057 { | |
1058 term_T *term = buf->b_term; | |
1059 term_T *tp; | |
1060 | |
1061 if (term == NULL) | |
1062 return; | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1063 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1064 // Unlink the terminal form the list of terminals. |
12502 | 1065 if (first_term == term) |
1066 first_term = term->tl_next; | |
1067 else | |
1068 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next) | |
1069 if (tp->tl_next == term) | |
1070 { | |
1071 tp->tl_next = term->tl_next; | |
1072 break; | |
1073 } | |
1074 | |
1075 if (term->tl_job != NULL) | |
1076 { | |
1077 if (term->tl_job->jv_status != JOB_ENDED | |
1078 && 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
|
1079 && term->tl_job->jv_status != JOB_FAILED) |
12502 | 1080 job_stop(term->tl_job, NULL, "kill"); |
1081 job_unref(term->tl_job); | |
1082 } | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1083 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
|
1084 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
|
1085 |
12502 | 1086 buf->b_term = NULL; |
1087 if (in_terminal_loop == term) | |
1088 in_terminal_loop = NULL; | |
1089 } | |
1090 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1091 void |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1092 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
|
1093 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1094 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
|
1095 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1096 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
|
1097 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1098 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
|
1099 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1100 free_scrollback(term); |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
1101 ga_clear(&term->tl_osc_buf); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1102 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1103 term_free_vterm(term); |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
1104 vim_free(term->tl_api); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1105 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
|
1106 #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
|
1107 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
|
1108 #endif |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1109 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
|
1110 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
|
1111 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
|
1112 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
|
1113 vim_free(term->tl_arg0_cmd); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1114 #ifdef MSWIN |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1115 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
|
1116 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
|
1117 #endif |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
1118 vim_free(term->tl_highlight_name); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1119 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
|
1120 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
|
1121 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1122 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1123 |
12502 | 1124 /* |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1125 * 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
|
1126 * 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
|
1127 * 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
|
1128 */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1129 static ch_part_T |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
1130 get_tty_part(term_T *term UNUSED) |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1131 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1132 #ifdef UNIX |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1133 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
|
1134 int i; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1135 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1136 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
|
1137 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1138 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
|
1139 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1140 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
|
1141 return parts[i]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1142 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1143 #endif |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1144 return PART_IN; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1145 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1146 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1147 /* |
26462
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1148 * Read any vterm output and send it on the channel. |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1149 */ |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1150 static void |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1151 term_forward_output(term_T *term) |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1152 { |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1153 VTerm *vterm = term->tl_vterm; |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1154 char buf[KEY_BUF_LEN]; |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1155 size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1156 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1157 if (curlen > 0) |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1158 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1159 (char_u *)buf, (int)curlen, NULL); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1160 } |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1161 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1162 /* |
12502 | 1163 * Write job output "msg[len]" to the vterm. |
1164 */ | |
1165 static void | |
26129
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1166 term_write_job_output(term_T *term, char_u *msg_arg, size_t len_arg) |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1167 { |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1168 char_u *msg = msg_arg; |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1169 size_t len = len_arg; |
12502 | 1170 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
|
1171 size_t prevlen = vterm_output_get_buffer_current(vterm); |
26129
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1172 size_t limit = term->tl_buffer->b_p_twsl * term->tl_cols * 3; |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1173 |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1174 // Limit the length to 'termwinscroll' * cols * 3 bytes. Keep the text at |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1175 // the end. |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1176 if (len > limit) |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1177 { |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1178 char_u *p = msg + len - limit; |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1179 |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1180 p -= (*mb_head_off)(msg, p); |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1181 len -= p - msg; |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1182 msg = p; |
ddfb2b8aed67
patch 8.2.3597: Vim seems to hang when writing a long text to a terminal
Bram Moolenaar <Bram@vim.org>
parents:
26105
diff
changeset
|
1183 } |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1184 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1185 vterm_input_write(vterm, (char *)msg, len); |
12502 | 1186 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1187 // flush vterm buffer when vterm responded to control sequence |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1188 if (prevlen != vterm_output_get_buffer_current(vterm)) |
26462
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1189 term_forward_output(term); |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1190 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1191 // this invokes the damage callbacks |
12502 | 1192 vterm_screen_flush_damage(vterm_obtain_screen(vterm)); |
1193 } | |
1194 | |
1195 static void | |
1196 update_cursor(term_T *term, int redraw) | |
1197 { | |
1198 if (term->tl_normal_mode) | |
1199 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
|
1200 #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
|
1201 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
|
1202 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
|
1203 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
|
1204 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1205 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1206 setcursor(); |
12502 | 1207 if (redraw) |
1208 { | |
1209 if (term->tl_buffer == curbuf && term->tl_cursor_visible) | |
1210 cursor_on(); | |
1211 out_flush(); | |
1212 #ifdef FEAT_GUI | |
1213 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
|
1214 { |
12502 | 1215 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
|
1216 gui_mch_flush(); |
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1217 } |
12502 | 1218 #endif |
1219 } | |
1220 } | |
1221 | |
1222 /* | |
1223 * Invoked when "msg" output from a job was received. Write it to the terminal | |
1224 * of "buffer". | |
1225 */ | |
1226 void | |
1227 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel) | |
1228 { | |
1229 size_t len = STRLEN(msg); | |
1230 term_T *term = buffer->b_term; | |
1231 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1232 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1233 // Win32: Cannot redirect output of the job, intercept it here and write to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1234 // the file. |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1235 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
|
1236 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1237 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
|
1238 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
|
1239 return; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1240 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1241 #endif |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1242 |
12502 | 1243 if (term->tl_vterm == NULL) |
1244 { | |
1245 ch_log(channel, "NOT writing %d bytes to terminal", (int)len); | |
1246 return; | |
1247 } | |
1248 ch_log(channel, "writing %d bytes to terminal", (int)len); | |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
1249 cursor_off(); |
12502 | 1250 term_write_job_output(term, msg, len); |
1251 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1252 #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
|
1253 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
|
1254 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1255 // show system output, scrolling up the screen as needed |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1256 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
|
1257 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
|
1258 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1259 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1260 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1261 // In Terminal-Normal mode we are displaying the buffer, not the terminal |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1262 // contents, thus no screen update is needed. |
12502 | 1263 if (!term->tl_normal_mode) |
1264 { | |
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
|
1265 // 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
|
1266 // 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
|
1267 // TODO: only update once in a while. |
12502 | 1268 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
|
1269 if (buffer == curbuf && (State & CMDLINE) == 0) |
12502 | 1270 { |
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
|
1271 update_screen(VALID_NO_UPDATE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1272 // update_screen() can be slow, check the terminal wasn't closed |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1273 // already |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1274 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
|
1275 update_cursor(curbuf->b_term, TRUE); |
12502 | 1276 } |
1277 else | |
26466
d413104a94c8
patch 8.2.3763: when editing the cmdline a callback may cause a scroll up
Bram Moolenaar <Bram@vim.org>
parents:
26462
diff
changeset
|
1278 redraw_after_callback(TRUE, FALSE); |
12502 | 1279 } |
1280 } | |
1281 | |
1282 /* | |
1283 * Send a mouse position and click to the vterm | |
1284 */ | |
1285 static int | |
1286 term_send_mouse(VTerm *vterm, int button, int pressed) | |
1287 { | |
1288 VTermModifier mod = VTERM_MOD_NONE; | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1289 int row = mouse_row - W_WINROW(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1290 int col = mouse_col - curwin->w_wincol; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1291 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1292 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1293 if (popup_is_popup(curwin)) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1294 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1295 row -= popup_top_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1296 col -= popup_left_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1297 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1298 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1299 vterm_mouse_move(vterm, row, col, mod); |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1300 if (button != 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1301 vterm_mouse_button(vterm, button, pressed, mod); |
12502 | 1302 return TRUE; |
1303 } | |
1304 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1305 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
|
1306 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
|
1307 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1308 /* |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1309 * 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
|
1310 * 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
|
1311 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1312 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
|
1313 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
|
1314 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1315 #if defined(FEAT_CLIPBOARD) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1316 // For modeless selection mouse drag and release events are ignored, unless |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1317 // they are preceded with a mouse down event |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1318 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
|
1319 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
|
1320 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1321 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
|
1322 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
|
1323 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1324 // Terminal is not using the mouse, use modeless selection. |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1325 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
|
1326 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1327 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
|
1328 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
|
1329 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
|
1330 case K_RIGHTRELEASE: |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1331 // Ignore drag and release events when the button-down wasn't |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1332 // seen before. |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1333 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
|
1334 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1335 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
|
1336 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1337 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
|
1338 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1339 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1340 // mouse click in the window gave us focus, handle that |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1341 // click now |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1342 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
|
1343 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
|
1344 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
|
1345 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
|
1346 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
|
1347 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
|
1348 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
|
1349 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1350 // FALLTHROUGH |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1351 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
|
1352 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
|
1353 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
|
1354 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
|
1355 else |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1356 ignore_drag_release = FALSE; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1357 // Should we call mouse_has() here? |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1358 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
|
1359 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1360 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
|
1361 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1362 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
|
1363 &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
|
1364 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
|
1365 && (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
|
1366 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1367 // Translate shift-left to right button. |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1368 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
|
1369 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
|
1370 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1371 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
|
1372 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1373 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1374 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1375 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
|
1376 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
|
1377 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
|
1378 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1379 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1380 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
|
1381 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
|
1382 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1383 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1384 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
|
1385 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1386 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
|
1387 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1388 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
|
1389 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
|
1390 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
|
1391 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
|
1392 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
|
1393 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
|
1394 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
|
1395 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
|
1396 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
|
1397 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
|
1398 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
|
1399 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
|
1400 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1401 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
|
1402 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1403 |
12502 | 1404 /* |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1405 * Convert typed key "c" with modifiers "modmask" into bytes to send to the |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1406 * job. |
12502 | 1407 * Return the number of bytes in "buf". |
1408 */ | |
1409 static int | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1410 term_convert_key(term_T *term, int c, int modmask, char *buf) |
12502 | 1411 { |
1412 VTerm *vterm = term->tl_vterm; | |
1413 VTermKey key = VTERM_KEY_NONE; | |
1414 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
|
1415 int other = FALSE; |
12502 | 1416 |
1417 switch (c) | |
1418 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1419 // don't use VTERM_KEY_ENTER, it may do an unwanted conversion |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1420 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1421 // don't use VTERM_KEY_BACKSPACE, it always |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1422 // becomes 0x7f DEL |
12502 | 1423 case K_BS: c = term_backspace_char; break; |
1424 | |
1425 case ESC: key = VTERM_KEY_ESCAPE; break; | |
1426 case K_DEL: key = VTERM_KEY_DEL; break; | |
1427 case K_DOWN: key = VTERM_KEY_DOWN; break; | |
1428 case K_S_DOWN: mod = VTERM_MOD_SHIFT; | |
1429 key = VTERM_KEY_DOWN; break; | |
1430 case K_END: key = VTERM_KEY_END; break; | |
1431 case K_S_END: mod = VTERM_MOD_SHIFT; | |
1432 key = VTERM_KEY_END; break; | |
1433 case K_C_END: mod = VTERM_MOD_CTRL; | |
1434 key = VTERM_KEY_END; break; | |
1435 case K_F10: key = VTERM_KEY_FUNCTION(10); break; | |
1436 case K_F11: key = VTERM_KEY_FUNCTION(11); break; | |
1437 case K_F12: key = VTERM_KEY_FUNCTION(12); break; | |
1438 case K_F1: key = VTERM_KEY_FUNCTION(1); break; | |
1439 case K_F2: key = VTERM_KEY_FUNCTION(2); break; | |
1440 case K_F3: key = VTERM_KEY_FUNCTION(3); break; | |
1441 case K_F4: key = VTERM_KEY_FUNCTION(4); break; | |
1442 case K_F5: key = VTERM_KEY_FUNCTION(5); break; | |
1443 case K_F6: key = VTERM_KEY_FUNCTION(6); break; | |
1444 case K_F7: key = VTERM_KEY_FUNCTION(7); break; | |
1445 case K_F8: key = VTERM_KEY_FUNCTION(8); break; | |
1446 case K_F9: key = VTERM_KEY_FUNCTION(9); break; | |
1447 case K_HOME: key = VTERM_KEY_HOME; break; | |
1448 case K_S_HOME: mod = VTERM_MOD_SHIFT; | |
1449 key = VTERM_KEY_HOME; break; | |
1450 case K_C_HOME: mod = VTERM_MOD_CTRL; | |
1451 key = VTERM_KEY_HOME; break; | |
1452 case K_INS: key = VTERM_KEY_INS; break; | |
1453 case K_K0: key = VTERM_KEY_KP_0; break; | |
1454 case K_K1: key = VTERM_KEY_KP_1; break; | |
1455 case K_K2: key = VTERM_KEY_KP_2; break; | |
1456 case K_K3: key = VTERM_KEY_KP_3; break; | |
1457 case K_K4: key = VTERM_KEY_KP_4; break; | |
1458 case K_K5: key = VTERM_KEY_KP_5; break; | |
1459 case K_K6: key = VTERM_KEY_KP_6; break; | |
1460 case K_K7: key = VTERM_KEY_KP_7; break; | |
1461 case K_K8: key = VTERM_KEY_KP_8; break; | |
1462 case K_K9: key = VTERM_KEY_KP_9; break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1463 case K_KDEL: key = VTERM_KEY_DEL; break; // TODO |
12502 | 1464 case K_KDIVIDE: key = VTERM_KEY_KP_DIVIDE; break; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1465 case K_KEND: key = VTERM_KEY_KP_1; break; // TODO |
12502 | 1466 case K_KENTER: key = VTERM_KEY_KP_ENTER; break; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1467 case K_KHOME: key = VTERM_KEY_KP_7; break; // TODO |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1468 case K_KINS: key = VTERM_KEY_KP_0; break; // TODO |
12502 | 1469 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break; |
1470 case K_KMULTIPLY: key = VTERM_KEY_KP_MULT; break; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1471 case K_KPAGEDOWN: key = VTERM_KEY_KP_3; break; // TODO |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1472 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; // TODO |
12502 | 1473 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break; |
1474 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break; | |
1475 case K_LEFT: key = VTERM_KEY_LEFT; break; | |
1476 case K_S_LEFT: mod = VTERM_MOD_SHIFT; | |
1477 key = VTERM_KEY_LEFT; break; | |
1478 case K_C_LEFT: mod = VTERM_MOD_CTRL; | |
1479 key = VTERM_KEY_LEFT; break; | |
1480 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break; | |
1481 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break; | |
1482 case K_RIGHT: key = VTERM_KEY_RIGHT; break; | |
1483 case K_S_RIGHT: mod = VTERM_MOD_SHIFT; | |
1484 key = VTERM_KEY_RIGHT; break; | |
1485 case K_C_RIGHT: mod = VTERM_MOD_CTRL; | |
1486 key = VTERM_KEY_RIGHT; break; | |
1487 case K_UP: key = VTERM_KEY_UP; break; | |
1488 case K_S_UP: mod = VTERM_MOD_SHIFT; | |
1489 key = VTERM_KEY_UP; break; | |
1490 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
|
1491 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
|
1492 key = VTERM_KEY_TAB; break; |
12502 | 1493 |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1494 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
|
1495 case K_MOUSEDOWN: other = term_send_mouse(vterm, 4, 1); break; |
21114
d0265fdadec9
patch 8.2.1108: mouse left-right scroll is not supported in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1496 case K_MOUSELEFT: other = term_send_mouse(vterm, 7, 1); break; |
d0265fdadec9
patch 8.2.1108: mouse left-right scroll is not supported in terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1497 case K_MOUSERIGHT: other = term_send_mouse(vterm, 6, 1); break; |
12502 | 1498 |
1499 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
|
1500 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
|
1501 case K_LEFTDRAG: |
12502 | 1502 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
|
1503 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
|
1504 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
|
1505 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
|
1506 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
|
1507 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
|
1508 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
|
1509 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
|
1510 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
|
1511 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
|
1512 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
|
1513 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1514 |
12502 | 1515 case K_X1MOUSE: /* TODO */ return 0; |
1516 case K_X1DRAG: /* TODO */ return 0; | |
1517 case K_X1RELEASE: /* TODO */ return 0; | |
1518 case K_X2MOUSE: /* TODO */ return 0; | |
1519 case K_X2DRAG: /* TODO */ return 0; | |
1520 case K_X2RELEASE: /* TODO */ return 0; | |
1521 | |
1522 case K_IGNORE: return 0; | |
1523 case K_NOP: return 0; | |
1524 case K_UNDO: return 0; | |
1525 case K_HELP: return 0; | |
1526 case K_XF1: key = VTERM_KEY_FUNCTION(1); break; | |
1527 case K_XF2: key = VTERM_KEY_FUNCTION(2); break; | |
1528 case K_XF3: key = VTERM_KEY_FUNCTION(3); break; | |
1529 case K_XF4: key = VTERM_KEY_FUNCTION(4); break; | |
1530 case K_SELECT: return 0; | |
1531 #ifdef FEAT_GUI | |
1532 case K_VER_SCROLLBAR: return 0; | |
1533 case K_HOR_SCROLLBAR: return 0; | |
1534 #endif | |
1535 #ifdef FEAT_GUI_TABLINE | |
1536 case K_TABLINE: return 0; | |
1537 case K_TABMENU: return 0; | |
1538 #endif | |
1539 #ifdef FEAT_NETBEANS_INTG | |
1540 case K_F21: key = VTERM_KEY_FUNCTION(21); break; | |
1541 #endif | |
1542 #ifdef FEAT_DND | |
1543 case K_DROP: return 0; | |
1544 #endif | |
1545 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
|
1546 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
|
1547 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
|
1548 break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1549 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
|
1550 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
|
1551 break; |
12502 | 1552 } |
1553 | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1554 // add modifiers for the typed key |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1555 if (modmask & MOD_MASK_SHIFT) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1556 mod |= VTERM_MOD_SHIFT; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1557 if (modmask & MOD_MASK_CTRL) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1558 mod |= VTERM_MOD_CTRL; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
1559 if (modmask & (MOD_MASK_ALT | MOD_MASK_META)) |
18301
506bf60a30a0
patch 8.1.2145: cannot map <C-H> when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18279
diff
changeset
|
1560 mod |= VTERM_MOD_ALT; |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1561 |
12502 | 1562 /* |
1563 * Convert special keys to vterm keys: | |
1564 * - Write keys to vterm: vterm_keyboard_key() | |
1565 * - Write output to channel. | |
1566 */ | |
1567 if (key != VTERM_KEY_NONE) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1568 // Special key, let vterm convert it. |
12502 | 1569 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
|
1570 else if (!other) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1571 // Normal character, let vterm convert it. |
12502 | 1572 vterm_keyboard_unichar(vterm, c, mod); |
1573 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1574 // Read back the converted escape sequence. |
12502 | 1575 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); |
1576 } | |
1577 | |
1578 /* | |
1579 * 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
|
1580 * 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
|
1581 * 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
|
1582 */ |
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
|
1583 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
|
1584 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
|
1585 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1586 // Also consider the job finished when the channel is closed, to avoid a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1587 // race condition when updating the title. |
13696
3b1cfbc70b43
patch 8.0.1720: when a timer is running a terminal window may not close
Christian Brabandt <cb@256bit.org>
parents:
13686
diff
changeset
|
1588 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
|
1589 && 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
|
1590 && 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
|
1591 { |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1592 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
|
1593 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26598
diff
changeset
|
1594 // Careful: Checking the job status may invoke callbacks, which close |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1595 // 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
|
1596 // 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
|
1597 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
|
1598 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
|
1599 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
|
1600 || (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
|
1601 } |
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
|
1602 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
|
1603 } |
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
|
1604 |
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
|
1605 /* |
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
|
1606 * Return TRUE if the job for "term" is still running. |
12502 | 1607 */ |
1608 int | |
1609 term_job_running(term_T *term) | |
1610 { | |
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
|
1611 return term_job_running_check(term, FALSE); |
12502 | 1612 } |
1613 | |
1614 /* | |
1615 * Return TRUE if "term" has an active channel and used ":term NONE". | |
1616 */ | |
1617 int | |
1618 term_none_open(term_T *term) | |
1619 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1620 // Also consider the job finished when the channel is closed, to avoid a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1621 // race condition when updating the title. |
12502 | 1622 return term != NULL |
1623 && term->tl_job != NULL | |
1624 && channel_is_open(term->tl_job->jv_channel) | |
1625 && term->tl_job->jv_channel->ch_keep_open; | |
1626 } | |
1627 | |
1628 /* | |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1629 * 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
|
1630 * 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
|
1631 * 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
|
1632 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1633 int |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1634 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
|
1635 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1636 int count; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1637 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
|
1638 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1639 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
1640 if ((how == NULL || *how == NUL) |
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
1641 && (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM))) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1642 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1643 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
|
1644 int ret; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1645 |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1646 dialog_msg(buff, _("Kill job in \"%s\"?"), buf_get_fname(buf)); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1647 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
|
1648 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
|
1649 how = "kill"; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1650 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
|
1651 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1652 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1653 #endif |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1654 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
|
1655 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1656 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1657 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
|
1658 |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1659 // 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
|
1660 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
|
1661 { |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1662 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
|
1663 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1664 // 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
|
1665 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
|
1666 || 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
|
1667 || 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
|
1668 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
|
1669 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
|
1670 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1671 // 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
|
1672 // 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
|
1673 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
|
1674 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
|
1675 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
|
1676 |
18420
3a3efaaa05c5
patch 8.1.2204: crash on exit when closing terminals
Bram Moolenaar <Bram@vim.org>
parents:
18402
diff
changeset
|
1677 ui_delay(10L, TRUE); |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
1678 term_flush_messages(); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1679 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1680 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1681 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1682 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1683 /* |
12502 | 1684 * Add the last line of the scrollback buffer to the buffer in the window. |
1685 */ | |
1686 static void | |
1687 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) | |
1688 { | |
1689 buf_T *buf = term->tl_buffer; | |
1690 int empty = (buf->b_ml.ml_flags & ML_EMPTY); | |
1691 linenr_T lnum = buf->b_ml.ml_line_count; | |
1692 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1693 #ifdef MSWIN |
12502 | 1694 if (!enc_utf8 && enc_codepage > 0) |
1695 { | |
1696 WCHAR *ret = NULL; | |
1697 int length = 0; | |
1698 | |
1699 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, | |
1700 &ret, &length); | |
1701 if (ret != NULL) | |
1702 { | |
1703 WideCharToMultiByte_alloc(enc_codepage, 0, | |
1704 ret, length, (char **)&text, &len, 0, 0); | |
1705 vim_free(ret); | |
1706 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); | |
1707 vim_free(text); | |
1708 } | |
1709 } | |
1710 else | |
1711 #endif | |
1712 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); | |
1713 if (empty) | |
1714 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1715 // Delete the empty line that was in the empty buffer. |
12502 | 1716 curbuf = buf; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1717 ml_delete(1); |
12502 | 1718 curbuf = curwin->w_buffer; |
1719 } | |
1720 } | |
1721 | |
1722 static void | |
1723 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr) | |
1724 { | |
1725 attr->width = cell->width; | |
1726 attr->attrs = cell->attrs; | |
1727 attr->fg = cell->fg; | |
1728 attr->bg = cell->bg; | |
1729 } | |
1730 | |
1731 static int | |
1732 equal_celattr(cellattr_T *a, cellattr_T *b) | |
1733 { | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
1734 // We only compare the RGB colors, ignoring the ANSI index and type. |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
1735 // Thus black set explicitly is equal the background black. |
12502 | 1736 return a->fg.red == b->fg.red |
1737 && a->fg.green == b->fg.green | |
1738 && a->fg.blue == b->fg.blue | |
1739 && a->bg.red == b->bg.red | |
1740 && a->bg.green == b->bg.green | |
1741 && a->bg.blue == b->bg.blue; | |
1742 } | |
1743 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1744 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1745 * 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
|
1746 * 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
|
1747 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1748 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1749 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
|
1750 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1751 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
|
1752 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1753 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
|
1754 + 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
|
1755 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1756 if (lnum > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1757 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1758 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1759 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1760 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
|
1761 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1762 *line = *(line - 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1763 --line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1764 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1765 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1766 line->sb_cols = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1767 line->sb_cells = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1768 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
|
1769 ++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
|
1770 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1771 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1772 return FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1773 } |
12502 | 1774 |
1775 /* | |
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
|
1776 * 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
|
1777 * 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
|
1778 * 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
|
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 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
|
1781 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
|
1782 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1783 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
|
1784 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
|
1785 |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1786 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
|
1787 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
|
1788 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
|
1789 && 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
|
1790 { |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1791 ml_delete(curbuf->b_ml.ml_line_count); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1792 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
|
1793 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
|
1794 --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
|
1795 } |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1796 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
|
1797 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
|
1798 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
|
1799 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1800 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1801 /* |
12502 | 1802 * Add the current lines of the terminal to scrollback and to the buffer. |
1803 */ | |
1804 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
|
1805 update_snapshot(term_T *term) |
12502 | 1806 { |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1807 VTermScreen *screen; |
12502 | 1808 int len; |
1809 int lines_skipped = 0; | |
1810 VTermPos pos; | |
1811 VTermScreenCell cell; | |
1812 cellattr_T fill_attr, new_fill_attr; | |
1813 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
|
1814 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1815 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
|
1816 "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
|
1817 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1818 // First remove the lines that were appended before, they might be |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1819 // outdated. |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1820 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
|
1821 |
12502 | 1822 screen = vterm_obtain_screen(term->tl_vterm); |
1823 fill_attr = new_fill_attr = term->tl_default_color; | |
1824 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row) | |
1825 { | |
1826 len = 0; | |
1827 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | |
1828 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | |
1829 && cell.chars[0] != NUL) | |
1830 { | |
1831 len = pos.col + 1; | |
1832 new_fill_attr = term->tl_default_color; | |
1833 } | |
1834 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1835 // Assume the last attr is the filler attr. |
12502 | 1836 cell2cellattr(&cell, &new_fill_attr); |
1837 | |
1838 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr)) | |
1839 ++lines_skipped; | |
1840 else | |
1841 { | |
1842 while (lines_skipped > 0) | |
1843 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1844 // Line was skipped, add an empty line. |
12502 | 1845 --lines_skipped; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1846 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
12502 | 1847 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
1848 } | |
1849 | |
1850 if (len == 0) | |
1851 p = NULL; | |
1852 else | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1853 p = ALLOC_MULT(cellattr_T, len); |
12502 | 1854 if ((p != NULL || len == 0) |
1855 && ga_grow(&term->tl_scrollback, 1) == OK) | |
1856 { | |
1857 garray_T ga; | |
1858 int width; | |
1859 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | |
1860 + term->tl_scrollback.ga_len; | |
1861 | |
1862 ga_init2(&ga, 1, 100); | |
1863 for (pos.col = 0; pos.col < len; pos.col += width) | |
1864 { | |
1865 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
1866 { | |
1867 width = 1; | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1868 CLEAR_POINTER(p + pos.col); |
12502 | 1869 if (ga_grow(&ga, 1) == OK) |
1870 ga.ga_len += utf_char2bytes(' ', | |
1871 (char_u *)ga.ga_data + ga.ga_len); | |
1872 } | |
1873 else | |
1874 { | |
1875 width = cell.width; | |
1876 | |
1877 cell2cellattr(&cell, &p[pos.col]); | |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1878 if (width == 2) |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1879 // second cell of double-width character has the |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1880 // same attributes. |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
1881 p[pos.col + 1] = p[pos.col]; |
12502 | 1882 |
15203
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1883 // 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
|
1884 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK) |
12502 | 1885 { |
1886 int i; | |
1887 int c; | |
1888 | |
1889 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) | |
1890 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
1891 (char_u *)ga.ga_data + ga.ga_len); | |
1892 } | |
1893 } | |
1894 } | |
1895 line->sb_cols = len; | |
1896 line->sb_cells = p; | |
1897 line->sb_fill_attr = new_fill_attr; | |
1898 fill_attr = new_fill_attr; | |
1899 ++term->tl_scrollback.ga_len; | |
1900 | |
1901 if (ga_grow(&ga, 1) == FAIL) | |
1902 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
1903 else | |
1904 { | |
1905 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
1906 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
1907 } | |
1908 ga_clear(&ga); | |
1909 } | |
1910 else | |
1911 vim_free(p); | |
1912 } | |
1913 } | |
1914 | |
15022
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1915 // 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
|
1916 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
|
1917 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
|
1918 ++pos.row) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1919 { |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1920 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
|
1921 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
|
1922 } |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1923 |
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
|
1924 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
|
1925 #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
|
1926 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
|
1927 #endif |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1928 } |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1929 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1930 /* |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1931 * Loop over all windows in the current tab, and also curwin, which is not |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1932 * encountered when using a terminal in a popup window. |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1933 * Return TRUE if "*wp" was set to the next window. |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1934 */ |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1935 static int |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1936 for_all_windows_and_curwin(win_T **wp, int *did_curwin) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1937 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1938 if (*wp == NULL) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1939 *wp = firstwin; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1940 else if ((*wp)->w_next != NULL) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1941 *wp = (*wp)->w_next; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1942 else if (!*did_curwin) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1943 *wp = curwin; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1944 else |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1945 return FALSE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1946 if (*wp == curwin) |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1947 *did_curwin = TRUE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1948 return TRUE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1949 } |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1950 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1951 /* |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1952 * 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
|
1953 * 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
|
1954 * 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
|
1955 * 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
|
1956 */ |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1957 static void |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1958 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
|
1959 { |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1960 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
|
1961 return; |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1962 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1963 // Update the snapshot only if something changes or the buffer does not |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1964 // have all the lines. |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1965 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
|
1966 <= 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
|
1967 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
|
1968 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1969 // Obtain the current background color. |
12502 | 1970 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
1971 &term->tl_default_color.fg, &term->tl_default_color.bg); | |
1972 | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1973 if (redraw) |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1974 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1975 win_T *wp = NULL; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1976 int did_curwin = FALSE; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1977 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1978 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 1979 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1980 if (wp->w_buffer == term->tl_buffer) |
12502 | 1981 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1982 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
|
1983 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
|
1984 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
|
1985 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
|
1986 { |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1987 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
|
1988 |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1989 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
|
1990 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
|
1991 } |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
1992 redraw_win_later(wp, NOT_VALID); |
12502 | 1993 } |
1994 } | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1995 } |
12502 | 1996 } |
1997 | |
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
|
1998 #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
|
1999 /* |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2000 * 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
|
2001 * 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
|
2002 * 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
|
2003 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2004 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
|
2005 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
|
2006 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2007 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
|
2008 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
|
2009 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
2010 FOR_ALL_TERMS(term) |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2011 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2012 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
|
2013 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2014 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
|
2015 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2016 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
|
2017 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2018 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
|
2019 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
|
2020 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2021 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
|
2022 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
|
2023 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2024 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2025 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2026 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
|
2027 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2028 #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
|
2029 |
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
|
2030 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2031 * 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
|
2032 * 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
|
2033 */ |
12502 | 2034 static void |
2035 set_terminal_mode(term_T *term, int normal_mode) | |
2036 { | |
2037 term->tl_normal_mode = normal_mode; | |
26042
6b39ab99e367
patch 8.2.3555: ModeChanged is not triggered on every mode change
Bram Moolenaar <Bram@vim.org>
parents:
25994
diff
changeset
|
2038 trigger_modechanged(); |
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
|
2039 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
|
2040 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
|
2041 VIM_CLEAR(term->tl_status_text); |
12502 | 2042 if (term->tl_buffer == curbuf) |
2043 maketitle(); | |
2044 } | |
2045 | |
2046 /* | |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2047 * Called after the job is finished and Terminal mode is not active: |
12502 | 2048 * Move the vterm contents into the scrollback buffer and free the vterm. |
2049 */ | |
2050 static void | |
2051 cleanup_vterm(term_T *term) | |
2052 { | |
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
|
2053 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
|
2054 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
|
2055 may_move_terminal_to_buffer(term, TRUE); |
12502 | 2056 term_free_vterm(term); |
2057 } | |
2058 | |
2059 /* | |
2060 * Switch from Terminal-Job mode to Terminal-Normal mode. | |
2061 * Suspends updating the terminal window. | |
2062 */ | |
2063 static void | |
2064 term_enter_normal_mode(void) | |
2065 { | |
2066 term_T *term = curbuf->b_term; | |
2067 | |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2068 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
|
2069 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2070 // 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
|
2071 may_move_terminal_to_buffer(term, TRUE); |
12502 | 2072 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2073 // Move the window cursor to the position of the cursor in the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2074 // terminal. |
12502 | 2075 curwin->w_cursor.lnum = term->tl_scrollback_scrolled |
2076 + term->tl_cursor_pos.row + 1; | |
2077 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
|
2078 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
|
2079 coladvance(MAXCOL); |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2080 curwin->w_set_curswant = TRUE; |
12502 | 2081 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2082 // Display the same lines as in the terminal. |
12502 | 2083 curwin->w_topline = term->tl_scrollback_scrolled + 1; |
2084 } | |
2085 | |
2086 /* | |
2087 * Returns TRUE if the current window contains a terminal and we are in | |
2088 * Terminal-Normal mode. | |
2089 */ | |
2090 int | |
2091 term_in_normal_mode(void) | |
2092 { | |
2093 term_T *term = curbuf->b_term; | |
2094 | |
2095 return term != NULL && term->tl_normal_mode; | |
2096 } | |
2097 | |
2098 /* | |
2099 * Switch from Terminal-Normal mode to Terminal-Job mode. | |
2100 * Restores updating the terminal window. | |
2101 */ | |
2102 void | |
2103 term_enter_job_mode() | |
2104 { | |
2105 term_T *term = curbuf->b_term; | |
2106 | |
2107 set_terminal_mode(term, FALSE); | |
2108 | |
2109 if (term->tl_channel_closed) | |
2110 cleanup_vterm(term); | |
2111 redraw_buf_and_status_later(curbuf, NOT_VALID); | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2112 #ifdef FEAT_PROP_POPUP |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2113 if (WIN_IS_POPUP(curwin)) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
2114 redraw_later(NOT_VALID); |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2115 #endif |
12502 | 2116 } |
2117 | |
2118 /* | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2119 * Get a key from the user with terminal mode mappings. |
12502 | 2120 * Note: while waiting a terminal may be closed and freed if the channel is |
26548
15764dc9a59d
patch 8.2.3803: GUI: crash with 'writedelay' set using a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26544
diff
changeset
|
2121 * closed and ++close was used. This may even happen before we get here. |
12502 | 2122 */ |
2123 static int | |
2124 term_vgetc() | |
2125 { | |
2126 int c; | |
2127 int save_State = State; | |
26548
15764dc9a59d
patch 8.2.3803: GUI: crash with 'writedelay' set using a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26544
diff
changeset
|
2128 int modify_other_keys = curbuf->b_term->tl_vterm == NULL ? FALSE |
15764dc9a59d
patch 8.2.3803: GUI: crash with 'writedelay' set using a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26544
diff
changeset
|
2129 : vterm_is_modify_other_keys(curbuf->b_term->tl_vterm); |
12502 | 2130 |
2131 State = TERMINAL; | |
2132 got_int = FALSE; | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2133 #ifdef MSWIN |
12502 | 2134 ctrl_break_was_pressed = FALSE; |
2135 #endif | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2136 if (modify_other_keys) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2137 ++no_reduce_keys; |
12502 | 2138 c = vgetc(); |
2139 got_int = FALSE; | |
2140 State = save_State; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2141 if (modify_other_keys) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2142 --no_reduce_keys; |
12502 | 2143 return c; |
2144 } | |
2145 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2146 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
|
2147 |
12502 | 2148 /* |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2149 * Send key "c" with modifiers "modmask" to terminal. |
12502 | 2150 * Return FAIL when the key needs to be handled in Normal mode. |
2151 * Return OK when the key was dropped or sent to the terminal. | |
2152 */ | |
2153 int | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2154 send_keys_to_term(term_T *term, int c, int modmask, int typed) |
12502 | 2155 { |
2156 char msg[KEY_BUF_LEN]; | |
2157 size_t len; | |
2158 int dragging_outside = FALSE; | |
2159 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2160 // Catch keys that need to be handled as in Normal mode. |
12502 | 2161 switch (c) |
2162 { | |
2163 case NUL: | |
2164 case K_ZERO: | |
2165 if (typed) | |
2166 stuffcharReadbuff(c); | |
2167 return FAIL; | |
2168 | |
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
|
2169 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
|
2170 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
|
2171 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
|
2172 |
12502 | 2173 case K_IGNORE: |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2174 case K_CANCEL: // used for :normal when running out of chars |
12502 | 2175 return FAIL; |
2176 | |
2177 case K_LEFTDRAG: | |
2178 case K_MIDDLEDRAG: | |
2179 case K_RIGHTDRAG: | |
2180 case K_X1DRAG: | |
2181 case K_X2DRAG: | |
2182 dragging_outside = mouse_was_outside; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2183 // FALLTHROUGH |
12502 | 2184 case K_LEFTMOUSE: |
2185 case K_LEFTMOUSE_NM: | |
2186 case K_LEFTRELEASE: | |
2187 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
|
2188 case K_MOUSEMOVE: |
12502 | 2189 case K_MIDDLEMOUSE: |
2190 case K_MIDDLERELEASE: | |
2191 case K_RIGHTMOUSE: | |
2192 case K_RIGHTRELEASE: | |
2193 case K_X1MOUSE: | |
2194 case K_X1RELEASE: | |
2195 case K_X2MOUSE: | |
2196 case K_X2RELEASE: | |
2197 | |
2198 case K_MOUSEUP: | |
2199 case K_MOUSEDOWN: | |
2200 case K_MOUSELEFT: | |
2201 case K_MOUSERIGHT: | |
2202 { | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2203 int row = mouse_row; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2204 int col = mouse_col; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2205 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2206 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2207 if (popup_is_popup(curwin)) |
12502 | 2208 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2209 row -= popup_top_extra(curwin); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2210 col -= popup_left_extra(curwin); |
12502 | 2211 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2212 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2213 if (row < W_WINROW(curwin) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2214 || row >= (W_WINROW(curwin) + curwin->w_height) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2215 || col < curwin->w_wincol |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2216 || col >= W_ENDCOL(curwin) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2217 || dragging_outside) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2218 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2219 // click or scroll outside the current window or on status |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2220 // line or vertical separator |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2221 if (typed) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2222 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2223 stuffcharReadbuff(c); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2224 mouse_was_outside = TRUE; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2225 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2226 return FAIL; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2227 } |
12502 | 2228 } |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2229 break; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2230 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2231 case K_COMMAND: |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2232 case K_SCRIPT_COMMAND: |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
2233 return do_cmdkey_command(c, 0); |
12502 | 2234 } |
2235 if (typed) | |
2236 mouse_was_outside = FALSE; | |
2237 | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2238 // Convert the typed key to a sequence of bytes for the job. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2239 len = term_convert_key(term, c, modmask, msg); |
12502 | 2240 if (len > 0) |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2241 // TODO: if FAIL is returned, stop? |
12502 | 2242 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
2243 (char_u *)msg, (int)len, NULL); | |
2244 | |
2245 return OK; | |
2246 } | |
2247 | |
2248 static void | |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2249 position_cursor(win_T *wp, VTermPos *pos) |
12502 | 2250 { |
2251 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); | |
2252 wp->w_wcol = MIN(pos->col, MAX(0, wp->w_width - 1)); | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2253 #ifdef FEAT_PROP_POPUP |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2254 if (popup_is_popup(wp)) |
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2255 { |
23041
139573353c6d
patch 8.2.2067: cursor position in popup terminal is wrong
Bram Moolenaar <Bram@vim.org>
parents:
23035
diff
changeset
|
2256 wp->w_wrow += popup_top_extra(wp); |
139573353c6d
patch 8.2.2067: cursor position in popup terminal is wrong
Bram Moolenaar <Bram@vim.org>
parents:
23035
diff
changeset
|
2257 wp->w_wcol += popup_left_extra(wp); |
22886
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2258 wp->w_flags |= WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED; |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2259 } |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2260 else |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2261 wp->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2262 #endif |
12502 | 2263 wp->w_valid |= (VALID_WCOL|VALID_WROW); |
2264 } | |
2265 | |
2266 /* | |
2267 * Handle CTRL-W "": send register contents to the job. | |
2268 */ | |
2269 static void | |
2270 term_paste_register(int prev_c UNUSED) | |
2271 { | |
2272 int c; | |
2273 list_T *l; | |
2274 listitem_T *item; | |
2275 long reglen = 0; | |
2276 int type; | |
2277 | |
2278 #ifdef FEAT_CMDL_INFO | |
2279 if (add_to_showcmd(prev_c)) | |
2280 if (add_to_showcmd('"')) | |
2281 out_flush(); | |
2282 #endif | |
2283 c = term_vgetc(); | |
2284 #ifdef FEAT_CMDL_INFO | |
2285 clear_showcmd(); | |
2286 #endif | |
2287 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2288 // job finished while waiting for a character |
12502 | 2289 return; |
2290 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2291 // CTRL-W "= prompt for expression to evaluate. |
12502 | 2292 if (c == '=' && get_expr_register() != '=') |
2293 return; | |
2294 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2295 // job finished while waiting for a character |
12502 | 2296 return; |
2297 | |
2298 l = (list_T *)get_reg_contents(c, GREG_LIST); | |
2299 if (l != NULL) | |
2300 { | |
2301 type = get_reg_type(c, ®len); | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
2302 FOR_ALL_LIST_ITEMS(l, item) |
12502 | 2303 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
2304 char_u *s = tv_get_string(&item->li_tv); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2305 #ifdef MSWIN |
12502 | 2306 char_u *tmp = s; |
2307 | |
2308 if (!enc_utf8 && enc_codepage > 0) | |
2309 { | |
2310 WCHAR *ret = NULL; | |
2311 int length = 0; | |
2312 | |
2313 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s, | |
2314 (int)STRLEN(s), &ret, &length); | |
2315 if (ret != NULL) | |
2316 { | |
2317 WideCharToMultiByte_alloc(CP_UTF8, 0, | |
2318 ret, length, (char **)&s, &length, 0, 0); | |
2319 vim_free(ret); | |
2320 } | |
2321 } | |
2322 #endif | |
2323 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2324 s, (int)STRLEN(s), NULL); | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2325 #ifdef MSWIN |
12502 | 2326 if (tmp != s) |
2327 vim_free(s); | |
2328 #endif | |
2329 | |
2330 if (item->li_next != NULL || type == MLINE) | |
2331 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2332 (char_u *)"\r", 1, NULL); | |
2333 } | |
2334 list_free(l); | |
2335 } | |
2336 } | |
2337 | |
2338 /* | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2339 * 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
|
2340 * terminal should be displayed. |
12502 | 2341 */ |
2342 int | |
2343 terminal_is_active() | |
2344 { | |
2345 return in_terminal_loop != NULL; | |
2346 } | |
2347 | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2348 /* |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2349 * Return the highight group ID for the terminal and the window. |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2350 */ |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2351 static int |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2352 term_get_highlight_id(term_T *term, win_T *wp) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2353 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2354 char_u *name; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2355 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2356 if (wp != NULL && *wp->w_p_wcr != NUL) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2357 name = wp->w_p_wcr; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2358 else if (term->tl_highlight_name != NULL) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2359 name = term->tl_highlight_name; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2360 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2361 name = (char_u*)"Terminal"; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2362 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2363 return syn_name2id(name); |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2364 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2365 |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2366 #if defined(FEAT_GUI) || defined(PROTO) |
12502 | 2367 cursorentry_T * |
2368 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) | |
2369 { | |
2370 term_T *term = in_terminal_loop; | |
2371 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
|
2372 int id; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2373 guicolor_T term_fg = INVALCOLOR; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2374 guicolor_T term_bg = INVALCOLOR; |
12502 | 2375 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2376 CLEAR_FIELD(entry); |
12502 | 2377 entry.shape = entry.mshape = |
2378 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : | |
2379 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : | |
2380 SHAPE_BLOCK; | |
2381 entry.percentage = 20; | |
2382 if (term->tl_cursor_blink) | |
2383 { | |
2384 entry.blinkwait = 700; | |
2385 entry.blinkon = 400; | |
2386 entry.blinkoff = 250; | |
2387 } | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2388 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2389 // The highlight group overrules the defaults. |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2390 id = term_get_highlight_id(term, curwin); |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2391 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
|
2392 syn_id2colors(id, &term_fg, &term_bg); |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2393 if (term_bg != INVALCOLOR) |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2394 *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
|
2395 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2396 *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
|
2397 |
12502 | 2398 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
|
2399 { |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2400 if (term_fg != INVALCOLOR) |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2401 *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
|
2402 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2403 *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
|
2404 } |
12502 | 2405 else |
2406 *bg = color_name2handle(term->tl_cursor_color); | |
2407 entry.name = "n"; | |
2408 entry.used_for = SHAPE_CURSOR; | |
2409 | |
2410 return &entry; | |
2411 } | |
2412 #endif | |
2413 | |
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
|
2414 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
|
2415 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
|
2416 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2417 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
|
2418 || 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
|
2419 || 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
|
2420 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2421 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
|
2422 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
|
2423 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
|
2424 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
|
2425 if (desired_cursor_shape == -1 || desired_cursor_blink == -1) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2426 // this will restore the initial cursor style, if possible |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2427 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
|
2428 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
|
2429 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
|
2430 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2431 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2432 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2433 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2434 * 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
|
2435 */ |
12502 | 2436 static void |
2437 may_set_cursor_props(term_T *term) | |
2438 { | |
2439 #ifdef FEAT_GUI | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2440 // For the GUI the cursor properties are obtained with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2441 // term_get_cursor_shape(). |
12502 | 2442 if (gui.in_use) |
2443 return; | |
2444 #endif | |
2445 if (in_terminal_loop == term) | |
2446 { | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2447 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
|
2448 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
|
2449 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
|
2450 may_output_cursor_props(); |
12502 | 2451 } |
2452 } | |
2453 | |
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
|
2454 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2455 * 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
|
2456 */ |
12502 | 2457 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
|
2458 prepare_restore_cursor_props(void) |
12502 | 2459 { |
2460 #ifdef FEAT_GUI | |
2461 if (gui.in_use) | |
2462 return; | |
2463 #endif | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2464 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
|
2465 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
|
2466 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
|
2467 may_output_cursor_props(); |
12502 | 2468 } |
2469 | |
2470 /* | |
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
|
2471 * 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
|
2472 * 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
|
2473 * 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
|
2474 */ |
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
|
2475 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
|
2476 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
|
2477 { |
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
|
2478 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
|
2479 |
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
|
2480 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
|
2481 && !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
|
2482 && 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
|
2483 && 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
|
2484 } |
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
|
2485 |
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
|
2486 /* |
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
|
2487 * 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
|
2488 * 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
|
2489 */ |
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
|
2490 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
|
2491 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
|
2492 { |
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
|
2493 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
|
2494 } |
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
|
2495 |
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
|
2496 /* |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2497 * 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
|
2498 * 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
|
2499 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2500 void |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2501 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
|
2502 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2503 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
|
2504 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2505 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
|
2506 { |
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
|
2507 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
|
2508 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2509 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
|
2510 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
|
2511 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
|
2512 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2513 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
|
2514 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
|
2515 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
|
2516 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2517 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2518 |
26462
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2519 void |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2520 term_focus_change(int in_focus) |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2521 { |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2522 term_T *term = curbuf->b_term; |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2523 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2524 if (term != NULL && term->tl_vterm != NULL) |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2525 { |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2526 VTermState *state = vterm_obtain_state(term->tl_vterm); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2527 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2528 if (in_focus) |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2529 vterm_state_focus_in(state); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2530 else |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2531 vterm_state_focus_out(state); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2532 term_forward_output(term); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2533 } |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2534 } |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2535 |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2536 /* |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2537 * vgetc() may not include CTRL in the key when modify_other_keys is set. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2538 * Return the Ctrl-key value in that case. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2539 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2540 static int |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2541 raw_c_to_ctrl(int c) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2542 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2543 if ((mod_mask & MOD_MASK_CTRL) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2544 && ((c >= '`' && c <= 0x7f) || (c >= '@' && c <= '_'))) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2545 return c & 0x1f; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2546 return c; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2547 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2548 |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2549 /* |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2550 * When modify_other_keys is set then do the reverse of raw_c_to_ctrl(). |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2551 * May set "mod_mask". |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2552 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2553 static int |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2554 ctrl_to_raw_c(int c) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2555 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2556 if (c < 0x20 && vterm_is_modify_other_keys(curbuf->b_term->tl_vterm)) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2557 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2558 mod_mask |= MOD_MASK_CTRL; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2559 return c + '@'; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2560 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2561 return c; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2562 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2563 |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2564 /* |
12502 | 2565 * Wait for input and send it to the job. |
2566 * When "blocking" is TRUE wait for a character to be typed. Otherwise return | |
2567 * when there is no more typahead. | |
2568 * Return when the start of a CTRL-W command is typed or anything else that | |
2569 * should be handled as a Normal mode command. | |
2570 * Returns OK if a typed character is to be handled in Normal mode, FAIL if | |
2571 * the terminal was closed. | |
2572 */ | |
2573 int | |
2574 terminal_loop(int blocking) | |
2575 { | |
2576 int c; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2577 int raw_c; |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2578 int termwinkey = 0; |
12502 | 2579 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
|
2580 #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
|
2581 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
|
2582 ->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
|
2583 #endif |
13906
0ae89b121c58
patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents:
13900
diff
changeset
|
2584 int restore_cursor = FALSE; |
12502 | 2585 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2586 // Remember the terminal we are sending keys to. However, the terminal |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2587 // might be closed while waiting for a character, e.g. typing "exit" in a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2588 // shell and ++close was used. Therefore use curbuf->b_term instead of a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2589 // stored reference. |
12502 | 2590 in_terminal_loop = curbuf->b_term; |
2591 | |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2592 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
|
2593 { |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2594 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
|
2595 if (termwinkey == Ctrl_W) |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2596 termwinkey = 0; |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2597 } |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2598 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos); |
12502 | 2599 may_set_cursor_props(curbuf->b_term); |
2600 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2601 while (blocking || vpeekc_nomap() != NUL) |
12502 | 2602 { |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2603 #ifdef FEAT_GUI |
22876
b952e0a3af2f
patch 8.2.1985: crash when closing terminal popup with <Cmd> mapping
Bram Moolenaar <Bram@vim.org>
parents:
22864
diff
changeset
|
2604 if (curbuf->b_term != NULL && !curbuf->b_term->tl_system) |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2605 #endif |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2606 // 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
|
2607 // 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
|
2608 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
|
2609 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
|
2610 break; |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2611 if (!term_use_loop_check(TRUE) || in_terminal_loop != curbuf->b_term) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2612 // job finished while redrawing |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2613 break; |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2614 |
12502 | 2615 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
|
2616 restore_cursor = TRUE; |
12502 | 2617 |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2618 raw_c = term_vgetc(); |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2619 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
|
2620 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2621 // Job finished while waiting for a character. Push back the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2622 // received character. |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2623 if (raw_c != K_IGNORE) |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2624 vungetc(raw_c); |
12502 | 2625 break; |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2626 } |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2627 if (raw_c == K_IGNORE) |
12502 | 2628 continue; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2629 c = raw_c_to_ctrl(raw_c); |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2630 |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2631 #ifdef UNIX |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2632 /* |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2633 * 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
|
2634 * 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
|
2635 * 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
|
2636 */ |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2637 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
|
2638 { |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2639 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
|
2640 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2641 // Get the current backspace character of the pty. |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2642 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
|
2643 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
|
2644 } |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2645 #endif |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2646 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2647 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2648 // On Windows winpty handles CTRL-C, don't send a CTRL_C_EVENT. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2649 // Use CTRL-BREAK to kill the job. |
12502 | 2650 if (ctrl_break_was_pressed) |
2651 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
2652 #endif | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2653 // Was either CTRL-W (termwinkey) or CTRL-\ pressed? |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2654 // 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
|
2655 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
|
2656 #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
|
2657 && !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
|
2658 #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
|
2659 ) |
12502 | 2660 { |
2661 int prev_c = c; | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2662 int prev_raw_c = raw_c; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2663 int prev_mod_mask = mod_mask; |
12502 | 2664 |
2665 #ifdef FEAT_CMDL_INFO | |
2666 if (add_to_showcmd(c)) | |
2667 out_flush(); | |
2668 #endif | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2669 raw_c = term_vgetc(); |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2670 c = raw_c_to_ctrl(raw_c); |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2671 |
12502 | 2672 #ifdef FEAT_CMDL_INFO |
2673 clear_showcmd(); | |
2674 #endif | |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2675 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
|
2676 || in_terminal_loop != curbuf->b_term) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2677 // job finished while waiting for a character |
12502 | 2678 break; |
2679 | |
2680 if (prev_c == Ctrl_BSL) | |
2681 { | |
2682 if (c == Ctrl_N) | |
2683 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2684 // CTRL-\ CTRL-N : go to Terminal-Normal mode. |
12502 | 2685 term_enter_normal_mode(); |
2686 ret = FAIL; | |
2687 goto theend; | |
2688 } | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2689 // Send both keys to the terminal, first one here, second one |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2690 // below. |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2691 send_keys_to_term(curbuf->b_term, prev_raw_c, prev_mod_mask, |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2692 TRUE); |
12502 | 2693 } |
2694 else if (c == Ctrl_C) | |
2695 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2696 // "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job |
12502 | 2697 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); |
2698 } | |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2699 else if (c == '.') |
12502 | 2700 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2701 // "CTRL-W .": send CTRL-W to the job |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2702 // "'termwinkey' .": send 'termwinkey' to the job |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2703 raw_c = ctrl_to_raw_c(termwinkey == 0 ? Ctrl_W : termwinkey); |
12502 | 2704 } |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2705 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
|
2706 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2707 // "CTRL-W CTRL-\": send CTRL-\ to the job |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2708 raw_c = ctrl_to_raw_c(Ctrl_BSL); |
13668
6a84e3d2b810
patch 8.0.1706: cannot sent CTRL- to a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13630
diff
changeset
|
2709 } |
12502 | 2710 else if (c == 'N') |
2711 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2712 // CTRL-W N : go to Terminal-Normal mode. |
12502 | 2713 term_enter_normal_mode(); |
2714 ret = FAIL; | |
2715 goto theend; | |
2716 } | |
2717 else if (c == '"') | |
2718 { | |
2719 term_paste_register(prev_c); | |
2720 continue; | |
2721 } | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2722 else if (termwinkey == 0 || c != termwinkey) |
12502 | 2723 { |
22448
5e287462487e
patch 8.2.1772: cannot use CTRL-W <Down> to move out of a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
2724 // space for CTRL-W, modifier, multi-byte char and NUL |
5e287462487e
patch 8.2.1772: cannot use CTRL-W <Down> to move out of a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
2725 char_u buf[1 + 3 + MB_MAXBYTES + 1]; |
17702
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2726 |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2727 // Put the command into the typeahead buffer, when using the |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2728 // stuff buffer KeyStuffed is set and 'langmap' won't be used. |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2729 buf[0] = Ctrl_W; |
22448
5e287462487e
patch 8.2.1772: cannot use CTRL-W <Down> to move out of a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
22230
diff
changeset
|
2730 buf[special_to_buf(c, mod_mask, FALSE, buf + 1) + 1] = NUL; |
17702
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2731 ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE); |
12502 | 2732 ret = OK; |
2733 goto theend; | |
2734 } | |
2735 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2736 # ifdef MSWIN |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2737 if (!enc_utf8 && has_mbyte && raw_c >= 0x80) |
12502 | 2738 { |
2739 WCHAR wc; | |
2740 char_u mb[3]; | |
2741 | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2742 mb[0] = (unsigned)raw_c >> 8; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2743 mb[1] = raw_c; |
12502 | 2744 if (MultiByteToWideChar(GetACP(), 0, (char*)mb, 2, &wc, 1) > 0) |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2745 raw_c = wc; |
12502 | 2746 } |
2747 # endif | |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2748 if (send_keys_to_term(curbuf->b_term, raw_c, mod_mask, TRUE) != OK) |
12502 | 2749 { |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2750 if (raw_c == K_MOUSEMOVE) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2751 // We are sure to come back here, don't reset the cursor color |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2752 // and shape to avoid flickering. |
13206
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2753 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
|
2754 |
12502 | 2755 ret = OK; |
2756 goto theend; | |
2757 } | |
2758 } | |
2759 ret = FAIL; | |
2760 | |
2761 theend: | |
2762 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
|
2763 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
|
2764 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
|
2765 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2766 // Move a snapshot of the screen contents to the buffer, so that completion |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2767 // 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
|
2768 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
|
2769 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
|
2770 |
12502 | 2771 return ret; |
2772 } | |
2773 | |
2774 static void | |
2775 may_toggle_cursor(term_T *term) | |
2776 { | |
2777 if (in_terminal_loop == term) | |
2778 { | |
2779 if (term->tl_cursor_visible) | |
2780 cursor_on(); | |
2781 else | |
2782 cursor_off(); | |
2783 } | |
2784 } | |
2785 | |
2786 /* | |
2787 * 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
|
2788 * First color is 1. Return 0 if no match found (default color). |
12502 | 2789 */ |
2790 static int | |
2791 color2index(VTermColor *color, int fg, int *boldp) | |
2792 { | |
2793 int red = color->red; | |
2794 int blue = color->blue; | |
2795 int green = color->green; | |
2796 | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2797 if (VTERM_COLOR_IS_INVALID(color)) |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2798 return 0; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2799 if (VTERM_COLOR_IS_INDEXED(color)) |
12502 | 2800 { |
16312
46e8430738fa
patch 8.1.1161: unreachable code
Bram Moolenaar <Bram@vim.org>
parents:
16283
diff
changeset
|
2801 // The first 16 colors and default: use the ANSI index. |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2802 switch (color->index + 1) |
12502 | 2803 { |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2804 case 0: return 0; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2805 case 1: return lookup_color( 0, fg, boldp) + 1; // black |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2806 case 2: return lookup_color( 4, fg, boldp) + 1; // dark red |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2807 case 3: return lookup_color( 2, fg, boldp) + 1; // dark green |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2808 case 4: return lookup_color( 7, fg, boldp) + 1; // dark yellow |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2809 case 5: return lookup_color( 1, fg, boldp) + 1; // dark blue |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2810 case 6: return lookup_color( 5, fg, boldp) + 1; // dark magenta |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2811 case 7: return lookup_color( 3, fg, boldp) + 1; // dark cyan |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2812 case 8: return lookup_color( 8, fg, boldp) + 1; // light grey |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2813 case 9: return lookup_color(12, fg, boldp) + 1; // dark grey |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2814 case 10: return lookup_color(20, fg, boldp) + 1; // red |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2815 case 11: return lookup_color(16, fg, boldp) + 1; // green |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2816 case 12: return lookup_color(24, fg, boldp) + 1; // yellow |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2817 case 13: return lookup_color(14, fg, boldp) + 1; // blue |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2818 case 14: return lookup_color(22, fg, boldp) + 1; // magenta |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2819 case 15: return lookup_color(18, fg, boldp) + 1; // cyan |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2820 case 16: return lookup_color(26, fg, boldp) + 1; // white |
12502 | 2821 } |
2822 } | |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2823 |
12502 | 2824 if (t_colors >= 256) |
2825 { | |
2826 if (red == blue && red == green) | |
2827 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2828 // 24-color greyscale plus white and black |
12502 | 2829 static int cutoff[23] = { |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2830 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
|
2831 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
|
2832 0xD5, 0xDF, 0xE9}; |
12502 | 2833 int i; |
2834 | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2835 if (red < 5) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2836 return 17; // 00/00/00 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2837 if (red > 245) // ff/ff/ff |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2838 return 232; |
12502 | 2839 for (i = 0; i < 23; ++i) |
2840 if (red < cutoff[i]) | |
2841 return i + 233; | |
2842 return 256; | |
2843 } | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2844 { |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2845 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
|
2846 int ri, gi, bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2847 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2848 // 216-color cube |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2849 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
|
2850 if (red < cutoff[ri]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2851 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2852 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
|
2853 if (green < cutoff[gi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2854 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2855 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
|
2856 if (blue < cutoff[bi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2857 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2858 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
|
2859 } |
12502 | 2860 } |
2861 return 0; | |
2862 } | |
2863 | |
2864 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2865 * Convert Vterm attributes to highlight flags. |
12502 | 2866 */ |
2867 static int | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2868 vtermAttr2hl(VTermScreenCellAttrs *cellattrs) |
12502 | 2869 { |
2870 int attr = 0; | |
2871 | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2872 if (cellattrs->bold) |
12502 | 2873 attr |= HL_BOLD; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2874 if (cellattrs->underline) |
12502 | 2875 attr |= HL_UNDERLINE; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2876 if (cellattrs->italic) |
12502 | 2877 attr |= HL_ITALIC; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2878 if (cellattrs->strike) |
12502 | 2879 attr |= HL_STRIKETHROUGH; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2880 if (cellattrs->reverse) |
12502 | 2881 attr |= HL_INVERSE; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2882 return attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2883 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2884 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2885 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2886 * 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
|
2887 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2888 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2889 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
|
2890 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2891 CLEAR_FIELD(cell->attrs); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2892 if (attr & HL_BOLD) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2893 cell->attrs.bold = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2894 if (attr & HL_UNDERLINE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2895 cell->attrs.underline = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2896 if (attr & HL_ITALIC) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2897 cell->attrs.italic = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2898 if (attr & HL_STRIKETHROUGH) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2899 cell->attrs.strike = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2900 if (attr & HL_INVERSE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2901 cell->attrs.reverse = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2902 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2903 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2904 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2905 * 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
|
2906 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2907 static int |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2908 cell2attr( |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2909 term_T *term, |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2910 win_T *wp, |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2911 VTermScreenCellAttrs *cellattrs, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2912 VTermColor *cellfg, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2913 VTermColor *cellbg) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2914 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2915 int attr = vtermAttr2hl(cellattrs); |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2916 VTermColor *fg = cellfg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2917 VTermColor *bg = cellbg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2918 int is_default_fg = VTERM_COLOR_IS_DEFAULT_FG(fg); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2919 int is_default_bg = VTERM_COLOR_IS_DEFAULT_BG(bg); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2920 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2921 if (is_default_fg || is_default_bg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2922 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2923 if (wp != NULL && *wp->w_p_wcr != NUL) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2924 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2925 if (is_default_fg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2926 fg = &wp->w_term_wincolor.fg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2927 if (is_default_bg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2928 bg = &wp->w_term_wincolor.bg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2929 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2930 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2931 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2932 if (is_default_fg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2933 fg = &term->tl_default_color.fg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2934 if (is_default_bg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2935 bg = &term->tl_default_color.bg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2936 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2937 } |
12502 | 2938 |
2939 #ifdef FEAT_GUI | |
2940 if (gui.in_use) | |
2941 { | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2942 guicolor_T guifg = gui_mch_get_rgb_color(fg->red, fg->green, fg->blue); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2943 guicolor_T guibg = gui_mch_get_rgb_color(bg->red, bg->green, bg->blue); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2944 return get_gui_attr_idx(attr, guifg, guibg); |
12502 | 2945 } |
2946 else | |
2947 #endif | |
2948 #ifdef FEAT_TERMGUICOLORS | |
2949 if (p_tgc) | |
2950 { | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2951 guicolor_T tgcfg = VTERM_COLOR_IS_INVALID(fg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2952 ? INVALCOLOR |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2953 : gui_get_rgb_color_cmn(fg->red, fg->green, fg->blue); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2954 guicolor_T tgcbg = VTERM_COLOR_IS_INVALID(bg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2955 ? INVALCOLOR |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2956 : gui_get_rgb_color_cmn(bg->red, bg->green, bg->blue); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2957 return get_tgc_attr_idx(attr, tgcfg, tgcbg); |
12502 | 2958 } |
2959 else | |
2960 #endif | |
2961 { | |
2962 int bold = MAYBE; | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2963 int ctermfg = color2index(fg, TRUE, &bold); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2964 int ctermbg = color2index(bg, FALSE, &bold); |
12969
a9f6a874b64f
patch 8.0.1360: the Terminal highlighting doesn't work in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12966
diff
changeset
|
2965 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2966 // with 8 colors set the bold attribute to get a bright foreground |
12502 | 2967 if (bold == TRUE) |
2968 attr |= HL_BOLD; | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2969 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2970 return get_cterm_attr_idx(attr, ctermfg, ctermbg); |
12502 | 2971 } |
2972 return 0; | |
2973 } | |
2974 | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2975 static void |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2976 set_dirty_snapshot(term_T *term) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2977 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2978 term->tl_dirty_snapshot = TRUE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2979 #ifdef FEAT_TIMERS |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2980 if (!term->tl_normal_mode) |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2981 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2982 // Update the snapshot after 100 msec of not getting updates. |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2983 profile_setlimit(100L, &term->tl_timer_due); |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2984 term->tl_timer_set = TRUE; |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2985 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2986 #endif |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2987 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2988 |
12502 | 2989 static int |
2990 handle_damage(VTermRect rect, void *user) | |
2991 { | |
2992 term_T *term = (term_T *)user; | |
2993 | |
2994 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row); | |
2995 term->tl_dirty_row_end = MAX(term->tl_dirty_row_end, rect.end_row); | |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2996 set_dirty_snapshot(term); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
2997 redraw_buf_later(term->tl_buffer, SOME_VALID); |
12502 | 2998 return 1; |
2999 } | |
3000 | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3001 static void |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3002 term_scroll_up(term_T *term, int start_row, int count) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3003 { |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
3004 win_T *wp = NULL; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
3005 int did_curwin = FALSE; |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3006 VTermColor fg, bg; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3007 VTermScreenCellAttrs attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3008 int clear_attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3009 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3010 CLEAR_FIELD(attr); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3011 |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
3012 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3013 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3014 if (wp->w_buffer == term->tl_buffer) |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3015 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3016 // Set the color to clear lines with. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3017 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3018 &fg, &bg); |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3019 clear_attr = cell2attr(term, wp, &attr, &fg, &bg); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3020 win_del_lines(wp, start_row, count, FALSE, FALSE, clear_attr); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3021 } |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3022 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3023 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3024 |
12502 | 3025 static int |
3026 handle_moverect(VTermRect dest, VTermRect src, void *user) | |
3027 { | |
3028 term_T *term = (term_T *)user; | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3029 int count = src.start_row - dest.start_row; |
12502 | 3030 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3031 // Scrolling up is done much more efficiently by deleting lines instead of |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3032 // redrawing the text. But avoid doing this multiple times, postpone until |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3033 // the redraw happens. |
12502 | 3034 if (dest.start_col == src.start_col |
3035 && dest.end_col == src.end_col | |
3036 && dest.start_row < src.start_row) | |
3037 { | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3038 if (dest.start_row == 0) |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3039 term->tl_postponed_scroll += count; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3040 else |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3041 term_scroll_up(term, dest.start_row, count); |
12502 | 3042 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3043 |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3044 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, dest.start_row); |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3045 term->tl_dirty_row_end = MIN(term->tl_dirty_row_end, dest.end_row); |
13878
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
3046 set_dirty_snapshot(term); |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3047 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3048 // Note sure if the scrolling will work correctly, let's do a complete |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3049 // redraw later. |
12502 | 3050 redraw_buf_later(term->tl_buffer, NOT_VALID); |
3051 return 1; | |
3052 } | |
3053 | |
3054 static int | |
3055 handle_movecursor( | |
3056 VTermPos pos, | |
3057 VTermPos oldpos UNUSED, | |
3058 int visible, | |
3059 void *user) | |
3060 { | |
3061 term_T *term = (term_T *)user; | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
3062 win_T *wp = NULL; |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
3063 int did_curwin = FALSE; |
12502 | 3064 |
3065 term->tl_cursor_pos = pos; | |
3066 term->tl_cursor_visible = visible; | |
3067 | |
19542
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
3068 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 3069 { |
3070 if (wp->w_buffer == term->tl_buffer) | |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
3071 position_cursor(wp, &pos); |
12502 | 3072 } |
3073 if (term->tl_buffer == curbuf && !term->tl_normal_mode) | |
3074 update_cursor(term, term->tl_cursor_visible); | |
3075 | |
3076 return 1; | |
3077 } | |
3078 | |
3079 static int | |
3080 handle_settermprop( | |
3081 VTermProp prop, | |
3082 VTermValue *value, | |
3083 void *user) | |
3084 { | |
3085 term_T *term = (term_T *)user; | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3086 char_u *strval = NULL; |
12502 | 3087 |
3088 switch (prop) | |
3089 { | |
3090 case VTERM_PROP_TITLE: | |
27257
68c33419fdc6
patch 8.2.4157: terminal test fails because Windows sets the title
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
3091 if (disable_vterm_title_for_testing) |
68c33419fdc6
patch 8.2.4157: terminal test fails because Windows sets the title
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
3092 break; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3093 strval = vim_strnsave((char_u *)value->string.str, |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20617
diff
changeset
|
3094 value->string.len); |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3095 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3096 break; |
12502 | 3097 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
|
3098 // 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
|
3099 // displayed |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3100 if (*skipwhite(strval) == NUL) |
12502 | 3101 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
|
3102 // 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
|
3103 else if (term->tl_arg0_cmd != NULL |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3104 && STRNCMP(term->tl_arg0_cmd, strval, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3105 (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
|
3106 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
|
3107 // Empty corrupted data of winpty |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3108 else if (STRNCMP(" - ", strval, 4) == 0) |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
3109 term->tl_title = NULL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3110 #ifdef MSWIN |
12502 | 3111 else if (!enc_utf8 && enc_codepage > 0) |
3112 { | |
3113 WCHAR *ret = NULL; | |
3114 int length = 0; | |
3115 | |
3116 MultiByteToWideChar_alloc(CP_UTF8, 0, | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3117 (char*)value->string.str, |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3118 (int)value->string.len, &ret, &length); |
12502 | 3119 if (ret != NULL) |
3120 { | |
3121 WideCharToMultiByte_alloc(enc_codepage, 0, | |
3122 ret, length, (char**)&term->tl_title, | |
3123 &length, 0, 0); | |
3124 vim_free(ret); | |
3125 } | |
3126 } | |
3127 #endif | |
3128 else | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3129 { |
20508
357dea6b9fde
patch 8.2.0808: not enough testing for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20500
diff
changeset
|
3130 term->tl_title = strval; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3131 strval = NULL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3132 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3133 VIM_CLEAR(term->tl_status_text); |
12502 | 3134 if (term == curbuf->b_term) |
3135 maketitle(); | |
3136 break; | |
3137 | |
3138 case VTERM_PROP_CURSORVISIBLE: | |
3139 term->tl_cursor_visible = value->boolean; | |
3140 may_toggle_cursor(term); | |
3141 out_flush(); | |
3142 break; | |
3143 | |
3144 case VTERM_PROP_CURSORBLINK: | |
3145 term->tl_cursor_blink = value->boolean; | |
3146 may_set_cursor_props(term); | |
3147 break; | |
3148 | |
3149 case VTERM_PROP_CURSORSHAPE: | |
3150 term->tl_cursor_shape = value->number; | |
3151 may_set_cursor_props(term); | |
3152 break; | |
3153 | |
3154 case VTERM_PROP_CURSORCOLOR: | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3155 strval = vim_strnsave((char_u *)value->string.str, |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20617
diff
changeset
|
3156 value->string.len); |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3157 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3158 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3159 cursor_color_copy(&term->tl_cursor_color, strval); |
12502 | 3160 may_set_cursor_props(term); |
3161 break; | |
3162 | |
3163 case VTERM_PROP_ALTSCREEN: | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3164 // TODO: do anything else? |
12502 | 3165 term->tl_using_altscreen = value->boolean; |
3166 break; | |
3167 | |
3168 default: | |
3169 break; | |
3170 } | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3171 vim_free(strval); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3172 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3173 // Always return 1, otherwise vterm doesn't store the value internally. |
12502 | 3174 return 1; |
3175 } | |
3176 | |
3177 /* | |
3178 * The job running in the terminal resized the terminal. | |
3179 */ | |
3180 static int | |
3181 handle_resize(int rows, int cols, void *user) | |
3182 { | |
3183 term_T *term = (term_T *)user; | |
3184 win_T *wp; | |
3185 | |
3186 term->tl_rows = rows; | |
3187 term->tl_cols = cols; | |
3188 if (term->tl_vterm_size_changed) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3189 // Size was set by vterm_set_size(), don't set the window size. |
12502 | 3190 term->tl_vterm_size_changed = FALSE; |
3191 else | |
3192 { | |
3193 FOR_ALL_WINDOWS(wp) | |
3194 { | |
3195 if (wp->w_buffer == term->tl_buffer) | |
3196 { | |
3197 win_setheight_win(rows, wp); | |
3198 win_setwidth_win(cols, wp); | |
3199 } | |
3200 } | |
3201 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3202 } | |
3203 return 1; | |
3204 } | |
3205 | |
3206 /* | |
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
|
3207 * 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
|
3208 * 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
|
3209 * "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
|
3210 * "update_buffer" is TRUE when the buffer should be updated. |
12502 | 3211 */ |
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
|
3212 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
|
3213 limit_scrollback(term_T *term, garray_T *gap, int update_buffer) |
12502 | 3214 { |
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
|
3215 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
|
3216 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
3217 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
|
3218 int i; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3219 |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3220 curbuf = term->tl_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3221 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
|
3222 { |
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
|
3223 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
|
3224 if (update_buffer) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
3225 ml_delete(1); |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3226 } |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3227 curbuf = curwin->w_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3228 |
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
|
3229 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
|
3230 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
|
3231 (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
|
3232 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
|
3233 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
|
3234 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
|
3235 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3236 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3237 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3238 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3239 * 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
|
3240 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3241 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
|
3242 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
|
3243 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3244 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
|
3245 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
|
3246 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
|
3247 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3248 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
|
3249 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3250 // 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
|
3251 // 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
|
3252 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
|
3253 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
|
3254 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3255 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
|
3256 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3257 // 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
|
3258 // 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
|
3259 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
|
3260 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
|
3261 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
|
3262 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3263 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3264 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
|
3265 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3266 if (ga_grow(gap, 1) == OK) |
12502 | 3267 { |
3268 cellattr_T *p = NULL; | |
3269 int len = 0; | |
3270 int i; | |
3271 int c; | |
3272 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
|
3273 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
|
3274 char_u *text; |
12502 | 3275 sb_line_T *line; |
3276 garray_T ga; | |
3277 cellattr_T fill_attr = term->tl_default_color; | |
3278 | |
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
|
3279 // do not store empty cells at the end |
12502 | 3280 for (i = 0; i < cols; ++i) |
3281 if (cells[i].chars[0] != 0) | |
3282 len = i + 1; | |
3283 else | |
3284 cell2cellattr(&cells[i], &fill_attr); | |
3285 | |
3286 ga_init2(&ga, 1, 100); | |
3287 if (len > 0) | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3288 p = ALLOC_MULT(cellattr_T, len); |
12502 | 3289 if (p != NULL) |
3290 { | |
3291 for (col = 0; col < len; col += cells[col].width) | |
3292 { | |
3293 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | |
3294 { | |
3295 ga.ga_len = 0; | |
3296 break; | |
3297 } | |
3298 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i) | |
3299 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
3300 (char_u *)ga.ga_data + ga.ga_len); | |
3301 cell2cellattr(&cells[col], &p[col]); | |
3302 } | |
3303 } | |
3304 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
|
3305 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3306 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
|
3307 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
|
3308 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
|
3309 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
|
3310 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
|
3311 } |
12502 | 3312 else |
3313 { | |
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
|
3314 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
|
3315 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
|
3316 *(text + text_len) = NUL; |
12502 | 3317 } |
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
|
3318 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
|
3319 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
|
3320 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3321 line = (sb_line_T *)gap->ga_data + gap->ga_len; |
12502 | 3322 line->sb_cols = len; |
3323 line->sb_cells = p; | |
3324 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
|
3325 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
|
3326 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3327 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
|
3328 ++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
|
3329 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
|
3330 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3331 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
|
3332 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3333 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
|
3334 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
|
3335 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3336 ++gap->ga_len; |
12502 | 3337 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3338 return 0; // ignored |
12502 | 3339 } |
3340 | |
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
|
3341 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3342 * 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
|
3343 * 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
|
3344 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3345 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
|
3346 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
|
3347 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3348 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
|
3349 |
16026
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3350 if (term->tl_scrollback_postponed.ga_len == 0) |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3351 return; |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3352 ch_log(NULL, "Moving postponed scrollback to scrollback"); |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3353 |
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
|
3354 // 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
|
3355 // 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
|
3356 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
|
3357 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3358 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
|
3359 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3360 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
|
3361 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
|
3362 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
|
3363 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3364 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
|
3365 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
|
3366 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
|
3367 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3368 text = 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
|
3369 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
|
3370 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
|
3371 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
|
3372 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
|
3373 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3374 line = (sb_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
|
3375 + 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
|
3376 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
|
3377 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
|
3378 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
|
3379 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
|
3380 ++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
|
3381 ++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
|
3382 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3383 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3384 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
|
3385 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
|
3386 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3387 |
12502 | 3388 static VTermScreenCallbacks screen_callbacks = { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3389 handle_damage, // damage |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3390 handle_moverect, // moverect |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3391 handle_movecursor, // movecursor |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3392 handle_settermprop, // settermprop |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3393 NULL, // bell |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3394 handle_resize, // resize |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3395 handle_pushline, // sb_pushline |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3396 NULL // sb_popline |
12502 | 3397 }; |
3398 | |
3399 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3400 * 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
|
3401 * 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
|
3402 * 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
|
3403 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3404 static int |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3405 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
|
3406 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3407 // Unless in Terminal-Normal mode: clear the vterm. |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3408 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
|
3409 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3410 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
|
3411 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3412 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
|
3413 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3414 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
|
3415 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3416 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
|
3417 int do_set_w_closing = term->tl_buffer->b_nwindows == 0; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3418 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3419 win_T *pwin = NULL; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3420 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3421 // If this was a terminal in a popup window, go back to the |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3422 // previous window. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3423 if (popup_is_popup(curwin) && curbuf == term->tl_buffer) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3424 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3425 pwin = curwin; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3426 if (win_valid(prevwin)) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3427 win_enter(prevwin, FALSE); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3428 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3429 else |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3430 #endif |
18402
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3431 // If this is the last normal window: exit Vim. |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3432 if (term->tl_buffer->b_nwindows > 0 && only_one_window()) |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3433 { |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3434 exarg_T ea; |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3435 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3436 CLEAR_FIELD(ea); |
18402
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3437 ex_quit(&ea); |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3438 return TRUE; |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3439 } |
527b7084c556
patch 8.1.2195: Vim does not exit when the terminal window is last window
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
3440 |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3441 // ++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
|
3442 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
|
3443 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
|
3444 // Avoid closing the window if we temporarily use it. |
17133
2a9a5e69fb3e
patch 8.1.1566: error message when terminal closes in another tab
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
3445 if (curwin == aucmd_win) |
2a9a5e69fb3e
patch 8.1.1566: error message when terminal closes in another tab
Bram Moolenaar <Bram@vim.org>
parents:
16912
diff
changeset
|
3446 do_set_w_closing = TRUE; |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3447 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
|
3448 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
|
3449 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
|
3450 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
|
3451 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
|
3452 aucmd_restbuf(&aco); |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3453 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3454 if (pwin != NULL) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3455 popup_close_with_retval(pwin, 0); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3456 #endif |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3457 return TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3458 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3459 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
|
3460 && 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
|
3461 { |
22864
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3462 char *cmd = term->tl_opencmd == NULL |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3463 ? "botright sbuf %d" |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3464 : (char *)term->tl_opencmd; |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3465 size_t len = strlen(cmd) + 50; |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3466 char *buf = alloc(len); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3467 |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3468 if (buf != NULL) |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3469 { |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3470 ch_log(NULL, "terminal job finished, opening window"); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3471 vim_snprintf(buf, len, cmd, fnum); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3472 do_cmdline_cmd((char_u *)buf); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3473 vim_free(buf); |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3474 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3475 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3476 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3477 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
|
3478 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3479 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3480 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
|
3481 return FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3482 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3483 |
19275
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3484 #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3485 /* |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3486 * If the current window is a terminal in a popup window and the job has |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3487 * finished, close the popup window and to back to the previous window. |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3488 * Otherwise return FAIL. |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3489 */ |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3490 int |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3491 may_close_term_popup(void) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3492 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3493 if (popup_is_popup(curwin) && curbuf->b_term != NULL |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3494 && !term_job_running(curbuf->b_term)) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3495 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3496 win_T *pwin = curwin; |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3497 |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3498 if (win_valid(prevwin)) |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3499 win_enter(prevwin, FALSE); |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3500 popup_close_with_retval(pwin, 0); |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3501 return OK; |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3502 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3503 return FAIL; |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3504 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3505 #endif |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3506 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3507 /* |
26217
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3508 * Called when a channel is going to be closed, before invoking the close |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3509 * callback. |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3510 */ |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3511 void |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3512 term_channel_closing(channel_T *ch) |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3513 { |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3514 term_T *term; |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3515 |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3516 for (term = first_term; term != NULL; term = term->tl_next) |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3517 if (term->tl_job == ch->ch_job && !term->tl_channel_closed) |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3518 term->tl_channel_closing = TRUE; |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3519 } |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3520 |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3521 /* |
12502 | 3522 * Called when a channel has been closed. |
3523 * If this was a channel for a terminal window then finish it up. | |
3524 */ | |
3525 void | |
3526 term_channel_closed(channel_T *ch) | |
3527 { | |
3528 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
|
3529 term_T *next_term; |
12502 | 3530 int did_one = FALSE; |
3531 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3532 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
|
3533 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3534 next_term = term->tl_next; |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
3535 if (term->tl_job == ch->ch_job && !term->tl_channel_closed) |
12502 | 3536 { |
3537 term->tl_channel_closed = TRUE; | |
3538 did_one = TRUE; | |
3539 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3540 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
|
3541 VIM_CLEAR(term->tl_status_text); |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3542 #ifdef MSWIN |
13862
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3543 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
|
3544 { |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3545 fclose(term->tl_out_fd); |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3546 term->tl_out_fd = NULL; |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3547 } |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3548 #endif |
12502 | 3549 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3550 if (updating_screen) |
12502 | 3551 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3552 // Cannot open or close windows now. Can happen when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3553 // 'lazyredraw' is set. |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3554 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
|
3555 continue; |
12502 | 3556 } |
3557 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3558 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
|
3559 next_term = first_term; |
12502 | 3560 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3561 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3562 |
12502 | 3563 if (did_one) |
3564 { | |
3565 redraw_statuslines(); | |
3566 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3567 // Need to break out of vgetc(). |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20555
diff
changeset
|
3568 ins_char_typebuf(K_IGNORE, 0); |
12502 | 3569 typebuf_was_filled = TRUE; |
3570 | |
3571 term = curbuf->b_term; | |
3572 if (term != NULL) | |
3573 { | |
3574 if (term->tl_job == ch->ch_job) | |
3575 maketitle(); | |
3576 update_cursor(term, term->tl_cursor_visible); | |
3577 } | |
3578 } | |
3579 } | |
3580 | |
3581 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3582 * 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
|
3583 * 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
|
3584 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3585 void |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3586 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
|
3587 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3588 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
|
3589 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
|
3590 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3591 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
|
3592 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3593 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
|
3594 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
|
3595 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3596 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
|
3597 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
|
3598 // 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
|
3599 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
|
3600 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3601 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3602 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3603 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3604 /* |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3605 * 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
|
3606 * 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
|
3607 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3608 static void |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3609 term_line2screenline( |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3610 term_T *term, |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3611 win_T *wp, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3612 VTermScreen *screen, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3613 VTermPos *pos, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3614 int max_col) |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3615 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3616 int 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
|
3617 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3618 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
|
3619 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3620 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
|
3621 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
|
3622 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3623 if (vterm_screen_get_cell(screen, *pos, &cell) == 0) |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3624 CLEAR_FIELD(cell); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3625 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3626 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
|
3627 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
|
3628 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3629 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
|
3630 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
|
3631 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
|
3632 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3633 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3634 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3635 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
|
3636 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3637 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
|
3638 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3639 // composing chars |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3640 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
|
3641 && 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
|
3642 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3643 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
|
3644 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
|
3645 break; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3646 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3647 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
|
3648 && 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
|
3649 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3650 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
|
3651 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
|
3652 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3653 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3654 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3655 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
|
3656 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
|
3657 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3658 } |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3659 #ifdef MSWIN |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3660 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
|
3661 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3662 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
|
3663 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
|
3664 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3665 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
|
3666 (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
|
3667 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3668 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
|
3669 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
|
3670 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
|
3671 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3672 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3673 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
|
3674 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3675 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3676 else |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3677 // This will only store the lower byte of "c". |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3678 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
|
3679 } |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3680 ScreenAttrs[off] = cell2attr(term, wp, &cell.attrs, &cell.fg, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3681 &cell.bg); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3682 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3683 ++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
|
3684 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3685 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
|
3686 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3687 // don't set the second byte to NUL for a DBCS encoding, it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3688 // has been set above |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3689 if (enc_utf8) |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3690 { |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3691 ScreenLinesUC[off] = NUL; |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3692 ScreenLines[off] = NUL; |
22832
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3693 } |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3694 else if (!has_mbyte) |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3695 { |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3696 // Can't show a double-width character with a single-byte |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3697 // 'encoding', just use a space. |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3698 ScreenLines[off] = ' '; |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3699 ScreenAttrs[off] = ScreenAttrs[off - 1]; |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3700 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3701 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3702 ++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
|
3703 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3704 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3705 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3706 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3707 |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3708 #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
|
3709 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
|
3710 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
|
3711 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3712 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
|
3713 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
|
3714 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3715 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
|
3716 return; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3717 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
|
3718 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3719 // Scroll up to make more room for terminal lines if needed. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3720 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
|
3721 && (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
|
3722 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3723 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
|
3724 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3725 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
|
3726 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
|
3727 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
|
3728 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
|
3729 --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
|
3730 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3731 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3732 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
|
3733 && 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
|
3734 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3735 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
|
3736 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3737 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
|
3738 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3739 term_line2screenline(term, NULL, screen, &pos, max_col); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3740 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3741 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3742 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
|
3743 |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3744 screen_line(term->tl_toprow + pos.row, 0, pos.col, Columns, 0); |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3745 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3746 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3747 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
|
3748 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
|
3749 } |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3750 #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
|
3751 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3752 /* |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3753 * 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
|
3754 * Returns FALSE when there is no terminal running in this window or it is in |
12502 | 3755 * Terminal-Normal mode. |
3756 */ | |
3757 int | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3758 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
|
3759 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3760 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
|
3761 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3762 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
|
3763 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3764 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3765 /* |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3766 * 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
|
3767 */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3768 void |
12502 | 3769 term_update_window(win_T *wp) |
3770 { | |
3771 term_T *term = wp->w_buffer->b_term; | |
3772 VTerm *vterm; | |
3773 VTermScreen *screen; | |
3774 VTermState *state; | |
3775 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
|
3776 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
|
3777 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
|
3778 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
|
3779 win_T *twp; |
12502 | 3780 |
3781 vterm = term->tl_vterm; | |
3782 screen = vterm_obtain_screen(vterm); | |
3783 state = vterm_obtain_state(vterm); | |
3784 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3785 // We use NOT_VALID on a resize or scroll, redraw everything then. With |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3786 // SOME_VALID only redraw what was marked dirty. |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3787 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
|
3788 { |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3789 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
|
3790 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
|
3791 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3792 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
|
3793 && term->tl_postponed_scroll < term->tl_rows / 3) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3794 // Scrolling is usually faster than redrawing, when there are only |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3795 // a few lines to scroll. |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3796 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
|
3797 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
|
3798 } |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3799 |
12502 | 3800 /* |
3801 * 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
|
3802 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size. |
12502 | 3803 */ |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3804 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
|
3805 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3806 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
|
3807 newcols = 99999; |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3808 for (twp = firstwin; ; twp = twp->w_next) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3809 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3810 // Always use curwin, it may be a popup window. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3811 win_T *wwp = twp == NULL ? curwin : twp; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3812 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3813 // When more than one window shows the same terminal, use the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3814 // smallest size. |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3815 if (wwp->w_buffer == term->tl_buffer) |
12502 | 3816 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3817 newrows = MIN(newrows, wwp->w_height); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3818 newcols = MIN(newcols, wwp->w_width); |
12502 | 3819 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3820 if (twp == NULL) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3821 break; |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3822 } |
18162
9c3347b21b89
patch 8.1.2076: crash when trying to put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3823 if (newrows == 99999 || newcols == 99999) |
9c3347b21b89
patch 8.1.2076: crash when trying to put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
18139
diff
changeset
|
3824 return; // safety exit |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3825 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
|
3826 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
|
3827 |
24006
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3828 // If no cell is visible there is no point in resizing. Also, vterm can't |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3829 // handle a zero height. |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3830 if (newrows == 0 || newcols == 0) |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3831 return; |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3832 |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3833 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
|
3834 { |
12502 | 3835 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
|
3836 vterm_set_size(vterm, newrows, newcols); |
12502 | 3837 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
|
3838 newrows); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3839 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
|
3840 |
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
|
3841 // 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
|
3842 // 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
|
3843 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
|
3844 may_move_terminal_to_buffer(term, FALSE); |
12502 | 3845 } |
3846 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3847 // The cursor may have been moved when resizing. |
12502 | 3848 vterm_state_get_cursorpos(state, &pos); |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
3849 position_cursor(wp, &pos); |
12502 | 3850 |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3851 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
|
3852 && pos.row < wp->w_height; ++pos.row) |
12502 | 3853 { |
3854 if (pos.row < term->tl_rows) | |
3855 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3856 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
|
3857 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3858 term_line2screenline(term, wp, screen, &pos, max_col); |
12502 | 3859 } |
3860 else | |
3861 pos.col = 0; | |
3862 | |
13458
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3863 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
|
3864 #ifdef FEAT_MENU |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3865 + winbar_height(wp) |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3866 #endif |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3867 , wp->w_wincol, pos.col, wp->w_width, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3868 #ifdef FEAT_PROP_POPUP |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3869 popup_is_popup(wp) ? SLF_POPUP : |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3870 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3871 0); |
12502 | 3872 } |
26544
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3873 } |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3874 |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3875 /* |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3876 * Called after updating all windows: may reset dirty rows. |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3877 */ |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3878 void |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3879 term_did_update_window(win_T *wp) |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3880 { |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3881 term_T *term = wp->w_buffer->b_term; |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3882 |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3883 if (term != NULL && term->tl_vterm != NULL && !term->tl_normal_mode |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3884 && wp->w_redr_type == 0) |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3885 { |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3886 term->tl_dirty_row_start = MAX_ROW; |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3887 term->tl_dirty_row_end = 0; |
30abd8e55ee5
patch 8.2.3801: if a terminal shows in two windows, only one is redrawn
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3888 } |
12502 | 3889 } |
3890 | |
3891 /* | |
3892 * Return TRUE if "wp" is a terminal window where the job has finished. | |
3893 */ | |
3894 int | |
3895 term_is_finished(buf_T *buf) | |
3896 { | |
3897 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL; | |
3898 } | |
3899 | |
3900 /* | |
3901 * Return TRUE if "wp" is a terminal window where the job has finished or we | |
3902 * are in Terminal-Normal mode, thus we show the buffer contents. | |
3903 */ | |
3904 int | |
3905 term_show_buffer(buf_T *buf) | |
3906 { | |
3907 term_T *term = buf->b_term; | |
3908 | |
3909 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode); | |
3910 } | |
3911 | |
3912 /* | |
3913 * The current buffer is going to be changed. If there is terminal | |
3914 * highlighting remove it now. | |
3915 */ | |
3916 void | |
3917 term_change_in_curbuf(void) | |
3918 { | |
3919 term_T *term = curbuf->b_term; | |
3920 | |
3921 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) | |
3922 { | |
3923 free_scrollback(term); | |
3924 redraw_buf_later(term->tl_buffer, NOT_VALID); | |
3925 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3926 // The buffer is now like a normal buffer, it cannot be easily |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3927 // abandoned when changed. |
12502 | 3928 set_string_option_direct((char_u *)"buftype", -1, |
3929 (char_u *)"", OPT_FREE|OPT_LOCAL, 0); | |
3930 } | |
3931 } | |
3932 | |
3933 /* | |
3934 * Get the screen attribute for a position in the buffer. | |
3935 * Use a negative "col" to get the filler background color. | |
3936 */ | |
3937 int | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3938 term_get_attr(win_T *wp, linenr_T lnum, int col) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3939 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3940 buf_T *buf = wp->w_buffer; |
12502 | 3941 term_T *term = buf->b_term; |
3942 sb_line_T *line; | |
3943 cellattr_T *cellattr; | |
3944 | |
3945 if (lnum > term->tl_scrollback.ga_len) | |
3946 cellattr = &term->tl_default_color; | |
3947 else | |
3948 { | |
3949 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1; | |
3950 if (col < 0 || col >= line->sb_cols) | |
3951 cellattr = &line->sb_fill_attr; | |
3952 else | |
3953 cellattr = line->sb_cells + col; | |
3954 } | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3955 return cell2attr(term, wp, &cellattr->attrs, &cellattr->fg, &cellattr->bg); |
12502 | 3956 } |
3957 | |
3958 /* | |
3959 * 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
|
3960 * This is compatible with xterm. |
12502 | 3961 */ |
3962 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
|
3963 cterm_color2vterm(int nr, VTermColor *rgb) |
12502 | 3964 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3965 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->index); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3966 if (rgb->index == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3967 rgb->type = VTERM_COLOR_RGB; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3968 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3969 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3970 rgb->type = VTERM_COLOR_INDEXED; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3971 --rgb->index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
3972 } |
12502 | 3973 } |
3974 | |
3975 /* | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3976 * Initialize vterm color from the synID. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3977 * Returns TRUE if color is set to "fg" and "bg". |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3978 * Otherwise returns FALSE. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3979 */ |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3980 static int |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3981 get_vterm_color_from_synid(int id, VTermColor *fg, VTermColor *bg) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3982 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3983 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3984 // Use the actual color for the GUI and when 'termguicolors' is set. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3985 if (0 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3986 # ifdef FEAT_GUI |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3987 || gui.in_use |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3988 # endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3989 # ifdef FEAT_TERMGUICOLORS |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3990 || p_tgc |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3991 # ifdef FEAT_VTP |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3992 // Finally get INVALCOLOR on this execution path |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3993 || (!p_tgc && t_colors >= 256) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3994 # endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3995 # endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3996 ) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3997 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3998 guicolor_T fg_rgb = INVALCOLOR; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3999 guicolor_T bg_rgb = INVALCOLOR; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4000 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4001 if (id > 0) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4002 syn_id2colors(id, &fg_rgb, &bg_rgb); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4003 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4004 if (fg_rgb != INVALCOLOR) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4005 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4006 long_u rgb = GUI_MCH_GET_RGB(fg_rgb); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4007 fg->red = (unsigned)(rgb >> 16); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4008 fg->green = (unsigned)(rgb >> 8) & 255; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4009 fg->blue = (unsigned)rgb & 255; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4010 fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4011 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4012 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4013 fg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4014 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4015 if (bg_rgb != INVALCOLOR) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4016 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4017 long_u rgb = GUI_MCH_GET_RGB(bg_rgb); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4018 bg->red = (unsigned)(rgb >> 16); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4019 bg->green = (unsigned)(rgb >> 8) & 255; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4020 bg->blue = (unsigned)rgb & 255; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4021 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4022 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4023 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4024 bg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4025 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4026 return TRUE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4027 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4028 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4029 #endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4030 if (t_colors >= 16) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4031 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4032 int cterm_fg = -1; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4033 int cterm_bg = -1; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4034 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4035 if (id > 0) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4036 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4037 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4038 if (cterm_fg >= 0) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4039 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4040 cterm_color2vterm(cterm_fg, fg); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4041 fg->type |= VTERM_COLOR_DEFAULT_FG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4042 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4043 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4044 fg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4045 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4046 if (cterm_bg >= 0) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4047 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4048 cterm_color2vterm(cterm_bg, bg); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4049 bg->type |= VTERM_COLOR_DEFAULT_BG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4050 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4051 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4052 bg->type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4053 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4054 return TRUE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4055 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4056 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4057 return FALSE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4058 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4059 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4060 void |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4061 term_reset_wincolor(win_T *wp) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4062 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4063 wp->w_term_wincolor.fg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4064 wp->w_term_wincolor.bg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4065 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4066 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4067 /* |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4068 * Cache the color of 'wincolor'. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4069 */ |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4070 void |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4071 term_update_wincolor(win_T *wp) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4072 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4073 int id = 0; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4074 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4075 if (*wp->w_p_wcr != NUL) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4076 id = syn_name2id(wp->w_p_wcr); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4077 if (id == 0 || !get_vterm_color_from_synid(id, &wp->w_term_wincolor.fg, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4078 &wp->w_term_wincolor.bg)) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4079 term_reset_wincolor(wp); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4080 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4081 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4082 /* |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4083 * Called when option 'termguicolors' was set, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4084 * or when any highlight is changed. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4085 */ |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4086 void |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4087 term_update_wincolor_all() |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4088 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4089 win_T *wp = NULL; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4090 int did_curwin = FALSE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4091 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4092 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4093 term_update_wincolor(wp); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4094 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4095 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4096 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4097 * Initialize term->tl_default_color from the environment. |
12502 | 4098 */ |
4099 static void | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4100 init_default_colors(term_T *term) |
12502 | 4101 { |
4102 VTermColor *fg, *bg; | |
4103 int fgval, bgval; | |
4104 int id; | |
4105 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4106 CLEAR_FIELD(term->tl_default_color.attrs); |
12502 | 4107 term->tl_default_color.width = 1; |
4108 fg = &term->tl_default_color.fg; | |
4109 bg = &term->tl_default_color.bg; | |
4110 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4111 // Vterm uses a default black background. Set it to white when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4112 // 'background' is "light". |
12502 | 4113 if (*p_bg == 'l') |
4114 { | |
4115 fgval = 0; | |
4116 bgval = 255; | |
4117 } | |
4118 else | |
4119 { | |
4120 fgval = 255; | |
4121 bgval = 0; | |
4122 } | |
4123 fg->red = fg->green = fg->blue = fgval; | |
4124 bg->red = bg->green = bg->blue = bgval; | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4125 fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4126 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG; |
12502 | 4127 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4128 // The highlight group overrules the defaults. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4129 id = term_get_highlight_id(term, NULL); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4130 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4131 if (!get_vterm_color_from_synid(id, fg, bg)) |
12502 | 4132 { |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4133 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
12502 | 4134 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
|
4135 #endif |
12502 | 4136 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4137 // In an MS-Windows console we know the normal colors. |
12502 | 4138 if (cterm_normal_fg_color > 0) |
4139 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
4140 cterm_color2vterm(cterm_normal_fg_color - 1, fg); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4141 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4142 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4143 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4144 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4145 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4146 tmp = fg->red; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4147 fg->red = fg->blue; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4148 fg->blue = tmp; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4149 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4150 # endif |
12502 | 4151 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4152 # 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
|
4153 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4154 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
|
4155 # 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
|
4156 |
12502 | 4157 if (cterm_normal_bg_color > 0) |
4158 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
4159 cterm_color2vterm(cterm_normal_bg_color - 1, bg); |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4160 # if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4161 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4162 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4163 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4164 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4165 tmp = fg->red; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4166 fg->red = fg->blue; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4167 fg->blue = tmp; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4168 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4169 # endif |
12502 | 4170 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4171 # 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
|
4172 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4173 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
|
4174 # endif |
12502 | 4175 } |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4176 } |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4177 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4178 #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
|
4179 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4180 * 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
|
4181 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4182 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
|
4183 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
|
4184 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4185 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
|
4186 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
|
4187 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4188 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
|
4189 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4190 VTermColor color; |
16283
1298cb5c1f72
patch 8.1.1146: in MS-Windows console colors in a terminal window are wrong
Bram Moolenaar <Bram@vim.org>
parents:
16253
diff
changeset
|
4191 |
26244
288bcbaa48ca
patch 8.2.3653: terminal ANSI colors may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
26217
diff
changeset
|
4192 color.type = VTERM_COLOR_RGB; |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4193 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
|
4194 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
|
4195 color.blue = (unsigned)rgb[index] & 255; |
27885
dd804c17e7e3
patch 8.2.4468: Coverity warns for uninitialized struct member
Bram Moolenaar <Bram@vim.org>
parents:
27257
diff
changeset
|
4196 color.index = 0; |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4197 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
|
4198 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4199 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4200 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4201 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4202 * 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
|
4203 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4204 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
|
4205 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
|
4206 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4207 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
|
4208 long_u rgb[16]; |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4209 listitem_T *li; |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4210 |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4211 for (li = list->lv_first; li != NULL && n < 16; li = li->li_next, n++) |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4212 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4213 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
|
4214 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
|
4215 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4216 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
|
4217 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
|
4218 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
|
4219 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4220 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
|
4221 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
|
4222 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
|
4223 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4224 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
|
4225 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4226 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4227 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
|
4228 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
|
4229 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4230 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
|
4231 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4232 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
|
4233 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4234 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4235 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4236 * 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
|
4237 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4238 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
|
4239 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
|
4240 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4241 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
|
4242 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4243 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
|
4244 && (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
|
4245 || var->di_tv.vval.v_list == NULL |
19241
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4246 || var->di_tv.vval.v_list->lv_first == &range_list_item |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4247 || set_ansi_colors_list(vterm, var->di_tv.vval.v_list) == FAIL)) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
4248 semsg(_(e_invalid_argument_str), "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
|
4249 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4250 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4251 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4252 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4253 * 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
|
4254 * "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
|
4255 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4256 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4257 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
|
4258 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4259 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
|
4260 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
|
4261 int bufnr; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4262 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
|
4263 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
|
4264 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
|
4265 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
|
4266 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4267 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
|
4268 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
|
4269 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4270 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
|
4271 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4272 // buffer is in a window already, go there |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4273 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
|
4274 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4275 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4276 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4277 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4278 CLEAR_FIELD(ea); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4279 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4280 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
|
4281 && 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
|
4282 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4283 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
|
4284 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
|
4285 |
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
|
4286 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
|
4287 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
|
4288 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
|
4289 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
|
4290 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4291 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
|
4292 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
|
4293 else |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4294 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
|
4295 } |
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
|
4296 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
|
4297 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
|
4298 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
|
4299 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
|
4300 { |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4301 ea.cmd = alloc(STRLEN(p) + 12); |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4302 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
|
4303 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4304 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
|
4305 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
|
4306 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
|
4307 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4308 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4309 |
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
|
4310 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
|
4311 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
|
4312 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
|
4313 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4314 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
|
4315 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
|
4316 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
|
4317 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
|
4318 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
|
4319 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
|
4320 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
|
4321 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
|
4322 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4323 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4324 // open in new window, like ":split fname" |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4325 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
|
4326 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
|
4327 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
|
4328 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
|
4329 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
|
4330 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4331 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
|
4332 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4333 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4334 /* |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4335 * Return TRUE if "func" starts with "pat" and "pat" isn't empty. |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4336 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4337 static int |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4338 is_permitted_term_api(char_u *func, char_u *pat) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4339 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4340 return pat != NULL && *pat != NUL && STRNICMP(func, pat, STRLEN(pat)) == 0; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4341 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4342 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4343 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4344 * 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
|
4345 * "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
|
4346 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4347 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4348 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
|
4349 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4350 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
|
4351 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
|
4352 typval_T rettv; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4353 funcexe_T funcexe; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4354 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4355 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
|
4356 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4357 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
|
4358 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4359 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4360 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
|
4361 |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4362 if (!is_permitted_term_api(func, term->tl_api)) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4363 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4364 ch_log(channel, "Unpermitted function: %s", func); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4365 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4366 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4367 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4368 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
|
4369 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
|
4370 argvars[1] = item->li_next->li_tv; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4371 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
4372 funcexe.fe_firstline = 1L; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
4373 funcexe.fe_lastline = 1L; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
4374 funcexe.fe_evaluate = TRUE; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17186
diff
changeset
|
4375 if (call_func(func, -1, &rettv, 2, argvars, &funcexe) == OK) |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4376 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4377 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
|
4378 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
|
4379 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4380 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4381 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
|
4382 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4383 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4384 /* |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4385 * URL decoding (also know as Percent-encoding). |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4386 * |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4387 * Note this function currently is only used for decoding shell's |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4388 * OSC 7 escape sequence which we can assume all bytes are valid |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4389 * UTF-8 bytes. Thus we don't need to deal with invalid UTF-8 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4390 * encoding bytes like 0xfe, 0xff. |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4391 */ |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4392 static size_t |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4393 url_decode(const char *src, const size_t len, char_u *dst) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4394 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4395 size_t i = 0, j = 0; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4396 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4397 while (i < len) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4398 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4399 if (src[i] == '%' && i + 2 < len) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4400 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4401 dst[j] = hexhex2nr((char_u *)&src[i + 1]); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4402 j++; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4403 i += 3; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4404 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4405 else |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4406 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4407 dst[j] = src[i]; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4408 i++; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4409 j++; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4410 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4411 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4412 dst[j] = '\0'; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4413 return j; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4414 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4415 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4416 /* |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4417 * Sync terminal buffer's cwd with shell's pwd with the help of OSC 7. |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4418 * |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4419 * The OSC 7 sequence has the format of |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4420 * "\033]7;file://HOSTNAME/CURRENT/DIR\033\\" |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4421 * and what VTerm provides via VTermStringFragment is |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4422 * "file://HOSTNAME/CURRENT/DIR" |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4423 */ |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4424 static void |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4425 sync_shell_dir(VTermStringFragment *frag) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4426 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4427 int offset = 7; // len of "file://" is 7 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4428 char *pos = (char *)frag->str + offset; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4429 char_u *new_dir; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4430 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4431 // remove HOSTNAME to get PWD |
24612
d957c7bbacf3
patch 8.2.2845: MS-Windows: warning for signed/unsigned comparison
Bram Moolenaar <Bram@vim.org>
parents:
24582
diff
changeset
|
4432 while (*pos != '/' && offset < (int)frag->len) |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4433 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4434 offset += 1; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4435 pos += 1; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4436 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4437 |
24612
d957c7bbacf3
patch 8.2.2845: MS-Windows: warning for signed/unsigned comparison
Bram Moolenaar <Bram@vim.org>
parents:
24582
diff
changeset
|
4438 if (offset >= (int)frag->len) |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4439 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4440 semsg(_(e_failed_to_extract_pwd_from_str_check_your_shell_config), |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4441 frag->str); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4442 return; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4443 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4444 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4445 new_dir = alloc(frag->len - offset + 1); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4446 url_decode(pos, frag->len-offset, new_dir); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4447 changedir_func(new_dir, TRUE, CDSCOPE_WINDOW); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4448 vim_free(new_dir); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4449 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4450 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4451 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4452 * 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
|
4453 * 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
|
4454 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4455 static int |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4456 parse_osc(int command, VTermStringFragment frag, void *user) |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4457 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4458 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
|
4459 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
|
4460 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
|
4461 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
|
4462 : term->tl_job->jv_channel; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4463 garray_T *gap = &term->tl_osc_buf; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4464 |
24268
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4465 // We recognize only OSC 5 1 ; {command} and OSC 7 ; {command} |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4466 if (p_asd && command == 7) |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4467 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4468 sync_shell_dir(&frag); |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4469 return 1; |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4470 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4471 |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4472 if (command != 51) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4473 return 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4474 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4475 // Concatenate what was received until the final piece is found. |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4476 if (ga_grow(gap, (int)frag.len + 1) == FAIL) |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4477 { |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4478 ga_clear(gap); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4479 return 1; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4480 } |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4481 mch_memmove((char *)gap->ga_data + gap->ga_len, frag.str, frag.len); |
20555
eedaa9a30ab4
patch 8.2.0831: compiler warnings for integer sizes
Bram Moolenaar <Bram@vim.org>
parents:
20508
diff
changeset
|
4482 gap->ga_len += (int)frag.len; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4483 if (!frag.final) |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4484 return 1; |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4485 |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4486 ((char *)gap->ga_data)[gap->ga_len] = 0; |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4487 reader.js_buf = gap->ga_data; |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4488 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
|
4489 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
|
4490 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
|
4491 && 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
|
4492 && 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
|
4493 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4494 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
|
4495 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4496 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
|
4497 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
|
4498 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4499 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4500 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
|
4501 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4502 // Make sure an invoked command doesn't delete the buffer (and the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4503 // terminal) under our fingers. |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13700
diff
changeset
|
4504 ++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
|
4505 |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4506 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
|
4507 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
|
4508 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
|
4509 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
|
4510 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
|
4511 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
|
4512 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
|
4513 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4514 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
|
4515 --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
|
4516 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4517 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4518 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4519 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
|
4520 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4521 ga_clear(gap); |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4522 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
|
4523 return 1; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4524 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4525 |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4526 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4527 * Called by libvterm when it cannot recognize a CSI sequence. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4528 * We recognize the window position report. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4529 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4530 static int |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4531 parse_csi( |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4532 const char *leader UNUSED, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4533 const long args[], |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4534 int argcount, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4535 const char *intermed UNUSED, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4536 char command, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4537 void *user) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4538 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4539 term_T *term = (term_T *)user; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4540 char buf[100]; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4541 int len; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4542 int x = 0; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4543 int y = 0; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4544 win_T *wp; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4545 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4546 // We recognize only CSI 13 t |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4547 if (command != 't' || argcount != 1 || args[0] != 13) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4548 return 0; // not handled |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4549 |
16245
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
4550 // When getting the window position is not possible or it fails it results |
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
4551 // in zero/zero. |
16253
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
4552 #if defined(FEAT_GUI) \ |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
4553 || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)) \ |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
4554 || defined(MSWIN) |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4555 (void)ui_get_winpos(&x, &y, (varnumber_T)100); |
16245
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
4556 #endif |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4557 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4558 FOR_ALL_WINDOWS(wp) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4559 if (wp->w_buffer == term->tl_buffer) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4560 break; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4561 if (wp != NULL) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4562 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4563 #ifdef FEAT_GUI |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4564 if (gui.in_use) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4565 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4566 x += wp->w_wincol * gui.char_width; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4567 y += W_WINROW(wp) * gui.char_height; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4568 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4569 else |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4570 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4571 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4572 // We roughly estimate the position of the terminal window inside |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16378
diff
changeset
|
4573 // the Vim window by assuming a 10 x 7 character cell. |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4574 x += wp->w_wincol * 7; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4575 y += W_WINROW(wp) * 10; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4576 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4577 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4578 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4579 len = vim_snprintf(buf, 100, "\x1b[3;%d;%dt", x, y); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4580 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4581 (char_u *)buf, len, NULL); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4582 return 1; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4583 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4584 |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4585 static VTermStateFallbacks state_fallbacks = { |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4586 NULL, // control |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4587 parse_csi, // csi |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4588 parse_osc, // osc |
26270
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4589 NULL, // dcs |
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4590 NULL, // apc |
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4591 NULL, // pm |
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4592 NULL // sos |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4593 }; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4594 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4595 /* |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4596 * 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
|
4597 */ |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4598 static void * |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4599 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
|
4600 { |
26105
fd1cbe72815a
patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
4601 // make sure that the length is not zero |
fd1cbe72815a
patch 8.2.3585: crash when passing float to "term_rows" of term_start()
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
4602 return alloc_clear(size == 0 ? 1L : size); |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4603 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4604 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4605 static void |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4606 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
|
4607 { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4608 vim_free(ptr); |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4609 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4610 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4611 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
|
4612 &vterm_malloc, |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4613 &vterm_memfree |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4614 }; |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4615 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4616 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4617 * 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
|
4618 * 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
|
4619 */ |
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
|
4620 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
|
4621 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
|
4622 { |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4623 VTerm *vterm; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4624 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
|
4625 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
|
4626 VTermValue value; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4627 |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4628 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
|
4629 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
|
4630 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
|
4631 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
|
4632 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4633 // 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
|
4634 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
|
4635 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
|
4636 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
|
4637 { |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4638 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
|
4639 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
|
4640 } |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4641 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4642 vterm_screen_set_callbacks(screen, &screen_callbacks, term); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4643 // TODO: depends on 'encoding'. |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4644 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
|
4645 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4646 init_default_colors(term); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4647 |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4648 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
|
4649 state, |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4650 &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
|
4651 &term->tl_default_color.bg); |
12502 | 4652 |
16656
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4653 if (t_colors < 16) |
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4654 // Less than 16 colors: assume that bold means using a bright color for |
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4655 // the foreground color. |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4656 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
|
4657 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4658 // Required to initialize most things. |
12502 | 4659 vterm_screen_reset(screen, 1 /* hard */); |
4660 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4661 // Allow using alternate screen. |
12502 | 4662 vterm_screen_enable_altscreen(screen, 1); |
4663 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4664 // For unix do not use a blinking cursor. In an xterm this causes the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4665 // cursor to blink if it's blinking in the xterm. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4666 // For Windows we respect the system wide setting. |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
4667 #ifdef MSWIN |
12502 | 4668 if (GetCaretBlinkTime() == INFINITE) |
4669 value.boolean = 0; | |
4670 else | |
4671 value.boolean = 1; | |
4672 #else | |
4673 value.boolean = 0; | |
4674 #endif | |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4675 vterm_state_set_termprop(state, VTERM_PROP_CURSORBLINK, &value); |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4676 vterm_state_set_unrecognised_fallbacks(state, &state_fallbacks, term); |
15249
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4677 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4678 return OK; |
12502 | 4679 } |
4680 | |
4681 /* | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4682 * Called when option 'background' or 'termguicolors' was set, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4683 * or when any highlight is changed. |
24582
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4684 */ |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4685 void |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4686 term_update_colors_all(void) |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4687 { |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4688 term_T *term; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4689 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4690 FOR_ALL_TERMS(term) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4691 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4692 if (term->tl_vterm == NULL) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4693 continue; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4694 init_default_colors(term); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4695 vterm_state_set_default_colors( |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4696 vterm_obtain_state(term->tl_vterm), |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4697 &term->tl_default_color.fg, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4698 &term->tl_default_color.bg); |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4699 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4700 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4701 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4702 /* |
12502 | 4703 * Return the text to show for the buffer name and status. |
4704 */ | |
4705 char_u * | |
4706 term_get_status_text(term_T *term) | |
4707 { | |
4708 if (term->tl_status_text == NULL) | |
4709 { | |
4710 char_u *txt; | |
4711 size_t len; | |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4712 char_u *fname; |
12502 | 4713 |
4714 if (term->tl_normal_mode) | |
4715 { | |
4716 if (term_job_running(term)) | |
4717 txt = (char_u *)_("Terminal"); | |
4718 else | |
4719 txt = (char_u *)_("Terminal-finished"); | |
4720 } | |
4721 else if (term->tl_title != NULL) | |
4722 txt = term->tl_title; | |
4723 else if (term_none_open(term)) | |
4724 txt = (char_u *)_("active"); | |
4725 else if (term_job_running(term)) | |
4726 txt = (char_u *)_("running"); | |
4727 else | |
4728 txt = (char_u *)_("finished"); | |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4729 fname = buf_get_fname(term->tl_buffer); |
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4730 len = 9 + STRLEN(fname) + STRLEN(txt); |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4731 term->tl_status_text = alloc(len); |
12502 | 4732 if (term->tl_status_text != NULL) |
4733 vim_snprintf((char *)term->tl_status_text, len, "%s [%s]", | |
22822
0b4658e030cb
patch 8.2.1959: crash when terminal buffer name is made empty
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
4734 fname, txt); |
12502 | 4735 } |
4736 return term->tl_status_text; | |
4737 } | |
4738 | |
4739 /* | |
26185
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4740 * Clear the cached value of the status text. |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4741 */ |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4742 void |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4743 term_clear_status_text(term_T *term) |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4744 { |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4745 VIM_CLEAR(term->tl_status_text); |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4746 } |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4747 |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4748 /* |
12502 | 4749 * Mark references in jobs of terminals. |
4750 */ | |
4751 int | |
4752 set_ref_in_term(int copyID) | |
4753 { | |
4754 int abort = FALSE; | |
4755 term_T *term; | |
4756 typval_T tv; | |
4757 | |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17133
diff
changeset
|
4758 for (term = first_term; !abort && term != NULL; term = term->tl_next) |
12502 | 4759 if (term->tl_job != NULL) |
4760 { | |
4761 tv.v_type = VAR_JOB; | |
4762 tv.vval.v_job = term->tl_job; | |
4763 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); | |
4764 } | |
4765 return abort; | |
4766 } | |
4767 | |
4768 /* | |
4769 * 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
|
4770 * 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
|
4771 * with "where". |
12502 | 4772 */ |
4773 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
|
4774 term_get_buf(typval_T *argvars, char *where) |
12502 | 4775 { |
4776 buf_T *buf; | |
4777 | |
4778 ++emsg_off; | |
15355
73b153ed5af8
patch 8.1.0685: get_buf_tv() is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
15273
diff
changeset
|
4779 buf = tv_get_buf(&argvars[0], FALSE); |
12502 | 4780 --emsg_off; |
4781 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
|
4782 { |
23029
bc3a083b50cb
patch 8.2.2061: Vim9: E1030 error when using empty string for term_sendkeys()
Bram Moolenaar <Bram@vim.org>
parents:
22886
diff
changeset
|
4783 (void)tv_get_number(&argvars[0]); // issue errmsg if type error |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
4784 ch_log(NULL, "%s: invalid buffer argument", where); |
12502 | 4785 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
|
4786 } |
12502 | 4787 return buf; |
4788 } | |
4789 | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4790 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4791 clear_cell(VTermScreenCell *cell) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4792 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4793 CLEAR_FIELD(*cell); |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4794 cell->fg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_FG; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4795 cell->bg.type = VTERM_COLOR_INVALID | VTERM_COLOR_DEFAULT_BG; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4796 } |
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 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4799 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
|
4800 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4801 int index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4802 |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4803 if (VTERM_COLOR_IS_INDEXED(color)) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4804 index = color->index + 1; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4805 else if (color->type == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4806 // use RGB values |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4807 index = 255; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4808 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4809 // default color |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4810 index = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4811 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
|
4812 (int)color->red, (int)color->green, (int)color->blue, |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4813 index); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4814 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4815 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4816 /* |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4817 * "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
|
4818 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4819 * 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
|
4820 * |{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
|
4821 * {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
|
4822 * 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
|
4823 * skipped. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4824 * {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
|
4825 * 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
|
4826 * {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
|
4827 * {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
|
4828 * {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
|
4829 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4830 * 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
|
4831 * |{characters} |
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 * 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
|
4834 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4835 * 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
|
4836 * @{count} |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4837 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4838 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4839 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
|
4840 { |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4841 buf_T *buf; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4842 term_T *term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4843 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
|
4844 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
|
4845 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
|
4846 stat_T st; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4847 FILE *fd; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4848 VTermPos pos; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4849 VTermScreen *screen; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4850 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
|
4851 VTermState *state; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4852 VTermPos cursor_pos; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4853 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4854 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
|
4855 return; |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4856 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4857 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4858 && (check_for_buffer_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4859 || check_for_string_arg(argvars, 1) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4860 || check_for_opt_dict_arg(argvars, 2) == FAIL)) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4861 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4862 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
4863 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
|
4864 if (buf == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4865 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4866 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
|
4867 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
|
4868 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
4869 emsg(_(e_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
|
4870 return; |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
4871 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4872 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4873 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
|
4874 { |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4875 dict_T *d; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4876 |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4877 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
|
4878 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4879 emsg(_(e_dictionary_required)); |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4880 return; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4881 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4882 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
|
4883 if (d != NULL) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4884 { |
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
|
4885 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
|
4886 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
|
4887 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4888 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4889 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4890 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
|
4891 if (fname == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4892 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4893 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
|
4894 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
4895 semsg(_(e_file_exists_str), fname); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4896 return; |
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 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
|
4900 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4901 semsg(_(e_cant_create_file_str), *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
|
4902 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4903 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4904 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4905 clear_cell(&prev_cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4906 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4907 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
|
4908 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
|
4909 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
|
4910 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4911 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
|
4912 && 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
|
4913 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4914 int repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4915 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
4916 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
|
4917 && 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
|
4918 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4919 VTermScreenCell cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4920 int same_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4921 int same_chars = TRUE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4922 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
|
4923 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
|
4924 && 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
|
4925 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4926 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4927 clear_cell(&cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4928 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4929 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
|
4930 { |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4931 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
|
4932 int pc = prev_cell.chars[i]; |
22687
73688eec32ca
patch 8.2.1892: valgrind warns for using uninitialized access in tests
Bram Moolenaar <Bram@vim.org>
parents:
22448
diff
changeset
|
4933 int should_break = c == NUL || pc == NUL; |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4934 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4935 // For the first character NUL is the same as space. |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4936 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
|
4937 { |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
4938 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
|
4939 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
|
4940 } |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
4941 if (c != pc) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4942 same_chars = FALSE; |
22687
73688eec32ca
patch 8.2.1892: valgrind warns for using uninitialized access in tests
Bram Moolenaar <Bram@vim.org>
parents:
22448
diff
changeset
|
4943 if (should_break) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4944 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4945 } |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4946 same_attr = vtermAttr2hl(&cell.attrs) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4947 == vtermAttr2hl(&prev_cell.attrs) |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4948 && vterm_color_is_equal(&cell.fg, &prev_cell.fg) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4949 && vterm_color_is_equal(&cell.bg, &prev_cell.bg); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4950 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
|
4951 && !is_cursor_pos) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4952 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4953 ++repeat; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4954 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4955 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4956 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4957 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4958 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4959 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4960 repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4961 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
4962 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
|
4963 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4964 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
|
4965 fputs(" ", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4966 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4967 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4968 char_u charbuf[10]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4969 int len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4970 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4971 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
|
4972 && 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
|
4973 { |
13557
4911058c43eb
patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents:
13547
diff
changeset
|
4974 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
|
4975 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
|
4976 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4977 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4978 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4979 // When only the characters differ we don't write anything, the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4980 // following "|", "@" or NL will indicate using the same |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4981 // attributes. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4982 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
|
4983 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4984 if (cell.width == 2) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4985 fputs("*", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4986 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4987 fputs("+", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4988 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4989 if (same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4990 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4991 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4992 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4993 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4994 { |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4995 fprintf(fd, "%d", vtermAttr2hl(&cell.attrs)); |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4996 if (vterm_color_is_equal(&cell.fg, &prev_cell.fg)) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4997 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4998 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
4999 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5000 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5001 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
|
5002 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5003 if (vterm_color_is_equal(&cell.bg, &prev_cell.bg)) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5004 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5005 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5006 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5007 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5008 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
|
5009 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5010 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5011 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5012 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5013 prev_cell = cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5014 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5015 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5016 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5017 ++pos.col; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5018 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5019 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5020 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5021 fputs("\n", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5022 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5023 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5024 fclose(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5025 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5026 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5027 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5028 * 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
|
5029 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5030 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5031 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
|
5032 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5033 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
|
5034 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5035 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5036 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5037 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
|
5038 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5039 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
|
5040 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5041 *(((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
|
5042 ++gap->ga_len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5043 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5044 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5045 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5046 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5047 clear_cellattr(cellattr_T *cell) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5048 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5049 CLEAR_FIELD(*cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5050 cell->fg.type = VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5051 cell->bg.type = VTERM_COLOR_DEFAULT_BG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5052 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5053 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5054 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5055 * 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
|
5056 * 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
|
5057 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5058 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
|
5059 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
|
5060 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5061 int c; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5062 garray_T ga_text; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5063 garray_T ga_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5064 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
|
5065 int attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5066 cellattr_T cell; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5067 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
|
5068 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
|
5069 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
|
5070 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
|
5071 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5072 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
|
5073 ga_init2(&ga_cell, sizeof(cellattr_T), 90); |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5074 clear_cellattr(&cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5075 clear_cellattr(&empty_cell); |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5076 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
|
5077 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
|
5078 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5079 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5080 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5081 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5082 if (c == EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5083 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
|
5084 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
|
5085 { |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
5086 // 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
|
5087 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
|
5088 } |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
5089 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
|
5090 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5091 // End of a line: append it to the buffer. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5092 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
|
5093 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
|
5094 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
|
5095 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5096 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
|
5097 + 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
|
5098 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5099 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
|
5100 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
|
5101 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
|
5102 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
|
5103 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
|
5104 ++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
|
5105 ga_init(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5106 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5107 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
|
5108 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
|
5109 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
|
5110 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5111 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5112 ga_clear(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5113 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
|
5114 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5115 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5116 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5117 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
|
5118 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5119 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
|
5120 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5121 if (c == '>') |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5122 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5123 if (cursor_pos->row != -1) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5124 dump_is_corrupt(&ga_text); // duplicate cursor |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5125 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
|
5126 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
|
5127 } |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5128 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5129 // normal character(s) followed by "+", "*", "|", "@" or NL |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5130 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5131 if (c != EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5132 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
|
5133 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5134 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5135 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
|
5136 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
|
5137 || c == EOF || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5138 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5139 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
|
5140 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5141 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5142 // save the character for repeating it |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5143 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5144 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
|
5145 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
|
5146 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
|
5147 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5148 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
|
5149 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5150 // use all attributes from previous cell |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5151 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5152 else if (c == '+' || c == '*') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5153 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5154 int is_bg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5155 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5156 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
|
5157 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5158 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5159 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5160 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5161 // use same attr as previous cell |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5162 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5163 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5164 else if (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5165 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5166 // get the decimal attribute |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5167 attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5168 while (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5169 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5170 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
|
5171 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5172 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5173 hl2vtermAttr(attr, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5174 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5175 // is_bg == 0: fg, is_bg == 1: bg |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5176 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
|
5177 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5178 if (c == '&') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5179 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5180 // use same color as previous cell |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5181 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5182 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5183 else if (c == '#') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5184 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5185 int red, green, blue, index = 0, type; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5186 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5187 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5188 red = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5189 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5190 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
|
5191 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5192 green = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5193 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5194 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
|
5195 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5196 blue = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5197 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5198 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
|
5199 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5200 if (!isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5201 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
|
5202 while (isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5203 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5204 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
|
5205 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5206 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5207 if (index == 0 || index == 255) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5208 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5209 type = VTERM_COLOR_RGB; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5210 if (index == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5211 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5212 if (is_bg) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5213 type |= VTERM_COLOR_DEFAULT_BG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5214 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5215 type |= VTERM_COLOR_DEFAULT_FG; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5216 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5217 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5218 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5219 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5220 type = VTERM_COLOR_INDEXED; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5221 index -= 1; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5222 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5223 if (is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5224 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5225 cell.bg.type = type; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5226 cell.bg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5227 cell.bg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5228 cell.bg.blue = blue; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5229 cell.bg.index = index; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5230 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5231 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5232 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5233 cell.fg.type = type; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5234 cell.fg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5235 cell.fg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5236 cell.fg.blue = blue; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5237 cell.fg.index = index; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5238 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5239 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5240 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5241 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
|
5242 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5243 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5244 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5245 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
|
5246 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5247 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5248 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
|
5249 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5250 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
|
5251 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5252 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
|
5253 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5254 else if (c == '@') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5255 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5256 if (prev_char == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5257 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
|
5258 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5259 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5260 int count = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5261 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5262 // repeat previous character, get the count |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5263 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5264 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5265 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5266 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5267 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5268 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
|
5269 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5270 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5271 while (count-- > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5272 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5273 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
|
5274 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
|
5275 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5276 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5277 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5278 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5279 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5280 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
|
5281 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5282 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5283 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5284 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5285 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
|
5286 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5287 // trailing characters after last NL |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5288 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
|
5289 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
|
5290 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
|
5291 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
|
5292 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5293 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5294 ga_clear(&ga_text); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
5295 ga_clear(&ga_cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5296 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5297 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5298 return max_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5299 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5300 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5301 /* |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5302 * 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
|
5303 * "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
|
5304 */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5305 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
|
5306 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
|
5307 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5308 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
|
5309 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
|
5310 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
|
5311 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
|
5312 int i; |
13630
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5313 size_t off; |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5314 |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5315 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
|
5316 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
|
5317 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
|
5318 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5319 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
|
5320 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
|
5321 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5322 // enough room, don't use the full window width |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5323 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
|
5324 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5325 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
|
5326 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5327 // full name doesn't fit, use only the tail |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5328 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
|
5329 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
|
5330 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5331 // skip characters until the name fits |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5332 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
|
5333 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5334 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
|
5335 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
|
5336 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5337 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5338 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
|
5339 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
|
5340 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
|
5341 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5342 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
|
5343 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
|
5344 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
|
5345 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
|
5346 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
|
5347 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
|
5348 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5349 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
|
5350 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5351 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5352 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5353 * 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
|
5354 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5355 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5356 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
|
5357 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5358 jobopt_T opt; |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5359 buf_T *buf = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5360 char_u buf1[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5361 char_u buf2[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5362 char_u *fname1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5363 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
|
5364 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
|
5365 FILE *fd1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5366 FILE *fd2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5367 char_u *textline = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5368 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5369 // 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
|
5370 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
|
5371 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
|
5372 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
|
5373 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
|
5374 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5375 emsg(_(e_invalid_argument)); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5376 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5377 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5378 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
|
5379 if (fd1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5380 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5381 semsg(_(e_cant_read_file_str), fname1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5382 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5383 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5384 if (do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5385 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5386 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
|
5387 if (fd2 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5388 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5389 fclose(fd1); |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5390 semsg(_(e_cant_read_file_str), fname2); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5391 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5392 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5393 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5394 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5395 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
|
5396 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
|
5397 && 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
|
5398 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
|
5399 + 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
|
5400 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
|
5401 |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5402 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
|
5403 { |
13505
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
5404 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
|
5405 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
5406 fname_tofree = alloc(len); |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5407 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
|
5408 { |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5409 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
|
5410 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
|
5411 } |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5412 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5413 |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5414 if (opt.jo_bufnr_buf != NULL) |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5415 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5416 win_T *wp = buf_jump_open_win(opt.jo_bufnr_buf); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5417 |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5418 // With "bufnr" argument: enter the window with this buffer and make it |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5419 // empty. |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5420 if (wp == NULL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5421 semsg(_(e_invalid_argument_str), "bufnr"); |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5422 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5423 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5424 buf = curbuf; |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5425 while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5426 ml_delete((linenr_T)1); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18170
diff
changeset
|
5427 free_scrollback(curbuf->b_term); |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5428 redraw_later(NOT_VALID); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5429 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5430 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5431 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5432 // Create a new terminal window. |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5433 buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB); |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5434 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5435 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
|
5436 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5437 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5438 linenr_T bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5439 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5440 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
|
5441 int width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5442 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
|
5443 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
|
5444 VTermPos cursor_pos2; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5445 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
5446 init_default_colors(term); |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
5447 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5448 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
|
5449 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5450 // 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
|
5451 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
|
5452 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5453 // position the cursor |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5454 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
|
5455 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5456 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
|
5457 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
|
5458 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5459 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5460 // Delete the empty line that was in the empty buffer. |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5461 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5462 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5463 // For term_dumpload() we are done here. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5464 if (!do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5465 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5466 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5467 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
|
5468 |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5469 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
|
5470 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5471 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5472 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
|
5473 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
|
5474 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
|
5475 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5476 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
|
5477 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
|
5478 goto theend; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5479 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
|
5480 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
|
5481 textline[width] = NUL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5482 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5483 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
|
5484 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
|
5485 if (width2 > width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5486 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5487 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5488 textline = alloc(width2 + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5489 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5490 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5491 width = width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5492 textline[width] = NUL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5493 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5494 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
|
5495 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5496 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
|
5497 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5498 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
|
5499 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5500 // bottom part has fewer rows, fill with "-" |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5501 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
|
5502 textline[i] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5503 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5504 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5505 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5506 char_u *line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5507 char_u *line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5508 char_u *p1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5509 char_u *p2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5510 int col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5511 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
|
5512 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
|
5513 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
|
5514 ->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5515 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5516 // Make a copy, getting the second line will invalidate it. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5517 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
|
5518 if (line1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5519 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5520 p1 = line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5521 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5522 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
|
5523 p2 = line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5524 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
|
5525 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5526 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
|
5527 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
|
5528 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5529 textline[col] = ' '; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5530 if (len1 != len2 || STRNCMP(p1, p2, len1) != 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5531 // text differs |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5532 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
|
5533 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
|
5534 && 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
|
5535 && (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
|
5536 || cursor_pos1.col != cursor_pos2.col)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5537 // cursor in first but not in second |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5538 textline[col] = '>'; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5539 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
|
5540 && 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
|
5541 && (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
|
5542 || cursor_pos1.col != cursor_pos2.col)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5543 // cursor in second but not in first |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5544 textline[col] = '<'; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5545 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
|
5546 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5547 if ((cellattr1 + col)->width |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5548 != (cellattr2 + col)->width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5549 textline[col] = 'w'; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5550 else if (!vterm_color_is_equal(&(cellattr1 + col)->fg, |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5551 &(cellattr2 + col)->fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5552 textline[col] = 'f'; |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5553 else if (!vterm_color_is_equal(&(cellattr1 + col)->bg, |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5554 &(cellattr2 + col)->bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5555 textline[col] = 'b'; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
5556 else if (vtermAttr2hl(&(cellattr1 + col)->attrs) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
5557 != vtermAttr2hl(&((cellattr2 + col)->attrs))) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5558 textline[col] = 'a'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5559 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5560 p1 += len1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5561 p2 += len2; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5562 // TODO: handle different width |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5563 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5564 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5565 while (col < width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5566 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5567 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
|
5568 textline[col] = '?'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5569 else if (*p1 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5570 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5571 textline[col] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5572 p2 += utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5573 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5574 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5575 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5576 textline[col] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5577 p1 += utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5578 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5579 ++col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5580 } |
15828
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5581 |
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5582 vim_free(line1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5583 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5584 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
|
5585 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
|
5586 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
|
5587 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5588 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5589 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5590 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
|
5591 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5592 // bottom part has more rows, fill with "+" |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5593 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
|
5594 textline[i] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5595 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
|
5596 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
|
5597 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
|
5598 ++lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5599 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5600 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5601 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5602 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
|
5603 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5604 // looks better without wrapping |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5605 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
|
5606 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5607 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5608 theend: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5609 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
|
5610 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
|
5611 fclose(fd1); |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5612 if (fd2 != NULL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5613 fclose(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5614 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5615 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5616 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5617 * 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
|
5618 * bottom files. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5619 * 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
|
5620 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5621 int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5622 term_swap_diff() |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5623 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5624 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
|
5625 linenr_T line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5626 linenr_T top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5627 linenr_T bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5628 linenr_T bot_start; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5629 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5630 char_u *p; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5631 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
|
5632 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5633 if (term == NULL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5634 || !term_is_finished(curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5635 || 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
|
5636 || 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
|
5637 return FAIL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5638 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5639 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
|
5640 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
|
5641 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
|
5642 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
|
5643 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
|
5644 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5645 // 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
|
5646 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
|
5647 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5648 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
|
5649 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5650 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5651 ml_append(bot_start, p, 0, FALSE); |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5652 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5653 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5654 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5655 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5656 // 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
|
5657 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
|
5658 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5659 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
|
5660 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5661 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5662 ml_delete(bot_start + lnum); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5663 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
|
5664 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5665 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5666 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5667 // 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
|
5668 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
|
5669 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
|
5670 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
|
5671 ml_append(line_count - top_rows - 1, p, 0, FALSE); |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5672 ml_delete(bot_rows + 1); |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5673 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
|
5674 |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5675 // 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
|
5676 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
|
5677 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
|
5678 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5679 ml_delete(line_count - top_rows); |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5680 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
|
5681 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
|
5682 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5683 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
|
5684 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5685 // rows counts are equal, can swap cell properties |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5686 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
|
5687 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5688 sb_line_T temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5689 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5690 temp = *(sb_line + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5691 *(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
|
5692 *(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
|
5693 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5694 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5695 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5696 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5697 size_t size = sizeof(sb_line_T) * term->tl_scrollback.ga_len; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5698 sb_line_T *temp = alloc(size); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5699 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5700 // need to copy cell properties into temp memory |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5701 if (temp != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5702 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5703 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
|
5704 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
|
5705 temp + bot_start, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5706 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
|
5707 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
|
5708 temp + top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5709 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
|
5710 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
|
5711 + line_count - top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5712 temp, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5713 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
|
5714 vim_free(temp); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5715 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5716 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5717 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5718 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
|
5719 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
|
5720 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5721 update_screen(NOT_VALID); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5722 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5723 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5724 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5725 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5726 * "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
|
5727 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5728 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5729 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
|
5730 { |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5731 if (in_vim9script() |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5732 && (check_for_string_arg(argvars, 0) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5733 || check_for_string_arg(argvars, 1) == FAIL |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5734 || check_for_opt_dict_arg(argvars, 2) == FAIL)) |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5735 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5736 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5737 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
|
5738 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5739 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5740 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5741 * "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
|
5742 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5743 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5744 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
|
5745 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5746 if (in_vim9script() |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5747 && (check_for_string_arg(argvars, 0) == FAIL |
25759
ea0820d05257
patch 8.2.3415: Vim9: not all function argument types are properly checked
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
5748 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5749 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5750 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5751 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
|
5752 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5753 |
12502 | 5754 /* |
5755 * "term_getaltscreen(buf)" function | |
5756 */ | |
5757 void | |
5758 f_term_getaltscreen(typval_T *argvars, typval_T *rettv) | |
5759 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5760 buf_T *buf; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5761 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5762 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5763 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5764 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5765 buf = term_get_buf(argvars, "term_getaltscreen()"); |
12502 | 5766 if (buf == NULL) |
5767 return; | |
5768 rettv->vval.v_number = buf->b_term->tl_using_altscreen; | |
5769 } | |
5770 | |
5771 /* | |
5772 * "term_getattr(attr, name)" function | |
5773 */ | |
5774 void | |
5775 f_term_getattr(typval_T *argvars, typval_T *rettv) | |
5776 { | |
5777 int attr; | |
5778 size_t i; | |
5779 char_u *name; | |
5780 | |
5781 static struct { | |
5782 char *name; | |
5783 int attr; | |
5784 } attrs[] = { | |
5785 {"bold", HL_BOLD}, | |
5786 {"italic", HL_ITALIC}, | |
5787 {"underline", HL_UNDERLINE}, | |
5788 {"strike", HL_STRIKETHROUGH}, | |
5789 {"reverse", HL_INVERSE}, | |
5790 }; | |
5791 | |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5792 if (in_vim9script() |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5793 && (check_for_number_arg(argvars, 0) == FAIL |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5794 || check_for_string_arg(argvars, 1) == FAIL)) |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5795 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5796 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5797 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
|
5798 name = tv_get_string_chk(&argvars[1]); |
12502 | 5799 if (name == NULL) |
5800 return; | |
5801 | |
18033
049a7481d737
patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17702
diff
changeset
|
5802 if (attr > HL_ALL) |
049a7481d737
patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17702
diff
changeset
|
5803 attr = syn_attr2attr(attr); |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24739
diff
changeset
|
5804 for (i = 0; i < ARRAY_LENGTH(attrs); ++i) |
12502 | 5805 if (STRCMP(name, attrs[i].name) == 0) |
5806 { | |
5807 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0; | |
5808 break; | |
5809 } | |
5810 } | |
5811 | |
5812 /* | |
5813 * "term_getcursor(buf)" function | |
5814 */ | |
5815 void | |
5816 f_term_getcursor(typval_T *argvars, typval_T *rettv) | |
5817 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5818 buf_T *buf; |
12502 | 5819 term_T *term; |
5820 list_T *l; | |
5821 dict_T *d; | |
5822 | |
5823 if (rettv_list_alloc(rettv) == FAIL) | |
5824 return; | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5825 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5826 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5827 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5828 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5829 buf = term_get_buf(argvars, "term_getcursor()"); |
12502 | 5830 if (buf == NULL) |
5831 return; | |
5832 term = buf->b_term; | |
5833 | |
5834 l = rettv->vval.v_list; | |
5835 list_append_number(l, term->tl_cursor_pos.row + 1); | |
5836 list_append_number(l, term->tl_cursor_pos.col + 1); | |
5837 | |
5838 d = dict_alloc(); | |
5839 if (d != NULL) | |
5840 { | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
5841 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
|
5842 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
|
5843 ? !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
|
5844 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
|
5845 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color)); |
12502 | 5846 list_append_dict(l, d); |
5847 } | |
5848 } | |
5849 | |
5850 /* | |
5851 * "term_getjob(buf)" function | |
5852 */ | |
5853 void | |
5854 f_term_getjob(typval_T *argvars, typval_T *rettv) | |
5855 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5856 buf_T *buf; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5857 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5858 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5859 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5860 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5861 buf = term_get_buf(argvars, "term_getjob()"); |
15217
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5862 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
|
5863 { |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5864 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
|
5865 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
|
5866 return; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5867 } |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
5868 |
12502 | 5869 rettv->v_type = VAR_JOB; |
5870 rettv->vval.v_job = buf->b_term->tl_job; | |
5871 if (rettv->vval.v_job != NULL) | |
5872 ++rettv->vval.v_job->jv_refcount; | |
5873 } | |
5874 | |
5875 static int | |
5876 get_row_number(typval_T *tv, term_T *term) | |
5877 { | |
5878 if (tv->v_type == VAR_STRING | |
5879 && tv->vval.v_string != NULL | |
5880 && STRCMP(tv->vval.v_string, ".") == 0) | |
5881 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
|
5882 return (int)tv_get_number(tv) - 1; |
12502 | 5883 } |
5884 | |
5885 /* | |
5886 * "term_getline(buf, row)" function | |
5887 */ | |
5888 void | |
5889 f_term_getline(typval_T *argvars, typval_T *rettv) | |
5890 { | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5891 buf_T *buf; |
12502 | 5892 term_T *term; |
5893 int row; | |
5894 | |
5895 rettv->v_type = VAR_STRING; | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5896 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5897 if (in_vim9script() |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5898 && (check_for_buffer_arg(argvars, 0) == FAIL |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5899 || check_for_lnum_arg(argvars, 1) == FAIL)) |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5900 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5901 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5902 buf = term_get_buf(argvars, "term_getline()"); |
12502 | 5903 if (buf == NULL) |
5904 return; | |
5905 term = buf->b_term; | |
5906 row = get_row_number(&argvars[1], term); | |
5907 | |
5908 if (term->tl_vterm == NULL) | |
5909 { | |
5910 linenr_T lnum = row + term->tl_scrollback_scrolled + 1; | |
5911 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5912 // vterm is finished, get the text from the buffer |
12502 | 5913 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count) |
5914 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE)); | |
5915 } | |
5916 else | |
5917 { | |
5918 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm); | |
5919 VTermRect rect; | |
5920 int len; | |
5921 char_u *p; | |
5922 | |
5923 if (row < 0 || row >= term->tl_rows) | |
5924 return; | |
5925 len = term->tl_cols * MB_MAXBYTES + 1; | |
5926 p = alloc(len); | |
5927 if (p == NULL) | |
5928 return; | |
5929 rettv->vval.v_string = p; | |
5930 | |
5931 rect.start_col = 0; | |
5932 rect.end_col = term->tl_cols; | |
5933 rect.start_row = row; | |
5934 rect.end_row = row + 1; | |
5935 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL; | |
5936 } | |
5937 } | |
5938 | |
5939 /* | |
5940 * "term_getscrolled(buf)" function | |
5941 */ | |
5942 void | |
5943 f_term_getscrolled(typval_T *argvars, typval_T *rettv) | |
5944 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5945 buf_T *buf; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5946 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5947 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5948 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5949 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5950 buf = term_get_buf(argvars, "term_getscrolled()"); |
12502 | 5951 if (buf == NULL) |
5952 return; | |
5953 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled; | |
5954 } | |
5955 | |
5956 /* | |
5957 * "term_getsize(buf)" function | |
5958 */ | |
5959 void | |
5960 f_term_getsize(typval_T *argvars, typval_T *rettv) | |
5961 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5962 buf_T *buf; |
12502 | 5963 list_T *l; |
5964 | |
5965 if (rettv_list_alloc(rettv) == FAIL) | |
5966 return; | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5967 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5968 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5969 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5970 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
5971 buf = term_get_buf(argvars, "term_getsize()"); |
12502 | 5972 if (buf == NULL) |
5973 return; | |
5974 | |
5975 l = rettv->vval.v_list; | |
5976 list_append_number(l, buf->b_term->tl_rows); | |
5977 list_append_number(l, buf->b_term->tl_cols); | |
5978 } | |
5979 | |
5980 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5981 * "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
|
5982 */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5983 void |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5984 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
|
5985 { |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5986 buf_T *buf; |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5987 term_T *term; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5988 varnumber_T rows, cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
5989 |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5990 if (in_vim9script() |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5991 && (check_for_buffer_arg(argvars, 0) == FAIL |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5992 || check_for_number_arg(argvars, 1) == FAIL |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5993 || check_for_number_arg(argvars, 2) == FAIL)) |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5994 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5995 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
5996 buf = term_get_buf(argvars, "term_setsize()"); |
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
|
5997 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
|
5998 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
5999 emsg(_(e_not_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
|
6000 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
|
6001 } |
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
|
6002 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
|
6003 return; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6004 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
|
6005 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
|
6006 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
|
6007 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
|
6008 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
|
6009 vterm_set_size(term->tl_vterm, rows, cols); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6010 // handle_resize() will resize the windows |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6011 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6012 // Get and remember the size we ended up with. Update the pty. |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6013 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
|
6014 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
|
6015 } |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6016 |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6017 /* |
12502 | 6018 * "term_getstatus(buf)" function |
6019 */ | |
6020 void | |
6021 f_term_getstatus(typval_T *argvars, typval_T *rettv) | |
6022 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6023 buf_T *buf; |
12502 | 6024 term_T *term; |
6025 char_u val[100]; | |
6026 | |
6027 rettv->v_type = VAR_STRING; | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6028 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6029 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6030 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6031 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6032 buf = term_get_buf(argvars, "term_getstatus()"); |
12502 | 6033 if (buf == NULL) |
6034 return; | |
6035 term = buf->b_term; | |
6036 | |
6037 if (term_job_running(term)) | |
6038 STRCPY(val, "running"); | |
6039 else | |
6040 STRCPY(val, "finished"); | |
6041 if (term->tl_normal_mode) | |
6042 STRCAT(val, ",normal"); | |
6043 rettv->vval.v_string = vim_strsave(val); | |
6044 } | |
6045 | |
6046 /* | |
6047 * "term_gettitle(buf)" function | |
6048 */ | |
6049 void | |
6050 f_term_gettitle(typval_T *argvars, typval_T *rettv) | |
6051 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6052 buf_T *buf; |
12502 | 6053 |
6054 rettv->v_type = VAR_STRING; | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6055 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6056 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6057 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6058 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6059 buf = term_get_buf(argvars, "term_gettitle()"); |
12502 | 6060 if (buf == NULL) |
6061 return; | |
6062 | |
6063 if (buf->b_term->tl_title != NULL) | |
6064 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title); | |
6065 } | |
6066 | |
6067 /* | |
6068 * "term_gettty(buf)" function | |
6069 */ | |
6070 void | |
6071 f_term_gettty(typval_T *argvars, typval_T *rettv) | |
6072 { | |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6073 buf_T *buf; |
13864
de8455bd2d05
patch 8.0.1803: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13862
diff
changeset
|
6074 char_u *p = NULL; |
12502 | 6075 int num = 0; |
6076 | |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6077 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6078 && (check_for_buffer_arg(argvars, 0) == FAIL |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6079 || check_for_opt_bool_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6080 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6081 |
12502 | 6082 rettv->v_type = VAR_STRING; |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6083 buf = term_get_buf(argvars, "term_gettty()"); |
12502 | 6084 if (buf == NULL) |
6085 return; | |
6086 if (argvars[1].v_type != VAR_UNKNOWN) | |
22155
de47cb7b41e6
patch 8.2.1627: Vim9: cannot pass "true" to submatch/term_gettty/term_start
Bram Moolenaar <Bram@vim.org>
parents:
22097
diff
changeset
|
6087 num = tv_get_bool(&argvars[1]); |
12502 | 6088 |
6089 switch (num) | |
6090 { | |
6091 case 0: | |
6092 if (buf->b_term->tl_job != NULL) | |
6093 p = buf->b_term->tl_job->jv_tty_out; | |
6094 break; | |
6095 case 1: | |
6096 if (buf->b_term->tl_job != NULL) | |
6097 p = buf->b_term->tl_job->jv_tty_in; | |
6098 break; | |
6099 default: | |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
6100 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[1])); |
12502 | 6101 return; |
6102 } | |
6103 if (p != NULL) | |
6104 rettv->vval.v_string = vim_strsave(p); | |
6105 } | |
6106 | |
6107 /* | |
6108 * "term_list()" function | |
6109 */ | |
6110 void | |
6111 f_term_list(typval_T *argvars UNUSED, typval_T *rettv) | |
6112 { | |
6113 term_T *tp; | |
6114 list_T *l; | |
6115 | |
6116 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL) | |
6117 return; | |
6118 | |
6119 l = rettv->vval.v_list; | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
6120 FOR_ALL_TERMS(tp) |
24582
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
6121 if (tp->tl_buffer != NULL) |
12502 | 6122 if (list_append_number(l, |
6123 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL) | |
6124 return; | |
6125 } | |
6126 | |
6127 /* | |
6128 * "term_scrape(buf, row)" function | |
6129 */ | |
6130 void | |
6131 f_term_scrape(typval_T *argvars, typval_T *rettv) | |
6132 { | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6133 buf_T *buf; |
12502 | 6134 VTermScreen *screen = NULL; |
6135 VTermPos pos; | |
6136 list_T *l; | |
6137 term_T *term; | |
6138 char_u *p; | |
6139 sb_line_T *line; | |
6140 | |
6141 if (rettv_list_alloc(rettv) == FAIL) | |
6142 return; | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6143 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6144 if (in_vim9script() |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6145 && (check_for_buffer_arg(argvars, 0) == FAIL |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6146 || check_for_lnum_arg(argvars, 1) == FAIL)) |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6147 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6148 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6149 buf = term_get_buf(argvars, "term_scrape()"); |
12502 | 6150 if (buf == NULL) |
6151 return; | |
6152 term = buf->b_term; | |
6153 | |
6154 l = rettv->vval.v_list; | |
6155 pos.row = get_row_number(&argvars[1], term); | |
6156 | |
6157 if (term->tl_vterm != NULL) | |
6158 { | |
6159 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
|
6160 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
|
6161 return; |
12502 | 6162 p = NULL; |
6163 line = NULL; | |
6164 } | |
6165 else | |
6166 { | |
6167 linenr_T lnum = pos.row + term->tl_scrollback_scrolled; | |
6168 | |
6169 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len) | |
6170 return; | |
6171 p = ml_get_buf(buf, lnum + 1, FALSE); | |
6172 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | |
6173 } | |
6174 | |
6175 for (pos.col = 0; pos.col < term->tl_cols; ) | |
6176 { | |
6177 dict_T *dcell; | |
6178 int width; | |
6179 VTermScreenCellAttrs attrs; | |
6180 VTermColor fg, bg; | |
6181 char_u rgb[8]; | |
6182 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1]; | |
6183 int off = 0; | |
6184 int i; | |
6185 | |
6186 if (screen == NULL) | |
6187 { | |
6188 cellattr_T *cellattr; | |
6189 int len; | |
6190 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6191 // vterm has finished, get the cell from scrollback |
12502 | 6192 if (pos.col >= line->sb_cols) |
6193 break; | |
6194 cellattr = line->sb_cells + pos.col; | |
6195 width = cellattr->width; | |
6196 attrs = cellattr->attrs; | |
6197 fg = cellattr->fg; | |
6198 bg = cellattr->bg; | |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
6199 len = mb_ptr2len(p); |
12502 | 6200 mch_memmove(mbs, p, len); |
6201 mbs[len] = NUL; | |
6202 p += len; | |
6203 } | |
6204 else | |
6205 { | |
6206 VTermScreenCell cell; | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
6207 |
12502 | 6208 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
6209 break; | |
6210 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | |
6211 { | |
6212 if (cell.chars[i] == 0) | |
6213 break; | |
6214 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off); | |
6215 } | |
6216 mbs[off] = NUL; | |
6217 width = cell.width; | |
6218 attrs = cell.attrs; | |
6219 fg = cell.fg; | |
6220 bg = cell.bg; | |
6221 } | |
6222 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
|
6223 if (dcell == NULL) |
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6224 break; |
12502 | 6225 list_append_dict(l, dcell); |
6226 | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
6227 dict_add_string(dcell, "chars", mbs); |
12502 | 6228 |
6229 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
6230 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
|
6231 dict_add_string(dcell, "fg", rgb); |
12502 | 6232 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", |
6233 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
|
6234 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
|
6235 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
6236 dict_add_number(dcell, "attr", |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
6237 cell2attr(term, NULL, &attrs, &fg, &bg)); |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
6238 dict_add_number(dcell, "width", width); |
12502 | 6239 |
6240 ++pos.col; | |
6241 if (width == 2) | |
6242 ++pos.col; | |
6243 } | |
6244 } | |
6245 | |
6246 /* | |
6247 * "term_sendkeys(buf, keys)" function | |
6248 */ | |
6249 void | |
19633
dd3e5533a7d2
patch 8.2.0373: type of term_sendkeys() is unknown
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
6250 f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED) |
12502 | 6251 { |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6252 buf_T *buf; |
12502 | 6253 char_u *msg; |
6254 term_T *term; | |
6255 | |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6256 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6257 && (check_for_buffer_arg(argvars, 0) == FAIL |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6258 || check_for_string_arg(argvars, 1) == FAIL)) |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6259 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6260 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6261 buf = term_get_buf(argvars, "term_sendkeys()"); |
12502 | 6262 if (buf == NULL) |
6263 return; | |
6264 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
6265 msg = tv_get_string_chk(&argvars[1]); |
12502 | 6266 if (msg == NULL) |
6267 return; | |
6268 term = buf->b_term; | |
6269 if (term->tl_vterm == NULL) | |
6270 return; | |
6271 | |
6272 while (*msg != NUL) | |
6273 { | |
14029
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6274 int c; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6275 |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6276 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
|
6277 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6278 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
|
6279 msg += 3; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6280 } |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6281 else |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6282 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6283 c = PTR2CHAR(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6284 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
|
6285 } |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
6286 send_keys_to_term(term, c, 0, FALSE); |
12502 | 6287 } |
6288 } | |
6289 | |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6290 #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
|
6291 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6292 * "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
|
6293 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6294 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6295 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
|
6296 { |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6297 buf_T *buf; |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6298 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
|
6299 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
|
6300 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
|
6301 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
|
6302 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
|
6303 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
|
6304 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6305 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
|
6306 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6307 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6308 if (in_vim9script() && check_for_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6309 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6310 |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6311 buf = term_get_buf(argvars, "term_getansicolors()"); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6312 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
|
6313 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6314 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
|
6315 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
|
6316 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6317 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6318 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
|
6319 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
|
6320 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
|
6321 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6322 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
|
6323 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
|
6324 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
|
6325 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
|
6326 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6327 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6328 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6329 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6330 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6331 * "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
|
6332 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6333 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6334 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
|
6335 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6336 buf_T *buf; |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6337 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
|
6338 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6339 if (in_vim9script() |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6340 && (check_for_buffer_arg(argvars, 0) == FAIL |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25342
diff
changeset
|
6341 || check_for_list_arg(argvars, 1) == FAIL)) |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6342 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6343 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6344 buf = term_get_buf(argvars, "term_setansicolors()"); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6345 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
|
6346 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6347 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
|
6348 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
|
6349 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6350 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6351 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
|
6352 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
6353 emsg(_(e_list_required)); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6354 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6355 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6356 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6357 if (set_ansi_colors_list(term->tl_vterm, argvars[1].vval.v_list) == FAIL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
6358 emsg(_(e_invalid_argument)); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6359 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6360 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6361 |
12502 | 6362 /* |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6363 * "term_setapi(buf, api)" function |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6364 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6365 void |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6366 f_term_setapi(typval_T *argvars, typval_T *rettv UNUSED) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6367 { |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6368 buf_T *buf; |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6369 term_T *term; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6370 char_u *api; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6371 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6372 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6373 && (check_for_buffer_arg(argvars, 0) == FAIL |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6374 || check_for_string_arg(argvars, 1) == FAIL)) |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6375 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6376 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6377 buf = term_get_buf(argvars, "term_setapi()"); |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6378 if (buf == NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6379 return; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6380 term = buf->b_term; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6381 vim_free(term->tl_api); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6382 api = tv_get_string_chk(&argvars[1]); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6383 if (api != NULL) |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6384 term->tl_api = vim_strsave(api); |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6385 else |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6386 term->tl_api = NULL; |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6387 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6388 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6389 /* |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6390 * "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
|
6391 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6392 void |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6393 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
|
6394 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6395 #if defined(FEAT_SESSION) |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6396 buf_T *buf; |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6397 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
|
6398 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
|
6399 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6400 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6401 && (check_for_buffer_arg(argvars, 0) == FAIL |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6402 || check_for_string_arg(argvars, 1) == FAIL)) |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6403 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6404 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6405 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
|
6406 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
|
6407 return; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6408 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
|
6409 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
|
6410 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
|
6411 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
|
6412 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
|
6413 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6414 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
|
6415 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6416 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6417 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6418 /* |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6419 * "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
|
6420 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6421 void |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6422 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
|
6423 { |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6424 buf_T *buf; |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6425 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
|
6426 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
|
6427 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6428 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6429 && (check_for_buffer_arg(argvars, 0) == FAIL |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6430 || check_for_string_arg(argvars, 1) == FAIL)) |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6431 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6432 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6433 buf = term_get_buf(argvars, "term_setkill()"); |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6434 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
|
6435 return; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6436 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
|
6437 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
|
6438 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
|
6439 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
|
6440 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
|
6441 else |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6442 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
|
6443 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6444 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6445 /* |
12502 | 6446 * "term_start(command, options)" function |
6447 */ | |
6448 void | |
6449 f_term_start(typval_T *argvars, typval_T *rettv) | |
6450 { | |
6451 jobopt_T opt; | |
6452 buf_T *buf; | |
6453 | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6454 if (in_vim9script() |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6455 && (check_for_string_or_list_arg(argvars, 0) == FAIL |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6456 || check_for_opt_dict_arg(argvars, 1) == FAIL)) |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6457 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6458 |
12502 | 6459 init_job_options(&opt); |
6460 if (argvars[1].v_type != VAR_UNKNOWN | |
6461 && get_job_options(&argvars[1], &opt, | |
6462 JO_TIMEOUT_ALL + JO_STOPONEXIT | |
6463 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK | |
6464 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO, | |
6465 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD | |
6466 + 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
|
6467 + JO2_CWD + JO2_ENV + JO2_EOF_CHARS |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
6468 + JO2_NORESTORE + JO2_TERM_KILL + JO2_TERM_HIGHLIGHT |
18170
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6469 + JO2_ANSI_COLORS + JO2_TTY_TYPE + JO2_TERM_API) == FAIL) |
12502 | 6470 return; |
6471 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6472 buf = term_start(&argvars[0], NULL, &opt, 0); |
12502 | 6473 |
6474 if (buf != NULL && buf->b_term != NULL) | |
6475 rettv->vval.v_number = buf->b_fnum; | |
6476 } | |
6477 | |
6478 /* | |
6479 * "term_wait" function | |
6480 */ | |
6481 void | |
6482 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | |
6483 { | |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6484 buf_T *buf; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6485 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6486 if (in_vim9script() |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6487 && (check_for_buffer_arg(argvars, 0) == FAIL |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6488 || check_for_opt_number_arg(argvars, 1) == FAIL)) |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6489 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6490 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6491 buf = term_get_buf(argvars, "term_wait()"); |
12502 | 6492 if (buf == NULL) |
6493 return; | |
6494 if (buf->b_term->tl_job == NULL) | |
6495 { | |
6496 ch_log(NULL, "term_wait(): no job to wait for"); | |
6497 return; | |
6498 } | |
6499 if (buf->b_term->tl_job->jv_channel == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6500 // channel is closed, nothing to do |
12502 | 6501 return; |
6502 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6503 // 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
|
6504 if (!buf->b_term->tl_job->jv_channel->ch_keep_open |
12502 | 6505 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) |
6506 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6507 // The job is dead, keep reading channel I/O until the channel is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6508 // closed. buf->b_term may become NULL if the terminal was closed while |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6509 // waiting. |
12502 | 6510 ch_log(NULL, "term_wait(): waiting for channel to close"); |
6511 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) | |
6512 { | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6513 term_flush_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6514 |
13996
59121ffd7fce
patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
13994
diff
changeset
|
6515 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
|
6516 if (!buf_valid(buf)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6517 // If the terminal is closed when the channel is closed the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6518 // buffer disappears. |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
6519 break; |
26217
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
6520 if (buf->b_term == NULL || buf->b_term->tl_channel_closing) |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
6521 // came here from a close callback, only wait one time |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
6522 break; |
12502 | 6523 } |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6524 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6525 term_flush_messages(); |
12502 | 6526 } |
6527 else | |
6528 { | |
6529 long wait = 10L; | |
6530 | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6531 term_flush_messages(); |
12502 | 6532 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6533 // Wait for some time for any channel I/O. |
12502 | 6534 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
|
6535 wait = tv_get_number(&argvars[1]); |
12502 | 6536 ui_delay(wait, TRUE); |
6537 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6538 // Flushing messages on channels is hopefully sufficient. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6539 // TODO: is there a better way? |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6540 term_flush_messages(); |
12502 | 6541 } |
6542 } | |
6543 | |
6544 /* | |
6545 * Called when a channel has sent all the lines to a terminal. | |
6546 * Send a CTRL-D to mark the end of the text. | |
6547 */ | |
6548 void | |
6549 term_send_eof(channel_T *ch) | |
6550 { | |
6551 term_T *term; | |
6552 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
6553 FOR_ALL_TERMS(term) |
12502 | 6554 if (term->tl_job == ch->ch_job) |
6555 { | |
6556 if (term->tl_eof_chars != NULL) | |
6557 { | |
6558 channel_send(ch, PART_IN, term->tl_eof_chars, | |
6559 (int)STRLEN(term->tl_eof_chars), NULL); | |
6560 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL); | |
6561 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6562 # ifdef MSWIN |
12502 | 6563 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6564 // Default: CTRL-D |
12502 | 6565 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL); |
6566 # endif | |
6567 } | |
6568 } | |
6569 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6570 #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
|
6571 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
|
6572 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
|
6573 { |
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
|
6574 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
|
6575 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6576 #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
|
6577 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6578 # if defined(MSWIN) || defined(PROTO) |
12502 | 6579 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6580 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6581 // 2. MS-Windows implementation. |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6582 #ifdef PROTO |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6583 typedef int COORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6584 typedef int DWORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6585 typedef int HANDLE; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6586 typedef int *DWORD_PTR; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6587 typedef int HPCON; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6588 typedef int HRESULT; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6589 typedef int LPPROC_THREAD_ATTRIBUTE_LIST; |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16354
diff
changeset
|
6590 typedef int SIZE_T; |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6591 typedef int PSIZE_T; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6592 typedef int PVOID; |
18508
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
6593 typedef int BOOL; |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
6594 # define WINAPI |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6595 #endif |
12502 | 6596 |
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
|
6597 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
|
6598 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
|
6599 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
|
6600 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
|
6601 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
|
6602 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
|
6603 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6604 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
|
6605 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
|
6606 { |
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
|
6607 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
|
6608 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
|
6609 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
|
6610 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6611 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
|
6612 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
|
6613 } 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
|
6614 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6615 {"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
|
6616 {"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
|
6617 {"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
|
6618 {"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
|
6619 (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
|
6620 {"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
|
6621 (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
|
6622 {"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
|
6623 (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
|
6624 {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
|
6625 }; |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6626 |
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
|
6627 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
|
6628 { |
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
|
6629 if (verbose) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
6630 emsg(_(e_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
|
6631 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
|
6632 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6633 |
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
|
6634 // 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
|
6635 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
|
6636 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
|
6637 |
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
|
6638 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
|
6639 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
|
6640 && 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
|
6641 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6642 if ((*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
|
6643 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
|
6644 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6645 if (verbose) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
6646 semsg(_(e_could_not_load_library_function_str), 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
|
6647 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
|
6648 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
|
6649 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6650 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6651 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6652 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
|
6653 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6654 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6655 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
|
6656 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
|
6657 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
|
6658 typval_T *argvar, |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
6659 char **argv UNUSED, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6660 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
|
6661 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
|
6662 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6663 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
|
6664 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
|
6665 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
|
6666 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
|
6667 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
|
6668 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
|
6669 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
|
6670 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
|
6671 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
|
6672 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
|
6673 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
|
6674 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
|
6675 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
|
6676 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
|
6677 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
|
6678 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
|
6679 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
|
6680 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
6681 ga_init2(&ga_cmd, sizeof(char*), 20); |
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
6682 ga_init2(&ga_env, sizeof(char*), 20); |
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
|
6683 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6684 if (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
|
6685 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6686 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
|
6687 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6688 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
|
6689 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6690 if (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
|
6691 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
|
6692 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
|
6693 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6694 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
|
6695 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
6696 emsg(_(e_invalid_argument)); |
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
|
6697 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
|
6698 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6699 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6700 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
|
6701 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6702 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
|
6703 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6704 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
|
6705 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6706 // Request by CreateProcessW |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6707 breq = wcslen(cmd_wchar) + 1 + 1; // Addition of NUL by API |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6708 cmd_wchar_copy = ALLOC_MULT(WCHAR, breq); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6709 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
|
6710 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6711 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6712 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
|
6713 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
|
6714 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
|
6715 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
|
6716 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
|
6717 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6718 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
|
6719 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
|
6720 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6721 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
|
6722 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
|
6723 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
|
6724 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
|
6725 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6726 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
|
6727 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
|
6728 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
|
6729 &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
|
6730 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
|
6731 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
|
6732 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6733 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
|
6734 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6735 // Set up pipe inheritance safely: Vista or later. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6736 pInitializeProcThreadAttributeList(NULL, 1, 0, &breq); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6737 term->tl_siex.lpAttributeList = alloc(breq); |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6738 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
|
6739 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
|
6740 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
|
6741 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
|
6742 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
|
6743 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
|
6744 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
|
6745 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
|
6746 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
|
6747 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
|
6748 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6749 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
|
6750 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
|
6751 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
|
6752 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6753 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
|
6754 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
|
6755 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
|
6756 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
|
6757 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6758 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
|
6759 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6760 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
|
6761 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6762 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
|
6763 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6764 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
|
6765 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6766 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
|
6767 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6768 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6769 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
|
6770 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
|
6771 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6772 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
|
6773 EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT |
20179
28d82a342331
patch 8.2.0645: MS-Windows terminal: CTRL-C does not get to child job
Bram Moolenaar <Bram@vim.org>
parents:
20176
diff
changeset
|
6774 | CREATE_SUSPENDED | CREATE_DEFAULT_ERROR_MODE, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6775 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
|
6776 &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
|
6777 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
|
6778 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6779 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
|
6780 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
|
6781 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6782 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
|
6783 (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
|
6784 (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
|
6785 (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
|
6786 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6787 // Write lines with CR instead of NL. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6788 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
|
6789 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6790 // Use to explicitly delete anonymous pipe handle. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6791 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
|
6792 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6793 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
|
6794 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
|
6795 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
|
6796 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6797 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
|
6798 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6799 // Failed, switch the way to terminate process with TerminateProcess. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6800 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
|
6801 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
|
6802 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6803 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6804 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
|
6805 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
|
6806 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6807 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
|
6808 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
|
6809 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
|
6810 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
|
6811 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6812 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
|
6813 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
|
6814 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6815 #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
|
6816 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
|
6817 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
|
6818 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
|
6819 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
|
6820 #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
|
6821 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6822 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
|
6823 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
|
6824 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6825 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
|
6826 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
|
6827 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
|
6828 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
|
6829 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
|
6830 ++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
|
6831 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
|
6832 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6833 // Redirecting stdout and stderr doesn't work at the job level. Instead |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6834 // open the file here and handle it in. opt->jo_io was changed in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6835 // setup_job_options(), use the original flags here. |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6836 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
|
6837 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6838 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
|
6839 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6840 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
|
6841 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
|
6842 if (term->tl_out_fd == NULL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
6843 semsg(_(e_cant_open_file_str), fname); |
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
|
6844 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6845 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6846 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
|
6847 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6848 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
|
6849 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
|
6850 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
|
6851 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
|
6852 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
|
6853 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
|
6854 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
|
6855 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
|
6856 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
|
6857 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6858 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
|
6859 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
|
6860 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6861 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
|
6862 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
|
6863 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
|
6864 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6865 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
|
6866 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6867 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
|
6868 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
|
6869 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6870 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
|
6871 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
|
6872 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
|
6873 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
|
6874 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
|
6875 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
|
6876 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
|
6877 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
|
6878 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
|
6879 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
|
6880 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
|
6881 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
|
6882 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
|
6883 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6884 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6885 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
|
6886 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
|
6887 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6888 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
|
6889 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6890 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
|
6891 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
|
6892 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
|
6893 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6894 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
18033
diff
changeset
|
6895 static void |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6896 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
|
6897 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6898 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
|
6899 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6900 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
|
6901 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
|
6902 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6903 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
|
6904 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
|
6905 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
|
6906 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
|
6907 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6908 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6909 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
|
6910 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
|
6911 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6912 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
|
6913 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6914 |
12502 | 6915 # ifndef PROTO |
6916 | |
6917 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul | |
6918 #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
|
6919 #define WINPTY_MOUSE_MODE_FORCE 2 |
12502 | 6920 |
6921 void* (*winpty_config_new)(UINT64, void*); | |
6922 void* (*winpty_open)(void*, void*); | |
6923 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*); | |
6924 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*); | |
6925 void (*winpty_config_set_mouse_mode)(void*, int); | |
6926 void (*winpty_config_set_initial_size)(void*, int, int); | |
6927 LPCWSTR (*winpty_conin_name)(void*); | |
6928 LPCWSTR (*winpty_conout_name)(void*); | |
6929 LPCWSTR (*winpty_conerr_name)(void*); | |
6930 void (*winpty_free)(void*); | |
6931 void (*winpty_config_free)(void*); | |
6932 void (*winpty_spawn_config_free)(void*); | |
6933 void (*winpty_error_free)(void*); | |
6934 LPCWSTR (*winpty_error_msg)(void*); | |
6935 BOOL (*winpty_set_size)(void*, int, int, void*); | |
6936 HANDLE (*winpty_agent_process)(void*); | |
6937 | |
6938 #define WINPTY_DLL "winpty.dll" | |
6939 | |
6940 static HINSTANCE hWinPtyDLL = NULL; | |
6941 # endif | |
6942 | |
6943 static int | |
6944 dyn_winpty_init(int verbose) | |
6945 { | |
6946 int i; | |
6947 static struct | |
6948 { | |
6949 char *name; | |
6950 FARPROC *ptr; | |
6951 } winpty_entry[] = | |
6952 { | |
6953 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name}, | |
6954 {"winpty_config_free", (FARPROC*)&winpty_config_free}, | |
6955 {"winpty_config_new", (FARPROC*)&winpty_config_new}, | |
6956 {"winpty_config_set_mouse_mode", | |
6957 (FARPROC*)&winpty_config_set_mouse_mode}, | |
6958 {"winpty_config_set_initial_size", | |
6959 (FARPROC*)&winpty_config_set_initial_size}, | |
6960 {"winpty_conin_name", (FARPROC*)&winpty_conin_name}, | |
6961 {"winpty_conout_name", (FARPROC*)&winpty_conout_name}, | |
6962 {"winpty_error_free", (FARPROC*)&winpty_error_free}, | |
6963 {"winpty_free", (FARPROC*)&winpty_free}, | |
6964 {"winpty_open", (FARPROC*)&winpty_open}, | |
6965 {"winpty_spawn", (FARPROC*)&winpty_spawn}, | |
6966 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free}, | |
6967 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new}, | |
6968 {"winpty_error_msg", (FARPROC*)&winpty_error_msg}, | |
6969 {"winpty_set_size", (FARPROC*)&winpty_set_size}, | |
6970 {"winpty_agent_process", (FARPROC*)&winpty_agent_process}, | |
6971 {NULL, NULL} | |
6972 }; | |
6973 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6974 // No need to initialize twice. |
12502 | 6975 if (hWinPtyDLL) |
6976 return OK; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6977 // Load winpty.dll, prefer using the 'winptydll' option, fall back to just |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6978 // winpty.dll. |
12502 | 6979 if (*p_winptydll != NUL) |
6980 hWinPtyDLL = vimLoadLib((char *)p_winptydll); | |
6981 if (!hWinPtyDLL) | |
6982 hWinPtyDLL = vimLoadLib(WINPTY_DLL); | |
6983 if (!hWinPtyDLL) | |
6984 { | |
6985 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
6986 semsg(_(e_could_not_load_library_str_str), |
25342
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
6987 (*p_winptydll != NUL ? p_winptydll : (char_u *)WINPTY_DLL), |
c4298ed56ffa
patch 8.2.3208: dynamic library load error does not mention why it failed
Bram Moolenaar <Bram@vim.org>
parents:
25338
diff
changeset
|
6988 GetWin32Error()); |
12502 | 6989 return FAIL; |
6990 } | |
6991 for (i = 0; winpty_entry[i].name != NULL | |
6992 && winpty_entry[i].ptr != NULL; ++i) | |
6993 { | |
6994 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL, | |
6995 winpty_entry[i].name)) == NULL) | |
6996 { | |
6997 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
6998 semsg(_(e_could_not_load_library_function_str), 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
|
6999 hWinPtyDLL = NULL; |
12502 | 7000 return FAIL; |
7001 } | |
7002 } | |
7003 | |
7004 return OK; | |
7005 } | |
7006 | |
7007 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
|
7008 winpty_term_and_job_init( |
12502 | 7009 term_T *term, |
7010 typval_T *argvar, | |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
7011 char **argv UNUSED, |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7012 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
|
7013 jobopt_T *orig_opt) |
12502 | 7014 { |
7015 WCHAR *cmd_wchar = NULL; | |
7016 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
|
7017 WCHAR *env_wchar = NULL; |
12502 | 7018 channel_T *channel = NULL; |
7019 job_T *job = NULL; | |
7020 DWORD error; | |
7021 HANDLE jo = NULL; | |
7022 HANDLE child_process_handle; | |
7023 HANDLE child_thread_handle; | |
13111
149347fda678
patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents:
13109
diff
changeset
|
7024 void *winpty_err = NULL; |
12502 | 7025 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
|
7026 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
|
7027 char_u *cmd = NULL; |
12502 | 7028 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
7029 ga_init2(&ga_cmd, sizeof(char*), 20); |
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
7030 ga_init2(&ga_env, sizeof(char*), 20); |
12502 | 7031 |
7032 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
|
7033 { |
12502 | 7034 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
|
7035 } |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7036 else if (argvar->v_type == VAR_LIST) |
12502 | 7037 { |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
7038 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
12502 | 7039 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
|
7040 cmd = ga_cmd.ga_data; |
12502 | 7041 } |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7042 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
|
7043 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
7044 emsg(_(e_invalid_argument)); |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7045 goto failed; |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7046 } |
12502 | 7047 |
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
|
7048 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
|
7049 |
12502 | 7050 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
|
7051 ga_clear(&ga_cmd); |
12502 | 7052 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
|
7053 goto failed; |
12502 | 7054 if (opt->jo_cwd != NULL) |
7055 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
|
7056 |
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
|
7057 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
|
7058 env_wchar = ga_env.ga_data; |
12502 | 7059 |
7060 term->tl_winpty_config = winpty_config_new(0, &winpty_err); | |
7061 if (term->tl_winpty_config == NULL) | |
7062 goto failed; | |
7063 | |
7064 winpty_config_set_mouse_mode(term->tl_winpty_config, | |
7065 WINPTY_MOUSE_MODE_FORCE); | |
7066 winpty_config_set_initial_size(term->tl_winpty_config, | |
7067 term->tl_cols, term->tl_rows); | |
7068 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err); | |
7069 if (term->tl_winpty == NULL) | |
7070 goto failed; | |
7071 | |
7072 spawn_config = winpty_spawn_config_new( | |
7073 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN | | |
7074 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN, | |
7075 NULL, | |
7076 cmd_wchar, | |
7077 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
|
7078 env_wchar, |
12502 | 7079 &winpty_err); |
7080 if (spawn_config == NULL) | |
7081 goto failed; | |
7082 | |
7083 channel = add_channel(); | |
7084 if (channel == NULL) | |
7085 goto failed; | |
7086 | |
7087 job = job_alloc(); | |
7088 if (job == NULL) | |
7089 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
|
7090 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
|
7091 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7092 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
|
7093 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7094 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
|
7095 } |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7096 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
|
7097 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7098 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
|
7099 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7100 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
|
7101 } |
12502 | 7102 |
7103 if (opt->jo_set & JO_IN_BUF) | |
7104 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); | |
7105 | |
7106 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle, | |
7107 &child_thread_handle, &error, &winpty_err)) | |
7108 goto failed; | |
7109 | |
7110 channel_set_pipes(channel, | |
7111 (sock_T)CreateFileW( | |
7112 winpty_conin_name(term->tl_winpty), | |
7113 GENERIC_WRITE, 0, NULL, | |
7114 OPEN_EXISTING, 0, NULL), | |
7115 (sock_T)CreateFileW( | |
7116 winpty_conout_name(term->tl_winpty), | |
7117 GENERIC_READ, 0, NULL, | |
7118 OPEN_EXISTING, 0, NULL), | |
7119 (sock_T)CreateFileW( | |
7120 winpty_conerr_name(term->tl_winpty), | |
7121 GENERIC_READ, 0, NULL, | |
7122 OPEN_EXISTING, 0, NULL)); | |
7123 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7124 // Write lines with CR instead of NL. |
12502 | 7125 channel->ch_write_text_mode = TRUE; |
7126 | |
7127 jo = CreateJobObject(NULL, NULL); | |
7128 if (jo == NULL) | |
7129 goto failed; | |
7130 | |
7131 if (!AssignProcessToJobObject(jo, child_process_handle)) | |
7132 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7133 // Failed, switch the way to terminate process with TerminateProcess. |
12502 | 7134 CloseHandle(jo); |
7135 jo = NULL; | |
7136 } | |
7137 | |
7138 winpty_spawn_config_free(spawn_config); | |
7139 vim_free(cmd_wchar); | |
7140 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
|
7141 vim_free(env_wchar); |
12502 | 7142 |
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
|
7143 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
|
7144 goto failed; |
12502 | 7145 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7146 #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
|
7147 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
|
7148 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
|
7149 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7150 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
|
7151 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7152 |
12502 | 7153 channel_set_job(channel, job, opt); |
7154 job_set_options(job, opt); | |
7155 | |
7156 job->jv_channel = channel; | |
7157 job->jv_proc_info.hProcess = child_process_handle; | |
7158 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle); | |
7159 job->jv_job_object = jo; | |
7160 job->jv_status = JOB_STARTED; | |
7161 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
|
7162 (short_u *)winpty_conin_name(term->tl_winpty), NULL); |
12502 | 7163 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
|
7164 (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
|
7165 job->jv_tty_type = vim_strsave((char_u *)"winpty"); |
12502 | 7166 ++job->jv_refcount; |
7167 term->tl_job = job; | |
7168 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7169 // Redirecting stdout and stderr doesn't work at the job level. Instead |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7170 // open the file here and handle it in. opt->jo_io was changed in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7171 // setup_job_options(), use the original flags here. |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7172 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
|
7173 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7174 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
|
7175 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7176 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
|
7177 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
|
7178 if (term->tl_out_fd == NULL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
7179 semsg(_(e_cant_open_file_str), fname); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7180 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7181 |
12502 | 7182 return OK; |
7183 | |
7184 failed: | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7185 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
|
7186 ga_clear(&ga_env); |
12502 | 7187 vim_free(cmd_wchar); |
7188 vim_free(cwd_wchar); | |
7189 if (spawn_config != NULL) | |
7190 winpty_spawn_config_free(spawn_config); | |
7191 if (channel != NULL) | |
7192 channel_clear(channel); | |
7193 if (job != NULL) | |
7194 { | |
7195 job->jv_channel = NULL; | |
7196 job_cleanup(job); | |
7197 } | |
7198 term->tl_job = NULL; | |
7199 if (jo != NULL) | |
7200 CloseHandle(jo); | |
7201 if (term->tl_winpty != NULL) | |
7202 winpty_free(term->tl_winpty); | |
7203 term->tl_winpty = NULL; | |
7204 if (term->tl_winpty_config != NULL) | |
7205 winpty_config_free(term->tl_winpty_config); | |
7206 term->tl_winpty_config = NULL; | |
7207 if (winpty_err != NULL) | |
7208 { | |
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
|
7209 char *msg = (char *)utf16_to_enc( |
12502 | 7210 (short_u *)winpty_error_msg(winpty_err), NULL); |
7211 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
7212 emsg(msg); |
12502 | 7213 winpty_error_free(winpty_err); |
7214 } | |
7215 return FAIL; | |
7216 } | |
7217 | |
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
|
7218 /* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7219 * 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
|
7220 * 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
|
7221 * 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
|
7222 */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7223 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
|
7224 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
|
7225 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
|
7226 typval_T *argvar, |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
7227 char **argv, |
15725
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7228 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
|
7229 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
|
7230 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7231 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
|
7232 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
|
7233 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
|
7234 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7235 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
|
7236 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
|
7237 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7238 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
|
7239 // 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
|
7240 // 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
|
7241 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
|
7242 |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7243 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
|
7244 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
|
7245 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7246 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
|
7247 { |
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
|
7248 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
|
7249 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
|
7250 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
|
7251 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
|
7252 // 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
|
7253 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7254 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
|
7255 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7256 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
|
7257 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
|
7258 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7259 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
|
7260 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7261 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
|
7262 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
|
7263 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
|
7264 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
|
7265 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7266 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7267 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
|
7268 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
|
7269 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7270 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
|
7271 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
|
7272 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7273 // 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
|
7274 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
|
7275 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7276 |
12502 | 7277 static int |
7278 create_pty_only(term_T *term, jobopt_T *options) | |
7279 { | |
7280 HANDLE hPipeIn = INVALID_HANDLE_VALUE; | |
7281 HANDLE hPipeOut = INVALID_HANDLE_VALUE; | |
7282 char in_name[80], out_name[80]; | |
7283 channel_T *channel = NULL; | |
7284 | |
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
|
7285 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
|
7286 return FAIL; |
12502 | 7287 |
7288 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d", | |
7289 GetCurrentProcessId(), | |
7290 curbuf->b_fnum); | |
7291 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND, | |
7292 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
7293 PIPE_UNLIMITED_INSTANCES, | |
7294 0, 0, NMPWAIT_NOWAIT, NULL); | |
7295 if (hPipeIn == INVALID_HANDLE_VALUE) | |
7296 goto failed; | |
7297 | |
7298 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d", | |
7299 GetCurrentProcessId(), | |
7300 curbuf->b_fnum); | |
7301 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND, | |
7302 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
7303 PIPE_UNLIMITED_INSTANCES, | |
7304 0, 0, 0, NULL); | |
7305 if (hPipeOut == INVALID_HANDLE_VALUE) | |
7306 goto failed; | |
7307 | |
7308 ConnectNamedPipe(hPipeIn, NULL); | |
7309 ConnectNamedPipe(hPipeOut, NULL); | |
7310 | |
7311 term->tl_job = job_alloc(); | |
7312 if (term->tl_job == NULL) | |
7313 goto failed; | |
7314 ++term->tl_job->jv_refcount; | |
7315 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7316 // behave like the job is already finished |
12502 | 7317 term->tl_job->jv_status = JOB_FINISHED; |
7318 | |
7319 channel = add_channel(); | |
7320 if (channel == NULL) | |
7321 goto failed; | |
7322 term->tl_job->jv_channel = channel; | |
7323 channel->ch_keep_open = TRUE; | |
7324 channel->ch_named_pipe = TRUE; | |
7325 | |
7326 channel_set_pipes(channel, | |
7327 (sock_T)hPipeIn, | |
7328 (sock_T)hPipeOut, | |
7329 (sock_T)hPipeOut); | |
7330 channel_set_job(channel, term->tl_job, options); | |
7331 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name); | |
7332 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name); | |
7333 | |
7334 return OK; | |
7335 | |
7336 failed: | |
7337 if (hPipeIn != NULL) | |
7338 CloseHandle(hPipeIn); | |
7339 if (hPipeOut != NULL) | |
7340 CloseHandle(hPipeOut); | |
7341 return FAIL; | |
7342 } | |
7343 | |
7344 /* | |
7345 * Free the terminal emulator part of "term". | |
7346 */ | |
7347 static void | |
7348 term_free_vterm(term_T *term) | |
7349 { | |
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
|
7350 term_free_conpty(term); |
12502 | 7351 if (term->tl_winpty != NULL) |
7352 winpty_free(term->tl_winpty); | |
7353 term->tl_winpty = NULL; | |
7354 if (term->tl_winpty_config != NULL) | |
7355 winpty_config_free(term->tl_winpty_config); | |
7356 term->tl_winpty_config = NULL; | |
7357 if (term->tl_vterm != NULL) | |
7358 vterm_free(term->tl_vterm); | |
7359 term->tl_vterm = NULL; | |
7360 } | |
7361 | |
7362 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7363 * Report the size to the terminal. |
12502 | 7364 */ |
7365 static void | |
7366 term_report_winsize(term_T *term, int rows, int cols) | |
7367 { | |
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
|
7368 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
|
7369 conpty_term_report_winsize(term, rows, cols); |
12502 | 7370 if (term->tl_winpty) |
7371 winpty_set_size(term->tl_winpty, cols, rows, NULL); | |
7372 } | |
7373 | |
7374 int | |
7375 terminal_enabled(void) | |
7376 { | |
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
|
7377 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK; |
12502 | 7378 } |
7379 | |
7380 # else | |
7381 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7382 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7383 // 3. Unix-like implementation. |
12502 | 7384 |
7385 /* | |
7386 * Create a new terminal of "rows" by "cols" cells. | |
7387 * Start job for "cmd". | |
7388 * 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
|
7389 * When "argv" is not NULL then "argvar" is not used. |
12502 | 7390 * Return OK or FAIL. |
7391 */ | |
7392 static int | |
7393 term_and_job_init( | |
7394 term_T *term, | |
7395 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
|
7396 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
|
7397 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
|
7398 jobopt_T *orig_opt UNUSED) |
12502 | 7399 { |
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
|
7400 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
|
7401 |
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
|
7402 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
|
7403 return FAIL; |
12502 | 7404 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7405 #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
|
7406 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
|
7407 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
|
7408 else |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7409 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
|
7410 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7411 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7412 // This may change a string in "argvar". |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
7413 term->tl_job = job_start(argvar, argv, opt, &term->tl_job); |
12502 | 7414 if (term->tl_job != NULL) |
7415 ++term->tl_job->jv_refcount; | |
7416 | |
7417 return term->tl_job != NULL | |
7418 && term->tl_job->jv_channel != NULL | |
7419 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL; | |
7420 } | |
7421 | |
7422 static int | |
7423 create_pty_only(term_T *term, jobopt_T *opt) | |
7424 { | |
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
|
7425 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
|
7426 return FAIL; |
12502 | 7427 |
7428 term->tl_job = job_alloc(); | |
7429 if (term->tl_job == NULL) | |
7430 return FAIL; | |
7431 ++term->tl_job->jv_refcount; | |
7432 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7433 // behave like the job is already finished |
12502 | 7434 term->tl_job->jv_status = JOB_FINISHED; |
7435 | |
7436 return mch_create_pty_channel(term->tl_job, opt); | |
7437 } | |
7438 | |
7439 /* | |
7440 * Free the terminal emulator part of "term". | |
7441 */ | |
7442 static void | |
7443 term_free_vterm(term_T *term) | |
7444 { | |
7445 if (term->tl_vterm != NULL) | |
7446 vterm_free(term->tl_vterm); | |
7447 term->tl_vterm = NULL; | |
7448 } | |
7449 | |
7450 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7451 * Report the size to the terminal. |
12502 | 7452 */ |
7453 static void | |
7454 term_report_winsize(term_T *term, int rows, int cols) | |
7455 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7456 // Use an ioctl() to report the new window size to the job. |
12502 | 7457 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) |
7458 { | |
7459 int fd = -1; | |
7460 int part; | |
7461 | |
7462 for (part = PART_OUT; part < PART_COUNT; ++part) | |
7463 { | |
7464 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
|
7465 if (mch_isatty(fd)) |
12502 | 7466 break; |
7467 } | |
7468 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) | |
7469 mch_signal_job(term->tl_job, (char_u *)"winch"); | |
7470 } | |
7471 } | |
7472 | |
7473 # endif | |
7474 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7475 #endif // FEAT_TERMINAL |