Mercurial > vim
annotate src/terminal.c @ 31439:735de21c5ce7 v9.0.1052
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Commit: https://github.com/vim/vim/commit/692fe0889c44d97c4a1cc822bc8de189859c51cb
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Dec 13 13:42:37 2022 +0000
patch 9.0.1052: using freed memory on exit when EXITFREE is defined
Problem: Using freed memory on exit when EXITFREE is defined.
Solution: Make a deep copy of the type. Make sure TTFLAG_STATIC is not set
in the copy.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 13 Dec 2022 14:45:05 +0100 |
parents | d8e7d725a666 |
children | 0d27ddce621d |
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 |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
165 long_u *tl_palette; // array of 16 colors specified by term_start, can |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
166 // be NULL |
12502 | 167 int tl_using_altscreen; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
168 garray_T tl_osc_buf; // incomplete OSC string |
12502 | 169 }; |
170 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
171 #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
|
172 #define TMODE_LOOP 2 // CTRL-W N used |
12502 | 173 |
174 /* | |
175 * List of all active terminals. | |
176 */ | |
177 static term_T *first_term = NULL; | |
178 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
179 // Terminal active in terminal_loop(). |
12502 | 180 static term_T *in_terminal_loop = NULL; |
181 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
182 #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
|
183 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
|
184 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
|
185 #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
|
186 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
187 #define MAX_ROW 999999 // used for tl_dirty_row_end to update all rows |
12502 | 188 #define KEY_BUF_LEN 200 |
189 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
190 #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
|
191 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
|
192 |
12502 | 193 /* |
194 * Functions with separate implementation for MS-Windows and Unix-like systems. | |
195 */ | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
196 static int term_and_job_init(term_T *term, typval_T *argvar, char **argv, jobopt_T *opt, jobopt_T *orig_opt); |
12502 | 197 static int create_pty_only(term_T *term, jobopt_T *opt); |
198 static void term_report_winsize(term_T *term, int rows, int cols); | |
199 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
|
200 #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
|
201 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
|
202 #endif |
12502 | 203 |
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
|
204 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
|
205 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
206 // 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
|
207 // backspace key. |
12502 | 208 static int term_backspace_char = BS; |
209 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
210 // 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
|
211 // 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
219 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
220 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
221 // 1. Generic code for all systems. |
12502 | 222 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
223 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
|
224 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
|
225 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
230 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
231 static void |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
232 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
|
233 { |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
234 // 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
|
235 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
|
236 return; |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
237 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
|
238 *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
|
239 } |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
240 |
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
241 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
|
242 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
|
243 { |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
244 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
|
245 } |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
246 |
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
247 |
12502 | 248 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
249 * 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
|
250 * 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
|
251 * 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
|
252 * 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
|
253 */ |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
254 static int |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
255 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
|
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 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
|
258 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
259 *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
|
260 *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
|
261 |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
262 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
|
263 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
264 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
|
265 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
266 // 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
|
267 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
|
268 { |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
269 minsize = TRUE; |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
270 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
|
271 } |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
272 *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
|
273 *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
|
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 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
|
276 } |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
277 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
278 /* |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
279 * Determine the terminal size from 'termwinsize' and the current window. |
12502 | 280 */ |
281 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
|
282 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
|
283 { |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
284 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
|
285 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
|
286 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
287 #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
|
288 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
|
289 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
290 // 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
|
291 // 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
|
292 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
|
293 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
|
294 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
|
295 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
296 #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
|
297 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
|
298 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
|
299 |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
300 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
|
301 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
|
302 { |
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_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
|
304 term->tl_rows = rows; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
305 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
|
306 term->tl_cols = cols; |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
307 } |
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 |
22097
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
317 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
|
318 { |
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_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
|
320 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
|
321 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
|
322 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
|
323 |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
324 // 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
|
325 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
|
326 { |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
327 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
|
328 |
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
329 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
|
330 term->tl_rows, term->tl_cols); |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28441
diff
changeset
|
331 set_option_value_give_err((char_u *)"termwinsize", |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28441
diff
changeset
|
332 0L, buf, OPT_LOCAL); |
22097
f369bbd71a53
patch 8.2.1598: starting a hidden terminal resizes the current window
Bram Moolenaar <Bram@vim.org>
parents:
22079
diff
changeset
|
333 } |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
334 } |
12502 | 335 } |
336 | |
337 /* | |
338 * Initialize job options for a terminal job. | |
339 * Caller may overrule some of them. | |
340 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
341 void |
12502 | 342 init_job_options(jobopt_T *opt) |
343 { | |
344 clear_job_options(opt); | |
345 | |
28769
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28441
diff
changeset
|
346 opt->jo_mode = CH_MODE_RAW; |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28441
diff
changeset
|
347 opt->jo_out_mode = CH_MODE_RAW; |
78fc778de076
patch 8.2.4909: MODE_ enum entries names are too generic
Bram Moolenaar <Bram@vim.org>
parents:
28441
diff
changeset
|
348 opt->jo_err_mode = CH_MODE_RAW; |
12502 | 349 opt->jo_set = JO_MODE | JO_OUT_MODE | JO_ERR_MODE; |
350 } | |
351 | |
352 /* | |
353 * Set job options mandatory for a terminal job. | |
354 */ | |
355 static void | |
356 setup_job_options(jobopt_T *opt, int rows, int cols) | |
357 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
358 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
359 // Win32: Redirecting the job output won't work, thus always connect stdout |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
360 // here. |
12502 | 361 if (!(opt->jo_set & JO_OUT_IO)) |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
362 #endif |
12502 | 363 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
364 // Connect stdout to the terminal. |
12502 | 365 opt->jo_io[PART_OUT] = JIO_BUFFER; |
366 opt->jo_io_buf[PART_OUT] = curbuf->b_fnum; | |
367 opt->jo_modifiable[PART_OUT] = 0; | |
368 opt->jo_set |= JO_OUT_IO + JO_OUT_BUF + JO_OUT_MODIFIABLE; | |
369 } | |
370 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
371 #ifndef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
372 // Win32: Redirecting the job output won't work, thus always connect stderr |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
373 // here. |
12502 | 374 if (!(opt->jo_set & JO_ERR_IO)) |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
375 #endif |
12502 | 376 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
377 // Connect stderr to the terminal. |
12502 | 378 opt->jo_io[PART_ERR] = JIO_BUFFER; |
379 opt->jo_io_buf[PART_ERR] = curbuf->b_fnum; | |
380 opt->jo_modifiable[PART_ERR] = 0; | |
381 opt->jo_set |= JO_ERR_IO + JO_ERR_BUF + JO_ERR_MODIFIABLE; | |
382 } | |
383 | |
384 opt->jo_pty = TRUE; | |
385 if ((opt->jo_set2 & JO2_TERM_ROWS) == 0) | |
386 opt->jo_term_rows = rows; | |
387 if ((opt->jo_set2 & JO2_TERM_COLS) == 0) | |
388 opt->jo_term_cols = cols; | |
389 } | |
390 | |
391 /* | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
392 * Flush messages on channels. |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
393 */ |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
394 static void |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
395 term_flush_messages() |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
396 { |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
397 mch_check_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
398 parse_queued_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
399 } |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
400 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
401 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
402 * Close a terminal buffer (and its window). Used when creating the terminal |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
403 * fails. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
404 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
405 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
406 term_close_buffer(buf_T *buf, buf_T *old_curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
407 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
408 free_terminal(buf); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
409 if (old_curbuf != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
410 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
411 --curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
412 curbuf = old_curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
413 curwin->w_buffer = curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
414 ++curbuf->b_nwindows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
415 } |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19542
diff
changeset
|
416 CHECK_CURBUF; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
417 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
418 // Wiping out the buffer will also close the window and call |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
419 // free_terminal(). |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
420 do_buffer(DOBUF_WIPE, DOBUF_FIRST, FORWARD, buf->b_fnum, TRUE); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
421 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
422 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
423 /* |
12502 | 424 * Start a terminal window and return its buffer. |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
425 * Use either "argvar" or "argv", the other must be NULL. |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
426 * When "flags" has TERM_START_NOJOB only create the buffer, b_term and open |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
427 * the window. |
12502 | 428 * Returns NULL when failed. |
429 */ | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
430 buf_T * |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
431 term_start( |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
432 typval_T *argvar, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
433 char **argv, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
434 jobopt_T *opt, |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
435 int flags) |
12502 | 436 { |
437 exarg_T split_ea; | |
438 win_T *old_curwin = curwin; | |
439 term_T *term; | |
440 buf_T *old_curbuf = NULL; | |
441 int res; | |
442 buf_T *newbuf; | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
443 int vertical = opt->jo_vertical || (cmdmod.cmod_split & WSP_VERT); |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
444 jobopt_T orig_opt; // only partly filled |
12502 | 445 |
446 if (check_restricted() || check_secure()) | |
447 return NULL; | |
24739
68e3adbeaf20
patch 8.2.2908: crash when using a terminal popup window from cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
24612
diff
changeset
|
448 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
|
449 { |
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 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
|
451 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
|
452 } |
12502 | 453 |
454 if ((opt->jo_set & (JO_IN_IO + JO_OUT_IO + JO_ERR_IO)) | |
455 == (JO_IN_IO + JO_OUT_IO + JO_ERR_IO) | |
456 || (!(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
|
457 || (!(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
|
458 || (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
|
459 && 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
|
460 && 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
|
461 && argvar->vval.v_list->lv_first == &range_list_item)) |
12502 | 462 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
463 emsg(_(e_invalid_argument)); |
12502 | 464 return NULL; |
465 } | |
466 | |
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
|
467 term = ALLOC_CLEAR_ONE(term_T); |
12502 | 468 if (term == NULL) |
469 return NULL; | |
470 term->tl_dirty_row_end = MAX_ROW; | |
471 term->tl_cursor_visible = TRUE; | |
472 term->tl_cursor_shape = VTERM_PROP_CURSORSHAPE_BLOCK; | |
473 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
|
474 #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
|
475 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
|
476 #endif |
12502 | 477 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
|
478 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
|
479 ga_init2(&term->tl_osc_buf, sizeof(char), 300); |
12502 | 480 |
24557
7a4cc4d3a40a
patch 8.2.2818: no jump added when opening terminal in current window
Bram Moolenaar <Bram@vim.org>
parents:
24268
diff
changeset
|
481 setpcmark(); |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
482 CLEAR_FIELD(split_ea); |
12502 | 483 if (opt->jo_curwin) |
484 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
485 // 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
|
486 if (!can_abandon(curbuf, flags & TERM_START_FORCEIT)) |
12502 | 487 { |
488 no_write_message(); | |
489 vim_free(term); | |
490 return NULL; | |
491 } | |
492 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
|
493 (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
|
494 + ((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
|
495 curwin) == FAIL) |
12502 | 496 { |
497 vim_free(term); | |
498 return NULL; | |
499 } | |
500 } | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
501 else if (opt->jo_hidden || (flags & TERM_START_SYSTEM)) |
12502 | 502 { |
503 buf_T *buf; | |
504 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
505 // 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
|
506 // a moment to be able to do the initializations. |
12502 | 507 buf = buflist_new((char_u *)"", NULL, (linenr_T)0, |
508 BLN_NEW | BLN_LISTED); | |
509 if (buf == NULL || ml_open(buf) == FAIL) | |
510 { | |
511 vim_free(term); | |
512 return NULL; | |
513 } | |
514 old_curbuf = curbuf; | |
515 --curbuf->b_nwindows; | |
516 curbuf = buf; | |
517 curwin->w_buffer = buf; | |
518 ++curbuf->b_nwindows; | |
519 } | |
520 else | |
521 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
522 // Open a new window or tab. |
12502 | 523 split_ea.cmdidx = CMD_new; |
524 split_ea.cmd = (char_u *)"new"; | |
525 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
|
526 if (opt->jo_term_rows > 0 && !vertical) |
12502 | 527 { |
528 split_ea.line2 = opt->jo_term_rows; | |
529 split_ea.addr_count = 1; | |
530 } | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
531 if (opt->jo_term_cols > 0 && vertical) |
12502 | 532 { |
533 split_ea.line2 = opt->jo_term_cols; | |
534 split_ea.addr_count = 1; | |
535 } | |
536 | |
13501
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
537 if (vertical) |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22687
diff
changeset
|
538 cmdmod.cmod_split |= WSP_VERT; |
12502 | 539 ex_splitview(&split_ea); |
540 if (curwin == old_curwin) | |
541 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
542 // split failed |
12502 | 543 vim_free(term); |
544 return NULL; | |
545 } | |
546 } | |
547 term->tl_buffer = curbuf; | |
548 curbuf->b_term = term; | |
549 | |
550 if (!opt->jo_hidden) | |
551 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
552 // 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
|
553 // "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
|
554 if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical)) |
12502 | 555 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
|
556 if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical)) |
12502 | 557 win_setwidth(opt->jo_term_cols); |
558 } | |
559 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
560 // Link the new terminal in the list of active terminals. |
12502 | 561 term->tl_next = first_term; |
562 first_term = term; | |
563 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
564 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
|
565 |
12502 | 566 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
|
567 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
568 vim_free(curbuf->b_ffname); |
12502 | 569 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
|
570 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
571 else if (argv != NULL) |
19744
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
572 { |
eb4887dd4b60
patch 8.2.0428: buffer name may leak
Bram Moolenaar <Bram@vim.org>
parents:
19713
diff
changeset
|
573 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
|
574 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
|
575 } |
12502 | 576 else |
577 { | |
578 int i; | |
579 size_t len; | |
580 char_u *cmd, *p; | |
581 | |
582 if (argvar->v_type == VAR_STRING) | |
583 { | |
584 cmd = argvar->vval.v_string; | |
585 if (cmd == NULL) | |
586 cmd = (char_u *)""; | |
587 else if (STRCMP(cmd, "NONE") == 0) | |
588 cmd = (char_u *)"pty"; | |
589 } | |
590 else if (argvar->v_type != VAR_LIST | |
591 || 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
|
592 || 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
|
593 || (cmd = tv_get_string_chk( |
12502 | 594 &argvar->vval.v_list->lv_first->li_tv)) == NULL) |
595 cmd = (char_u*)""; | |
596 | |
597 len = STRLEN(cmd) + 10; | |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
598 p = alloc(len); |
12502 | 599 |
600 for (i = 0; p != NULL; ++i) | |
601 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
602 // 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
|
603 // the executable, otherwise ":w!" would overwrite it. |
12502 | 604 if (i == 0) |
605 vim_snprintf((char *)p, len, "!%s", cmd); | |
606 else | |
607 vim_snprintf((char *)p, len, "!%s (%d)", cmd, i); | |
608 if (buflist_findname(p) == NULL) | |
609 { | |
610 vim_free(curbuf->b_ffname); | |
611 curbuf->b_ffname = p; | |
612 break; | |
613 } | |
614 } | |
615 } | |
19513
274052873790
patch 8.2.0314: short name not set for terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
19358
diff
changeset
|
616 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
|
617 curbuf->b_sfname = vim_strsave(curbuf->b_ffname); |
12502 | 618 curbuf->b_fname = curbuf->b_ffname; |
619 | |
19713
8514e8b7e661
patch 8.2.0413: buffer menu does not handle special buffers properly
Bram Moolenaar <Bram@vim.org>
parents:
19633
diff
changeset
|
620 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
|
621 |
12502 | 622 if (opt->jo_term_opencmd != NULL) |
623 term->tl_opencmd = vim_strsave(opt->jo_term_opencmd); | |
624 | |
625 if (opt->jo_eof_chars != NULL) | |
626 term->tl_eof_chars = vim_strsave(opt->jo_eof_chars); | |
627 | |
628 set_string_option_direct((char_u *)"buftype", -1, | |
629 (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
|
630 // 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
|
631 curbuf->b_p_initialized = TRUE; |
12502 | 632 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
633 // 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
|
634 // the job finished. |
12502 | 635 curbuf->b_p_ma = FALSE; |
636 | |
22079
ba2c3f38a596
patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents:
21114
diff
changeset
|
637 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
|
638 #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
|
639 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
|
640 #endif |
12502 | 641 setup_job_options(opt, term->tl_rows, term->tl_cols); |
642 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
643 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
|
644 return curbuf; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
645 |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
646 #if defined(FEAT_SESSION) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
647 // 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
|
648 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
|
649 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
|
650 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
|
651 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
652 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
|
653 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
654 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
|
655 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
|
656 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
657 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
|
658 && 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
|
659 && 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
|
660 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
661 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
|
662 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
|
663 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
664 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
|
665 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
|
666 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
667 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
|
668 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
|
669 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
670 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
|
671 break; |
25994
e8873138ffbb
patch 8.2.3530: ":buf {a}" fails while ":edit {a}" works
Bram Moolenaar <Bram@vim.org>
parents:
25965
diff
changeset
|
672 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
|
673 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
|
674 break; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
675 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
|
676 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
|
677 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
|
678 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
679 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
|
680 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
681 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
|
682 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
|
683 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
684 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
685 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
|
686 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
687 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
688 |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
689 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
|
690 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
691 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
|
692 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
693 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
|
694 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
695 |
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
|
696 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
|
697 { |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
698 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
|
699 |
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
700 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
|
701 } |
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
|
702 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
|
703 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
|
704 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
705 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
|
706 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
|
707 |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
708 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
709 // Save the user-defined palette, it is only used in GUI (or 'tgc' is on). |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
710 if (opt->jo_set2 & JO2_ANSI_COLORS) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
711 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
712 term->tl_palette = ALLOC_MULT(long_u, 16); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
713 if (term->tl_palette == NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
714 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
715 vim_free(term); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
716 return NULL; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
717 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
718 memcpy(term->tl_palette, opt->jo_ansi_colors, sizeof(long_u) * 16); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
719 } |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
720 #endif |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
721 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
722 // 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
|
723 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
|
724 && argvar->v_type == VAR_STRING |
12502 | 725 && argvar->vval.v_string != NULL |
726 && STRCMP(argvar->vval.v_string, "NONE") == 0) | |
727 res = create_pty_only(term, opt); | |
728 else | |
13860
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
729 res = term_and_job_init(term, argvar, argv, opt, &orig_opt); |
12502 | 730 |
731 newbuf = curbuf; | |
732 if (res == OK) | |
733 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
734 // Get and remember the size we ended up with. Update the pty. |
12502 | 735 vterm_get_size(term->tl_vterm, &term->tl_rows, &term->tl_cols); |
736 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
|
737 #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
|
738 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
|
739 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
740 // 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
|
741 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
|
742 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
|
743 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
744 #endif |
12502 | 745 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
746 // 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
|
747 // a deadlock if the job is waiting for Vim to read. |
12502 | 748 channel_set_nonblock(term->tl_job->jv_channel, PART_IN); |
749 | |
13835
8e583c52eb44
patch 8.0.1789: BufWinEnter does not work well for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13829
diff
changeset
|
750 if (old_curbuf != NULL) |
12502 | 751 { |
752 --curbuf->b_nwindows; | |
753 curbuf = old_curbuf; | |
754 curwin->w_buffer = curbuf; | |
755 ++curbuf->b_nwindows; | |
756 } | |
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
|
757 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
|
758 #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
|
759 || 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
|
760 #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
|
761 || 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
|
762 { |
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
|
763 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
|
764 |
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
|
765 // 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
|
766 // 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 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
|
773 } |
12502 | 774 } |
775 else | |
776 { | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
777 term_close_buffer(curbuf, old_curbuf); |
12502 | 778 return NULL; |
779 } | |
13444
9f06f7aca74c
patch 8.0.1596: no autocommand specifically for opening a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13438
diff
changeset
|
780 |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
781 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
|
782 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
|
783 apply_autocmds(EVENT_TERMINALWINOPEN, NULL, NULL, FALSE, newbuf); |
12502 | 784 return newbuf; |
785 } | |
786 | |
787 /* | |
788 * ":terminal": open a terminal window and execute a job in it. | |
789 */ | |
790 void | |
791 ex_terminal(exarg_T *eap) | |
792 { | |
793 typval_T argvar[2]; | |
794 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
|
795 int opt_shell = FALSE; |
12502 | 796 char_u *cmd; |
797 char_u *tofree = NULL; | |
798 | |
799 init_job_options(&opt); | |
800 | |
801 cmd = eap->arg; | |
13219
4b8d89ea9edb
patch 8.0.1484: reduntant conditions
Christian Brabandt <cb@256bit.org>
parents:
13206
diff
changeset
|
802 while (*cmd == '+' && *(cmd + 1) == '+') |
12502 | 803 { |
804 char_u *p, *ep; | |
805 | |
806 cmd += 2; | |
807 p = skiptowhite(cmd); | |
808 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
|
809 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
|
810 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
811 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
|
812 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
|
813 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
|
814 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
|
815 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
816 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
817 # 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
|
818 && 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
|
819 if (OPTARG_HAS("close")) |
12502 | 820 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
|
821 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
|
822 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
|
823 else if (OPTARG_HAS("open")) |
12502 | 824 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
|
825 else if (OPTARG_HAS("curwin")) |
12502 | 826 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
|
827 else if (OPTARG_HAS("hidden")) |
12502 | 828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
835 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
|
836 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
|
837 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
|
838 } |
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
|
839 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
|
840 { |
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 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
|
842 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
|
843 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
844 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
|
845 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
|
846 } |
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 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
848 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
|
849 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
850 else if (OPTARG_HAS("rows") && ep != NULL && isdigit(ep[1])) |
12502 | 851 { |
852 opt.jo_set2 |= JO2_TERM_ROWS; | |
853 opt.jo_term_rows = atoi((char *)ep + 1); | |
854 p = skiptowhite(cmd); | |
855 } | |
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
|
856 else if (OPTARG_HAS("cols") && ep != NULL && isdigit(ep[1])) |
12502 | 857 { |
858 opt.jo_set2 |= JO2_TERM_COLS; | |
859 opt.jo_term_cols = atoi((char *)ep + 1); | |
860 p = skiptowhite(cmd); | |
861 } | |
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
|
862 else if (OPTARG_HAS("eof") && ep != NULL) |
12502 | 863 { |
864 char_u *buf = NULL; | |
865 char_u *keys; | |
866 | |
19245
5ed8297121fa
patch 8.2.0181: problems parsing :term arguments
Bram Moolenaar <Bram@vim.org>
parents:
19241
diff
changeset
|
867 vim_free(opt.jo_eof_chars); |
12502 | 868 p = skiptowhite(cmd); |
869 *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
|
870 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
|
871 REPTERM_FROM_PART | REPTERM_DO_LT | REPTERM_SPECIAL, NULL); |
12502 | 872 opt.jo_set2 |= JO2_EOF_CHARS; |
873 opt.jo_eof_chars = vim_strsave(keys); | |
874 vim_free(buf); | |
875 *p = ' '; | |
876 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
877 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
878 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
|
879 && 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
|
880 { |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
881 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
|
882 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
883 p = skiptowhite(cmd); |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
884 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
|
885 tty_type = 'w'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
886 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
|
887 tty_type = 'c'; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
888 else |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
889 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
890 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
|
891 goto theend; |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
892 } |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
893 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
|
894 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
|
895 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
896 #endif |
12502 | 897 else |
898 { | |
899 if (*p) | |
900 *p = NUL; | |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
901 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
|
902 goto theend; |
12502 | 903 } |
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
|
904 # undef OPTARG_HAS |
12502 | 905 cmd = skipwhite(p); |
906 } | |
907 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
|
908 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
909 // Make a copy of 'shell', an autocommand may change the option. |
12502 | 910 tofree = cmd = vim_strsave(p_sh); |
911 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
912 // 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
|
913 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
|
914 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
|
915 } |
d130044d4f1f
patch 8.0.1612: need to close terminal after shell stopped
Christian Brabandt <cb@256bit.org>
parents:
13474
diff
changeset
|
916 |
12502 | 917 if (eap->addr_count > 0) |
918 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
919 // Write lines from current buffer to the job. |
12502 | 920 opt.jo_set |= JO_IN_IO | JO_IN_BUF | JO_IN_TOP | JO_IN_BOT; |
921 opt.jo_io[PART_IN] = JIO_BUFFER; | |
922 opt.jo_io_buf[PART_IN] = curbuf->b_fnum; | |
923 opt.jo_in_top = eap->line1; | |
924 opt.jo_in_bot = eap->line2; | |
925 } | |
926 | |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
927 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
|
928 { |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
929 #ifdef UNIX |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
930 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
|
931 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
|
932 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
|
933 |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
934 // :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
|
935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 #else |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
942 # ifdef MSWIN |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
943 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
|
944 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
|
945 |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
946 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
|
947 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
|
948 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
949 tofree = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
950 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
|
951 cmd = newcmd; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
952 # else |
26897
d02d40f0261c
patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
953 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
|
954 goto theend; |
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
955 # endif |
18514
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
956 #endif |
39b0c28fe495
patch 8.1.2251: ":term command" may not work without a shell
Bram Moolenaar <Bram@vim.org>
parents:
18508
diff
changeset
|
957 } |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
958 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
|
959 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
|
960 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
|
961 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
|
962 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
963 theend: |
18522
dfdc29643c91
patch 8.1.2255: ":term ++shell" does not work on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
18514
diff
changeset
|
964 vim_free(tofree); |
12502 | 965 vim_free(opt.jo_eof_chars); |
966 } | |
967 | |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
968 #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
|
969 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
970 * 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
|
971 * 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
|
972 * 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
|
973 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
974 int |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
975 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
|
976 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
977 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
|
978 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
|
979 |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
980 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
|
981 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
982 // 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
|
983 // 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
|
984 // 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
|
985 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
|
986 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
|
987 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
988 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
|
989 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
990 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
|
991 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
|
992 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
993 // 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
|
994 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
|
995 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
996 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
|
997 } |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
998 } |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
999 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1000 // 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
|
1001 // 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
|
1002 // 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
|
1003 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
|
1004 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
|
1005 return FAIL; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1006 #ifdef MSWIN |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
1007 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
|
1008 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
|
1009 #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
|
1010 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
|
1011 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
|
1012 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
|
1013 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1014 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1015 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
|
1016 return FAIL; |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1017 |
22230
0bbc8be90207
patch 8.2.1664: memory leak when using :mkview with a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
22226
diff
changeset
|
1018 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
|
1019 { |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1020 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
|
1021 |
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1022 vim_snprintf(hash_key, NUMBUFLEN, "%d", bufnr); |
31231
684e6dfa2fba
patch 9.0.0949: crash when unletting a variable while listing variables
Bram Moolenaar <Bram@vim.org>
parents:
31213
diff
changeset
|
1023 hash_add(terminal_bufs, (char_u *)hash_key, "terminal session"); |
22226
4ed106deb772
patch 8.2.1662: :mksession does not restore shared terminal buffer properly
Bram Moolenaar <Bram@vim.org>
parents:
22155
diff
changeset
|
1024 } |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1025 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1026 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
|
1027 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1028 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1029 /* |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1030 * 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
|
1031 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1032 int |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1033 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
|
1034 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1035 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
|
1036 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1037 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
|
1038 || 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
|
1039 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1040 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1041 |
12502 | 1042 /* |
1043 * Free the scrollback buffer for "term". | |
1044 */ | |
1045 static void | |
1046 free_scrollback(term_T *term) | |
1047 { | |
1048 int i; | |
1049 | |
1050 for (i = 0; i < term->tl_scrollback.ga_len; ++i) | |
1051 vim_free(((sb_line_T *)term->tl_scrollback.ga_data + i)->sb_cells); | |
1052 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
|
1053 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
|
1054 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
|
1055 ga_clear(&term->tl_scrollback_postponed); |
12502 | 1056 } |
1057 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1058 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1059 // 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
|
1060 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
|
1061 |
12502 | 1062 /* |
1063 * Free a terminal and everything it refers to. | |
1064 * Kills the job if there is one. | |
1065 * 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
|
1066 * 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
|
1067 * 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
|
1068 * referenced. |
12502 | 1069 */ |
1070 void | |
1071 free_terminal(buf_T *buf) | |
1072 { | |
1073 term_T *term = buf->b_term; | |
1074 term_T *tp; | |
1075 | |
1076 if (term == NULL) | |
1077 return; | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1078 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1079 // Unlink the terminal form the list of terminals. |
12502 | 1080 if (first_term == term) |
1081 first_term = term->tl_next; | |
1082 else | |
1083 for (tp = first_term; tp->tl_next != NULL; tp = tp->tl_next) | |
1084 if (tp->tl_next == term) | |
1085 { | |
1086 tp->tl_next = term->tl_next; | |
1087 break; | |
1088 } | |
1089 | |
1090 if (term->tl_job != NULL) | |
1091 { | |
1092 if (term->tl_job->jv_status != JOB_ENDED | |
1093 && 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
|
1094 && term->tl_job->jv_status != JOB_FAILED) |
12502 | 1095 job_stop(term->tl_job, NULL, "kill"); |
1096 job_unref(term->tl_job); | |
1097 } | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1098 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
|
1099 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
|
1100 |
12502 | 1101 buf->b_term = NULL; |
1102 if (in_terminal_loop == term) | |
1103 in_terminal_loop = NULL; | |
1104 } | |
1105 | |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1106 void |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1107 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
|
1108 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1109 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
|
1110 { |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1111 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
|
1112 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1113 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
|
1114 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1115 free_scrollback(term); |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
1116 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
|
1117 |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1118 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
|
1119 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
|
1120 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
|
1121 #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
|
1122 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
|
1123 #endif |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1124 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
|
1125 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
|
1126 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
|
1127 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
|
1128 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
|
1129 #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
|
1130 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
|
1131 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
|
1132 #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
|
1133 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
|
1134 vim_free(term->tl_cursor_color); |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
1135 vim_free(term->tl_palette); |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1136 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
|
1137 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1138 } |
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1139 |
12502 | 1140 /* |
13132
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1141 * 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
|
1142 * 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
|
1143 * 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
|
1144 */ |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1145 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
|
1146 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
|
1147 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1148 #ifdef UNIX |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1149 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
|
1150 int i; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1151 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1152 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
|
1153 { |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1154 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
|
1155 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1156 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
|
1157 return parts[i]; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1158 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1159 #endif |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1160 return PART_IN; |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1161 } |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1162 |
fe0cec169589
patch 8.0.1440: terminal window: some vterm responses are delayed
Christian Brabandt <cb@256bit.org>
parents:
13111
diff
changeset
|
1163 /* |
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
|
1164 * 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
|
1165 */ |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1166 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
|
1167 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
|
1168 { |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1169 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
|
1170 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
|
1171 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
|
1172 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1173 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
|
1174 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
|
1175 (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
|
1176 } |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1177 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
1178 /* |
12502 | 1179 * Write job output "msg[len]" to the vterm. |
1180 */ | |
1181 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
|
1182 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
|
1183 { |
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
|
1184 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
|
1185 size_t len = len_arg; |
12502 | 1186 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
|
1187 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
|
1188 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
|
1189 |
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
|
1190 // 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
|
1191 // 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
|
1192 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
|
1193 { |
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
|
1194 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
|
1195 |
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
|
1196 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
|
1197 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
|
1198 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
|
1199 } |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1200 |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
1201 vterm_input_write(vterm, (char *)msg, len); |
12502 | 1202 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1203 // 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
|
1204 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
|
1205 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
|
1206 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1207 // this invokes the damage callbacks |
12502 | 1208 vterm_screen_flush_damage(vterm_obtain_screen(vterm)); |
1209 } | |
1210 | |
1211 static void | |
1212 update_cursor(term_T *term, int redraw) | |
1213 { | |
1214 if (term->tl_normal_mode) | |
1215 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
|
1216 #ifdef FEAT_GUI |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1217 if (term->tl_system) |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1218 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
|
1219 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
|
1220 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1221 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1222 setcursor(); |
12502 | 1223 if (redraw) |
1224 { | |
30843
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1225 aco_save_T aco; |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1226 |
12502 | 1227 if (term->tl_buffer == curbuf && term->tl_cursor_visible) |
1228 cursor_on(); | |
1229 out_flush(); | |
1230 #ifdef FEAT_GUI | |
1231 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
|
1232 { |
12502 | 1233 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
|
1234 gui_mch_flush(); |
6f98a5fd0c19
patch 8.0.1376: cursor in terminal not always updated
Christian Brabandt <cb@256bit.org>
parents:
12984
diff
changeset
|
1235 } |
12502 | 1236 #endif |
31201
b1c66bff0a66
patch 9.0.0934: various code formatting issues
Bram Moolenaar <Bram@vim.org>
parents:
31192
diff
changeset
|
1237 // Make sure an invoked autocmd doesn't delete the buffer (and the |
b1c66bff0a66
patch 9.0.0934: various code formatting issues
Bram Moolenaar <Bram@vim.org>
parents:
31192
diff
changeset
|
1238 // terminal) under our fingers. |
30843
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1239 ++term->tl_buffer->b_locked; |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1240 |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1241 // save and restore curwin and curbuf, in case the autocmd changes them |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1242 aucmd_prepbuf(&aco, curbuf); |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1243 apply_autocmds(EVENT_TEXTCHANGEDT, NULL, NULL, FALSE, term->tl_buffer); |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1244 aucmd_restbuf(&aco); |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1245 |
82e62fd4eae9
patch 9.0.0756: no autocmd event for changing text in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
30825
diff
changeset
|
1246 --term->tl_buffer->b_locked; |
12502 | 1247 } |
1248 } | |
1249 | |
1250 /* | |
1251 * Invoked when "msg" output from a job was received. Write it to the terminal | |
1252 * of "buffer". | |
1253 */ | |
1254 void | |
1255 write_to_term(buf_T *buffer, char_u *msg, channel_T *channel) | |
1256 { | |
1257 size_t len = STRLEN(msg); | |
1258 term_T *term = buffer->b_term; | |
1259 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1260 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1261 // 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
|
1262 // 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
|
1263 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
|
1264 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1265 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
|
1266 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
|
1267 return; |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1268 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1269 #endif |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
1270 |
12502 | 1271 if (term->tl_vterm == NULL) |
1272 { | |
1273 ch_log(channel, "NOT writing %d bytes to terminal", (int)len); | |
1274 return; | |
1275 } | |
1276 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
|
1277 cursor_off(); |
12502 | 1278 term_write_job_output(term, msg, len); |
1279 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1280 #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
|
1281 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
|
1282 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1283 // 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
|
1284 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
|
1285 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
|
1286 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1287 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
1288 #endif |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1289 // 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
|
1290 // contents, thus no screen update is needed. |
12502 | 1291 if (!term->tl_normal_mode) |
1292 { | |
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
|
1293 // 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
|
1294 // 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
|
1295 // TODO: only update once in a while. |
12502 | 1296 ch_log(term->tl_job->jv_channel, "updating screen"); |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28769
diff
changeset
|
1297 if (buffer == curbuf && (State & MODE_CMDLINE) == 0) |
12502 | 1298 { |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
1299 update_screen(UPD_VALID_NO_UPDATE); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1300 // 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
|
1301 // already |
13886
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
1302 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
|
1303 update_cursor(curbuf->b_term, TRUE); |
12502 | 1304 } |
1305 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
|
1306 redraw_after_callback(TRUE, FALSE); |
12502 | 1307 } |
1308 } | |
1309 | |
1310 /* | |
1311 * Send a mouse position and click to the vterm | |
1312 */ | |
1313 static int | |
1314 term_send_mouse(VTerm *vterm, int button, int pressed) | |
1315 { | |
1316 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
|
1317 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
|
1318 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
|
1319 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1320 #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
|
1321 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
|
1322 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1323 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
|
1324 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
|
1325 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1326 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
1327 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
|
1328 if (button != 0) |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12845
diff
changeset
|
1329 vterm_mouse_button(vterm, button, pressed, mod); |
12502 | 1330 return TRUE; |
1331 } | |
1332 | |
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 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
|
1334 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
|
1335 |
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 * 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
|
1338 * 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
|
1339 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1340 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
|
1341 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
|
1342 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1343 #if defined(FEAT_CLIPBOARD) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1344 // 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
|
1345 // 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
|
1346 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
|
1347 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
|
1348 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1349 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
|
1350 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
|
1351 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1352 // 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
|
1353 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
|
1354 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1355 case K_LEFTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1356 case K_LEFTRELEASE: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1357 case K_RIGHTDRAG: |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1358 case K_RIGHTRELEASE: |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1359 // 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
|
1360 // 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
|
1361 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
|
1362 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1363 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
|
1364 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1365 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
|
1366 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1367 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1368 // 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
|
1369 // 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
|
1370 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
|
1371 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
|
1372 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
|
1373 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
|
1374 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
|
1375 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
|
1376 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
|
1377 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1378 // 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
|
1379 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
|
1380 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
|
1381 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
|
1382 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
|
1383 else |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1384 ignore_drag_release = FALSE; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1385 // 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
|
1386 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
|
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 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
|
1389 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1390 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
|
1391 &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
|
1392 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
|
1393 && (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
|
1394 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1395 // 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
|
1396 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
|
1397 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
|
1398 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1399 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
|
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 break; |
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 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
|
1404 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
|
1405 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
|
1406 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1407 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1408 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
|
1409 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
|
1410 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1411 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1412 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
|
1413 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1414 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
|
1415 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1416 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
|
1417 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
|
1418 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
|
1419 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
|
1420 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
|
1421 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
|
1422 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
|
1423 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
|
1424 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
|
1425 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
|
1426 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
|
1427 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
|
1428 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1429 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
|
1430 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1431 |
12502 | 1432 /* |
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
|
1433 * 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
|
1434 * job. |
12502 | 1435 * Return the number of bytes in "buf". |
1436 */ | |
1437 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
|
1438 term_convert_key(term_T *term, int c, int modmask, char *buf) |
12502 | 1439 { |
1440 VTerm *vterm = term->tl_vterm; | |
1441 VTermKey key = VTERM_KEY_NONE; | |
1442 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
|
1443 int other = FALSE; |
12502 | 1444 |
1445 switch (c) | |
1446 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1447 // 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
|
1448 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1449 // 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
|
1450 // becomes 0x7f DEL |
12502 | 1451 case K_BS: c = term_backspace_char; break; |
1452 | |
1453 case ESC: key = VTERM_KEY_ESCAPE; break; | |
1454 case K_DEL: key = VTERM_KEY_DEL; break; | |
1455 case K_DOWN: key = VTERM_KEY_DOWN; break; | |
1456 case K_S_DOWN: mod = VTERM_MOD_SHIFT; | |
1457 key = VTERM_KEY_DOWN; break; | |
1458 case K_END: key = VTERM_KEY_END; break; | |
1459 case K_S_END: mod = VTERM_MOD_SHIFT; | |
1460 key = VTERM_KEY_END; break; | |
1461 case K_C_END: mod = VTERM_MOD_CTRL; | |
1462 key = VTERM_KEY_END; break; | |
1463 case K_F10: key = VTERM_KEY_FUNCTION(10); break; | |
1464 case K_F11: key = VTERM_KEY_FUNCTION(11); break; | |
1465 case K_F12: key = VTERM_KEY_FUNCTION(12); break; | |
1466 case K_F1: key = VTERM_KEY_FUNCTION(1); break; | |
1467 case K_F2: key = VTERM_KEY_FUNCTION(2); break; | |
1468 case K_F3: key = VTERM_KEY_FUNCTION(3); break; | |
1469 case K_F4: key = VTERM_KEY_FUNCTION(4); break; | |
1470 case K_F5: key = VTERM_KEY_FUNCTION(5); break; | |
1471 case K_F6: key = VTERM_KEY_FUNCTION(6); break; | |
1472 case K_F7: key = VTERM_KEY_FUNCTION(7); break; | |
1473 case K_F8: key = VTERM_KEY_FUNCTION(8); break; | |
1474 case K_F9: key = VTERM_KEY_FUNCTION(9); break; | |
1475 case K_HOME: key = VTERM_KEY_HOME; break; | |
1476 case K_S_HOME: mod = VTERM_MOD_SHIFT; | |
1477 key = VTERM_KEY_HOME; break; | |
1478 case K_C_HOME: mod = VTERM_MOD_CTRL; | |
1479 key = VTERM_KEY_HOME; break; | |
1480 case K_INS: key = VTERM_KEY_INS; break; | |
1481 case K_K0: key = VTERM_KEY_KP_0; break; | |
1482 case K_K1: key = VTERM_KEY_KP_1; break; | |
1483 case K_K2: key = VTERM_KEY_KP_2; break; | |
1484 case K_K3: key = VTERM_KEY_KP_3; break; | |
1485 case K_K4: key = VTERM_KEY_KP_4; break; | |
1486 case K_K5: key = VTERM_KEY_KP_5; break; | |
1487 case K_K6: key = VTERM_KEY_KP_6; break; | |
1488 case K_K7: key = VTERM_KEY_KP_7; break; | |
1489 case K_K8: key = VTERM_KEY_KP_8; break; | |
1490 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
|
1491 case K_KDEL: key = VTERM_KEY_DEL; break; // TODO |
12502 | 1492 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
|
1493 case K_KEND: key = VTERM_KEY_KP_1; break; // TODO |
12502 | 1494 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
|
1495 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
|
1496 case K_KINS: key = VTERM_KEY_KP_0; break; // TODO |
12502 | 1497 case K_KMINUS: key = VTERM_KEY_KP_MINUS; break; |
1498 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
|
1499 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
|
1500 case K_KPAGEUP: key = VTERM_KEY_KP_9; break; // TODO |
12502 | 1501 case K_KPLUS: key = VTERM_KEY_KP_PLUS; break; |
1502 case K_KPOINT: key = VTERM_KEY_KP_PERIOD; break; | |
1503 case K_LEFT: key = VTERM_KEY_LEFT; break; | |
1504 case K_S_LEFT: mod = VTERM_MOD_SHIFT; | |
1505 key = VTERM_KEY_LEFT; break; | |
1506 case K_C_LEFT: mod = VTERM_MOD_CTRL; | |
1507 key = VTERM_KEY_LEFT; break; | |
1508 case K_PAGEDOWN: key = VTERM_KEY_PAGEDOWN; break; | |
1509 case K_PAGEUP: key = VTERM_KEY_PAGEUP; break; | |
1510 case K_RIGHT: key = VTERM_KEY_RIGHT; break; | |
1511 case K_S_RIGHT: mod = VTERM_MOD_SHIFT; | |
1512 key = VTERM_KEY_RIGHT; break; | |
1513 case K_C_RIGHT: mod = VTERM_MOD_CTRL; | |
1514 key = VTERM_KEY_RIGHT; break; | |
1515 case K_UP: key = VTERM_KEY_UP; break; | |
1516 case K_S_UP: mod = VTERM_MOD_SHIFT; | |
1517 key = VTERM_KEY_UP; break; | |
1518 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
|
1519 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
|
1520 key = VTERM_KEY_TAB; break; |
12502 | 1521 |
12845
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1522 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
|
1523 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
|
1524 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
|
1525 case K_MOUSERIGHT: other = term_send_mouse(vterm, 6, 1); break; |
12502 | 1526 |
1527 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
|
1528 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
|
1529 case K_LEFTDRAG: |
12502 | 1530 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
|
1531 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
|
1532 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
|
1533 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
|
1534 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
|
1535 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
|
1536 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
|
1537 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
|
1538 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
|
1539 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
|
1540 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
|
1541 break; |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
1542 |
12502 | 1543 case K_X1MOUSE: /* TODO */ return 0; |
1544 case K_X1DRAG: /* TODO */ return 0; | |
1545 case K_X1RELEASE: /* TODO */ return 0; | |
1546 case K_X2MOUSE: /* TODO */ return 0; | |
1547 case K_X2DRAG: /* TODO */ return 0; | |
1548 case K_X2RELEASE: /* TODO */ return 0; | |
1549 | |
1550 case K_IGNORE: return 0; | |
1551 case K_NOP: return 0; | |
1552 case K_UNDO: return 0; | |
1553 case K_HELP: return 0; | |
1554 case K_XF1: key = VTERM_KEY_FUNCTION(1); break; | |
1555 case K_XF2: key = VTERM_KEY_FUNCTION(2); break; | |
1556 case K_XF3: key = VTERM_KEY_FUNCTION(3); break; | |
1557 case K_XF4: key = VTERM_KEY_FUNCTION(4); break; | |
1558 case K_SELECT: return 0; | |
1559 #ifdef FEAT_GUI | |
1560 case K_VER_SCROLLBAR: return 0; | |
1561 case K_HOR_SCROLLBAR: return 0; | |
1562 #endif | |
1563 #ifdef FEAT_GUI_TABLINE | |
1564 case K_TABLINE: return 0; | |
1565 case K_TABMENU: return 0; | |
1566 #endif | |
1567 #ifdef FEAT_NETBEANS_INTG | |
1568 case K_F21: key = VTERM_KEY_FUNCTION(21); break; | |
1569 #endif | |
1570 #ifdef FEAT_DND | |
1571 case K_DROP: return 0; | |
1572 #endif | |
1573 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
|
1574 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
|
1575 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
|
1576 break; |
15696054bc6c
patch 8.0.1299: bracketed paste does not work well in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12800
diff
changeset
|
1577 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
|
1578 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
|
1579 break; |
12502 | 1580 } |
1581 | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
1582 // 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
|
1583 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
|
1584 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
|
1585 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
|
1586 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
|
1587 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
|
1588 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
|
1589 |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
1590 // Ctrl-Shift-i may have the key "I" instead of "i", but for the kitty |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
1591 // keyboard protocol should use "i". Applies to all ascii letters. |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
1592 if (ASCII_ISUPPER(c) |
31213
d26436d305cc
patch 9.0.0940: crash when typing a letter in a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
31201
diff
changeset
|
1593 && vterm_is_kitty_keyboard(vterm) |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
1594 && mod == (VTERM_MOD_CTRL | VTERM_MOD_SHIFT)) |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
1595 c = TOLOWER_ASC(c); |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
1596 |
12502 | 1597 /* |
1598 * Convert special keys to vterm keys: | |
1599 * - Write keys to vterm: vterm_keyboard_key() | |
1600 * - Write output to channel. | |
1601 */ | |
1602 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
|
1603 // Special key, let vterm convert it. |
12502 | 1604 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
|
1605 else if (!other) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1606 // Normal character, let vterm convert it. |
12502 | 1607 vterm_keyboard_unichar(vterm, c, mod); |
1608 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1609 // Read back the converted escape sequence. |
12502 | 1610 return (int)vterm_output_read(vterm, buf, KEY_BUF_LEN); |
1611 } | |
1612 | |
1613 /* | |
1614 * 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
|
1615 * 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
|
1616 * 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
|
1617 */ |
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
|
1618 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
|
1619 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
|
1620 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1621 // 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
|
1622 // 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
|
1623 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
|
1624 && 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
|
1625 && 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
|
1626 { |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
1627 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
|
1628 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26598
diff
changeset
|
1629 // 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
|
1630 // 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
|
1631 // 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
|
1632 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
|
1633 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
|
1634 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
|
1635 || (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
|
1636 } |
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
|
1637 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
|
1638 } |
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
|
1639 |
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
|
1640 /* |
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
|
1641 * Return TRUE if the job for "term" is still running. |
12502 | 1642 */ |
1643 int | |
1644 term_job_running(term_T *term) | |
1645 { | |
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
|
1646 return term_job_running_check(term, FALSE); |
12502 | 1647 } |
1648 | |
1649 /* | |
29038
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1650 * Return TRUE if the job for "term" is still running, ignoring the job was |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1651 * "NONE". |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1652 */ |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1653 int |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1654 term_job_running_not_none(term_T *term) |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1655 { |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1656 return term_job_running(term) && !term_none_open(term); |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1657 } |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1658 |
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
1659 /* |
12502 | 1660 * Return TRUE if "term" has an active channel and used ":term NONE". |
1661 */ | |
1662 int | |
1663 term_none_open(term_T *term) | |
1664 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1665 // 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
|
1666 // race condition when updating the title. |
12502 | 1667 return term != NULL |
1668 && term->tl_job != NULL | |
1669 && channel_is_open(term->tl_job->jv_channel) | |
1670 && term->tl_job->jv_channel->ch_keep_open; | |
1671 } | |
1672 | |
30747
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1673 // |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1674 // Used to confirm whether we would like to kill a terminal. |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1675 // Return OK when the user confirms to kill it. |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1676 // Return FAIL if the user selects otherwise. |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1677 // |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1678 int |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1679 term_confirm_stop(buf_T *buf) |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1680 { |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1681 char_u buff[DIALOG_MSG_SIZE]; |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1682 int ret; |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1683 |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1684 dialog_msg(buff, _("Kill job in \"%s\"?"), buf_get_fname(buf)); |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1685 ret = vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1); |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1686 if (ret == VIM_YES) |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1687 return OK; |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1688 else |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1689 return FAIL; |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1690 } |
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1691 |
12502 | 1692 /* |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1693 * 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
|
1694 * 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
|
1695 * 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
|
1696 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1697 int |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1698 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
|
1699 { |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1700 int count; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1701 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
|
1702 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1703 #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
|
1704 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
|
1705 && (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
|
1706 { |
30747
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1707 if (term_confirm_stop(buf) == OK) |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1708 how = "kill"; |
30747
58592b6af4e2
patch 9.0.0708: :confirm does not work properly for a terminal buffer
Bram Moolenaar <Bram@vim.org>
parents:
30645
diff
changeset
|
1709 else |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1710 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1711 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1712 #endif |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1713 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
|
1714 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1715 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1716 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
|
1717 |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1718 // 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
|
1719 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
|
1720 { |
15679
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1721 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
|
1722 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1723 // 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
|
1724 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
|
1725 || 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
|
1726 || 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
|
1727 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
|
1728 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
|
1729 |
d8b4cbb14e1e
patch 8.1.0847: may use terminal after it was cleaned up
Bram Moolenaar <Bram@vim.org>
parents:
15675
diff
changeset
|
1730 // 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
|
1731 // 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
|
1732 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
|
1733 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
|
1734 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
|
1735 |
18420
3a3efaaa05c5
patch 8.1.2204: crash on exit when closing terminals
Bram Moolenaar <Bram@vim.org>
parents:
18402
diff
changeset
|
1736 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
|
1737 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
|
1738 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1739 return FAIL; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1740 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1741 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
1742 /* |
12502 | 1743 * Add the last line of the scrollback buffer to the buffer in the window. |
1744 */ | |
1745 static void | |
1746 add_scrollback_line_to_buffer(term_T *term, char_u *text, int len) | |
1747 { | |
1748 buf_T *buf = term->tl_buffer; | |
1749 int empty = (buf->b_ml.ml_flags & ML_EMPTY); | |
1750 linenr_T lnum = buf->b_ml.ml_line_count; | |
1751 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
1752 #ifdef MSWIN |
12502 | 1753 if (!enc_utf8 && enc_codepage > 0) |
1754 { | |
1755 WCHAR *ret = NULL; | |
1756 int length = 0; | |
1757 | |
1758 MultiByteToWideChar_alloc(CP_UTF8, 0, (char*)text, len + 1, | |
1759 &ret, &length); | |
1760 if (ret != NULL) | |
1761 { | |
1762 WideCharToMultiByte_alloc(enc_codepage, 0, | |
1763 ret, length, (char **)&text, &len, 0, 0); | |
1764 vim_free(ret); | |
1765 ml_append_buf(term->tl_buffer, lnum, text, len, FALSE); | |
1766 vim_free(text); | |
1767 } | |
1768 } | |
1769 else | |
1770 #endif | |
1771 ml_append_buf(term->tl_buffer, lnum, text, len + 1, FALSE); | |
1772 if (empty) | |
1773 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1774 // Delete the empty line that was in the empty buffer. |
12502 | 1775 curbuf = buf; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1776 ml_delete(1); |
12502 | 1777 curbuf = curwin->w_buffer; |
1778 } | |
1779 } | |
1780 | |
1781 static void | |
1782 cell2cellattr(const VTermScreenCell *cell, cellattr_T *attr) | |
1783 { | |
1784 attr->width = cell->width; | |
1785 attr->attrs = cell->attrs; | |
1786 attr->fg = cell->fg; | |
1787 attr->bg = cell->bg; | |
1788 } | |
1789 | |
1790 static int | |
1791 equal_celattr(cellattr_T *a, cellattr_T *b) | |
1792 { | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
1793 // 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
|
1794 // Thus black set explicitly is equal the background black. |
12502 | 1795 return a->fg.red == b->fg.red |
1796 && a->fg.green == b->fg.green | |
1797 && a->fg.blue == b->fg.blue | |
1798 && a->bg.red == b->bg.red | |
1799 && a->bg.green == b->bg.green | |
1800 && a->bg.blue == b->bg.blue; | |
1801 } | |
1802 | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1803 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1804 * 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
|
1805 * 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
|
1806 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1807 static int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1808 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
|
1809 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1810 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
|
1811 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1812 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
|
1813 + 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
|
1814 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1815 if (lnum > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1816 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1817 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1818 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1819 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
|
1820 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1821 *line = *(line - 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1822 --line; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1823 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1824 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1825 line->sb_cols = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1826 line->sb_cells = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1827 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
|
1828 ++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
|
1829 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1830 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1831 return FALSE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1832 } |
12502 | 1833 |
1834 /* | |
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
|
1835 * 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
|
1836 * 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
|
1837 * 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
|
1838 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1839 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
|
1840 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
|
1841 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1842 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
|
1843 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
|
1844 |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1845 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
|
1846 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
|
1847 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
|
1848 && 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
|
1849 { |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1850 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
|
1851 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
|
1852 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
|
1853 --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
|
1854 } |
13894
3969c9d3a859
patch 8.0.1818: lines remove from wrong buffer when using terminal window
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1855 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
|
1856 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
|
1857 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
|
1858 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1859 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1860 /* |
12502 | 1861 * Add the current lines of the terminal to scrollback and to the buffer. |
1862 */ | |
1863 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
|
1864 update_snapshot(term_T *term) |
12502 | 1865 { |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1866 VTermScreen *screen; |
12502 | 1867 int len; |
1868 int lines_skipped = 0; | |
1869 VTermPos pos; | |
1870 VTermScreenCell cell; | |
1871 cellattr_T fill_attr, new_fill_attr; | |
1872 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
|
1873 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
1874 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
|
1875 "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
|
1876 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1877 // 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
|
1878 // 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
|
1879 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
|
1880 |
12502 | 1881 screen = vterm_obtain_screen(term->tl_vterm); |
1882 fill_attr = new_fill_attr = term->tl_default_color; | |
1883 for (pos.row = 0; pos.row < term->tl_rows; ++pos.row) | |
1884 { | |
1885 len = 0; | |
1886 for (pos.col = 0; pos.col < term->tl_cols; ++pos.col) | |
1887 if (vterm_screen_get_cell(screen, pos, &cell) != 0 | |
1888 && cell.chars[0] != NUL) | |
1889 { | |
1890 len = pos.col + 1; | |
1891 new_fill_attr = term->tl_default_color; | |
1892 } | |
1893 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1894 // Assume the last attr is the filler attr. |
12502 | 1895 cell2cellattr(&cell, &new_fill_attr); |
1896 | |
1897 if (len == 0 && equal_celattr(&new_fill_attr, &fill_attr)) | |
1898 ++lines_skipped; | |
1899 else | |
1900 { | |
1901 while (lines_skipped > 0) | |
1902 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
1903 // Line was skipped, add an empty line. |
12502 | 1904 --lines_skipped; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
1905 if (add_empty_scrollback(term, &fill_attr, 0) == OK) |
12502 | 1906 add_scrollback_line_to_buffer(term, (char_u *)"", 0); |
1907 } | |
1908 | |
1909 if (len == 0) | |
1910 p = NULL; | |
1911 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
|
1912 p = ALLOC_MULT(cellattr_T, len); |
12502 | 1913 if ((p != NULL || len == 0) |
1914 && ga_grow(&term->tl_scrollback, 1) == OK) | |
1915 { | |
1916 garray_T ga; | |
1917 int width; | |
1918 sb_line_T *line = (sb_line_T *)term->tl_scrollback.ga_data | |
1919 + term->tl_scrollback.ga_len; | |
1920 | |
1921 ga_init2(&ga, 1, 100); | |
1922 for (pos.col = 0; pos.col < len; pos.col += width) | |
1923 { | |
1924 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | |
1925 { | |
1926 width = 1; | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
1927 CLEAR_POINTER(p + pos.col); |
12502 | 1928 if (ga_grow(&ga, 1) == OK) |
1929 ga.ga_len += utf_char2bytes(' ', | |
1930 (char_u *)ga.ga_data + ga.ga_len); | |
1931 } | |
1932 else | |
1933 { | |
1934 width = cell.width; | |
1935 | |
1936 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
|
1937 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
|
1938 // 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
|
1939 // 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
|
1940 p[pos.col + 1] = p[pos.col]; |
12502 | 1941 |
15203
aa877e0b7f62
patch 8.1.0611: crash when using terminal with long composing characters
Bram Moolenaar <Bram@vim.org>
parents:
15146
diff
changeset
|
1942 // 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
|
1943 if (ga_grow(&ga, VTERM_MAX_CHARS_PER_CELL * 6) == OK) |
12502 | 1944 { |
1945 int i; | |
1946 int c; | |
1947 | |
1948 for (i = 0; (c = cell.chars[i]) > 0 || i == 0; ++i) | |
1949 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
1950 (char_u *)ga.ga_data + ga.ga_len); | |
1951 } | |
1952 } | |
1953 } | |
1954 line->sb_cols = len; | |
1955 line->sb_cells = p; | |
1956 line->sb_fill_attr = new_fill_attr; | |
1957 fill_attr = new_fill_attr; | |
1958 ++term->tl_scrollback.ga_len; | |
1959 | |
1960 if (ga_grow(&ga, 1) == FAIL) | |
1961 add_scrollback_line_to_buffer(term, (char_u *)"", 0); | |
1962 else | |
1963 { | |
1964 *((char_u *)ga.ga_data + ga.ga_len) = NUL; | |
1965 add_scrollback_line_to_buffer(term, ga.ga_data, ga.ga_len); | |
1966 } | |
1967 ga_clear(&ga); | |
1968 } | |
1969 else | |
1970 vim_free(p); | |
1971 } | |
1972 } | |
1973 | |
15022
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1974 // 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
|
1975 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
|
1976 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
|
1977 ++pos.row) |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1978 { |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1979 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
|
1980 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
|
1981 } |
f3b4cd98944c
patch 8.1.0522: :terminal does not show trailing empty lines
Bram Moolenaar <Bram@vim.org>
parents:
14960
diff
changeset
|
1982 |
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
|
1983 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
|
1984 #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
|
1985 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
|
1986 #endif |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1987 } |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1988 |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
1989 /* |
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
|
1990 * 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
|
1991 * 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
|
1992 * 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
|
1993 */ |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1994 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
|
1995 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
|
1996 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
1997 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
|
1998 *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
|
1999 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
|
2000 *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
|
2001 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
|
2002 *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
|
2003 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
|
2004 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
|
2005 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
|
2006 *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
|
2007 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
|
2008 } |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2009 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2010 /* |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
2011 * 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
|
2012 * 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
|
2013 * 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
|
2014 * 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
|
2015 */ |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
2016 static void |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
2017 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
|
2018 { |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
2019 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
|
2020 return; |
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
2021 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2022 // 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
|
2023 // 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
|
2024 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
|
2025 <= 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
|
2026 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
|
2027 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2028 // Obtain the current background color. |
12502 | 2029 vterm_state_get_default_colors(vterm_obtain_state(term->tl_vterm), |
2030 &term->tl_default_color.fg, &term->tl_default_color.bg); | |
2031 | |
13919
bfca3dbdbf9e
patch 8.0.1830: switching to Terminal-Normal mode does not redraw
Christian Brabandt <cb@256bit.org>
parents:
13906
diff
changeset
|
2032 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
|
2033 { |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2034 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
|
2035 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
|
2036 |
9e428147e4ee
patch 8.2.0328: no redraw when leaving term-normal mode in popup terminal
Bram Moolenaar <Bram@vim.org>
parents:
19513
diff
changeset
|
2037 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 2038 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2039 if (wp->w_buffer == term->tl_buffer) |
12502 | 2040 { |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2041 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
|
2042 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
|
2043 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
|
2044 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
|
2045 { |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2046 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
|
2047 |
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2048 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
|
2049 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
|
2050 } |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
2051 redraw_win_later(wp, UPD_NOT_VALID); |
12502 | 2052 } |
2053 } | |
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
|
2054 } |
12502 | 2055 } |
2056 | |
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
|
2057 #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
|
2058 /* |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2059 * 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
|
2060 * 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
|
2061 * 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
|
2062 */ |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2063 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
|
2064 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
|
2065 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2066 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
|
2067 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
|
2068 |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
2069 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
|
2070 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2071 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
|
2072 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2073 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
|
2074 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2075 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
|
2076 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2077 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
|
2078 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
|
2079 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2080 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
|
2081 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
|
2082 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2083 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2084 |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2085 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
|
2086 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
2087 #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
|
2088 |
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
|
2089 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
2090 * 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
|
2091 * 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
|
2092 */ |
12502 | 2093 static void |
2094 set_terminal_mode(term_T *term, int normal_mode) | |
2095 { | |
2096 term->tl_normal_mode = normal_mode; | |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
28315
diff
changeset
|
2097 may_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
|
2098 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
|
2099 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
|
2100 VIM_CLEAR(term->tl_status_text); |
12502 | 2101 if (term->tl_buffer == curbuf) |
2102 maketitle(); | |
2103 } | |
2104 | |
2105 /* | |
20176
901dc0e81e0b
patch 8.2.0643: terminal uses brown instead of dark yellow
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2106 * Called after the job is finished and Terminal mode is not active: |
12502 | 2107 * Move the vterm contents into the scrollback buffer and free the vterm. |
2108 */ | |
2109 static void | |
2110 cleanup_vterm(term_T *term) | |
2111 { | |
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
|
2112 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
|
2113 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
|
2114 may_move_terminal_to_buffer(term, TRUE); |
12502 | 2115 term_free_vterm(term); |
2116 } | |
2117 | |
2118 /* | |
2119 * Switch from Terminal-Job mode to Terminal-Normal mode. | |
2120 * Suspends updating the terminal window. | |
2121 */ | |
2122 static void | |
2123 term_enter_normal_mode(void) | |
2124 { | |
2125 term_T *term = curbuf->b_term; | |
2126 | |
13900
f71ed35527eb
patch 8.0.1821: cursor in terminal window moves when pressing CTRL-W
Christian Brabandt <cb@256bit.org>
parents:
13894
diff
changeset
|
2127 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
|
2128 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2129 // 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
|
2130 may_move_terminal_to_buffer(term, TRUE); |
12502 | 2131 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2132 // 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
|
2133 // terminal. |
12502 | 2134 curwin->w_cursor.lnum = term->tl_scrollback_scrolled |
2135 + term->tl_cursor_pos.row + 1; | |
2136 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
|
2137 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
|
2138 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
|
2139 curwin->w_set_curswant = TRUE; |
12502 | 2140 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2141 // Display the same lines as in the terminal. |
12502 | 2142 curwin->w_topline = term->tl_scrollback_scrolled + 1; |
2143 } | |
2144 | |
2145 /* | |
2146 * Returns TRUE if the current window contains a terminal and we are in | |
2147 * Terminal-Normal mode. | |
2148 */ | |
2149 int | |
2150 term_in_normal_mode(void) | |
2151 { | |
2152 term_T *term = curbuf->b_term; | |
2153 | |
2154 return term != NULL && term->tl_normal_mode; | |
2155 } | |
2156 | |
2157 /* | |
2158 * Switch from Terminal-Normal mode to Terminal-Job mode. | |
2159 * Restores updating the terminal window. | |
2160 */ | |
2161 void | |
2162 term_enter_job_mode() | |
2163 { | |
2164 term_T *term = curbuf->b_term; | |
2165 | |
2166 set_terminal_mode(term, FALSE); | |
2167 | |
2168 if (term->tl_channel_closed) | |
2169 cleanup_vterm(term); | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
2170 redraw_buf_and_status_later(curbuf, UPD_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
|
2171 #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
|
2172 if (WIN_IS_POPUP(curwin)) |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
2173 redraw_later(UPD_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
|
2174 #endif |
12502 | 2175 } |
2176 | |
2177 /* | |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2178 * When "modify_other_keys" is set then vgetc() should not reduce a key with |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2179 * modifiers into a basic key. However, we may only find out after calling |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2180 * vgetc(). Therefore vgetorpeek() will call check_no_reduce_keys() to update |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2181 * "no_reduce_keys" before using it. |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2182 */ |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2183 typedef enum { |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2184 NRKS_NONE, // initial value |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2185 NRKS_CHECK, // modify_other_keys was off before calling vgetc() |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2186 NRKS_SET, // no_reduce_keys was incremented in term_vgetc() or |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2187 // check_no_reduce_keys(), must be decremented. |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2188 } reduce_key_state_T; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2189 |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2190 static reduce_key_state_T no_reduce_key_state = NRKS_NONE; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2191 |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2192 /* |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2193 * Return TRUE if the term is using modifyOtherKeys level 2 or the kitty |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2194 * keyboard protocol. |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2195 */ |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2196 static int |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2197 vterm_using_key_protocol(void) |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2198 { |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2199 return curbuf->b_term != NULL |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2200 && curbuf->b_term->tl_vterm != NULL |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2201 && (vterm_is_modify_other_keys(curbuf->b_term->tl_vterm) |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2202 || vterm_is_kitty_keyboard(curbuf->b_term->tl_vterm)); |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2203 } |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2204 |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2205 void |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2206 check_no_reduce_keys(void) |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2207 { |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2208 if (no_reduce_key_state != NRKS_CHECK |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2209 || no_reduce_keys >= 1 |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2210 || curbuf->b_term == NULL |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2211 || curbuf->b_term->tl_vterm == NULL) |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2212 return; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2213 |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2214 if (vterm_using_key_protocol()) |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2215 { |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2216 // "modify_other_keys" or kitty keyboard protocol was enabled while |
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2217 // waiting. |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2218 no_reduce_key_state = NRKS_SET; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2219 ++no_reduce_keys; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2220 } |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2221 } |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2222 |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2223 /* |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2224 * Get a key from the user with terminal mode mappings. |
12502 | 2225 * 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
|
2226 * closed and ++close was used. This may even happen before we get here. |
12502 | 2227 */ |
2228 static int | |
2229 term_vgetc() | |
2230 { | |
2231 int c; | |
2232 int save_State = State; | |
2233 | |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28769
diff
changeset
|
2234 State = MODE_TERMINAL; |
12502 | 2235 got_int = FALSE; |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2236 #ifdef MSWIN |
12502 | 2237 ctrl_break_was_pressed = FALSE; |
2238 #endif | |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2239 |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2240 if (vterm_using_key_protocol()) |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2241 { |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2242 ++no_reduce_keys; |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2243 no_reduce_key_state = NRKS_SET; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2244 } |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2245 else |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2246 { |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2247 no_reduce_key_state = NRKS_CHECK; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2248 } |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2249 |
12502 | 2250 c = vgetc(); |
2251 got_int = FALSE; | |
2252 State = save_State; | |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2253 |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2254 if (no_reduce_key_state == NRKS_SET) |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2255 --no_reduce_keys; |
31156
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2256 no_reduce_key_state = NRKS_NONE; |
0ecb16d5f86f
patch 9.0.0912: libvterm with modifyOtherKeys level 2 does not match xterm
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
2257 |
12502 | 2258 return c; |
2259 } | |
2260 | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2261 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
|
2262 |
12502 | 2263 /* |
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
|
2264 * Send key "c" with modifiers "modmask" to terminal. |
12502 | 2265 * Return FAIL when the key needs to be handled in Normal mode. |
2266 * Return OK when the key was dropped or sent to the terminal. | |
2267 */ | |
2268 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
|
2269 send_keys_to_term(term_T *term, int c, int modmask, int typed) |
12502 | 2270 { |
2271 char msg[KEY_BUF_LEN]; | |
2272 size_t len; | |
2273 int dragging_outside = FALSE; | |
2274 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2275 // Catch keys that need to be handled as in Normal mode. |
12502 | 2276 switch (c) |
2277 { | |
2278 case NUL: | |
2279 case K_ZERO: | |
2280 if (typed) | |
2281 stuffcharReadbuff(c); | |
2282 return FAIL; | |
2283 | |
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
|
2284 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
|
2285 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
|
2286 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
|
2287 |
12502 | 2288 case K_IGNORE: |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2289 case K_CANCEL: // used for :normal when running out of chars |
12502 | 2290 return FAIL; |
2291 | |
2292 case K_LEFTDRAG: | |
2293 case K_MIDDLEDRAG: | |
2294 case K_RIGHTDRAG: | |
2295 case K_X1DRAG: | |
2296 case K_X2DRAG: | |
2297 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
|
2298 // FALLTHROUGH |
12502 | 2299 case K_LEFTMOUSE: |
2300 case K_LEFTMOUSE_NM: | |
2301 case K_LEFTRELEASE: | |
2302 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
|
2303 case K_MOUSEMOVE: |
12502 | 2304 case K_MIDDLEMOUSE: |
2305 case K_MIDDLERELEASE: | |
2306 case K_RIGHTMOUSE: | |
2307 case K_RIGHTRELEASE: | |
2308 case K_X1MOUSE: | |
2309 case K_X1RELEASE: | |
2310 case K_X2MOUSE: | |
2311 case K_X2RELEASE: | |
2312 | |
2313 case K_MOUSEUP: | |
2314 case K_MOUSEDOWN: | |
2315 case K_MOUSELEFT: | |
2316 case K_MOUSERIGHT: | |
2317 { | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2318 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
|
2319 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
|
2320 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2321 #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
|
2322 if (popup_is_popup(curwin)) |
12502 | 2323 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2324 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
|
2325 col -= popup_left_extra(curwin); |
12502 | 2326 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2327 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2328 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
|
2329 || 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
|
2330 || 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
|
2331 || 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
|
2332 || dragging_outside) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2333 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2334 // 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
|
2335 // 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
|
2336 if (typed) |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2337 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2338 stuffcharReadbuff(c); |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2339 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
|
2340 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2341 return FAIL; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
2342 } |
12502 | 2343 } |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2344 break; |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2345 |
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22832
diff
changeset
|
2346 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
|
2347 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
|
2348 return do_cmdkey_command(c, 0); |
12502 | 2349 } |
2350 if (typed) | |
2351 mouse_was_outside = FALSE; | |
2352 | |
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
|
2353 // 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
|
2354 len = term_convert_key(term, c, modmask, msg); |
12502 | 2355 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
|
2356 // TODO: if FAIL is returned, stop? |
12502 | 2357 channel_send(term->tl_job->jv_channel, get_tty_part(term), |
2358 (char_u *)msg, (int)len, NULL); | |
2359 | |
2360 return OK; | |
2361 } | |
2362 | |
2363 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
|
2364 position_cursor(win_T *wp, VTermPos *pos) |
12502 | 2365 { |
2366 wp->w_wrow = MIN(pos->row, MAX(0, wp->w_height - 1)); | |
2367 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
|
2368 #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
|
2369 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
|
2370 { |
23041
139573353c6d
patch 8.2.2067: cursor position in popup terminal is wrong
Bram Moolenaar <Bram@vim.org>
parents:
23035
diff
changeset
|
2371 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
|
2372 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
|
2373 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
|
2374 } |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2375 else |
38324d4f1c94
patch 8.2.1990: cursor position wrong in terminal popup with finished job
Bram Moolenaar <Bram@vim.org>
parents:
22876
diff
changeset
|
2376 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
|
2377 #endif |
12502 | 2378 wp->w_valid |= (VALID_WCOL|VALID_WROW); |
2379 } | |
2380 | |
2381 /* | |
2382 * Handle CTRL-W "": send register contents to the job. | |
2383 */ | |
2384 static void | |
2385 term_paste_register(int prev_c UNUSED) | |
2386 { | |
2387 int c; | |
2388 list_T *l; | |
2389 listitem_T *item; | |
2390 long reglen = 0; | |
2391 int type; | |
2392 | |
2393 if (add_to_showcmd(prev_c)) | |
2394 if (add_to_showcmd('"')) | |
2395 out_flush(); | |
30825
c7983f593fa7
patch 9.0.0747: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30747
diff
changeset
|
2396 |
12502 | 2397 c = term_vgetc(); |
2398 clear_showcmd(); | |
30825
c7983f593fa7
patch 9.0.0747: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30747
diff
changeset
|
2399 |
12502 | 2400 if (!term_use_loop()) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2401 // job finished while waiting for a character |
12502 | 2402 return; |
2403 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2404 // CTRL-W "= prompt for expression to evaluate. |
12502 | 2405 if (c == '=' && get_expr_register() != '=') |
2406 return; | |
2407 if (!term_use_loop()) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2408 // job finished while waiting for a character |
12502 | 2409 return; |
2410 | |
2411 l = (list_T *)get_reg_contents(c, GREG_LIST); | |
2412 if (l != NULL) | |
2413 { | |
2414 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
|
2415 FOR_ALL_LIST_ITEMS(l, item) |
12502 | 2416 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
2417 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
|
2418 #ifdef MSWIN |
12502 | 2419 char_u *tmp = s; |
2420 | |
2421 if (!enc_utf8 && enc_codepage > 0) | |
2422 { | |
2423 WCHAR *ret = NULL; | |
2424 int length = 0; | |
2425 | |
2426 MultiByteToWideChar_alloc(enc_codepage, 0, (char *)s, | |
2427 (int)STRLEN(s), &ret, &length); | |
2428 if (ret != NULL) | |
2429 { | |
2430 WideCharToMultiByte_alloc(CP_UTF8, 0, | |
2431 ret, length, (char **)&s, &length, 0, 0); | |
2432 vim_free(ret); | |
2433 } | |
2434 } | |
2435 #endif | |
2436 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2437 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
|
2438 #ifdef MSWIN |
12502 | 2439 if (tmp != s) |
2440 vim_free(s); | |
2441 #endif | |
2442 | |
2443 if (item->li_next != NULL || type == MLINE) | |
2444 channel_send(curbuf->b_term->tl_job->jv_channel, PART_IN, | |
2445 (char_u *)"\r", 1, NULL); | |
2446 } | |
2447 list_free(l); | |
2448 } | |
2449 } | |
2450 | |
2451 /* | |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2452 * 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
|
2453 * terminal should be displayed. |
12502 | 2454 */ |
2455 int | |
2456 terminal_is_active() | |
2457 { | |
2458 return in_terminal_loop != NULL; | |
2459 } | |
2460 | |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2461 /* |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30880
diff
changeset
|
2462 * Return the highlight 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
|
2463 */ |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2464 static int |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2465 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
|
2466 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2467 char_u *name; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2468 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2469 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
|
2470 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
|
2471 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
|
2472 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
|
2473 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2474 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
|
2475 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2476 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
|
2477 } |
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2478 |
13829
044337cbf854
patch 8.0.1786: no test for 'termwinkey'
Christian Brabandt <cb@256bit.org>
parents:
13823
diff
changeset
|
2479 #if defined(FEAT_GUI) || defined(PROTO) |
12502 | 2480 cursorentry_T * |
2481 term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg) | |
2482 { | |
2483 term_T *term = in_terminal_loop; | |
2484 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
|
2485 int id; |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2486 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
|
2487 guicolor_T term_bg = INVALCOLOR; |
12502 | 2488 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2489 CLEAR_FIELD(entry); |
12502 | 2490 entry.shape = entry.mshape = |
2491 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR : | |
2492 term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER : | |
2493 SHAPE_BLOCK; | |
2494 entry.percentage = 20; | |
2495 if (term->tl_cursor_blink) | |
2496 { | |
2497 entry.blinkwait = 700; | |
2498 entry.blinkon = 400; | |
2499 entry.blinkoff = 250; | |
2500 } | |
14939
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2501 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
2502 // 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
|
2503 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
|
2504 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
|
2505 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
|
2506 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
|
2507 *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
|
2508 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2509 *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
|
2510 |
12502 | 2511 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
|
2512 { |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2513 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
|
2514 *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
|
2515 else |
c085c4cd9bba
patch 8.1.0481: when "Terminal" highlight is reverted cursor doesn't show
Bram Moolenaar <Bram@vim.org>
parents:
14691
diff
changeset
|
2516 *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
|
2517 } |
12502 | 2518 else |
2519 *bg = color_name2handle(term->tl_cursor_color); | |
2520 entry.name = "n"; | |
2521 entry.used_for = SHAPE_CURSOR; | |
2522 | |
2523 return &entry; | |
2524 } | |
2525 #endif | |
2526 | |
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
|
2527 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
|
2528 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
|
2529 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2530 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
|
2531 || 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
|
2532 || 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
|
2533 { |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2534 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
|
2535 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
|
2536 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
|
2537 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
|
2538 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
|
2539 // 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
|
2540 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
|
2541 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
|
2542 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
|
2543 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2544 } |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2545 |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2546 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2547 * 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
|
2548 */ |
12502 | 2549 static void |
2550 may_set_cursor_props(term_T *term) | |
2551 { | |
2552 #ifdef FEAT_GUI | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2553 // 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
|
2554 // term_get_cursor_shape(). |
12502 | 2555 if (gui.in_use) |
2556 return; | |
2557 #endif | |
2558 if (in_terminal_loop == term) | |
2559 { | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2560 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
|
2561 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
|
2562 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
|
2563 may_output_cursor_props(); |
12502 | 2564 } |
2565 } | |
2566 | |
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
|
2567 /* |
53f0c469dfc6
patch 8.0.1477: redraw flicker when moving the mouse outside of terminal window
Christian Brabandt <cb@256bit.org>
parents:
13132
diff
changeset
|
2568 * 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
|
2569 */ |
12502 | 2570 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
|
2571 prepare_restore_cursor_props(void) |
12502 | 2572 { |
2573 #ifdef FEAT_GUI | |
2574 if (gui.in_use) | |
2575 return; | |
2576 #endif | |
13990
017c5462ed5e
patch 8.1.0013: using freed memory when changing terminal cursor color
Christian Brabandt <cb@256bit.org>
parents:
13961
diff
changeset
|
2577 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
|
2578 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
|
2579 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
|
2580 may_output_cursor_props(); |
12502 | 2581 } |
2582 | |
2583 /* | |
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
|
2584 * 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
|
2585 * 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
|
2586 * 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
|
2587 */ |
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
|
2588 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
|
2589 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
|
2590 { |
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
|
2591 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
|
2592 |
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
|
2593 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
|
2594 && !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
|
2595 && 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
|
2596 && 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
|
2597 } |
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
|
2598 |
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
|
2599 /* |
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
|
2600 * 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
|
2601 * 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
|
2602 */ |
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
|
2603 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
|
2604 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
|
2605 { |
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
|
2606 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
|
2607 } |
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
|
2608 |
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
|
2609 /* |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2610 * 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
|
2611 * 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
|
2612 */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2613 void |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2614 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
|
2615 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2616 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
|
2617 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2618 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
|
2619 { |
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
|
2620 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
|
2621 { |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2622 reset_VIsual_and_resel(); |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28769
diff
changeset
|
2623 if (State & MODE_INSERT) |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2624 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
|
2625 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2626 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
|
2627 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
|
2628 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
|
2629 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2630 } |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2631 |
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
|
2632 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
|
2633 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
|
2634 { |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2635 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
|
2636 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2637 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
|
2638 { |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2639 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
|
2640 |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2641 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
|
2642 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
|
2643 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
|
2644 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
|
2645 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
|
2646 } |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2647 } |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26270
diff
changeset
|
2648 |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13444
diff
changeset
|
2649 /* |
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
|
2650 * 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
|
2651 * 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
|
2652 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2653 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
|
2654 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
|
2655 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2656 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
|
2657 && ((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
|
2658 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
|
2659 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
|
2660 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2661 |
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 /* |
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 * When modify_other_keys is set then do the reverse of raw_c_to_ctrl(). |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2664 * Also when the Kitty keyboard protocol is used. |
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
|
2665 * 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
|
2666 */ |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2667 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
|
2668 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
|
2669 { |
31192
dcde141f2d1e
patch 9.0.0930: cannot debug the Kitty keyboard protocol with TermDebug
Bram Moolenaar <Bram@vim.org>
parents:
31156
diff
changeset
|
2670 if (c < 0x20 && vterm_using_key_protocol()) |
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
|
2671 { |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2672 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
|
2673 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
|
2674 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2675 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
|
2676 } |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2677 |
3cd689e9eb7f
patch 8.1.2248: CTRL-W dot does not work when modifyOtherKeys is enabled
Bram Moolenaar <Bram@vim.org>
parents:
18450
diff
changeset
|
2678 /* |
12502 | 2679 * Wait for input and send it to the job. |
2680 * When "blocking" is TRUE wait for a character to be typed. Otherwise return | |
2681 * when there is no more typahead. | |
2682 * Return when the start of a CTRL-W command is typed or anything else that | |
2683 * should be handled as a Normal mode command. | |
2684 * Returns OK if a typed character is to be handled in Normal mode, FAIL if | |
2685 * the terminal was closed. | |
2686 */ | |
2687 int | |
2688 terminal_loop(int blocking) | |
2689 { | |
2690 int c; | |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
2691 int raw_c; |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2692 int termwinkey = 0; |
12502 | 2693 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
|
2694 #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
|
2695 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
|
2696 ->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
|
2697 #endif |
13906
0ae89b121c58
patch 8.0.1824: Coverity warns for variable that may be uninitialized
Christian Brabandt <cb@256bit.org>
parents:
13900
diff
changeset
|
2698 int restore_cursor = FALSE; |
12502 | 2699 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2700 // 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
|
2701 // 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
|
2702 // 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
|
2703 // stored reference. |
12502 | 2704 in_terminal_loop = curbuf->b_term; |
2705 | |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2706 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
|
2707 { |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2708 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
|
2709 if (termwinkey == Ctrl_W) |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2710 termwinkey = 0; |
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2711 } |
23035
fabd80ec9620
patch 8.2.2064: terminal: cursor is on while redrawing, causing flicker
Bram Moolenaar <Bram@vim.org>
parents:
23029
diff
changeset
|
2712 position_cursor(curwin, &curbuf->b_term->tl_cursor_pos); |
12502 | 2713 may_set_cursor_props(curbuf->b_term); |
2714 | |
13344
68c4fc9ae216
patch 8.0.1546: using feedkeys() in a terminal may trigger mappings
Christian Brabandt <cb@256bit.org>
parents:
13335
diff
changeset
|
2715 while (blocking || vpeekc_nomap() != NUL) |
12502 | 2716 { |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
2717 #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
|
2718 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
|
2719 #endif |
15675
01890a3caefd
patch 8.1.0845: having job_status() free the job causes problems
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
2720 // 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
|
2721 // 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
|
2722 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
|
2723 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
|
2724 break; |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2725 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
|
2726 // 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
|
2727 break; |
bbf5bdba4a80
patch 8.0.1814: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13878
diff
changeset
|
2728 |
12502 | 2729 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
|
2730 restore_cursor = TRUE; |
12502 | 2731 |
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
|
2732 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
|
2733 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
|
2734 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2735 // 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
|
2736 // 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
|
2737 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
|
2738 vungetc(raw_c); |
12502 | 2739 break; |
12798
5ae0d05e046a
patch 8.0.1276: key lost when window closed in exit callback
Christian Brabandt <cb@256bit.org>
parents:
12767
diff
changeset
|
2740 } |
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
|
2741 if (raw_c == K_IGNORE) |
12502 | 2742 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
|
2743 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
|
2744 |
12800
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2745 #ifdef UNIX |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2746 /* |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2747 * 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
|
2748 * 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
|
2749 * 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
|
2750 */ |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2751 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
|
2752 { |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2753 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
|
2754 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2755 // 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
|
2756 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
|
2757 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
|
2758 } |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2759 #endif |
8dfeed7e07e7
patch 8.0.1277: terminal window CR-NL conversions may cause problems
Christian Brabandt <cb@256bit.org>
parents:
12798
diff
changeset
|
2760 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2761 #ifdef MSWIN |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2762 // 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
|
2763 // Use CTRL-BREAK to kill the job. |
12502 | 2764 if (ctrl_break_was_pressed) |
2765 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); | |
2766 #endif | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2767 // 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
|
2768 // 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
|
2769 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
|
2770 #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
|
2771 && !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
|
2772 #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
|
2773 ) |
12502 | 2774 { |
2775 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
|
2776 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
|
2777 int prev_mod_mask = mod_mask; |
12502 | 2778 |
2779 if (add_to_showcmd(c)) | |
2780 out_flush(); | |
30825
c7983f593fa7
patch 9.0.0747: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30747
diff
changeset
|
2781 |
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
|
2782 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
|
2783 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
|
2784 |
12502 | 2785 clear_showcmd(); |
30825
c7983f593fa7
patch 9.0.0747: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
30747
diff
changeset
|
2786 |
13994
411dd50f1daa
patch 8.1.0015: cursor color wrong when closing a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13990
diff
changeset
|
2787 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
|
2788 || 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
|
2789 // job finished while waiting for a character |
12502 | 2790 break; |
2791 | |
2792 if (prev_c == Ctrl_BSL) | |
2793 { | |
2794 if (c == Ctrl_N) | |
2795 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2796 // CTRL-\ CTRL-N : go to Terminal-Normal mode. |
12502 | 2797 term_enter_normal_mode(); |
2798 ret = FAIL; | |
2799 goto theend; | |
2800 } | |
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
|
2801 // 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
|
2802 // 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
|
2803 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
|
2804 TRUE); |
12502 | 2805 } |
2806 else if (c == Ctrl_C) | |
2807 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2808 // "CTRL-W CTRL-C" or 'termwinkey' CTRL-C: end the job |
12502 | 2809 mch_signal_job(curbuf->b_term->tl_job, (char_u *)"kill"); |
2810 } | |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2811 else if (c == '.') |
12502 | 2812 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2813 // "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
|
2814 // "'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
|
2815 raw_c = ctrl_to_raw_c(termwinkey == 0 ? Ctrl_W : termwinkey); |
12502 | 2816 } |
14109
279465096a16
patch 8.1.0072: use of 'termwinkey' is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14065
diff
changeset
|
2817 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
|
2818 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2819 // "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
|
2820 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
|
2821 } |
12502 | 2822 else if (c == 'N') |
2823 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2824 // CTRL-W N : go to Terminal-Normal mode. |
12502 | 2825 term_enter_normal_mode(); |
2826 ret = FAIL; | |
2827 goto theend; | |
2828 } | |
2829 else if (c == '"') | |
2830 { | |
2831 term_paste_register(prev_c); | |
2832 continue; | |
2833 } | |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
2834 else if (termwinkey == 0 || c != termwinkey) |
12502 | 2835 { |
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
|
2836 // 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
|
2837 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
|
2838 |
ba18f78c8529
patch 8.1.1848: 'langmap' is not used for CTRL-W command in terminal
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
2839 // 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
|
2840 // 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
|
2841 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
|
2842 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
|
2843 ins_typebuf(buf, REMAP_NONE, 0, TRUE, FALSE); |
12502 | 2844 ret = OK; |
2845 goto theend; | |
2846 } | |
2847 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
2848 # 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
|
2849 if (!enc_utf8 && has_mbyte && raw_c >= 0x80) |
12502 | 2850 { |
2851 WCHAR wc; | |
2852 char_u mb[3]; | |
2853 | |
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
|
2854 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
|
2855 mb[1] = raw_c; |
12502 | 2856 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
|
2857 raw_c = wc; |
12502 | 2858 } |
2859 # 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
|
2860 if (send_keys_to_term(curbuf->b_term, raw_c, mod_mask, TRUE) != OK) |
12502 | 2861 { |
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
|
2862 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
|
2863 // 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
|
2864 // 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
|
2865 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
|
2866 |
12502 | 2867 ret = OK; |
2868 goto theend; | |
2869 } | |
2870 } | |
2871 ret = FAIL; | |
2872 | |
2873 theend: | |
2874 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
|
2875 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
|
2876 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
|
2877 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2878 // 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
|
2879 // 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
|
2880 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
|
2881 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
|
2882 |
12502 | 2883 return ret; |
2884 } | |
2885 | |
2886 static void | |
2887 may_toggle_cursor(term_T *term) | |
2888 { | |
2889 if (in_terminal_loop == term) | |
2890 { | |
2891 if (term->tl_cursor_visible) | |
2892 cursor_on(); | |
2893 else | |
2894 cursor_off(); | |
2895 } | |
2896 } | |
2897 | |
2898 /* | |
2899 * 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
|
2900 * First color is 1. Return 0 if no match found (default color). |
12502 | 2901 */ |
2902 static int | |
2903 color2index(VTermColor *color, int fg, int *boldp) | |
2904 { | |
2905 int red = color->red; | |
2906 int blue = color->blue; | |
2907 int green = color->green; | |
2908 | |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2909 *boldp = FALSE; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2910 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2911 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
|
2912 return 0; |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2913 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
2914 if (VTERM_COLOR_IS_INDEXED(color)) |
12502 | 2915 { |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2916 // Use the color as-is if possible, give up otherwise. |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2917 if (color->index < t_colors) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2918 return color->index + 1; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2919 // 8-color terminals can actually display twice as many colors by |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2920 // setting the high-intensity/bold bit. |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2921 else if (t_colors == 8 && fg && color->index < 16) |
12502 | 2922 { |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2923 *boldp = TRUE; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2924 return (color->index & 7) + 1; |
12502 | 2925 } |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2926 return 0; |
12502 | 2927 } |
12966
c5bccd50100e
patch 8.0.1359: libvterm ANSI colors can not always be recognized
Christian Brabandt <cb@256bit.org>
parents:
12907
diff
changeset
|
2928 |
12502 | 2929 if (t_colors >= 256) |
2930 { | |
2931 if (red == blue && red == green) | |
2932 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2933 // 24-color greyscale plus white and black |
12502 | 2934 static int cutoff[23] = { |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2935 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
|
2936 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
|
2937 0xD5, 0xDF, 0xE9}; |
12502 | 2938 int i; |
2939 | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2940 if (red < 5) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2941 return 17; // 00/00/00 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2942 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
|
2943 return 232; |
12502 | 2944 for (i = 0; i < 23; ++i) |
2945 if (red < cutoff[i]) | |
2946 return i + 233; | |
2947 return 256; | |
2948 } | |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2949 { |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2950 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
|
2951 int ri, gi, bi; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2952 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
2953 // 216-color cube |
12541
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2954 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
|
2955 if (red < cutoff[ri]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2956 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2957 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
|
2958 if (green < cutoff[gi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2959 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2960 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
|
2961 if (blue < cutoff[bi]) |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2962 break; |
fcb11cfca8b3
patch 8.0.1149: libvterm colors differ from xterm
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2963 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
|
2964 } |
12502 | 2965 } |
2966 return 0; | |
2967 } | |
2968 | |
2969 /* | |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2970 * Convert Vterm attributes to highlight flags. |
12502 | 2971 */ |
2972 static int | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2973 vtermAttr2hl(VTermScreenCellAttrs *cellattrs) |
12502 | 2974 { |
2975 int attr = 0; | |
2976 | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
2977 if (cellattrs->bold) |
12502 | 2978 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
|
2979 if (cellattrs->underline) |
12502 | 2980 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
|
2981 if (cellattrs->italic) |
12502 | 2982 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
|
2983 if (cellattrs->strike) |
12502 | 2984 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
|
2985 if (cellattrs->reverse) |
12502 | 2986 attr |= HL_INVERSE; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2987 return attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2988 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2989 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2990 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2991 * 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
|
2992 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2993 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2994 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
|
2995 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2996 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
|
2997 if (attr & HL_BOLD) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2998 cell->attrs.bold = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
2999 if (attr & HL_UNDERLINE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3000 cell->attrs.underline = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3001 if (attr & HL_ITALIC) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3002 cell->attrs.italic = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3003 if (attr & HL_STRIKETHROUGH) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3004 cell->attrs.strike = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3005 if (attr & HL_INVERSE) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3006 cell->attrs.reverse = 1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3007 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3008 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3009 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3010 * 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
|
3011 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3012 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
|
3013 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
|
3014 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
|
3015 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
|
3016 VTermScreenCellAttrs *cellattrs, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3017 VTermColor *cellfg, |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3018 VTermColor *cellbg) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3019 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
3020 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
|
3021 VTermColor *fg = cellfg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3022 VTermColor *bg = cellbg; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3023 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
|
3024 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
|
3025 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3026 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
|
3027 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3028 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
|
3029 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3030 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
|
3031 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
|
3032 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
|
3033 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
|
3034 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3035 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3036 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3037 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
|
3038 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
|
3039 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
|
3040 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
|
3041 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3042 } |
12502 | 3043 |
3044 #ifdef FEAT_GUI | |
3045 if (gui.in_use) | |
3046 { | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3047 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
|
3048 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
|
3049 return get_gui_attr_idx(attr, guifg, guibg); |
12502 | 3050 } |
3051 else | |
3052 #endif | |
3053 #ifdef FEAT_TERMGUICOLORS | |
3054 if (p_tgc) | |
3055 { | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3056 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
|
3057 ? INVALCOLOR |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3058 : 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
|
3059 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
|
3060 ? INVALCOLOR |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3061 : 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
|
3062 return get_tgc_attr_idx(attr, tgcfg, tgcbg); |
12502 | 3063 } |
3064 else | |
3065 #endif | |
3066 { | |
3067 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
|
3068 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
|
3069 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
|
3070 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3071 // with 8 colors set the bold attribute to get a bright foreground |
12502 | 3072 if (bold == TRUE) |
3073 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
|
3074 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3075 return get_cterm_attr_idx(attr, ctermfg, ctermbg); |
12502 | 3076 } |
3077 return 0; | |
3078 } | |
3079 | |
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
|
3080 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
|
3081 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
|
3082 { |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
3083 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
|
3084 #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
|
3085 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
|
3086 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3087 // 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
|
3088 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
|
3089 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
|
3090 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
3091 #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
|
3092 } |
a590029f16a0
patch 8.0.1810: buffer of a terminal only updated in Terminal-Normal mode
Christian Brabandt <cb@256bit.org>
parents:
13864
diff
changeset
|
3093 |
12502 | 3094 static int |
3095 handle_damage(VTermRect rect, void *user) | |
3096 { | |
3097 term_T *term = (term_T *)user; | |
3098 | |
3099 term->tl_dirty_row_start = MIN(term->tl_dirty_row_start, rect.start_row); | |
3100 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
|
3101 set_dirty_snapshot(term); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3102 redraw_buf_later(term->tl_buffer, UPD_SOME_VALID); |
12502 | 3103 return 1; |
3104 } | |
3105 | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3106 static void |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3107 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
|
3108 { |
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
|
3109 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
|
3110 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
|
3111 VTermColor fg, bg; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3112 VTermScreenCellAttrs attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3113 int clear_attr; |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3114 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3115 CLEAR_FIELD(attr); |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3116 |
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
|
3117 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
|
3118 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3119 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
|
3120 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3121 // 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
|
3122 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
|
3123 &fg, &bg); |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3124 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
|
3125 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
|
3126 } |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3127 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3128 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3129 |
12502 | 3130 static int |
3131 handle_moverect(VTermRect dest, VTermRect src, void *user) | |
3132 { | |
3133 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
|
3134 int count = src.start_row - dest.start_row; |
12502 | 3135 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3136 // 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
|
3137 // 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
|
3138 // the redraw happens. |
12502 | 3139 if (dest.start_col == src.start_col |
3140 && dest.end_col == src.end_col | |
3141 && dest.start_row < src.start_row) | |
3142 { | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3143 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
|
3144 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
|
3145 else |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3146 term_scroll_up(term, dest.start_row, count); |
12502 | 3147 } |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3148 |
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3149 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
|
3150 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
|
3151 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
|
3152 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3153 // 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
|
3154 // redraw later. |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3155 redraw_buf_later(term->tl_buffer, UPD_NOT_VALID); |
12502 | 3156 return 1; |
3157 } | |
3158 | |
3159 static int | |
3160 handle_movecursor( | |
3161 VTermPos pos, | |
3162 VTermPos oldpos UNUSED, | |
3163 int visible, | |
3164 void *user) | |
3165 { | |
3166 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
|
3167 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
|
3168 int did_curwin = FALSE; |
12502 | 3169 |
3170 term->tl_cursor_pos = pos; | |
3171 term->tl_cursor_visible = visible; | |
3172 | |
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
|
3173 while (for_all_windows_and_curwin(&wp, &did_curwin)) |
12502 | 3174 { |
3175 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
|
3176 position_cursor(wp, &pos); |
12502 | 3177 } |
3178 if (term->tl_buffer == curbuf && !term->tl_normal_mode) | |
3179 update_cursor(term, term->tl_cursor_visible); | |
3180 | |
3181 return 1; | |
3182 } | |
3183 | |
3184 static int | |
3185 handle_settermprop( | |
3186 VTermProp prop, | |
3187 VTermValue *value, | |
3188 void *user) | |
3189 { | |
3190 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
|
3191 char_u *strval = NULL; |
12502 | 3192 |
3193 switch (prop) | |
3194 { | |
3195 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
|
3196 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
|
3197 break; |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3198 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
|
3199 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
|
3200 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3201 break; |
12502 | 3202 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
|
3203 // 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
|
3204 // displayed |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3205 if (*skipwhite(strval) == NUL) |
12502 | 3206 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
|
3207 // 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
|
3208 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
|
3209 && 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
|
3210 (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
|
3211 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
|
3212 // 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
|
3213 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
|
3214 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
|
3215 #ifdef MSWIN |
12502 | 3216 else if (!enc_utf8 && enc_codepage > 0) |
3217 { | |
3218 WCHAR *ret = NULL; | |
3219 int length = 0; | |
3220 | |
3221 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
|
3222 (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
|
3223 (int)value->string.len, &ret, &length); |
12502 | 3224 if (ret != NULL) |
3225 { | |
3226 WideCharToMultiByte_alloc(enc_codepage, 0, | |
3227 ret, length, (char**)&term->tl_title, | |
3228 &length, 0, 0); | |
3229 vim_free(ret); | |
3230 } | |
3231 } | |
3232 #endif | |
3233 else | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3234 { |
20508
357dea6b9fde
patch 8.2.0808: not enough testing for the terminal window
Bram Moolenaar <Bram@vim.org>
parents:
20500
diff
changeset
|
3235 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
|
3236 strval = NULL; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3237 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3238 VIM_CLEAR(term->tl_status_text); |
12502 | 3239 if (term == curbuf->b_term) |
29067
87c00c420d27
patch 8.2.5055: statusline is not updated when terminal title changes
Bram Moolenaar <Bram@vim.org>
parents:
29038
diff
changeset
|
3240 { |
12502 | 3241 maketitle(); |
29067
87c00c420d27
patch 8.2.5055: statusline is not updated when terminal title changes
Bram Moolenaar <Bram@vim.org>
parents:
29038
diff
changeset
|
3242 curwin->w_redr_status = TRUE; |
87c00c420d27
patch 8.2.5055: statusline is not updated when terminal title changes
Bram Moolenaar <Bram@vim.org>
parents:
29038
diff
changeset
|
3243 } |
12502 | 3244 break; |
3245 | |
3246 case VTERM_PROP_CURSORVISIBLE: | |
3247 term->tl_cursor_visible = value->boolean; | |
3248 may_toggle_cursor(term); | |
3249 out_flush(); | |
3250 break; | |
3251 | |
3252 case VTERM_PROP_CURSORBLINK: | |
3253 term->tl_cursor_blink = value->boolean; | |
3254 may_set_cursor_props(term); | |
3255 break; | |
3256 | |
3257 case VTERM_PROP_CURSORSHAPE: | |
3258 term->tl_cursor_shape = value->number; | |
3259 may_set_cursor_props(term); | |
3260 break; | |
3261 | |
3262 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
|
3263 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
|
3264 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
|
3265 if (strval == NULL) |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3266 break; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3267 cursor_color_copy(&term->tl_cursor_color, strval); |
12502 | 3268 may_set_cursor_props(term); |
3269 break; | |
3270 | |
3271 case VTERM_PROP_ALTSCREEN: | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3272 // TODO: do anything else? |
12502 | 3273 term->tl_using_altscreen = value->boolean; |
3274 break; | |
3275 | |
3276 default: | |
3277 break; | |
3278 } | |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3279 vim_free(strval); |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
3280 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3281 // Always return 1, otherwise vterm doesn't store the value internally. |
12502 | 3282 return 1; |
3283 } | |
3284 | |
3285 /* | |
3286 * The job running in the terminal resized the terminal. | |
3287 */ | |
3288 static int | |
3289 handle_resize(int rows, int cols, void *user) | |
3290 { | |
3291 term_T *term = (term_T *)user; | |
3292 win_T *wp; | |
3293 | |
3294 term->tl_rows = rows; | |
3295 term->tl_cols = cols; | |
3296 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
|
3297 // Size was set by vterm_set_size(), don't set the window size. |
12502 | 3298 term->tl_vterm_size_changed = FALSE; |
3299 else | |
3300 { | |
3301 FOR_ALL_WINDOWS(wp) | |
3302 { | |
3303 if (wp->w_buffer == term->tl_buffer) | |
3304 { | |
3305 win_setheight_win(rows, wp); | |
3306 win_setwidth_win(cols, wp); | |
3307 } | |
3308 } | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3309 redraw_buf_later(term->tl_buffer, UPD_NOT_VALID); |
12502 | 3310 } |
3311 return 1; | |
3312 } | |
3313 | |
3314 /* | |
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
|
3315 * 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
|
3316 * 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
|
3317 * "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
|
3318 * "update_buffer" is TRUE when the buffer should be updated. |
12502 | 3319 */ |
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
|
3320 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
|
3321 limit_scrollback(term_T *term, garray_T *gap, int update_buffer) |
12502 | 3322 { |
15826
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3323 if (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
|
3324 { |
13742
a34b1323286c
patch 8.0.1743: terminal window options are named inconsistently
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
3325 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
|
3326 int i; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3327 |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3328 curbuf = term->tl_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3329 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
|
3330 { |
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
|
3331 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
|
3332 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
|
3333 ml_delete(1); |
13680
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3334 } |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3335 curbuf = curwin->w_buffer; |
c32e9628dc30
patch 8.0.1712: terminal scrollback is not limited
Christian Brabandt <cb@256bit.org>
parents:
13678
diff
changeset
|
3336 |
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
|
3337 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
|
3338 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
|
3339 (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
|
3340 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
|
3341 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
|
3342 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
|
3343 } |
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 |
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 /* |
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 * 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
|
3348 */ |
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 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
|
3350 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
|
3351 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3352 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
|
3353 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
|
3354 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
|
3355 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3356 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
|
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 // 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
|
3359 // 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
|
3360 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
|
3361 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
|
3362 } |
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 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
|
3364 { |
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 // 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
|
3366 // 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
|
3367 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
|
3368 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
|
3369 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
|
3370 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3371 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3372 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
|
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 if (ga_grow(gap, 1) == OK) |
12502 | 3375 { |
3376 cellattr_T *p = NULL; | |
3377 int len = 0; | |
3378 int i; | |
3379 int c; | |
3380 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
|
3381 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
|
3382 char_u *text; |
12502 | 3383 sb_line_T *line; |
3384 garray_T ga; | |
3385 cellattr_T fill_attr = term->tl_default_color; | |
3386 | |
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
|
3387 // do not store empty cells at the end |
12502 | 3388 for (i = 0; i < cols; ++i) |
3389 if (cells[i].chars[0] != 0) | |
3390 len = i + 1; | |
3391 else | |
3392 cell2cellattr(&cells[i], &fill_attr); | |
3393 | |
3394 ga_init2(&ga, 1, 100); | |
3395 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
|
3396 p = ALLOC_MULT(cellattr_T, len); |
12502 | 3397 if (p != NULL) |
3398 { | |
3399 for (col = 0; col < len; col += cells[col].width) | |
3400 { | |
3401 if (ga_grow(&ga, MB_MAXBYTES) == FAIL) | |
3402 { | |
3403 ga.ga_len = 0; | |
3404 break; | |
3405 } | |
3406 for (i = 0; (c = cells[col].chars[i]) > 0 || i == 0; ++i) | |
3407 ga.ga_len += utf_char2bytes(c == NUL ? ' ' : c, | |
3408 (char_u *)ga.ga_data + ga.ga_len); | |
3409 cell2cellattr(&cells[col], &p[col]); | |
3410 } | |
3411 } | |
3412 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
|
3413 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3414 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
|
3415 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
|
3416 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
|
3417 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
|
3418 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
|
3419 } |
12502 | 3420 else |
3421 { | |
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
|
3422 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
|
3423 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
|
3424 *(text + text_len) = NUL; |
12502 | 3425 } |
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
|
3426 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
|
3427 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
|
3428 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3429 line = (sb_line_T *)gap->ga_data + gap->ga_len; |
12502 | 3430 line->sb_cols = len; |
3431 line->sb_cells = p; | |
3432 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
|
3433 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
|
3434 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3435 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
|
3436 ++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
|
3437 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
|
3438 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3439 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
|
3440 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3441 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
|
3442 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
|
3443 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3444 ++gap->ga_len; |
12502 | 3445 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3446 return 0; // ignored |
12502 | 3447 } |
3448 | |
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
|
3449 /* |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3450 * 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
|
3451 * 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
|
3452 */ |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3453 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
|
3454 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
|
3455 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3456 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
|
3457 |
16026
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3458 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
|
3459 return; |
5b29ab8415df
patch 8.1.1018: window cleared when entering Terminal-Normal twice
Bram Moolenaar <Bram@vim.org>
parents:
15953
diff
changeset
|
3460 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
|
3461 |
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
|
3462 // 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
|
3463 // 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
|
3464 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
|
3465 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3466 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
|
3467 { |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3468 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
|
3469 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
|
3470 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
|
3471 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3472 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
|
3473 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
|
3474 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
|
3475 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3476 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
|
3477 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
|
3478 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
|
3479 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
|
3480 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
|
3481 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3482 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
|
3483 + 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
|
3484 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
|
3485 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
|
3486 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
|
3487 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
|
3488 ++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
|
3489 ++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
|
3490 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3491 |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3492 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
|
3493 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
|
3494 } |
1f2edc01e7ed
patch 8.1.0920: in Terminal-Normal mode job output messes up the window
Bram Moolenaar <Bram@vim.org>
parents:
15810
diff
changeset
|
3495 |
28439
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3496 /* |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3497 * Called when the terminal wants to ring the system bell. |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3498 */ |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3499 static int |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3500 handle_bell(void *user UNUSED) |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3501 { |
28441
f4d2dcfd18ac
patch 8.2.4745: using wrong flag for using bell in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
28439
diff
changeset
|
3502 vim_beep(BO_TERM); |
28439
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3503 return 0; |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3504 } |
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3505 |
12502 | 3506 static VTermScreenCallbacks screen_callbacks = { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3507 handle_damage, // damage |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3508 handle_moverect, // moverect |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3509 handle_movecursor, // movecursor |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3510 handle_settermprop, // settermprop |
28439
16bd027b039e
patch 8.2.4744: a terminal window can't use the bell
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
3511 handle_bell, // bell |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3512 handle_resize, // resize |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3513 handle_pushline, // sb_pushline |
30880
82336c3b679d
patch 9.0.0774: the libvterm code is outdated
Bram Moolenaar <Bram@vim.org>
parents:
30843
diff
changeset
|
3514 NULL, // sb_popline |
82336c3b679d
patch 9.0.0774: the libvterm code is outdated
Bram Moolenaar <Bram@vim.org>
parents:
30843
diff
changeset
|
3515 NULL // sb_clear |
12502 | 3516 }; |
3517 | |
3518 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3519 * 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
|
3520 * 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
|
3521 * 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
|
3522 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3523 static int |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3524 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
|
3525 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3526 // 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
|
3527 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
|
3528 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3529 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
|
3530 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3531 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
|
3532 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3533 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
|
3534 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3535 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
|
3536 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
|
3537 #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
|
3538 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
|
3539 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3540 // 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
|
3541 // previous window. |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3542 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
|
3543 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3544 pwin = curwin; |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3545 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
|
3546 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
|
3547 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3548 else |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3549 #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
|
3550 // 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
|
3551 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
|
3552 { |
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
|
3553 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
|
3554 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
3555 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
|
3556 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
|
3557 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
|
3558 } |
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
|
3559 |
14459
ecf6c05d8ac3
patch 8.1.0243: using :term ++close ++hidden closes a window
Christian Brabandt <cb@256bit.org>
parents:
14449
diff
changeset
|
3560 // ++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
|
3561 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
|
3562 aucmd_prepbuf(&aco, term->tl_buffer); |
31263
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3563 if (curbuf == term->tl_buffer) |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3564 { |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3565 // Avoid closing the window if we temporarily use it. |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3566 if (is_aucmd_win(curwin)) |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3567 do_set_w_closing = TRUE; |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3568 if (do_set_w_closing) |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3569 curwin->w_closing = TRUE; |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3570 do_bufdel(DOBUF_WIPE, (char_u *)"", 1, fnum, fnum, FALSE); |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3571 if (do_set_w_closing) |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3572 curwin->w_closing = FALSE; |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3573 aucmd_restbuf(&aco); |
d8e7d725a666
patch 9.0.0965: using one window for executing autocommands is insufficient
Bram Moolenaar <Bram@vim.org>
parents:
31231
diff
changeset
|
3574 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3575 #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
|
3576 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
|
3577 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
|
3578 #endif |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3579 return TRUE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3580 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3581 if (term->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
|
3582 && 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
|
3583 { |
22864
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3584 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
|
3585 ? "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
|
3586 : (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
|
3587 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
|
3588 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
|
3589 |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3590 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
|
3591 { |
b825d8ec9a76
patch 8.2.1979: "term_opencmd" option of term_start() is truncated
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3592 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
|
3593 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
|
3594 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
|
3595 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
|
3596 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3597 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3598 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3599 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
|
3600 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3601 |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3602 redraw_buf_and_status_later(term->tl_buffer, UPD_NOT_VALID); |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3603 return FALSE; |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3604 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3605 |
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
|
3606 #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
|
3607 /* |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3608 * 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
|
3609 * 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
|
3610 * 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
|
3611 */ |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3612 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
|
3613 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
|
3614 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3615 if (popup_is_popup(curwin) && curbuf->b_term != NULL |
29038
ad99b7b9df13
patch 8.2.5041: cannot close a terminal popup with "NONE" job
Bram Moolenaar <Bram@vim.org>
parents:
28998
diff
changeset
|
3616 && !term_job_running_not_none(curbuf->b_term)) |
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
|
3617 { |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3618 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
|
3619 |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3620 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
|
3621 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
|
3622 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
|
3623 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
|
3624 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3625 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
|
3626 } |
2142fb624658
patch 8.2.0196: blocking commands for a finished job in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19265
diff
changeset
|
3627 #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
|
3628 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3629 /* |
26217
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3630 * 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
|
3631 * callback. |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3632 */ |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3633 void |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3634 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
|
3635 { |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3636 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
|
3637 |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3638 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
|
3639 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
|
3640 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
|
3641 } |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3642 |
d25c0b0aad7d
patch 8.2.3640: freeze when calling term_wait() in a close callback
Bram Moolenaar <Bram@vim.org>
parents:
26193
diff
changeset
|
3643 /* |
12502 | 3644 * Called when a channel has been closed. |
3645 * If this was a channel for a terminal window then finish it up. | |
3646 */ | |
3647 void | |
3648 term_channel_closed(channel_T *ch) | |
3649 { | |
3650 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
|
3651 term_T *next_term; |
12502 | 3652 int did_one = FALSE; |
3653 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3654 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
|
3655 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3656 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
|
3657 if (term->tl_job == ch->ch_job && !term->tl_channel_closed) |
12502 | 3658 { |
3659 term->tl_channel_closed = TRUE; | |
3660 did_one = TRUE; | |
3661 | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13219
diff
changeset
|
3662 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
|
3663 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
|
3664 #ifdef MSWIN |
13862
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3665 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
|
3666 { |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3667 fclose(term->tl_out_fd); |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3668 term->tl_out_fd = NULL; |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3669 } |
b201372b91a4
patch 8.0.1802: MS-Windows: terminal test fails
Christian Brabandt <cb@256bit.org>
parents:
13860
diff
changeset
|
3670 #endif |
12502 | 3671 |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3672 if (updating_screen) |
12502 | 3673 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3674 // 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
|
3675 // '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
|
3676 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
|
3677 continue; |
12502 | 3678 } |
3679 | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3680 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
|
3681 next_term = first_term; |
12502 | 3682 } |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3683 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3684 |
12502 | 3685 if (did_one) |
3686 { | |
3687 redraw_statuslines(); | |
3688 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3689 // 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
|
3690 ins_char_typebuf(K_IGNORE, 0); |
12502 | 3691 typebuf_was_filled = TRUE; |
3692 | |
3693 term = curbuf->b_term; | |
3694 if (term != NULL) | |
3695 { | |
3696 if (term->tl_job == ch->ch_job) | |
3697 maketitle(); | |
3698 update_cursor(term, term->tl_cursor_visible); | |
3699 } | |
3700 } | |
3701 } | |
3702 | |
3703 /* | |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3704 * 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
|
3705 * 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
|
3706 */ |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3707 void |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3708 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
|
3709 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3710 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
|
3711 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
|
3712 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3713 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
|
3714 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3715 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
|
3716 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
|
3717 { |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3718 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
|
3719 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
|
3720 // 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
|
3721 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
|
3722 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3723 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3724 } |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3725 |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13886
diff
changeset
|
3726 /* |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3727 * 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
|
3728 * 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
|
3729 */ |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3730 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
|
3731 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
|
3732 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
|
3733 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
|
3734 VTermScreen *screen, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3735 VTermPos *pos, |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3736 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
|
3737 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3738 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
|
3739 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3740 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
|
3741 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3742 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
|
3743 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
|
3744 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3745 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
|
3746 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
|
3747 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3748 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
|
3749 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
|
3750 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3751 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
|
3752 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
|
3753 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
|
3754 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3755 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3756 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3757 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
|
3758 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3759 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
|
3760 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3761 // 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
|
3762 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
|
3763 && 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
|
3764 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3765 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
|
3766 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
|
3767 break; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3768 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3769 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
|
3770 && 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
|
3771 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3772 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
|
3773 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
|
3774 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3775 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3776 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3777 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
|
3778 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
|
3779 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3780 } |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
3781 #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
|
3782 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
|
3783 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3784 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
|
3785 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
|
3786 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3787 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
|
3788 (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
|
3789 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3790 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
|
3791 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
|
3792 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
|
3793 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3794 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3795 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
|
3796 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3797 #endif |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3798 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
|
3799 // 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
|
3800 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
|
3801 } |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
3802 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
|
3803 &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
|
3804 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3805 ++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
|
3806 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3807 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
|
3808 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3809 // 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
|
3810 // 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
|
3811 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
|
3812 { |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3813 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
|
3814 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
|
3815 } |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3816 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
|
3817 { |
8059beb101d0
patch 8.2.1963: crash when using a popup window with "latin1" encoding
Bram Moolenaar <Bram@vim.org>
parents:
22822
diff
changeset
|
3818 // 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
|
3819 // '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
|
3820 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
|
3821 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
|
3822 } |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3823 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3824 ++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
|
3825 ++off; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3826 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3827 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3828 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3829 |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3830 #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
|
3831 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
|
3832 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
|
3833 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3834 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
|
3835 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
|
3836 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3837 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
|
3838 return; |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3839 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
|
3840 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3841 // 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
|
3842 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
|
3843 && (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
|
3844 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3845 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
|
3846 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3847 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
|
3848 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
|
3849 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
|
3850 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
|
3851 --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
|
3852 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3853 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3854 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
|
3855 && 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
|
3856 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3857 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
|
3858 { |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3859 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
|
3860 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3861 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
|
3862 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3863 else |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3864 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
|
3865 |
29389
9ec0dafac7fc
patch 9.0.0037: build error
Bram Moolenaar <Bram@vim.org>
parents:
29067
diff
changeset
|
3866 screen_line(curwin, 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
|
3867 } |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3868 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3869 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
|
3870 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
|
3871 } |
13472
f6a4614edea4
patch 8.0.1610: cannot build without GUI
Christian Brabandt <cb@256bit.org>
parents:
13470
diff
changeset
|
3872 #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
|
3873 |
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3874 /* |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3875 * 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
|
3876 * Returns FALSE when there is no terminal running in this window or it is in |
12502 | 3877 * Terminal-Normal mode. |
3878 */ | |
3879 int | |
13851
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3880 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
|
3881 { |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3882 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
|
3883 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3884 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
|
3885 } |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3886 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3887 /* |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3888 * 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
|
3889 */ |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3890 void |
12502 | 3891 term_update_window(win_T *wp) |
3892 { | |
3893 term_T *term = wp->w_buffer->b_term; | |
3894 VTerm *vterm; | |
3895 VTermScreen *screen; | |
3896 VTermState *state; | |
3897 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
|
3898 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
|
3899 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
|
3900 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
|
3901 win_T *twp; |
12502 | 3902 |
3903 vterm = term->tl_vterm; | |
3904 screen = vterm_obtain_screen(vterm); | |
3905 state = vterm_obtain_state(vterm); | |
3906 | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3907 // We use UPD_NOT_VALID on a resize or scroll, redraw everything then. |
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3908 // With UPD_SOME_VALID only redraw what was marked dirty. |
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3909 if (wp->w_redr_type > UPD_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
|
3910 { |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3911 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
|
3912 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
|
3913 |
3edac4cd1c0a
patch 8.0.1797: terminal window is redrawn too often
Christian Brabandt <cb@256bit.org>
parents:
13849
diff
changeset
|
3914 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
|
3915 && 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
|
3916 // 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
|
3917 // 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
|
3918 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
|
3919 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
|
3920 } |
3c46dcf3b335
patch 8.0.1173: terminal window is not redrawn after CTRL-L
Christian Brabandt <cb@256bit.org>
parents:
12578
diff
changeset
|
3921 |
12502 | 3922 /* |
3923 * 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
|
3924 * Adjust the size of the vterm unless 'termwinsize' specifies a fixed size. |
12502 | 3925 */ |
13845
f22db93bd887
patch 8.0.1794: duplicate term options after renaming
Christian Brabandt <cb@256bit.org>
parents:
13835
diff
changeset
|
3926 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
|
3927 |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3928 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
|
3929 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
|
3930 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
|
3931 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3932 // 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
|
3933 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
|
3934 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3935 // 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
|
3936 // 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
|
3937 if (wwp->w_buffer == term->tl_buffer) |
12502 | 3938 { |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3939 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
|
3940 newcols = MIN(newcols, wwp->w_width); |
12502 | 3941 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3942 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
|
3943 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
|
3944 } |
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
|
3945 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
|
3946 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
|
3947 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
|
3948 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
|
3949 |
24006
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3950 // 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
|
3951 // 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
|
3952 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
|
3953 return; |
d9afd9008910
patch 8.2.2545: errors and crash when terminal window is zero height
Bram Moolenaar <Bram@vim.org>
parents:
23041
diff
changeset
|
3954 |
13700
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3955 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
|
3956 { |
12502 | 3957 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
|
3958 vterm_set_size(vterm, newrows, newcols); |
12502 | 3959 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
|
3960 newrows); |
b28d679b1843
patch 8.0.1722: cannot specify a minimal size for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13696
diff
changeset
|
3961 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
|
3962 |
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
|
3963 // 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
|
3964 // 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
|
3965 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
|
3966 may_move_terminal_to_buffer(term, FALSE); |
12502 | 3967 } |
3968 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
3969 // The cursor may have been moved when resizing. |
12502 | 3970 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
|
3971 position_cursor(wp, &pos); |
12502 | 3972 |
12578
f8beecfea2c4
patch 8.0.1167: Motif: typing in terminal window is slow
Christian Brabandt <cb@256bit.org>
parents:
12541
diff
changeset
|
3973 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
|
3974 && pos.row < wp->w_height; ++pos.row) |
12502 | 3975 { |
3976 if (pos.row < term->tl_rows) | |
3977 { | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
3978 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
|
3979 |
19797
d73d982499ae
patch 8.2.0455: cannot set the highlight group for a specific terminal
Bram Moolenaar <Bram@vim.org>
parents:
19744
diff
changeset
|
3980 term_line2screenline(term, wp, screen, &pos, max_col); |
12502 | 3981 } |
3982 else | |
3983 pos.col = 0; | |
3984 | |
29389
9ec0dafac7fc
patch 9.0.0037: build error
Bram Moolenaar <Bram@vim.org>
parents:
29067
diff
changeset
|
3985 screen_line(wp, wp->w_winrow + pos.row |
13458
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3986 #ifdef FEAT_MENU |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3987 + winbar_height(wp) |
0e7a56b18d61
patch 8.0.1603: cannot build with +terminal but without +menu
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
3988 #endif |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3989 , 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
|
3990 #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
|
3991 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
|
3992 #endif |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
3993 0); |
12502 | 3994 } |
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
|
3995 } |
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
|
3996 |
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
|
3997 /* |
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
|
3998 * 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
|
3999 */ |
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
|
4000 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
|
4001 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
|
4002 { |
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
|
4003 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
|
4004 |
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
|
4005 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
|
4006 && 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
|
4007 { |
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
|
4008 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
|
4009 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
|
4010 } |
12502 | 4011 } |
4012 | |
4013 /* | |
4014 * Return TRUE if "wp" is a terminal window where the job has finished. | |
4015 */ | |
4016 int | |
4017 term_is_finished(buf_T *buf) | |
4018 { | |
4019 return buf->b_term != NULL && buf->b_term->tl_vterm == NULL; | |
4020 } | |
4021 | |
4022 /* | |
4023 * Return TRUE if "wp" is a terminal window where the job has finished or we | |
4024 * are in Terminal-Normal mode, thus we show the buffer contents. | |
4025 */ | |
4026 int | |
4027 term_show_buffer(buf_T *buf) | |
4028 { | |
4029 term_T *term = buf->b_term; | |
4030 | |
4031 return term != NULL && (term->tl_vterm == NULL || term->tl_normal_mode); | |
4032 } | |
4033 | |
4034 /* | |
4035 * The current buffer is going to be changed. If there is terminal | |
4036 * highlighting remove it now. | |
4037 */ | |
4038 void | |
4039 term_change_in_curbuf(void) | |
4040 { | |
4041 term_T *term = curbuf->b_term; | |
4042 | |
4043 if (term_is_finished(curbuf) && term->tl_scrollback.ga_len > 0) | |
4044 { | |
4045 free_scrollback(term); | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
4046 redraw_buf_later(term->tl_buffer, UPD_NOT_VALID); |
12502 | 4047 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4048 // 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
|
4049 // abandoned when changed. |
12502 | 4050 set_string_option_direct((char_u *)"buftype", -1, |
4051 (char_u *)"", OPT_FREE|OPT_LOCAL, 0); | |
4052 } | |
4053 } | |
4054 | |
4055 /* | |
4056 * Get the screen attribute for a position in the buffer. | |
4057 * Use a negative "col" to get the filler background color. | |
4058 */ | |
4059 int | |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4060 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
|
4061 { |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4062 buf_T *buf = wp->w_buffer; |
12502 | 4063 term_T *term = buf->b_term; |
4064 sb_line_T *line; | |
4065 cellattr_T *cellattr; | |
4066 | |
4067 if (lnum > term->tl_scrollback.ga_len) | |
4068 cellattr = &term->tl_default_color; | |
4069 else | |
4070 { | |
4071 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum - 1; | |
4072 if (col < 0 || col >= line->sb_cols) | |
4073 cellattr = &line->sb_fill_attr; | |
4074 else | |
4075 cellattr = line->sb_cells + col; | |
4076 } | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4077 return cell2attr(term, wp, &cellattr->attrs, &cellattr->fg, &cellattr->bg); |
12502 | 4078 } |
4079 | |
4080 /* | |
4081 * 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
|
4082 * This is compatible with xterm. |
12502 | 4083 */ |
4084 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
|
4085 cterm_color2vterm(int nr, VTermColor *rgb) |
12502 | 4086 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4087 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
|
4088 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
|
4089 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
|
4090 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4091 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4092 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
|
4093 --rgb->index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4094 } |
12502 | 4095 } |
4096 | |
4097 /* | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4098 * 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
|
4099 * 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
|
4100 * Otherwise returns FALSE. |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4101 */ |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4102 static int |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4103 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
|
4104 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4105 #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
|
4106 // 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
|
4107 if (0 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4108 # ifdef FEAT_GUI |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4109 || gui.in_use |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4110 # endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4111 # ifdef FEAT_TERMGUICOLORS |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4112 || p_tgc |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4113 # ifdef FEAT_VTP |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4114 // 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
|
4115 || (!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
|
4116 # endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4117 # endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4118 ) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4119 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4120 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
|
4121 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
|
4122 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4123 if (id > 0) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4124 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
|
4125 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4126 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
|
4127 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4128 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
|
4129 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
|
4130 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
|
4131 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
|
4132 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
|
4133 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4134 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4135 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
|
4136 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4137 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
|
4138 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4139 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
|
4140 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
|
4141 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
|
4142 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
|
4143 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
|
4144 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4145 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4146 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
|
4147 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4148 return TRUE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4149 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4150 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4151 #endif |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4152 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
|
4153 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4154 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
|
4155 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
|
4156 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4157 if (id > 0) |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4158 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
|
4159 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4160 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
|
4161 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4162 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
|
4163 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
|
4164 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4165 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4166 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
|
4167 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4168 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
|
4169 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4170 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
|
4171 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
|
4172 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4173 else |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4174 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
|
4175 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4176 return TRUE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4177 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4178 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4179 return FALSE; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4180 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4181 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4182 void |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4183 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
|
4184 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4185 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
|
4186 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
|
4187 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4188 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4189 /* |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4190 * 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
|
4191 */ |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4192 void |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4193 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
|
4194 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4195 int id = 0; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4196 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4197 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
|
4198 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
|
4199 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
|
4200 &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
|
4201 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
|
4202 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4203 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4204 /* |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4205 * 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
|
4206 * 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
|
4207 */ |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4208 void |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4209 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
|
4210 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4211 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
|
4212 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
|
4213 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4214 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
|
4215 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
|
4216 } |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4217 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4218 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4219 * Initialize term->tl_default_color from the environment. |
12502 | 4220 */ |
4221 static void | |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4222 init_default_colors(term_T *term) |
12502 | 4223 { |
4224 VTermColor *fg, *bg; | |
4225 int fgval, bgval; | |
4226 int id; | |
4227 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4228 CLEAR_FIELD(term->tl_default_color.attrs); |
12502 | 4229 term->tl_default_color.width = 1; |
4230 fg = &term->tl_default_color.fg; | |
4231 bg = &term->tl_default_color.bg; | |
4232 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4233 // 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
|
4234 // 'background' is "light". |
12502 | 4235 if (*p_bg == 'l') |
4236 { | |
4237 fgval = 0; | |
4238 bgval = 255; | |
4239 } | |
4240 else | |
4241 { | |
4242 fgval = 255; | |
4243 bgval = 0; | |
4244 } | |
4245 fg->red = fg->green = fg->blue = fgval; | |
4246 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
|
4247 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
|
4248 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG; |
12502 | 4249 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4250 // 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
|
4251 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
|
4252 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4253 if (!get_vterm_color_from_synid(id, fg, bg)) |
12502 | 4254 { |
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
|
4255 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
12502 | 4256 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
|
4257 #endif |
12502 | 4258 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4259 // In an MS-Windows console we know the normal colors. |
12502 | 4260 if (cterm_normal_fg_color > 0) |
4261 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
4262 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
|
4263 # 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
|
4264 # 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
|
4265 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
|
4266 # 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
|
4267 { |
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
|
4268 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
|
4269 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
|
4270 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
|
4271 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4272 # endif |
12502 | 4273 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4274 # 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
|
4275 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4276 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
|
4277 # 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
|
4278 |
12502 | 4279 if (cterm_normal_bg_color > 0) |
4280 { | |
13823
d0d8125ba692
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents:
13750
diff
changeset
|
4281 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
|
4282 # 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
|
4283 # 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
|
4284 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
|
4285 # 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
|
4286 { |
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
|
4287 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
|
4288 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
|
4289 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
|
4290 } |
12632
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4291 # endif |
12502 | 4292 } |
12634
94566ecb55f0
patch 8.0.1195: can't build on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
12632
diff
changeset
|
4293 # 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
|
4294 else |
b1a7e3968a31
patch 8.0.1194: actual fg and bg colors of terminal are unknown
Christian Brabandt <cb@256bit.org>
parents:
12598
diff
changeset
|
4295 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
|
4296 # endif |
12502 | 4297 } |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4298 } |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4299 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4300 #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
|
4301 /* |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4302 * Return TRUE if the user-defined palette (either g:terminal_ansi_colors or the |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4303 * "ansi_colors" argument in term_start()) shall be applied. |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4304 */ |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4305 static int |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4306 term_use_palette() |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4307 { |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4308 if (0 |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4309 #ifdef FEAT_GUI |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4310 || gui.in_use |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4311 #endif |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4312 #ifdef FEAT_TERMGUICOLORS |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4313 || p_tgc |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4314 #endif |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4315 ) |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4316 return TRUE; |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4317 return FALSE; |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4318 } |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4319 |
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4320 /* |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4321 * 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
|
4322 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4323 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
|
4324 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
|
4325 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4326 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
|
4327 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
|
4328 |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4329 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
|
4330 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4331 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
|
4332 |
26244
288bcbaa48ca
patch 8.2.3653: terminal ANSI colors may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
26217
diff
changeset
|
4333 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
|
4334 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
|
4335 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
|
4336 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
|
4337 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
|
4338 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
|
4339 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4340 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4341 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4342 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4343 * 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
|
4344 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4345 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
|
4346 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
|
4347 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4348 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
|
4349 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
|
4350 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
|
4351 |
c53dbbf3229b
patch 8.2.0179: still a few places where range() does not work
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
4352 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
|
4353 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4354 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
|
4355 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
|
4356 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4357 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
|
4358 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
|
4359 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
|
4360 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4361 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
|
4362 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
|
4363 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
|
4364 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4365 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
|
4366 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4367 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4368 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
|
4369 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
|
4370 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4371 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
|
4372 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4373 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
|
4374 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4375 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4376 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4377 * 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
|
4378 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4379 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
|
4380 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
|
4381 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4382 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
|
4383 |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4384 if (var == NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4385 return; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4386 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4387 if (var->di_tv.v_type != VAR_LIST |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4388 || var->di_tv.vval.v_list == NULL |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4389 || var->di_tv.vval.v_list->lv_first == &range_list_item |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4390 || 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
|
4391 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
|
4392 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4393 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
4394 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4395 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4396 * 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
|
4397 * "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
|
4398 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4399 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4400 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
|
4401 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4402 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
|
4403 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
|
4404 int bufnr; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4405 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
|
4406 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
|
4407 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
|
4408 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
|
4409 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4410 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
|
4411 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
|
4412 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4413 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
|
4414 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4415 // 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
|
4416 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
|
4417 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4418 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4419 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4420 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4421 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
|
4422 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4423 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
|
4424 && 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
|
4425 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4426 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
|
4427 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
|
4428 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
4429 p = dict_get_string(dict, "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
|
4430 if (p == NULL) |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
4431 p = dict_get_string(dict, "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
|
4432 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
|
4433 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4434 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
|
4435 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
|
4436 else |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4437 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
|
4438 } |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
4439 p = dict_get_string(dict, "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
|
4440 if (p == NULL) |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
4441 p = dict_get_string(dict, "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
|
4442 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
|
4443 { |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4444 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
|
4445 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
|
4446 { |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4447 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
|
4448 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
|
4449 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
|
4450 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4451 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4452 |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
4453 p = dict_get_string(dict, "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
|
4454 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
|
4455 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
|
4456 |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
27885
diff
changeset
|
4457 if (dict_has_key(dict, "bin")) |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4458 ea.force_bin = FORCE_BIN; |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
27885
diff
changeset
|
4459 if (dict_has_key(dict, "binary")) |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4460 ea.force_bin = FORCE_BIN; |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
27885
diff
changeset
|
4461 if (dict_has_key(dict, "nobin")) |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4462 ea.force_bin = FORCE_NOBIN; |
28315
62cc3b60493b
patch 8.2.4683: verbose check with dict_find() to see if a key is present
Bram Moolenaar <Bram@vim.org>
parents:
27885
diff
changeset
|
4463 if (dict_has_key(dict, "nobinary")) |
13575
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4464 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
|
4465 } |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4466 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4467 // 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
|
4468 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
|
4469 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
|
4470 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
|
4471 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
|
4472 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
|
4473 |
4df23d9bad47
patch 8.0.1660: the terminal API "drop" command doesn't support options
Christian Brabandt <cb@256bit.org>
parents:
13557
diff
changeset
|
4474 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
|
4475 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4476 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4477 /* |
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
|
4478 * 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
|
4479 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4480 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
|
4481 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
|
4482 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4483 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
|
4484 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4485 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4486 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4487 * 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
|
4488 * "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
|
4489 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4490 static void |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4491 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
|
4492 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4493 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
|
4494 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
|
4495 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
|
4496 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
|
4497 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4498 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
|
4499 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4500 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
|
4501 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4502 } |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4503 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
|
4504 |
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
|
4505 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
|
4506 { |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
4507 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
|
4508 return; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4509 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4510 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4511 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
|
4512 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
|
4513 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
|
4514 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
|
4515 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
|
4516 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
|
4517 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
|
4518 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
|
4519 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4520 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
|
4521 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
|
4522 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4523 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4524 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
|
4525 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4526 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4527 /* |
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
|
4528 * 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
|
4529 * |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4530 * 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
|
4531 * 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
|
4532 * 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
|
4533 * 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
|
4534 */ |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4535 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
|
4536 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
|
4537 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4538 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
|
4539 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4540 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
|
4541 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4542 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
|
4543 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4544 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
|
4545 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
|
4546 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
|
4547 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4548 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
|
4549 { |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4550 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
|
4551 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
|
4552 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
|
4553 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4554 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4555 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
|
4556 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
|
4557 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4558 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4559 /* |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4560 * 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
|
4561 * |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4562 * 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
|
4563 * "\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
|
4564 * 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
|
4565 * "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
|
4566 */ |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4567 static void |
29792
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4568 sync_shell_dir(garray_T *gap) |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4569 { |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4570 int offset = 7; // len of "file://" is 7 |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4571 char *pos = (char *)gap->ga_data + offset; |
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
|
4572 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
|
4573 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4574 // remove HOSTNAME to get PWD |
29792
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4575 while (offset < (int)gap->ga_len && *pos != '/' ) |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4576 { |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4577 ++offset; |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4578 ++pos; |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4579 } |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4580 |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4581 if (offset >= (int)gap->ga_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
|
4582 { |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
4583 semsg(_(e_failed_to_extract_pwd_from_str_check_your_shell_config), |
29792
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4584 gap->ga_data); |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
4585 return; |
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
|
4586 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4587 |
29792
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4588 new_dir = alloc(gap->ga_len - offset + 1); |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4589 url_decode(pos, gap->ga_len-offset, new_dir); |
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
|
4590 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
|
4591 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
|
4592 } |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4593 |
9257f3980f4a
patch 8.2.2675: directory change in a terminal window shell is not followed
Bram Moolenaar <Bram@vim.org>
parents:
24006
diff
changeset
|
4594 /* |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4595 * 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
|
4596 * 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
|
4597 */ |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4598 static int |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4599 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
|
4600 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4601 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
|
4602 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
|
4603 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
|
4604 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
|
4605 : 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
|
4606 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
|
4607 |
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
|
4608 // We recognize only OSC 5 1 ; {command} and OSC 7 ; {command} |
29792
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4609 if (command != 51 && (command != 7 || !p_asd)) |
20488
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4610 return 0; |
1d595fada804
patch 8.2.0798: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20179
diff
changeset
|
4611 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4612 // 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
|
4613 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
|
4614 { |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4615 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
|
4616 return 1; |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4617 } |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4618 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
|
4619 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
|
4620 if (!frag.final) |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4621 return 1; |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4622 |
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4623 ((char *)gap->ga_data)[gap->ga_len] = 0; |
29792
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4624 |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4625 if (command == 7) |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4626 { |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4627 sync_shell_dir(gap); |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4628 ga_clear(gap); |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4629 return 1; |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4630 } |
f661bbf74a6d
patch 9.0.0235: 'autoshelldir' does not work with chunked respose
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
4631 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4632 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
|
4633 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
|
4634 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
|
4635 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
|
4636 && 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
|
4637 && 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
|
4638 { |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4639 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
|
4640 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4641 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
|
4642 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
|
4643 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4644 { |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
4645 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
|
4646 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4647 // 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
|
4648 // 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
|
4649 ++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
|
4650 |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4651 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
|
4652 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
|
4653 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
|
4654 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
|
4655 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
|
4656 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
|
4657 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
|
4658 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4659 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
|
4660 --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
|
4661 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4662 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4663 else |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4664 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
|
4665 |
20494
4f6904d8b258
patch 8.2.0801: terminal test fails on Mac
Bram Moolenaar <Bram@vim.org>
parents:
20488
diff
changeset
|
4666 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
|
4667 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
|
4668 return 1; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4669 } |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4670 |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4671 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4672 * 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
|
4673 * 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
|
4674 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4675 static int |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4676 parse_csi( |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4677 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
|
4678 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
|
4679 int argcount, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4680 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
|
4681 char command, |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4682 void *user) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4683 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4684 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
|
4685 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
|
4686 int len; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4687 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
|
4688 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
|
4689 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
|
4690 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4691 // 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
|
4692 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
|
4693 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
|
4694 |
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
|
4695 // 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
|
4696 // 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
|
4697 #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
|
4698 || (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
|
4699 || 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
|
4700 (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
|
4701 #endif |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4702 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4703 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
|
4704 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
|
4705 break; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4706 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
|
4707 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4708 #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
|
4709 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
|
4710 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4711 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
|
4712 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
|
4713 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4714 else |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4715 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4716 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4717 // 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
|
4718 // 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
|
4719 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
|
4720 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
|
4721 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4722 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4723 |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4724 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
|
4725 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
|
4726 (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
|
4727 return 1; |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4728 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4729 |
20496
747a270eb1db
patch 8.2.0802: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20494
diff
changeset
|
4730 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
|
4731 NULL, // control |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4732 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
|
4733 parse_osc, // osc |
26270
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4734 NULL, // dcs |
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4735 NULL, // apc |
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4736 NULL, // pm |
f93337ae0612
patch 8.2.3666: libvterm is outdated
Bram Moolenaar <Bram@vim.org>
parents:
26244
diff
changeset
|
4737 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
|
4738 }; |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4739 |
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4740 /* |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4741 * 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
|
4742 */ |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4743 static void * |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4744 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
|
4745 { |
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
|
4746 // 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
|
4747 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
|
4748 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4749 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4750 static void |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4751 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
|
4752 { |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4753 vim_free(ptr); |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4754 } |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4755 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4756 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
|
4757 &vterm_malloc, |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4758 &vterm_memfree |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4759 }; |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4760 |
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4761 /* |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4762 * 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
|
4763 * 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
|
4764 */ |
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
|
4765 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
|
4766 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
|
4767 { |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4768 VTerm *vterm; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4769 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
|
4770 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
|
4771 VTermValue value; |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4772 |
13616
b6998c6374e1
patch 8.0.1680: memory allocated by libvterm is not profiled
Christian Brabandt <cb@256bit.org>
parents:
13583
diff
changeset
|
4773 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
|
4774 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
|
4775 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
|
4776 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
|
4777 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4778 // 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
|
4779 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
|
4780 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
|
4781 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
|
4782 { |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4783 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
|
4784 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
|
4785 } |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4786 |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4787 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
|
4788 // 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
|
4789 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
|
4790 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4791 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
|
4792 |
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4793 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
|
4794 state, |
13483
f7ef5d579758
patch 8.0.1615: term_dumpload() does not use the right colors
Christian Brabandt <cb@256bit.org>
parents:
13476
diff
changeset
|
4795 &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
|
4796 &term->tl_default_color.bg); |
12502 | 4797 |
16656
e8c081146788
patch 8.1.1330: using bold attribute in terminal changes the color
Bram Moolenaar <Bram@vim.org>
parents:
16634
diff
changeset
|
4798 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
|
4799 // 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
|
4800 // 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
|
4801 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
|
4802 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4803 // Required to initialize most things. |
12502 | 4804 vterm_screen_reset(screen, 1 /* hard */); |
4805 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4806 // Allow using alternate screen. |
12502 | 4807 vterm_screen_enable_altscreen(screen, 1); |
4808 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
4809 // 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
|
4810 // 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
|
4811 // 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
|
4812 #ifdef MSWIN |
12502 | 4813 if (GetCaretBlinkTime() == INFINITE) |
4814 value.boolean = 0; | |
4815 else | |
4816 value.boolean = 1; | |
4817 #else | |
4818 value.boolean = 0; | |
4819 #endif | |
13535
e9ffb5b35266
patch 8.0.1641: job in terminal can't communicate with Vim
Christian Brabandt <cb@256bit.org>
parents:
13517
diff
changeset
|
4820 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
|
4821 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
|
4822 |
544490b69e1d
patch 8.1.0633: crash when out of memory while opening a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
15217
diff
changeset
|
4823 return OK; |
12502 | 4824 } |
4825 | |
4826 /* | |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4827 * Reset the terminal palette to its default value. |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4828 */ |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4829 static void |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4830 term_reset_palette(VTerm *vterm) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4831 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4832 VTermState *state = vterm_obtain_state(vterm); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4833 int index; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4834 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4835 for (index = 0; index < 16; index++) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4836 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4837 VTermColor color; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4838 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4839 color.type = VTERM_COLOR_INDEXED; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4840 ansi_color2rgb(index, &color.red, &color.green, &color.blue, |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4841 &color.index); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4842 // The first valid index starts at 1. |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4843 color.index -= 1; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4844 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4845 vterm_state_set_palette_color(state, index, &color); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4846 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4847 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4848 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4849 static void |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4850 term_update_palette(term_T *term) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4851 { |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4852 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4853 if (term_use_palette() |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4854 && (term->tl_palette != NULL |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4855 || find_var((char_u *)"g:terminal_ansi_colors", NULL, TRUE) |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4856 != NULL)) |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4857 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4858 if (term->tl_palette != NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4859 set_vterm_palette(term->tl_vterm, term->tl_palette); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4860 else |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4861 init_vterm_ansi_colors(term->tl_vterm); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4862 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4863 else |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
4864 #endif |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4865 term_reset_palette(term->tl_vterm); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4866 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4867 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4868 /* |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4869 * Called when option 'termguicolors' is changed. |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4870 */ |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4871 void |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4872 term_update_palette_all() |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4873 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4874 term_T *term; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4875 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4876 FOR_ALL_TERMS(term) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4877 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4878 if (term->tl_vterm == NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4879 continue; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4880 term_update_palette(term); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4881 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4882 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4883 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
4884 /* |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4885 * 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
|
4886 * 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
|
4887 */ |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4888 void |
1a658c5eb326
patch 8.2.2830: terminal colors are not updated when 'background' is set
Bram Moolenaar <Bram@vim.org>
parents:
24557
diff
changeset
|
4889 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
|
4890 { |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4891 term_T *term; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4892 |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4893 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
|
4894 { |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4895 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
|
4896 continue; |
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
4897 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
|
4898 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
|
4899 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
|
4900 &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
|
4901 &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
|
4902 } |
19265
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4903 } |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4904 |
ce8c47ed54e5
patch 8.2.0191: cannot put a terminal in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
19245
diff
changeset
|
4905 /* |
12502 | 4906 * Return the text to show for the buffer name and status. |
4907 */ | |
4908 char_u * | |
4909 term_get_status_text(term_T *term) | |
4910 { | |
4911 if (term->tl_status_text == NULL) | |
4912 { | |
4913 char_u *txt; | |
4914 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
|
4915 char_u *fname; |
12502 | 4916 |
4917 if (term->tl_normal_mode) | |
4918 { | |
4919 if (term_job_running(term)) | |
4920 txt = (char_u *)_("Terminal"); | |
4921 else | |
4922 txt = (char_u *)_("Terminal-finished"); | |
4923 } | |
4924 else if (term->tl_title != NULL) | |
4925 txt = term->tl_title; | |
4926 else if (term_none_open(term)) | |
4927 txt = (char_u *)_("active"); | |
4928 else if (term_job_running(term)) | |
4929 txt = (char_u *)_("running"); | |
4930 else | |
4931 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
|
4932 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
|
4933 len = 9 + STRLEN(fname) + STRLEN(txt); |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
4934 term->tl_status_text = alloc(len); |
12502 | 4935 if (term->tl_status_text != NULL) |
4936 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
|
4937 fname, txt); |
12502 | 4938 } |
4939 return term->tl_status_text; | |
4940 } | |
4941 | |
4942 /* | |
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
|
4943 * 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
|
4944 */ |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4945 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
|
4946 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
|
4947 { |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4948 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
|
4949 } |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4950 |
582218dbc6b3
patch 8.2.3624: when renaming a terminal buffer status text is not updated
Bram Moolenaar <Bram@vim.org>
parents:
26129
diff
changeset
|
4951 /* |
12502 | 4952 * Mark references in jobs of terminals. |
4953 */ | |
4954 int | |
4955 set_ref_in_term(int copyID) | |
4956 { | |
4957 int abort = FALSE; | |
4958 term_T *term; | |
4959 typval_T tv; | |
4960 | |
17151
ebe9aab81898
patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents:
17133
diff
changeset
|
4961 for (term = first_term; !abort && term != NULL; term = term->tl_next) |
12502 | 4962 if (term->tl_job != NULL) |
4963 { | |
4964 tv.v_type = VAR_JOB; | |
4965 tv.vval.v_job = term->tl_job; | |
4966 abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); | |
4967 } | |
4968 return abort; | |
4969 } | |
4970 | |
4971 /* | |
4972 * 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
|
4973 * 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
|
4974 * with "where". |
12502 | 4975 */ |
4976 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
|
4977 term_get_buf(typval_T *argvars, char *where) |
12502 | 4978 { |
4979 buf_T *buf; | |
4980 | |
4981 ++emsg_off; | |
15355
73b153ed5af8
patch 8.1.0685: get_buf_tv() is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
15273
diff
changeset
|
4982 buf = tv_get_buf(&argvars[0], FALSE); |
12502 | 4983 --emsg_off; |
4984 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
|
4985 { |
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
|
4986 (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
|
4987 ch_log(NULL, "%s: invalid buffer argument", where); |
12502 | 4988 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
|
4989 } |
12502 | 4990 return buf; |
4991 } | |
4992 | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4993 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4994 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
|
4995 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
4996 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
|
4997 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
|
4998 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
|
4999 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5000 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5001 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5002 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
|
5003 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5004 int index; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5005 |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5006 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
|
5007 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
|
5008 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
|
5009 // use RGB values |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5010 index = 255; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5011 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5012 // default color |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5013 index = 0; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5014 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
|
5015 (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
|
5016 index); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5017 } |
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 /* |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5020 * "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
|
5021 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5022 * 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
|
5023 * |{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
|
5024 * {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
|
5025 * 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
|
5026 * skipped. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5027 * {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
|
5028 * 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
|
5029 * {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
|
5030 * {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
|
5031 * {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
|
5032 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5033 * 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
|
5034 * |{characters} |
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 * 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
|
5037 * |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5038 * 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
|
5039 * @{count} |
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 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5042 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
|
5043 { |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5044 buf_T *buf; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5045 term_T *term; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5046 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
|
5047 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
|
5048 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
|
5049 stat_T st; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5050 FILE *fd; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5051 VTermPos pos; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5052 VTermScreen *screen; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5053 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
|
5054 VTermState *state; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5055 VTermPos cursor_pos; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5056 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5057 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
|
5058 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
|
5059 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5060 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
|
5061 && (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
|
5062 || 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
|
5063 || 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
|
5064 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5065 |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5066 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
|
5067 if (buf == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5068 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5069 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
|
5070 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
|
5071 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
5072 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
|
5073 return; |
e2497d9c51c4
patch 8.1.0358: crash when using term_dumpwrite() after the job finished
Christian Brabandt <cb@256bit.org>
parents:
14625
diff
changeset
|
5074 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5075 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5076 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
|
5077 { |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5078 dict_T *d; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5079 |
29994
86eb4aba16c3
patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents:
29792
diff
changeset
|
5080 if (check_for_dict_arg(argvars, 2) == FAIL) |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5081 return; |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5082 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
|
5083 if (d != NULL) |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5084 { |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
5085 max_height = dict_get_number(d, "rows"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29389
diff
changeset
|
5086 max_width = dict_get_number(d, "columns"); |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5087 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5088 } |
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5089 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5090 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
|
5091 if (fname == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5092 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5093 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
|
5094 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
5095 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
|
5096 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5097 } |
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 (*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
|
5100 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5101 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
|
5102 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5103 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5104 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5105 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
|
5106 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5107 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
|
5108 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
|
5109 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
|
5110 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5111 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
|
5112 && 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
|
5113 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5114 int repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5115 |
13329
424321d6eea7
patch 8.0.1539: no test for the popup menu positioning
Christian Brabandt <cb@256bit.org>
parents:
13304
diff
changeset
|
5116 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
|
5117 && 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
|
5118 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5119 VTermScreenCell cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5120 int same_attr; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5121 int same_chars = TRUE; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5122 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
|
5123 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
|
5124 && 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
|
5125 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5126 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
|
5127 clear_cell(&cell); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5128 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5129 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
|
5130 { |
13517
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
5131 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
|
5132 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
|
5133 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
|
5134 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5135 // 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
|
5136 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
|
5137 { |
d0d66898e98b
patch 8.0.1632: in a terminal dump NUL and space are different
Christian Brabandt <cb@256bit.org>
parents:
13505
diff
changeset
|
5138 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
|
5139 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
|
5140 } |
14625
cd3f0987c0bc
patch 8.1.0326: screen dump does not consider NUL and space equal
Christian Brabandt <cb@256bit.org>
parents:
14459
diff
changeset
|
5141 if (c != pc) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5142 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
|
5143 if (should_break) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5144 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5145 } |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
5146 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
|
5147 == 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
|
5148 && 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
|
5149 && 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
|
5150 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
|
5151 && !is_cursor_pos) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5152 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5153 ++repeat; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5154 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5155 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5156 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5157 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5158 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5159 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5160 repeat = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5161 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5162 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
|
5163 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5164 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
|
5165 fputs(" ", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5166 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5167 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5168 char_u charbuf[10]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5169 int len; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5170 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5171 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
|
5172 && 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
|
5173 { |
13557
4911058c43eb
patch 8.0.1652: term_dumpwrite() does not output composing characters
Christian Brabandt <cb@256bit.org>
parents:
13547
diff
changeset
|
5174 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
|
5175 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
|
5176 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5177 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5178 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5179 // 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
|
5180 // 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
|
5181 // attributes. |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5182 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
|
5183 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5184 if (cell.width == 2) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5185 fputs("*", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5186 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5187 fputs("+", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5188 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5189 if (same_attr) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5190 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5191 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5192 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5193 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5194 { |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
5195 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
|
5196 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
|
5197 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5198 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5199 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5200 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5201 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
|
5202 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5203 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
|
5204 fputs("&", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5205 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5206 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5207 fputs("#", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5208 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
|
5209 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5210 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5211 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5212 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5213 prev_cell = cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5214 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5215 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5216 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5217 ++pos.col; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5218 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5219 if (repeat > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5220 fprintf(fd, "@%d", repeat); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5221 fputs("\n", fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5222 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5223 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5224 fclose(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5225 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5226 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5227 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5228 * 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
|
5229 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5230 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5231 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
|
5232 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5233 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
|
5234 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5235 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5236 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5237 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
|
5238 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5239 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
|
5240 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5241 *(((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
|
5242 ++gap->ga_len; |
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 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5245 |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5246 static void |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5247 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
|
5248 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5249 CLEAR_FIELD(*cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5250 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
|
5251 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
|
5252 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5253 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5254 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5255 * 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
|
5256 * 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
|
5257 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5258 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
|
5259 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
|
5260 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5261 int c; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5262 garray_T ga_text; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5263 garray_T ga_cell; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5264 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
|
5265 int attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5266 cellattr_T cell; |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5267 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
|
5268 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
|
5269 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
|
5270 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
|
5271 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5272 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
|
5273 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
|
5274 clear_cellattr(&cell); |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5275 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
|
5276 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
|
5277 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
|
5278 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5279 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5280 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5281 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5282 if (c == EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5283 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
|
5284 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
|
5285 { |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
5286 // 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
|
5287 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
|
5288 } |
47931abb9f31
patch 8.1.0491: if a terminal dump has CR it is considered corrupt
Bram Moolenaar <Bram@vim.org>
parents:
14939
diff
changeset
|
5289 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
|
5290 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5291 // 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
|
5292 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
|
5293 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
|
5294 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
|
5295 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5296 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
|
5297 + 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
|
5298 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5299 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
|
5300 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
|
5301 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
|
5302 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
|
5303 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
|
5304 ++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
|
5305 ga_init(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5306 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5307 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
|
5308 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
|
5309 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
|
5310 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5311 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5312 ga_clear(&ga_cell); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5313 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
|
5314 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5315 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5316 } |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5317 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
|
5318 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5319 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
|
5320 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5321 if (c == '>') |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5322 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5323 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
|
5324 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
|
5325 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
|
5326 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
|
5327 } |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5328 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5329 // 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
|
5330 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5331 if (c != EOF) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5332 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
|
5333 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5334 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5335 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
|
5336 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
|
5337 || c == EOF || c == '\n') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5338 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5339 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
|
5340 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5341 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5342 // 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
|
5343 vim_free(prev_char); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5344 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
|
5345 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
|
5346 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
|
5347 |
13335
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5348 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
|
5349 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5350 // 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
|
5351 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5352 else if (c == '+' || c == '*') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5353 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5354 int is_bg; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5355 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5356 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
|
5357 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5358 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5359 if (c == '&') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5360 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5361 // 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
|
5362 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5363 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5364 else if (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5365 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5366 // 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
|
5367 attr = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5368 while (isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5369 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5370 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
|
5371 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5372 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5373 hl2vtermAttr(attr, &cell); |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5374 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5375 // 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
|
5376 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
|
5377 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5378 if (c == '&') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5379 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5380 // 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
|
5381 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5382 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5383 else if (c == '#') |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5384 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5385 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
|
5386 |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5387 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5388 red = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5389 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5390 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
|
5391 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5392 green = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5393 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5394 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
|
5395 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5396 blue = hex2nr(c); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5397 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5398 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
|
5399 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5400 if (!isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5401 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
|
5402 while (isdigit(c)) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5403 { |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5404 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
|
5405 c = fgetc(fd); |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5406 } |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5407 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
|
5408 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5409 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
|
5410 if (index == 0) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5411 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5412 if (is_bg) |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5413 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
|
5414 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5415 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
|
5416 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5417 } |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5418 else |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5419 { |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5420 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
|
5421 index -= 1; |
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5422 } |
15504
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5423 if (is_bg) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5424 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5425 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
|
5426 cell.bg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5427 cell.bg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5428 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
|
5429 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
|
5430 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5431 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5432 { |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
5433 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
|
5434 cell.fg.red = red; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5435 cell.fg.green = green; |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5436 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
|
5437 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
|
5438 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5439 } |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5440 else |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5441 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
|
5442 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5443 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5444 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5445 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
|
5446 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5447 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5448 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
|
5449 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5450 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
|
5451 if (cell.width == 2) |
247511eadb7a
patch 8.1.0760: no proper test for using 'termencoding'
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5452 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
|
5453 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5454 else if (c == '@') |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5455 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5456 if (prev_char == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5457 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
|
5458 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5459 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5460 int count = 0; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5461 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5462 // 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
|
5463 for (;;) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5464 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5465 c = fgetc(fd); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5466 if (!isdigit(c)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5467 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5468 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
|
5469 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5470 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5471 while (count-- > 0) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5472 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5473 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
|
5474 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
|
5475 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5476 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5477 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5478 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5479 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5480 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
|
5481 c = fgetc(fd); |
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 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5484 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5485 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
|
5486 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5487 // 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
|
5488 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
|
5489 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
|
5490 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
|
5491 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
|
5492 } |
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 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
|
5495 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
|
5496 vim_free(prev_char); |
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 return max_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5499 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5500 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5501 /* |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5502 * 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
|
5503 * "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
|
5504 */ |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5505 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
|
5506 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
|
5507 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5508 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
|
5509 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
|
5510 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
|
5511 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
|
5512 int i; |
13630
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5513 size_t off; |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5514 |
fd3389d64825
patch 8.0.1687: 64 bit compiler warnings
Christian Brabandt <cb@256bit.org>
parents:
13626
diff
changeset
|
5515 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
|
5516 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
|
5517 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
|
5518 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5519 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
|
5520 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
|
5521 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5522 // 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
|
5523 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
|
5524 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5525 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
|
5526 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5527 // 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
|
5528 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
|
5529 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
|
5530 } |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5531 // 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
|
5532 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
|
5533 { |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5534 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
|
5535 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
|
5536 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5537 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5538 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
|
5539 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
|
5540 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
|
5541 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5542 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
|
5543 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
|
5544 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
|
5545 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
|
5546 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
|
5547 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
|
5548 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5549 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
|
5550 } |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5551 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5552 /* |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5553 * 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
|
5554 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5555 static void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5556 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
|
5557 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5558 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
|
5559 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
|
5560 char_u buf1[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5561 char_u buf2[NUMBUFLEN]; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5562 char_u *fname1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5563 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
|
5564 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
|
5565 FILE *fd1; |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5566 FILE *fd2 = NULL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5567 char_u *textline = NULL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5568 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5569 // 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
|
5570 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
|
5571 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
|
5572 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
|
5573 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
|
5574 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5575 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
|
5576 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5577 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5578 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
|
5579 if (fd1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5580 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5581 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
|
5582 return; |
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 (do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5585 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5586 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
|
5587 if (fd2 == NULL) |
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 fclose(fd1); |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5590 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
|
5591 return; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5592 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5593 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5594 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5595 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
|
5596 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
|
5597 && 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
|
5598 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
|
5599 + 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
|
5600 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
|
5601 |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5602 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
|
5603 { |
13505
a784ef72b617
patch 8.0.1626: compiler warning for possible loss of data
Christian Brabandt <cb@256bit.org>
parents:
13501
diff
changeset
|
5604 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
|
5605 |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
5606 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
|
5607 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
|
5608 { |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5609 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
|
5610 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
|
5611 } |
a4a559e08798
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Christian Brabandt <cb@256bit.org>
parents:
13483
diff
changeset
|
5612 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5613 |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5614 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
|
5615 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5616 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
|
5617 |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5618 // 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
|
5619 // empty. |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5620 if (wp == NULL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
5621 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
|
5622 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5623 { |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5624 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
|
5625 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
|
5626 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
|
5627 free_scrollback(curbuf->b_term); |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
5628 redraw_later(UPD_NOT_VALID); |
16912
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5629 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5630 } |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5631 else |
a5e3509b33ca
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5632 // 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
|
5633 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
|
5634 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5635 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
|
5636 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5637 int i; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5638 linenr_T bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5639 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5640 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
|
5641 int width; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5642 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
|
5643 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
|
5644 VTermPos cursor_pos2; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5645 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
5646 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
|
5647 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5648 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
|
5649 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5650 // 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
|
5651 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
|
5652 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5653 // 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
|
5654 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
|
5655 { |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5656 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
|
5657 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
|
5658 } |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5659 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5660 // 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
|
5661 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5662 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5663 // 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
|
5664 if (!do_diff) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5665 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5666 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5667 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
|
5668 |
13579
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5669 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
|
5670 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5671 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5672 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
|
5673 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
|
5674 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
|
5675 |
486ad9fd9038
patch 8.0.1662: showing dump diff doesn't mention both file names
Christian Brabandt <cb@256bit.org>
parents:
13577
diff
changeset
|
5676 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
|
5677 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
|
5678 goto theend; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5679 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
|
5680 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
|
5681 textline[width] = NUL; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5682 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5683 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
|
5684 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
|
5685 if (width2 > width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5686 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5687 vim_free(textline); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5688 textline = alloc(width2 + 1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5689 if (textline == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5690 goto theend; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5691 width = width2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5692 textline[width] = NUL; |
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 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
|
5695 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5696 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
|
5697 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5698 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
|
5699 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5700 // 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
|
5701 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
|
5702 textline[i] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5703 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5704 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5705 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5706 char_u *line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5707 char_u *line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5708 char_u *p1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5709 char_u *p2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5710 int col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5711 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
|
5712 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
|
5713 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
|
5714 ->sb_cells; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5715 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5716 // 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
|
5717 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
|
5718 if (line1 == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5719 break; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5720 p1 = line1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5721 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5722 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
|
5723 p2 = line2; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5724 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
|
5725 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5726 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
|
5727 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
|
5728 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5729 textline[col] = ' '; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5730 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
|
5731 // text differs |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5732 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
|
5733 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
|
5734 && 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
|
5735 && (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
|
5736 || 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
|
5737 // 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
|
5738 textline[col] = '>'; |
73325d39591a
patch 8.0.1542: terminal screen dump does not include cursor position
Christian Brabandt <cb@256bit.org>
parents:
13329
diff
changeset
|
5739 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
|
5740 && 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
|
5741 && (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
|
5742 || 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
|
5743 // 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
|
5744 textline[col] = '<'; |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5745 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
|
5746 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5747 if ((cellattr1 + col)->width |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5748 != (cellattr2 + col)->width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5749 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
|
5750 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
|
5751 &(cellattr2 + col)->fg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5752 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
|
5753 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
|
5754 &(cellattr2 + col)->bg)) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5755 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
|
5756 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
|
5757 != 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
|
5758 textline[col] = 'a'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5759 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5760 p1 += len1; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5761 p2 += len2; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5762 // 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
|
5763 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5764 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5765 while (col < width) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5766 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5767 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
|
5768 textline[col] = '?'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5769 else if (*p1 == NUL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5770 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5771 textline[col] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5772 p2 += utfc_ptr2len(p2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5773 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5774 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5775 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5776 textline[col] = '-'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5777 p1 += utfc_ptr2len(p1); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5778 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5779 ++col; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5780 } |
15828
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5781 |
8f112782a2e9
patch 8.1.0921: terminal test sometimes fails; using memory after free
Bram Moolenaar <Bram@vim.org>
parents:
15826
diff
changeset
|
5782 vim_free(line1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5783 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5784 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
|
5785 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
|
5786 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
|
5787 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5788 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5789 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5790 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
|
5791 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5792 // 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
|
5793 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
|
5794 textline[i] = '+'; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5795 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
|
5796 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
|
5797 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
|
5798 ++lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5799 ++bot_lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5800 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5801 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5802 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
|
5803 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5804 // 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
|
5805 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
|
5806 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5807 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5808 theend: |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5809 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
|
5810 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
|
5811 fclose(fd1); |
13300
803294329951
patch 8.0.1524: compiler warnings for uninitialized variables
Christian Brabandt <cb@256bit.org>
parents:
13298
diff
changeset
|
5812 if (fd2 != NULL) |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5813 fclose(fd2); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5814 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5815 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5816 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5817 * 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
|
5818 * bottom files. |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5819 * 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
|
5820 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5821 int |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5822 term_swap_diff() |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5823 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5824 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
|
5825 linenr_T line_count; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5826 linenr_T top_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5827 linenr_T bot_rows; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5828 linenr_T bot_start; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5829 linenr_T lnum; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5830 char_u *p; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5831 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
|
5832 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5833 if (term == NULL |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5834 || !term_is_finished(curbuf) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5835 || 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
|
5836 || 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
|
5837 return FAIL; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5838 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5839 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
|
5840 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
|
5841 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
|
5842 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
|
5843 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
|
5844 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5845 // 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
|
5846 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
|
5847 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5848 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
|
5849 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5850 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5851 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
|
5852 ml_delete(1); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5853 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5854 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5855 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5856 // 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
|
5857 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
|
5858 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5859 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
|
5860 if (p == NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5861 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5862 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
|
5863 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
|
5864 vim_free(p); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5865 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5866 |
15832
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5867 // 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
|
5868 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
|
5869 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
|
5870 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
|
5871 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
|
5872 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
|
5873 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
|
5874 |
85c94163c4ab
patch 8.1.0923: terminal dump diff swap does not update file names
Bram Moolenaar <Bram@vim.org>
parents:
15828
diff
changeset
|
5875 // 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
|
5876 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
|
5877 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
|
5878 return OK; |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
5879 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
|
5880 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
|
5881 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
|
5882 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5883 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
|
5884 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5885 // 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
|
5886 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
|
5887 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5888 sb_line_T temp; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5889 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5890 temp = *(sb_line + lnum); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5891 *(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
|
5892 *(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
|
5893 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5894 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5895 else |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5896 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5897 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
|
5898 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
|
5899 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
5900 // 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
|
5901 if (temp != NULL) |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5902 { |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5903 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
|
5904 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
|
5905 temp + bot_start, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5906 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
|
5907 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
|
5908 temp + top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5909 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
|
5910 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
|
5911 + line_count - top_rows, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5912 temp, |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5913 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
|
5914 vim_free(temp); |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5915 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5916 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5917 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5918 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
|
5919 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
|
5920 |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
5921 update_screen(UPD_NOT_VALID); |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5922 return OK; |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5923 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5924 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5925 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5926 * "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
|
5927 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5928 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5929 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
|
5930 { |
25338
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5931 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
|
5932 && (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
|
5933 || 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
|
5934 || 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
|
5935 return; |
e2be9f3c5907
patch 8.2.3206: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25314
diff
changeset
|
5936 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5937 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
|
5938 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5939 |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5940 /* |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5941 * "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
|
5942 */ |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5943 void |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5944 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
|
5945 { |
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
|
5946 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
|
5947 && (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
|
5948 || 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
|
5949 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
|
5950 |
13298
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5951 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
|
5952 } |
a88c5e12b860
patch 8.0.1523: cannot write and read terminal screendumps
Christian Brabandt <cb@256bit.org>
parents:
13294
diff
changeset
|
5953 |
12502 | 5954 /* |
5955 * "term_getaltscreen(buf)" function | |
5956 */ | |
5957 void | |
5958 f_term_getaltscreen(typval_T *argvars, typval_T *rettv) | |
5959 { | |
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
|
5960 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
|
5961 |
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 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
|
5963 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
|
5964 |
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
|
5965 buf = term_get_buf(argvars, "term_getaltscreen()"); |
12502 | 5966 if (buf == NULL) |
5967 return; | |
5968 rettv->vval.v_number = buf->b_term->tl_using_altscreen; | |
5969 } | |
5970 | |
5971 /* | |
5972 * "term_getattr(attr, name)" function | |
5973 */ | |
5974 void | |
5975 f_term_getattr(typval_T *argvars, typval_T *rettv) | |
5976 { | |
5977 int attr; | |
5978 size_t i; | |
5979 char_u *name; | |
5980 | |
5981 static struct { | |
5982 char *name; | |
5983 int attr; | |
5984 } attrs[] = { | |
5985 {"bold", HL_BOLD}, | |
5986 {"italic", HL_ITALIC}, | |
5987 {"underline", HL_UNDERLINE}, | |
5988 {"strike", HL_STRIKETHROUGH}, | |
5989 {"reverse", HL_INVERSE}, | |
5990 }; | |
5991 | |
25252
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5992 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
|
5993 && (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
|
5994 || 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
|
5995 return; |
acda780ffc3e
patch 8.2.3162: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25198
diff
changeset
|
5996 |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
5997 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
|
5998 name = tv_get_string_chk(&argvars[1]); |
12502 | 5999 if (name == NULL) |
6000 return; | |
6001 | |
18033
049a7481d737
patch 8.1.2012: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
17702
diff
changeset
|
6002 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
|
6003 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
|
6004 for (i = 0; i < ARRAY_LENGTH(attrs); ++i) |
12502 | 6005 if (STRCMP(name, attrs[i].name) == 0) |
6006 { | |
6007 rettv->vval.v_number = (attr & attrs[i].attr) != 0 ? 1 : 0; | |
6008 break; | |
6009 } | |
6010 } | |
6011 | |
6012 /* | |
6013 * "term_getcursor(buf)" function | |
6014 */ | |
6015 void | |
6016 f_term_getcursor(typval_T *argvars, typval_T *rettv) | |
6017 { | |
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
|
6018 buf_T *buf; |
12502 | 6019 term_T *term; |
6020 list_T *l; | |
6021 dict_T *d; | |
6022 | |
6023 if (rettv_list_alloc(rettv) == FAIL) | |
6024 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
|
6025 |
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
|
6026 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
|
6027 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
|
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 buf = term_get_buf(argvars, "term_getcursor()"); |
12502 | 6030 if (buf == NULL) |
6031 return; | |
6032 term = buf->b_term; | |
6033 | |
6034 l = rettv->vval.v_list; | |
6035 list_append_number(l, term->tl_cursor_pos.row + 1); | |
6036 list_append_number(l, term->tl_cursor_pos.col + 1); | |
6037 | |
6038 d = dict_alloc(); | |
6039 if (d != NULL) | |
6040 { | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
6041 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
|
6042 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
|
6043 ? !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
|
6044 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
|
6045 dict_add_string(d, "color", cursor_color_get(term->tl_cursor_color)); |
12502 | 6046 list_append_dict(l, d); |
6047 } | |
6048 } | |
6049 | |
6050 /* | |
6051 * "term_getjob(buf)" function | |
6052 */ | |
6053 void | |
6054 f_term_getjob(typval_T *argvars, typval_T *rettv) | |
6055 { | |
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
|
6056 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
|
6057 |
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 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
|
6059 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
|
6060 |
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
|
6061 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
|
6062 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
|
6063 { |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6064 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
|
6065 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
|
6066 return; |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6067 } |
49bc670c3ee9
patch 8.1.0618: term_getjob() does not return v:null as documented
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
6068 |
12502 | 6069 rettv->v_type = VAR_JOB; |
6070 rettv->vval.v_job = buf->b_term->tl_job; | |
6071 if (rettv->vval.v_job != NULL) | |
6072 ++rettv->vval.v_job->jv_refcount; | |
6073 } | |
6074 | |
6075 static int | |
6076 get_row_number(typval_T *tv, term_T *term) | |
6077 { | |
6078 if (tv->v_type == VAR_STRING | |
6079 && tv->vval.v_string != NULL | |
6080 && STRCMP(tv->vval.v_string, ".") == 0) | |
6081 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
|
6082 return (int)tv_get_number(tv) - 1; |
12502 | 6083 } |
6084 | |
6085 /* | |
6086 * "term_getline(buf, row)" function | |
6087 */ | |
6088 void | |
6089 f_term_getline(typval_T *argvars, typval_T *rettv) | |
6090 { | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6091 buf_T *buf; |
12502 | 6092 term_T *term; |
6093 int row; | |
6094 | |
6095 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
|
6096 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6097 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
|
6098 && (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
|
6099 || 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
|
6100 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6101 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6102 buf = term_get_buf(argvars, "term_getline()"); |
12502 | 6103 if (buf == NULL) |
6104 return; | |
6105 term = buf->b_term; | |
6106 row = get_row_number(&argvars[1], term); | |
6107 | |
6108 if (term->tl_vterm == NULL) | |
6109 { | |
6110 linenr_T lnum = row + term->tl_scrollback_scrolled + 1; | |
6111 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6112 // vterm is finished, get the text from the buffer |
12502 | 6113 if (lnum > 0 && lnum <= buf->b_ml.ml_line_count) |
6114 rettv->vval.v_string = vim_strsave(ml_get_buf(buf, lnum, FALSE)); | |
6115 } | |
6116 else | |
6117 { | |
6118 VTermScreen *screen = vterm_obtain_screen(term->tl_vterm); | |
6119 VTermRect rect; | |
6120 int len; | |
6121 char_u *p; | |
6122 | |
6123 if (row < 0 || row >= term->tl_rows) | |
6124 return; | |
6125 len = term->tl_cols * MB_MAXBYTES + 1; | |
6126 p = alloc(len); | |
6127 if (p == NULL) | |
6128 return; | |
6129 rettv->vval.v_string = p; | |
6130 | |
6131 rect.start_col = 0; | |
6132 rect.end_col = term->tl_cols; | |
6133 rect.start_row = row; | |
6134 rect.end_row = row + 1; | |
6135 p[vterm_screen_get_text(screen, (char *)p, len, rect)] = NUL; | |
6136 } | |
6137 } | |
6138 | |
6139 /* | |
6140 * "term_getscrolled(buf)" function | |
6141 */ | |
6142 void | |
6143 f_term_getscrolled(typval_T *argvars, typval_T *rettv) | |
6144 { | |
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
|
6145 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
|
6146 |
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
|
6147 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
|
6148 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
|
6149 |
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
|
6150 buf = term_get_buf(argvars, "term_getscrolled()"); |
12502 | 6151 if (buf == NULL) |
6152 return; | |
6153 rettv->vval.v_number = buf->b_term->tl_scrollback_scrolled; | |
6154 } | |
6155 | |
6156 /* | |
6157 * "term_getsize(buf)" function | |
6158 */ | |
6159 void | |
6160 f_term_getsize(typval_T *argvars, typval_T *rettv) | |
6161 { | |
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
|
6162 buf_T *buf; |
12502 | 6163 list_T *l; |
6164 | |
6165 if (rettv_list_alloc(rettv) == FAIL) | |
6166 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
|
6167 |
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
|
6168 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
|
6169 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
|
6170 |
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
|
6171 buf = term_get_buf(argvars, "term_getsize()"); |
12502 | 6172 if (buf == NULL) |
6173 return; | |
6174 | |
6175 l = rettv->vval.v_list; | |
6176 list_append_number(l, buf->b_term->tl_rows); | |
6177 list_append_number(l, buf->b_term->tl_cols); | |
6178 } | |
6179 | |
6180 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6181 * "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
|
6182 */ |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6183 void |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6184 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
|
6185 { |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6186 buf_T *buf; |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6187 term_T *term; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6188 varnumber_T rows, cols; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6189 |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6190 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
|
6191 && (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
|
6192 || 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
|
6193 || 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
|
6194 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6195 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6196 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
|
6197 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
|
6198 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
6199 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
|
6200 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
|
6201 } |
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
|
6202 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
|
6203 return; |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6204 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
|
6205 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
|
6206 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
|
6207 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
|
6208 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
|
6209 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
|
6210 // 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
|
6211 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6212 // 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
|
6213 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
|
6214 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
|
6215 } |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6216 |
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
6217 /* |
12502 | 6218 * "term_getstatus(buf)" function |
6219 */ | |
6220 void | |
6221 f_term_getstatus(typval_T *argvars, typval_T *rettv) | |
6222 { | |
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
|
6223 buf_T *buf; |
12502 | 6224 term_T *term; |
6225 char_u val[100]; | |
6226 | |
6227 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
|
6228 |
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
|
6229 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
|
6230 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
|
6231 |
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
|
6232 buf = term_get_buf(argvars, "term_getstatus()"); |
12502 | 6233 if (buf == NULL) |
6234 return; | |
6235 term = buf->b_term; | |
6236 | |
6237 if (term_job_running(term)) | |
6238 STRCPY(val, "running"); | |
6239 else | |
6240 STRCPY(val, "finished"); | |
6241 if (term->tl_normal_mode) | |
6242 STRCAT(val, ",normal"); | |
6243 rettv->vval.v_string = vim_strsave(val); | |
6244 } | |
6245 | |
6246 /* | |
6247 * "term_gettitle(buf)" function | |
6248 */ | |
6249 void | |
6250 f_term_gettitle(typval_T *argvars, typval_T *rettv) | |
6251 { | |
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
|
6252 buf_T *buf; |
12502 | 6253 |
6254 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
|
6255 |
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
|
6256 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
|
6257 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
|
6258 |
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
|
6259 buf = term_get_buf(argvars, "term_gettitle()"); |
12502 | 6260 if (buf == NULL) |
6261 return; | |
6262 | |
6263 if (buf->b_term->tl_title != NULL) | |
6264 rettv->vval.v_string = vim_strsave(buf->b_term->tl_title); | |
6265 } | |
6266 | |
6267 /* | |
6268 * "term_gettty(buf)" function | |
6269 */ | |
6270 void | |
6271 f_term_gettty(typval_T *argvars, typval_T *rettv) | |
6272 { | |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6273 buf_T *buf; |
13864
de8455bd2d05
patch 8.0.1803: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
13862
diff
changeset
|
6274 char_u *p = NULL; |
12502 | 6275 int num = 0; |
6276 | |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6277 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
|
6278 && (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
|
6279 || 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
|
6280 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6281 |
12502 | 6282 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
|
6283 buf = term_get_buf(argvars, "term_gettty()"); |
12502 | 6284 if (buf == NULL) |
6285 return; | |
6286 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
|
6287 num = tv_get_bool(&argvars[1]); |
12502 | 6288 |
6289 switch (num) | |
6290 { | |
6291 case 0: | |
6292 if (buf->b_term->tl_job != NULL) | |
6293 p = buf->b_term->tl_job->jv_tty_out; | |
6294 break; | |
6295 case 1: | |
6296 if (buf->b_term->tl_job != NULL) | |
6297 p = buf->b_term->tl_job->jv_tty_in; | |
6298 break; | |
6299 default: | |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
6300 semsg(_(e_invalid_argument_str), tv_get_string(&argvars[1])); |
12502 | 6301 return; |
6302 } | |
6303 if (p != NULL) | |
6304 rettv->vval.v_string = vim_strsave(p); | |
6305 } | |
6306 | |
6307 /* | |
6308 * "term_list()" function | |
6309 */ | |
6310 void | |
6311 f_term_list(typval_T *argvars UNUSED, typval_T *rettv) | |
6312 { | |
6313 term_T *tp; | |
6314 list_T *l; | |
6315 | |
6316 if (rettv_list_alloc(rettv) == FAIL || first_term == NULL) | |
6317 return; | |
6318 | |
6319 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
|
6320 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
|
6321 if (tp->tl_buffer != NULL) |
12502 | 6322 if (list_append_number(l, |
6323 (varnumber_T)tp->tl_buffer->b_fnum) == FAIL) | |
6324 return; | |
6325 } | |
6326 | |
6327 /* | |
6328 * "term_scrape(buf, row)" function | |
6329 */ | |
6330 void | |
6331 f_term_scrape(typval_T *argvars, typval_T *rettv) | |
6332 { | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6333 buf_T *buf; |
12502 | 6334 VTermScreen *screen = NULL; |
6335 VTermPos pos; | |
6336 list_T *l; | |
6337 term_T *term; | |
6338 char_u *p; | |
6339 sb_line_T *line; | |
6340 | |
6341 if (rettv_list_alloc(rettv) == FAIL) | |
6342 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
|
6343 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6344 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
|
6345 && (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
|
6346 || 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
|
6347 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6348 |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6349 buf = term_get_buf(argvars, "term_scrape()"); |
12502 | 6350 if (buf == NULL) |
6351 return; | |
6352 term = buf->b_term; | |
6353 | |
6354 l = rettv->vval.v_list; | |
6355 pos.row = get_row_number(&argvars[1], term); | |
6356 | |
6357 if (term->tl_vterm != NULL) | |
6358 { | |
6359 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
|
6360 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
|
6361 return; |
12502 | 6362 p = NULL; |
6363 line = NULL; | |
6364 } | |
6365 else | |
6366 { | |
6367 linenr_T lnum = pos.row + term->tl_scrollback_scrolled; | |
6368 | |
6369 if (lnum < 0 || lnum >= term->tl_scrollback.ga_len) | |
6370 return; | |
6371 p = ml_get_buf(buf, lnum + 1, FALSE); | |
6372 line = (sb_line_T *)term->tl_scrollback.ga_data + lnum; | |
6373 } | |
6374 | |
6375 for (pos.col = 0; pos.col < term->tl_cols; ) | |
6376 { | |
6377 dict_T *dcell; | |
6378 int width; | |
6379 VTermScreenCellAttrs attrs; | |
6380 VTermColor fg, bg; | |
6381 char_u rgb[8]; | |
6382 char_u mbs[MB_MAXBYTES * VTERM_MAX_CHARS_PER_CELL + 1]; | |
6383 int off = 0; | |
6384 int i; | |
6385 | |
6386 if (screen == NULL) | |
6387 { | |
6388 cellattr_T *cellattr; | |
6389 int len; | |
6390 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6391 // vterm has finished, get the cell from scrollback |
12502 | 6392 if (pos.col >= line->sb_cols) |
6393 break; | |
6394 cellattr = line->sb_cells + pos.col; | |
6395 width = cellattr->width; | |
6396 attrs = cellattr->attrs; | |
6397 fg = cellattr->fg; | |
6398 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
|
6399 len = mb_ptr2len(p); |
12502 | 6400 mch_memmove(mbs, p, len); |
6401 mbs[len] = NUL; | |
6402 p += len; | |
6403 } | |
6404 else | |
6405 { | |
6406 VTermScreenCell cell; | |
20500
03826c672315
patch 8.2.0804: libvterm code lags behind the upstream version
Bram Moolenaar <Bram@vim.org>
parents:
20496
diff
changeset
|
6407 |
12502 | 6408 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
6409 break; | |
6410 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | |
6411 { | |
6412 if (cell.chars[i] == 0) | |
6413 break; | |
6414 off += (*utf_char2bytes)((int)cell.chars[i], mbs + off); | |
6415 } | |
6416 mbs[off] = NUL; | |
6417 width = cell.width; | |
6418 attrs = cell.attrs; | |
6419 fg = cell.fg; | |
6420 bg = cell.bg; | |
6421 } | |
6422 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
|
6423 if (dcell == NULL) |
fc33325c91c1
patch 8.0.1499: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6424 break; |
12502 | 6425 list_append_dict(l, dcell); |
6426 | |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14139
diff
changeset
|
6427 dict_add_string(dcell, "chars", mbs); |
12502 | 6428 |
6429 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", | |
6430 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
|
6431 dict_add_string(dcell, "fg", rgb); |
12502 | 6432 vim_snprintf((char *)rgb, 8, "#%02x%02x%02x", |
6433 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
|
6434 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
|
6435 |
26193
c83460a14407
patch 8.2.3628: looking terminal colors is a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
26185
diff
changeset
|
6436 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
|
6437 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
|
6438 dict_add_number(dcell, "width", width); |
12502 | 6439 |
6440 ++pos.col; | |
6441 if (width == 2) | |
6442 ++pos.col; | |
6443 } | |
6444 } | |
6445 | |
6446 /* | |
6447 * "term_sendkeys(buf, keys)" function | |
6448 */ | |
6449 void | |
19633
dd3e5533a7d2
patch 8.2.0373: type of term_sendkeys() is unknown
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
6450 f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED) |
12502 | 6451 { |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6452 buf_T *buf; |
12502 | 6453 char_u *msg; |
6454 term_T *term; | |
6455 | |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6456 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
|
6457 && (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
|
6458 || 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
|
6459 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6460 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6461 buf = term_get_buf(argvars, "term_sendkeys()"); |
12502 | 6462 if (buf == NULL) |
6463 return; | |
6464 | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15203
diff
changeset
|
6465 msg = tv_get_string_chk(&argvars[1]); |
12502 | 6466 if (msg == NULL) |
6467 return; | |
6468 term = buf->b_term; | |
6469 if (term->tl_vterm == NULL) | |
6470 return; | |
6471 | |
6472 while (*msg != NUL) | |
6473 { | |
14029
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6474 int c; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6475 |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6476 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
|
6477 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6478 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
|
6479 msg += 3; |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6480 } |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6481 else |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6482 { |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6483 c = PTR2CHAR(msg); |
d9fc15c833d5
patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents:
13996
diff
changeset
|
6484 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
|
6485 } |
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
|
6486 send_keys_to_term(term, c, 0, FALSE); |
12502 | 6487 } |
6488 } | |
6489 | |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6490 #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
|
6491 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6492 * "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
|
6493 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6494 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6495 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
|
6496 { |
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
|
6497 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
|
6498 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
|
6499 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
|
6500 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
|
6501 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
|
6502 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
|
6503 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
|
6504 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6505 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
|
6506 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6507 |
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
|
6508 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
|
6509 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
|
6510 |
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
|
6511 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
|
6512 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
|
6513 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6514 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
|
6515 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
|
6516 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6517 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6518 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
|
6519 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
|
6520 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
|
6521 { |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6522 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
|
6523 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
|
6524 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
|
6525 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
|
6526 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6527 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6528 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6529 |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6530 /* |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6531 * "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
|
6532 */ |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6533 void |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6534 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
|
6535 { |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6536 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
|
6537 term_T *term; |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6538 listitem_T *li; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6539 int n = 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
|
6540 |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6541 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
|
6542 && (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
|
6543 || 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
|
6544 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6545 |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25272
diff
changeset
|
6546 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
|
6547 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
|
6548 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6549 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
|
6550 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
|
6551 return; |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6552 |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
6553 if (check_for_nonnull_list_arg(argvars, 1) == FAIL) |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6554 return; |
30015
adb0de8be4ce
patch 9.0.0345: error message for list argument could be clearer
Bram Moolenaar <Bram@vim.org>
parents:
29994
diff
changeset
|
6555 |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6556 if (argvars[1].vval.v_list->lv_first == &range_list_item |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6557 || argvars[1].vval.v_list->lv_len != 16) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6558 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
6559 emsg(_(e_invalid_argument)); |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6560 return; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6561 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6562 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6563 if (term->tl_palette == NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6564 term->tl_palette = ALLOC_MULT(long_u, 16); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6565 if (term->tl_palette == NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6566 return; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6567 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6568 FOR_ALL_LIST_ITEMS(argvars[1].vval.v_list, li) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6569 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6570 char_u *color_name; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6571 guicolor_T guicolor; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6572 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6573 color_name = tv_get_string_chk(&li->li_tv); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6574 if (color_name == NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6575 return; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6576 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6577 guicolor = GUI_GET_COLOR(color_name); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6578 if (guicolor == INVALCOLOR) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6579 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6580 semsg(_(e_cannot_allocate_color_str), color_name); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6581 return; |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6582 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6583 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6584 term->tl_palette[n++] = GUI_MCH_GET_RGB(guicolor); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6585 } |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6586 |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
6587 term_update_palette(term); |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6588 } |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6589 #endif |
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
6590 |
12502 | 6591 /* |
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
|
6592 * "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
|
6593 */ |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6594 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
|
6595 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
|
6596 { |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6597 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
|
6598 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
|
6599 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
|
6600 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6601 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
|
6602 && (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
|
6603 || 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
|
6604 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6605 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6606 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
|
6607 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
|
6608 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
|
6609 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
|
6610 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
|
6611 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
|
6612 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
|
6613 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
|
6614 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
|
6615 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
|
6616 } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6617 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
18162
diff
changeset
|
6618 /* |
13435
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6619 * "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
|
6620 */ |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6621 void |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6622 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
|
6623 { |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6624 #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
|
6625 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
|
6626 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
|
6627 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
|
6628 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6629 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
|
6630 && (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
|
6631 || 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
|
6632 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6633 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6634 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
|
6635 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
|
6636 return; |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6637 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
|
6638 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
|
6639 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
|
6640 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
|
6641 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
|
6642 else |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6643 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
|
6644 #endif |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6645 } |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6646 |
fa198b71bab2
patch 8.0.1592: terminal windows in a session are not properly restored
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
6647 /* |
13438
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6648 * "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
|
6649 */ |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6650 void |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6651 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
|
6652 { |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6653 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
|
6654 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
|
6655 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
|
6656 |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6657 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
|
6658 && (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
|
6659 || 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
|
6660 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6661 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6662 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
|
6663 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
|
6664 return; |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6665 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
|
6666 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
|
6667 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
|
6668 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
|
6669 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
|
6670 else |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6671 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
|
6672 } |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6673 |
33eea5ce5415
patch 8.0.1593: :qall never exits with an active terminal window
Christian Brabandt <cb@256bit.org>
parents:
13435
diff
changeset
|
6674 /* |
12502 | 6675 * "term_start(command, options)" function |
6676 */ | |
6677 void | |
6678 f_term_start(typval_T *argvars, typval_T *rettv) | |
6679 { | |
6680 jobopt_T opt; | |
6681 buf_T *buf; | |
6682 | |
25314
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6683 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
|
6684 && (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
|
6685 || 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
|
6686 return; |
7e620652bd13
patch 8.2.3194: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
6687 |
12502 | 6688 init_job_options(&opt); |
6689 if (argvars[1].v_type != VAR_UNKNOWN | |
6690 && get_job_options(&argvars[1], &opt, | |
6691 JO_TIMEOUT_ALL + JO_STOPONEXIT | |
6692 + JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK | |
6693 + JO_EXIT_CB + JO_CLOSE_CALLBACK + JO_OUT_IO, | |
6694 JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD | |
6695 + 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
|
6696 + 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
|
6697 + 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
|
6698 + JO2_ANSI_COLORS + JO2_TTY_TYPE + JO2_TERM_API) == FAIL) |
12502 | 6699 return; |
6700 | |
13470
6faef782f50b
patch 8.0.1609: shell commands in the GUI use a dumb terminal
Christian Brabandt <cb@256bit.org>
parents:
13458
diff
changeset
|
6701 buf = term_start(&argvars[0], NULL, &opt, 0); |
12502 | 6702 |
6703 if (buf != NULL && buf->b_term != NULL) | |
6704 rettv->vval.v_number = buf->b_fnum; | |
6705 } | |
6706 | |
6707 /* | |
6708 * "term_wait" function | |
6709 */ | |
6710 void | |
6711 f_term_wait(typval_T *argvars, typval_T *rettv UNUSED) | |
6712 { | |
25272
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6713 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
|
6714 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6715 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
|
6716 && (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
|
6717 || 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
|
6718 return; |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6719 |
712e867f9721
patch 8.2.3173: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
25252
diff
changeset
|
6720 buf = term_get_buf(argvars, "term_wait()"); |
12502 | 6721 if (buf == NULL) |
6722 return; | |
6723 if (buf->b_term->tl_job == NULL) | |
6724 { | |
6725 ch_log(NULL, "term_wait(): no job to wait for"); | |
6726 return; | |
6727 } | |
6728 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
|
6729 // channel is closed, nothing to do |
12502 | 6730 return; |
6731 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6732 // 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
|
6733 if (!buf->b_term->tl_job->jv_channel->ch_keep_open |
12502 | 6734 && STRCMP(job_status(buf->b_term->tl_job), "dead") == 0) |
6735 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6736 // 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
|
6737 // 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
|
6738 // waiting. |
12502 | 6739 ch_log(NULL, "term_wait(): waiting for channel to close"); |
6740 while (buf->b_term != NULL && !buf->b_term->tl_channel_closed) | |
6741 { | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6742 term_flush_messages(); |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6743 |
13996
59121ffd7fce
patch 8.1.0016: possible crash in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
13994
diff
changeset
|
6744 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
|
6745 if (!buf_valid(buf)) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6746 // 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
|
6747 // buffer disappears. |
12881
1c05b29ab125
patch 8.0.1317: accessing freed memory in term_wait()
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
6748 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
|
6749 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
|
6750 // 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
|
6751 break; |
12502 | 6752 } |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6753 |
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6754 term_flush_messages(); |
12502 | 6755 } |
6756 else | |
6757 { | |
6758 long wait = 10L; | |
6759 | |
17186
278583ff5e44
patch 8.1.1592: may start file dialog while exiting
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
6760 term_flush_messages(); |
12502 | 6761 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6762 // Wait for some time for any channel I/O. |
12502 | 6763 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
|
6764 wait = tv_get_number(&argvars[1]); |
12502 | 6765 ui_delay(wait, TRUE); |
6766 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6767 // 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
|
6768 // 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
|
6769 term_flush_messages(); |
12502 | 6770 } |
6771 } | |
6772 | |
6773 /* | |
6774 * Called when a channel has sent all the lines to a terminal. | |
6775 * Send a CTRL-D to mark the end of the text. | |
6776 */ | |
6777 void | |
6778 term_send_eof(channel_T *ch) | |
6779 { | |
6780 term_T *term; | |
6781 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19832
diff
changeset
|
6782 FOR_ALL_TERMS(term) |
12502 | 6783 if (term->tl_job == ch->ch_job) |
6784 { | |
6785 if (term->tl_eof_chars != NULL) | |
6786 { | |
6787 channel_send(ch, PART_IN, term->tl_eof_chars, | |
6788 (int)STRLEN(term->tl_eof_chars), NULL); | |
6789 channel_send(ch, PART_IN, (char_u *)"\r", 1, NULL); | |
6790 } | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6791 # ifdef MSWIN |
12502 | 6792 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6793 // Default: CTRL-D |
12502 | 6794 channel_send(ch, PART_IN, (char_u *)"\004\r", 2, NULL); |
6795 # endif | |
6796 } | |
6797 } | |
6798 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6799 #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
|
6800 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
|
6801 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
|
6802 { |
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
|
6803 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
|
6804 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15504
diff
changeset
|
6805 #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
|
6806 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15844
diff
changeset
|
6807 # if defined(MSWIN) || defined(PROTO) |
12502 | 6808 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6809 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6810 // 2. MS-Windows implementation. |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6811 #ifdef PROTO |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6812 typedef int COORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6813 typedef int DWORD; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6814 typedef int HANDLE; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6815 typedef int *DWORD_PTR; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6816 typedef int HPCON; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6817 typedef int HRESULT; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6818 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
|
6819 typedef int SIZE_T; |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6820 typedef int PSIZE_T; |
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6821 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
|
6822 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
|
6823 # define WINAPI |
16354
b3bc3ba07bef
patch 8.1.1182: some function prototypes are outdated
Bram Moolenaar <Bram@vim.org>
parents:
16312
diff
changeset
|
6824 #endif |
12502 | 6825 |
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
|
6826 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
|
6827 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
|
6828 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
|
6829 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
|
6830 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
|
6831 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
|
6832 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6833 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
|
6834 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
|
6835 { |
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
|
6836 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
|
6837 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
|
6838 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
|
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 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
|
6841 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
|
6842 } 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
|
6843 { |
a3e2e7948ee4
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 {"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
|
6845 {"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
|
6846 {"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
|
6847 {"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
|
6848 (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
|
6849 {"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
|
6850 (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
|
6851 {"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
|
6852 (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
|
6853 {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
|
6854 }; |
a3e2e7948ee4
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 |
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
|
6856 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
|
6857 { |
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
|
6858 if (verbose) |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
6859 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
|
6860 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
|
6861 } |
a3e2e7948ee4
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 |
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
|
6863 // 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
|
6864 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
|
6865 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
|
6866 |
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
|
6867 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
|
6868 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
|
6869 && 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
|
6870 { |
a3e2e7948ee4
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 ((*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
|
6872 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
|
6873 { |
a3e2e7948ee4
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 if (verbose) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
6875 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
|
6876 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
|
6877 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
|
6878 } |
a3e2e7948ee4
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 } |
a3e2e7948ee4
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 |
a3e2e7948ee4
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 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
|
6882 } |
a3e2e7948ee4
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 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
|
6885 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
|
6886 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
|
6887 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
|
6888 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
|
6889 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
|
6890 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
|
6891 { |
a3e2e7948ee4
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 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
|
6893 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
|
6894 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
|
6895 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
|
6896 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
|
6897 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
|
6898 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
|
6899 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
|
6900 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
|
6901 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
|
6902 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
|
6903 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
|
6904 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
|
6905 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
|
6906 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
|
6907 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
|
6908 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
|
6909 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
6910 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
|
6911 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
|
6912 |
a3e2e7948ee4
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 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
|
6914 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6915 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
|
6916 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6917 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
|
6918 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6919 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
|
6920 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
|
6921 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
|
6922 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6923 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
|
6924 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
6925 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
|
6926 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
|
6927 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6928 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6929 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
|
6930 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6931 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
|
6932 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6933 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
|
6934 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6935 // Request by CreateProcessW |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6936 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
|
6937 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
|
6938 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
|
6939 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6940 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6941 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
|
6942 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
|
6943 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
|
6944 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
|
6945 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
|
6946 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6947 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
|
6948 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
|
6949 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6950 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
|
6951 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
|
6952 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
|
6953 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
|
6954 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6955 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
|
6956 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
|
6957 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
|
6958 &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
|
6959 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
|
6960 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
|
6961 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6962 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
|
6963 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
6964 // 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
|
6965 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
|
6966 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
|
6967 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
|
6968 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
|
6969 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
|
6970 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
|
6971 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
|
6972 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
|
6973 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
|
6974 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
|
6975 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
|
6976 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
|
6977 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6978 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
|
6979 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
|
6980 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
|
6981 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6982 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
|
6983 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
|
6984 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
|
6985 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
|
6986 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6987 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
|
6988 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6989 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
|
6990 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6991 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
|
6992 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6993 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
|
6994 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6995 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
|
6996 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6997 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
6998 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
|
6999 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
|
7000 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7001 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
|
7002 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
|
7003 | 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
|
7004 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
|
7005 &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
|
7006 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
|
7007 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7008 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
|
7009 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
|
7010 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7011 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
|
7012 (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
|
7013 (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
|
7014 (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
|
7015 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7016 // 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
|
7017 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
|
7018 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7019 // 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
|
7020 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
|
7021 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7022 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
|
7023 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
|
7024 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
|
7025 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7026 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
|
7027 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7028 // 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
|
7029 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
|
7030 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
|
7031 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7032 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7033 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
|
7034 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
|
7035 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7036 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
|
7037 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
|
7038 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
|
7039 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
|
7040 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7041 if (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
|
7042 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
|
7043 |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
7044 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7045 if (term_use_palette()) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7046 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7047 if (term->tl_palette != NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7048 set_vterm_palette(term->tl_vterm, term->tl_palette); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7049 else |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7050 init_vterm_ansi_colors(term->tl_vterm); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7051 } |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
7052 #endif |
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
|
7053 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7054 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
|
7055 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
|
7056 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7057 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
|
7058 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
|
7059 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
|
7060 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
|
7061 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
|
7062 ++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
|
7063 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
|
7064 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7065 // 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
|
7066 // 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
|
7067 // 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
|
7068 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
|
7069 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7070 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
|
7071 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7072 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
|
7073 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
|
7074 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
|
7075 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
|
7076 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7077 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7078 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
|
7079 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7080 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
|
7081 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
|
7082 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
|
7083 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
|
7084 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
|
7085 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
|
7086 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
|
7087 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
|
7088 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
|
7089 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7090 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
|
7091 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
|
7092 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7093 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
|
7094 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
|
7095 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
|
7096 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7097 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
|
7098 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7099 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
|
7100 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
|
7101 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7102 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
|
7103 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
|
7104 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
|
7105 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
|
7106 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
|
7107 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
|
7108 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
|
7109 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
|
7110 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
|
7111 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
|
7112 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
|
7113 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
|
7114 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
|
7115 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7116 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7117 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
|
7118 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
|
7119 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7120 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
|
7121 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7122 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
|
7123 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
|
7124 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
|
7125 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7126 |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
18033
diff
changeset
|
7127 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
|
7128 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
|
7129 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7130 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
|
7131 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7132 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
|
7133 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
|
7134 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7135 term->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
|
7136 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
|
7137 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
|
7138 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
|
7139 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7140 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7141 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
|
7142 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
|
7143 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7144 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
|
7145 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7146 |
12502 | 7147 # ifndef PROTO |
7148 | |
7149 #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul | |
7150 #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
|
7151 #define WINPTY_MOUSE_MODE_FORCE 2 |
12502 | 7152 |
7153 void* (*winpty_config_new)(UINT64, void*); | |
7154 void* (*winpty_open)(void*, void*); | |
7155 void* (*winpty_spawn_config_new)(UINT64, void*, LPCWSTR, void*, void*, void*); | |
7156 BOOL (*winpty_spawn)(void*, void*, HANDLE*, HANDLE*, DWORD*, void*); | |
7157 void (*winpty_config_set_mouse_mode)(void*, int); | |
7158 void (*winpty_config_set_initial_size)(void*, int, int); | |
7159 LPCWSTR (*winpty_conin_name)(void*); | |
7160 LPCWSTR (*winpty_conout_name)(void*); | |
7161 LPCWSTR (*winpty_conerr_name)(void*); | |
7162 void (*winpty_free)(void*); | |
7163 void (*winpty_config_free)(void*); | |
7164 void (*winpty_spawn_config_free)(void*); | |
7165 void (*winpty_error_free)(void*); | |
7166 LPCWSTR (*winpty_error_msg)(void*); | |
7167 BOOL (*winpty_set_size)(void*, int, int, void*); | |
7168 HANDLE (*winpty_agent_process)(void*); | |
7169 | |
7170 #define WINPTY_DLL "winpty.dll" | |
7171 | |
7172 static HINSTANCE hWinPtyDLL = NULL; | |
7173 # endif | |
7174 | |
7175 static int | |
7176 dyn_winpty_init(int verbose) | |
7177 { | |
7178 int i; | |
7179 static struct | |
7180 { | |
7181 char *name; | |
7182 FARPROC *ptr; | |
7183 } winpty_entry[] = | |
7184 { | |
7185 {"winpty_conerr_name", (FARPROC*)&winpty_conerr_name}, | |
7186 {"winpty_config_free", (FARPROC*)&winpty_config_free}, | |
7187 {"winpty_config_new", (FARPROC*)&winpty_config_new}, | |
7188 {"winpty_config_set_mouse_mode", | |
7189 (FARPROC*)&winpty_config_set_mouse_mode}, | |
7190 {"winpty_config_set_initial_size", | |
7191 (FARPROC*)&winpty_config_set_initial_size}, | |
7192 {"winpty_conin_name", (FARPROC*)&winpty_conin_name}, | |
7193 {"winpty_conout_name", (FARPROC*)&winpty_conout_name}, | |
7194 {"winpty_error_free", (FARPROC*)&winpty_error_free}, | |
7195 {"winpty_free", (FARPROC*)&winpty_free}, | |
7196 {"winpty_open", (FARPROC*)&winpty_open}, | |
7197 {"winpty_spawn", (FARPROC*)&winpty_spawn}, | |
7198 {"winpty_spawn_config_free", (FARPROC*)&winpty_spawn_config_free}, | |
7199 {"winpty_spawn_config_new", (FARPROC*)&winpty_spawn_config_new}, | |
7200 {"winpty_error_msg", (FARPROC*)&winpty_error_msg}, | |
7201 {"winpty_set_size", (FARPROC*)&winpty_set_size}, | |
7202 {"winpty_agent_process", (FARPROC*)&winpty_agent_process}, | |
7203 {NULL, NULL} | |
7204 }; | |
7205 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7206 // No need to initialize twice. |
12502 | 7207 if (hWinPtyDLL) |
7208 return OK; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7209 // 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
|
7210 // winpty.dll. |
12502 | 7211 if (*p_winptydll != NUL) |
7212 hWinPtyDLL = vimLoadLib((char *)p_winptydll); | |
7213 if (!hWinPtyDLL) | |
7214 hWinPtyDLL = vimLoadLib(WINPTY_DLL); | |
7215 if (!hWinPtyDLL) | |
7216 { | |
7217 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
7218 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
|
7219 (*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
|
7220 GetWin32Error()); |
12502 | 7221 return FAIL; |
7222 } | |
7223 for (i = 0; winpty_entry[i].name != NULL | |
7224 && winpty_entry[i].ptr != NULL; ++i) | |
7225 { | |
7226 if ((*winpty_entry[i].ptr = (FARPROC)GetProcAddress(hWinPtyDLL, | |
7227 winpty_entry[i].name)) == NULL) | |
7228 { | |
7229 if (verbose) | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
7230 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
|
7231 hWinPtyDLL = NULL; |
12502 | 7232 return FAIL; |
7233 } | |
7234 } | |
7235 | |
7236 return OK; | |
7237 } | |
7238 | |
7239 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
|
7240 winpty_term_and_job_init( |
12502 | 7241 term_T *term, |
7242 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
|
7243 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
|
7244 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
|
7245 jobopt_T *orig_opt) |
12502 | 7246 { |
7247 WCHAR *cmd_wchar = NULL; | |
7248 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
|
7249 WCHAR *env_wchar = NULL; |
12502 | 7250 channel_T *channel = NULL; |
7251 job_T *job = NULL; | |
7252 DWORD error; | |
7253 HANDLE jo = NULL; | |
7254 HANDLE child_process_handle; | |
7255 HANDLE child_thread_handle; | |
13111
149347fda678
patch 8.0.1430: crash when term_start() fails
Christian Brabandt <cb@256bit.org>
parents:
13109
diff
changeset
|
7256 void *winpty_err = NULL; |
12502 | 7257 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
|
7258 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
|
7259 char_u *cmd = NULL; |
12502 | 7260 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
7261 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
|
7262 ga_init2(&ga_env, sizeof(char*), 20); |
12502 | 7263 |
7264 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
|
7265 { |
12502 | 7266 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
|
7267 } |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7268 else if (argvar->v_type == VAR_LIST) |
12502 | 7269 { |
12724
17c257dd2438
patch 8.0.1240: MS-Windows: term_start() does not support environment
Christian Brabandt <cb@256bit.org>
parents:
12650
diff
changeset
|
7270 if (win32_build_cmd(argvar->vval.v_list, &ga_cmd) == FAIL) |
12502 | 7271 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
|
7272 cmd = ga_cmd.ga_data; |
12502 | 7273 } |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7274 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
|
7275 { |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
7276 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
|
7277 goto failed; |
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7278 } |
12502 | 7279 |
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
|
7280 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
|
7281 |
12502 | 7282 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
|
7283 ga_clear(&ga_cmd); |
12502 | 7284 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
|
7285 goto failed; |
12502 | 7286 if (opt->jo_cwd != NULL) |
7287 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
|
7288 |
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
|
7289 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
|
7290 env_wchar = ga_env.ga_data; |
12502 | 7291 |
7292 term->tl_winpty_config = winpty_config_new(0, &winpty_err); | |
7293 if (term->tl_winpty_config == NULL) | |
7294 goto failed; | |
7295 | |
7296 winpty_config_set_mouse_mode(term->tl_winpty_config, | |
7297 WINPTY_MOUSE_MODE_FORCE); | |
7298 winpty_config_set_initial_size(term->tl_winpty_config, | |
7299 term->tl_cols, term->tl_rows); | |
7300 term->tl_winpty = winpty_open(term->tl_winpty_config, &winpty_err); | |
7301 if (term->tl_winpty == NULL) | |
7302 goto failed; | |
7303 | |
7304 spawn_config = winpty_spawn_config_new( | |
7305 WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN | | |
7306 WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN, | |
7307 NULL, | |
7308 cmd_wchar, | |
7309 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
|
7310 env_wchar, |
12502 | 7311 &winpty_err); |
7312 if (spawn_config == NULL) | |
7313 goto failed; | |
7314 | |
7315 channel = add_channel(); | |
7316 if (channel == NULL) | |
7317 goto failed; | |
7318 | |
7319 job = job_alloc(); | |
7320 if (job == NULL) | |
7321 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
|
7322 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
|
7323 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7324 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
|
7325 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7326 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
|
7327 } |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7328 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
|
7329 { |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7330 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
|
7331 |
3ab6198c1f9a
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd
Christian Brabandt <cb@256bit.org>
parents:
13746
diff
changeset
|
7332 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
|
7333 } |
12502 | 7334 |
7335 if (opt->jo_set & JO_IN_BUF) | |
7336 job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); | |
7337 | |
7338 if (!winpty_spawn(term->tl_winpty, spawn_config, &child_process_handle, | |
7339 &child_thread_handle, &error, &winpty_err)) | |
7340 goto failed; | |
7341 | |
7342 channel_set_pipes(channel, | |
7343 (sock_T)CreateFileW( | |
7344 winpty_conin_name(term->tl_winpty), | |
7345 GENERIC_WRITE, 0, NULL, | |
7346 OPEN_EXISTING, 0, NULL), | |
7347 (sock_T)CreateFileW( | |
7348 winpty_conout_name(term->tl_winpty), | |
7349 GENERIC_READ, 0, NULL, | |
7350 OPEN_EXISTING, 0, NULL), | |
7351 (sock_T)CreateFileW( | |
7352 winpty_conerr_name(term->tl_winpty), | |
7353 GENERIC_READ, 0, NULL, | |
7354 OPEN_EXISTING, 0, NULL)); | |
7355 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7356 // Write lines with CR instead of NL. |
12502 | 7357 channel->ch_write_text_mode = TRUE; |
7358 | |
7359 jo = CreateJobObject(NULL, NULL); | |
7360 if (jo == NULL) | |
7361 goto failed; | |
7362 | |
7363 if (!AssignProcessToJobObject(jo, child_process_handle)) | |
7364 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7365 // Failed, switch the way to terminate process with TerminateProcess. |
12502 | 7366 CloseHandle(jo); |
7367 jo = NULL; | |
7368 } | |
7369 | |
7370 winpty_spawn_config_free(spawn_config); | |
7371 vim_free(cmd_wchar); | |
7372 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
|
7373 vim_free(env_wchar); |
12502 | 7374 |
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
|
7375 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
|
7376 goto failed; |
12502 | 7377 |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
7378 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7379 if (term_use_palette()) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7380 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7381 if (term->tl_palette != NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7382 set_vterm_palette(term->tl_vterm, term->tl_palette); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7383 else |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7384 init_vterm_ansi_colors(term->tl_vterm); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7385 } |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
7386 #endif |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7387 |
12502 | 7388 channel_set_job(channel, job, opt); |
7389 job_set_options(job, opt); | |
7390 | |
7391 job->jv_channel = channel; | |
7392 job->jv_proc_info.hProcess = child_process_handle; | |
7393 job->jv_proc_info.dwProcessId = GetProcessId(child_process_handle); | |
7394 job->jv_job_object = jo; | |
7395 job->jv_status = JOB_STARTED; | |
7396 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
|
7397 (short_u *)winpty_conin_name(term->tl_winpty), NULL); |
12502 | 7398 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
|
7399 (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
|
7400 job->jv_tty_type = vim_strsave((char_u *)"winpty"); |
12502 | 7401 ++job->jv_refcount; |
7402 term->tl_job = job; | |
7403 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7404 // 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
|
7405 // 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
|
7406 // 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
|
7407 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
|
7408 { |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7409 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
|
7410 |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7411 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
|
7412 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
|
7413 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
|
7414 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
|
7415 } |
7f892e37b017
patch 8.0.1801: MS-Windows: redirecting terminal output does not work
Christian Brabandt <cb@256bit.org>
parents:
13851
diff
changeset
|
7416 |
12502 | 7417 return OK; |
7418 | |
7419 failed: | |
13109
fb1b162cdcf6
patch 8.0.1429: crash when calling term_start() with empty argument
Christian Brabandt <cb@256bit.org>
parents:
13000
diff
changeset
|
7420 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
|
7421 ga_clear(&ga_env); |
12502 | 7422 vim_free(cmd_wchar); |
7423 vim_free(cwd_wchar); | |
7424 if (spawn_config != NULL) | |
7425 winpty_spawn_config_free(spawn_config); | |
7426 if (channel != NULL) | |
7427 channel_clear(channel); | |
7428 if (job != NULL) | |
7429 { | |
7430 job->jv_channel = NULL; | |
7431 job_cleanup(job); | |
7432 } | |
7433 term->tl_job = NULL; | |
7434 if (jo != NULL) | |
7435 CloseHandle(jo); | |
7436 if (term->tl_winpty != NULL) | |
7437 winpty_free(term->tl_winpty); | |
7438 term->tl_winpty = NULL; | |
7439 if (term->tl_winpty_config != NULL) | |
7440 winpty_config_free(term->tl_winpty_config); | |
7441 term->tl_winpty_config = NULL; | |
7442 if (winpty_err != NULL) | |
7443 { | |
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
|
7444 char *msg = (char *)utf16_to_enc( |
12502 | 7445 (short_u *)winpty_error_msg(winpty_err), NULL); |
7446 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15355
diff
changeset
|
7447 emsg(msg); |
12502 | 7448 winpty_error_free(winpty_err); |
7449 } | |
7450 return FAIL; | |
7451 } | |
7452 | |
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
|
7453 /* |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7454 * 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
|
7455 * 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
|
7456 * 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
|
7457 */ |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7458 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
|
7459 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
|
7460 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
|
7461 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
|
7462 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
|
7463 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
|
7464 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
|
7465 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7466 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
|
7467 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
|
7468 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
|
7469 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7470 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
|
7471 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
|
7472 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7473 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
|
7474 // 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
|
7475 // 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
|
7476 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
|
7477 |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7478 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
|
7479 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
|
7480 |
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7481 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
|
7482 { |
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
|
7483 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
|
7484 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
|
7485 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
|
7486 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
|
7487 // 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
|
7488 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7489 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
|
7490 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7491 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
|
7492 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
|
7493 } |
15746
c017195b121b
patch 8.1.0880: MS-Windows: inconsistent selection of winpty/conpty
Bram Moolenaar <Bram@vim.org>
parents:
15725
diff
changeset
|
7494 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
|
7495 { |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7496 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
|
7497 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
|
7498 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
|
7499 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
|
7500 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7501 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7502 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
|
7503 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
|
7504 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7505 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
|
7506 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
|
7507 |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7508 // 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
|
7509 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
|
7510 } |
a3e2e7948ee4
patch 8.1.0870: Vim doesn't use the new ConPTY support in Windows 10
Bram Moolenaar <Bram@vim.org>
parents:
15679
diff
changeset
|
7511 |
12502 | 7512 static int |
7513 create_pty_only(term_T *term, jobopt_T *options) | |
7514 { | |
7515 HANDLE hPipeIn = INVALID_HANDLE_VALUE; | |
7516 HANDLE hPipeOut = INVALID_HANDLE_VALUE; | |
7517 char in_name[80], out_name[80]; | |
7518 channel_T *channel = NULL; | |
7519 | |
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
|
7520 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
|
7521 return FAIL; |
12502 | 7522 |
7523 vim_snprintf(in_name, sizeof(in_name), "\\\\.\\pipe\\vim-%d-in-%d", | |
7524 GetCurrentProcessId(), | |
7525 curbuf->b_fnum); | |
7526 hPipeIn = CreateNamedPipe(in_name, PIPE_ACCESS_OUTBOUND, | |
7527 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
7528 PIPE_UNLIMITED_INSTANCES, | |
7529 0, 0, NMPWAIT_NOWAIT, NULL); | |
7530 if (hPipeIn == INVALID_HANDLE_VALUE) | |
7531 goto failed; | |
7532 | |
7533 vim_snprintf(out_name, sizeof(out_name), "\\\\.\\pipe\\vim-%d-out-%d", | |
7534 GetCurrentProcessId(), | |
7535 curbuf->b_fnum); | |
7536 hPipeOut = CreateNamedPipe(out_name, PIPE_ACCESS_INBOUND, | |
7537 PIPE_TYPE_MESSAGE | PIPE_NOWAIT, | |
7538 PIPE_UNLIMITED_INSTANCES, | |
7539 0, 0, 0, NULL); | |
7540 if (hPipeOut == INVALID_HANDLE_VALUE) | |
7541 goto failed; | |
7542 | |
7543 ConnectNamedPipe(hPipeIn, NULL); | |
7544 ConnectNamedPipe(hPipeOut, NULL); | |
7545 | |
7546 term->tl_job = job_alloc(); | |
7547 if (term->tl_job == NULL) | |
7548 goto failed; | |
7549 ++term->tl_job->jv_refcount; | |
7550 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7551 // behave like the job is already finished |
12502 | 7552 term->tl_job->jv_status = JOB_FINISHED; |
7553 | |
7554 channel = add_channel(); | |
7555 if (channel == NULL) | |
7556 goto failed; | |
7557 term->tl_job->jv_channel = channel; | |
7558 channel->ch_keep_open = TRUE; | |
7559 channel->ch_named_pipe = TRUE; | |
7560 | |
7561 channel_set_pipes(channel, | |
7562 (sock_T)hPipeIn, | |
7563 (sock_T)hPipeOut, | |
7564 (sock_T)hPipeOut); | |
7565 channel_set_job(channel, term->tl_job, options); | |
7566 term->tl_job->jv_tty_in = vim_strsave((char_u*)in_name); | |
7567 term->tl_job->jv_tty_out = vim_strsave((char_u*)out_name); | |
7568 | |
7569 return OK; | |
7570 | |
7571 failed: | |
7572 if (hPipeIn != NULL) | |
7573 CloseHandle(hPipeIn); | |
7574 if (hPipeOut != NULL) | |
7575 CloseHandle(hPipeOut); | |
7576 return FAIL; | |
7577 } | |
7578 | |
7579 /* | |
7580 * Free the terminal emulator part of "term". | |
7581 */ | |
7582 static void | |
7583 term_free_vterm(term_T *term) | |
7584 { | |
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
|
7585 term_free_conpty(term); |
12502 | 7586 if (term->tl_winpty != NULL) |
7587 winpty_free(term->tl_winpty); | |
7588 term->tl_winpty = NULL; | |
7589 if (term->tl_winpty_config != NULL) | |
7590 winpty_config_free(term->tl_winpty_config); | |
7591 term->tl_winpty_config = NULL; | |
7592 if (term->tl_vterm != NULL) | |
7593 vterm_free(term->tl_vterm); | |
7594 term->tl_vterm = NULL; | |
7595 } | |
7596 | |
7597 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7598 * Report the size to the terminal. |
12502 | 7599 */ |
7600 static void | |
7601 term_report_winsize(term_T *term, int rows, int cols) | |
7602 { | |
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
|
7603 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
|
7604 conpty_term_report_winsize(term, rows, cols); |
12502 | 7605 if (term->tl_winpty) |
7606 winpty_set_size(term->tl_winpty, cols, rows, NULL); | |
7607 } | |
7608 | |
7609 int | |
7610 terminal_enabled(void) | |
7611 { | |
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
|
7612 return dyn_winpty_init(FALSE) == OK || dyn_conpty_init(FALSE) == OK; |
12502 | 7613 } |
7614 | |
7615 # else | |
7616 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7617 /////////////////////////////////////// |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7618 // 3. Unix-like implementation. |
12502 | 7619 |
7620 /* | |
7621 * Create a new terminal of "rows" by "cols" cells. | |
7622 * Start job for "cmd". | |
7623 * 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
|
7624 * When "argv" is not NULL then "argvar" is not used. |
12502 | 7625 * Return OK or FAIL. |
7626 */ | |
7627 static int | |
7628 term_and_job_init( | |
7629 term_T *term, | |
7630 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
|
7631 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
|
7632 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
|
7633 jobopt_T *orig_opt UNUSED) |
12502 | 7634 { |
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
|
7635 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
|
7636 |
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
|
7637 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
|
7638 return FAIL; |
12502 | 7639 |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
7640 #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) |
28919
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7641 if (term_use_palette()) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7642 { |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7643 if (term->tl_palette != NULL) |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7644 set_vterm_palette(term->tl_vterm, term->tl_palette); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7645 else |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7646 init_vterm_ansi_colors(term->tl_vterm); |
99c1356f4210
patch 8.2.4982: colors in terminal window are not 100% correct
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
7647 } |
28998
983ec746af54
patch 8.2.5021: build fails with normal features and +terminal
Bram Moolenaar <Bram@vim.org>
parents:
28919
diff
changeset
|
7648 #endif |
13626
ab89131d30e0
patch 8.0.1685: can't set ANSI colors of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13624
diff
changeset
|
7649 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7650 // 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
|
7651 term->tl_job = job_start(argvar, argv, opt, &term->tl_job); |
12502 | 7652 if (term->tl_job != NULL) |
7653 ++term->tl_job->jv_refcount; | |
7654 | |
7655 return term->tl_job != NULL | |
7656 && term->tl_job->jv_channel != NULL | |
7657 && term->tl_job->jv_status != JOB_FAILED ? OK : FAIL; | |
7658 } | |
7659 | |
7660 static int | |
7661 create_pty_only(term_T *term, jobopt_T *opt) | |
7662 { | |
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
|
7663 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
|
7664 return FAIL; |
12502 | 7665 |
7666 term->tl_job = job_alloc(); | |
7667 if (term->tl_job == NULL) | |
7668 return FAIL; | |
7669 ++term->tl_job->jv_refcount; | |
7670 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7671 // behave like the job is already finished |
12502 | 7672 term->tl_job->jv_status = JOB_FINISHED; |
7673 | |
7674 return mch_create_pty_channel(term->tl_job, opt); | |
7675 } | |
7676 | |
7677 /* | |
7678 * Free the terminal emulator part of "term". | |
7679 */ | |
7680 static void | |
7681 term_free_vterm(term_T *term) | |
7682 { | |
7683 if (term->tl_vterm != NULL) | |
7684 vterm_free(term->tl_vterm); | |
7685 term->tl_vterm = NULL; | |
7686 } | |
7687 | |
7688 /* | |
13678
39fcaaa973db
patch 8.0.1711: term_setsize() is not implemented yet
Christian Brabandt <cb@256bit.org>
parents:
13668
diff
changeset
|
7689 * Report the size to the terminal. |
12502 | 7690 */ |
7691 static void | |
7692 term_report_winsize(term_T *term, int rows, int cols) | |
7693 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7694 // Use an ioctl() to report the new window size to the job. |
12502 | 7695 if (term->tl_job != NULL && term->tl_job->jv_channel != NULL) |
7696 { | |
7697 int fd = -1; | |
7698 int part; | |
7699 | |
7700 for (part = PART_OUT; part < PART_COUNT; ++part) | |
7701 { | |
7702 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
|
7703 if (mch_isatty(fd)) |
12502 | 7704 break; |
7705 } | |
7706 if (part < PART_COUNT && mch_report_winsize(fd, rows, cols) == OK) | |
7707 mch_signal_job(term->tl_job, (char_u *)"winch"); | |
7708 } | |
7709 } | |
7710 | |
7711 # endif | |
7712 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18595
diff
changeset
|
7713 #endif // FEAT_TERMINAL |