Mercurial > vim
annotate src/ui.c @ 31803:7a9569aecc51
Added tag v9.0.1233 for changeset ddbc560ecc41b458d417c497737166c889707a8d
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Jan 2023 21:15:04 +0100 |
parents | fa309d9af73c |
children | 1009c33499e7 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 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 * ui.c: functions that handle the user interface. | |
12 * 1. Keyboard input stuff, and a bit of windowing stuff. These are called | |
13 * before the machine specific stuff (mch_*) so that we can call the GUI | |
14 * stuff instead if the GUI is running. | |
19774
00a1b89256ea
patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
19750
diff
changeset
|
15 * 2. Input buffer stuff. |
7 | 16 */ |
17 | |
18 #include "vim.h" | |
19 | |
20 void | |
24194
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
21 ui_write(char_u *s, int len, int console UNUSED) |
7 | 22 { |
23 #ifdef FEAT_GUI | |
24194
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
24 if (gui.in_use && !gui.dying && !gui.starting |
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
25 # ifndef NO_CONSOLE |
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
26 && !console |
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
27 # endif |
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
28 ) |
7 | 29 { |
30 gui_write(s, len); | |
31 if (p_wd) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
32 gui_wait_for_chars(p_wd, typebuf.tb_change_cnt); |
7 | 33 return; |
34 } | |
35 #endif | |
36 #ifndef NO_CONSOLE | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
37 // Don't output anything in silent mode ("ex -s") unless 'verbose' set |
7 | 38 if (!(silent_mode && p_verbose == 0)) |
39 { | |
24194
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
40 # if !defined(MSWIN) |
7 | 41 char_u *tofree = NULL; |
42 | |
43 if (output_conv.vc_type != CONV_NONE) | |
44 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
45 // Convert characters from 'encoding' to 'termencoding'. |
7 | 46 tofree = string_convert(&output_conv, s, &len); |
47 if (tofree != NULL) | |
48 s = tofree; | |
49 } | |
24194
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
50 # endif |
7 | 51 |
52 mch_write(s, len); | |
24196
1040b294bfd3
patch 8.2.2639: build failure when fsync() is not available
Bram Moolenaar <Bram@vim.org>
parents:
24194
diff
changeset
|
53 # if defined(HAVE_FSYNC) |
24194
9f64c420f280
patch 8.2.2638: cannot write a message to the terminal from the GUI
Bram Moolenaar <Bram@vim.org>
parents:
23612
diff
changeset
|
54 if (console && s[len - 1] == '\n') |
24196
1040b294bfd3
patch 8.2.2639: build failure when fsync() is not available
Bram Moolenaar <Bram@vim.org>
parents:
24194
diff
changeset
|
55 vim_fsync(1); |
1040b294bfd3
patch 8.2.2639: build failure when fsync() is not available
Bram Moolenaar <Bram@vim.org>
parents:
24194
diff
changeset
|
56 # endif |
7 | 57 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
58 # if !defined(MSWIN) |
7 | 59 if (output_conv.vc_type != CONV_NONE) |
60 vim_free(tofree); | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
61 # endif |
7 | 62 } |
63 #endif | |
64 } | |
65 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
66 #if defined(UNIX) || defined(VMS) || defined(PROTO) || defined(MSWIN) |
7 | 67 /* |
68 * When executing an external program, there may be some typed characters that | |
69 * are not consumed by it. Give them back to ui_inchar() and they are stored | |
70 * here for the next call. | |
71 */ | |
72 static char_u *ta_str = NULL; | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
73 static int ta_off; // offset for next char to use when ta_str != NULL |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
74 static int ta_len; // length of ta_str when it's not NULL |
7 | 75 |
76 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
77 ui_inchar_undo(char_u *s, int len) |
7 | 78 { |
79 char_u *new; | |
80 int newlen; | |
81 | |
82 newlen = len; | |
83 if (ta_str != NULL) | |
84 newlen += ta_len - ta_off; | |
85 new = alloc(newlen); | |
86 if (new != NULL) | |
87 { | |
88 if (ta_str != NULL) | |
89 { | |
90 mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off)); | |
91 mch_memmove(new + ta_len - ta_off, s, (size_t)len); | |
92 vim_free(ta_str); | |
93 } | |
94 else | |
95 mch_memmove(new, s, (size_t)len); | |
96 ta_str = new; | |
97 ta_len = newlen; | |
98 ta_off = 0; | |
99 } | |
100 } | |
101 #endif | |
102 | |
103 /* | |
3877 | 104 * ui_inchar(): low level input function. |
7 | 105 * Get characters from the keyboard. |
106 * Return the number of characters that are available. | |
107 * If "wtime" == 0 do not wait for characters. | |
108 * If "wtime" == -1 wait forever for characters. | |
109 * If "wtime" > 0 wait "wtime" milliseconds for a character. | |
110 * | |
111 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
112 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
113 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL | |
114 * otherwise. | |
115 */ | |
116 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
117 ui_inchar( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
118 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
119 int maxlen, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
120 long wtime, // don't use "time", MIPS cannot handle it |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
121 int tb_change_cnt) |
7 | 122 { |
123 int retval = 0; | |
124 | |
125 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS)) | |
126 /* | |
127 * Use the typeahead if there is any. | |
128 */ | |
129 if (ta_str != NULL) | |
130 { | |
131 if (maxlen >= ta_len - ta_off) | |
132 { | |
133 mch_memmove(buf, ta_str + ta_off, (size_t)ta_len); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
134 VIM_CLEAR(ta_str); |
7 | 135 return ta_len; |
136 } | |
137 mch_memmove(buf, ta_str + ta_off, (size_t)maxlen); | |
138 ta_off += maxlen; | |
139 return maxlen; | |
140 } | |
141 #endif | |
142 | |
170 | 143 #ifdef FEAT_PROFILE |
791 | 144 if (do_profiling == PROF_YES && wtime != 0) |
170 | 145 prof_inchar_enter(); |
146 #endif | |
147 | |
7 | 148 #ifdef NO_CONSOLE_INPUT |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
149 // Don't wait for character input when the window hasn't been opened yet. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
150 // Do try reading, this works when redirecting stdin from a file. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
151 // Must return something, otherwise we'll loop forever. If we run into |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
152 // this very often we probably got stuck, exit Vim. |
7 | 153 if (no_console_input()) |
154 { | |
155 static int count = 0; | |
156 | |
157 # ifndef NO_CONSOLE | |
15075
fd9c4b1a71aa
patch 8.1.0548: crash when job callback unloads a buffer
Bram Moolenaar <Bram@vim.org>
parents:
15052
diff
changeset
|
158 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); |
228 | 159 if (retval > 0 || typebuf_changed(tb_change_cnt) || wtime >= 0) |
170 | 160 goto theend; |
7 | 161 # endif |
162 if (wtime == -1 && ++count == 1000) | |
163 read_error_exit(); | |
164 buf[0] = CAR; | |
170 | 165 retval = 1; |
166 goto theend; | |
7 | 167 } |
168 #endif | |
169 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
170 // If we are going to wait for some time or block... |
1086 | 171 if (wtime == -1 || wtime > 100L) |
172 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
173 // ... allow signals to kill us. |
1086 | 174 (void)vim_handle_signal(SIGNAL_UNBLOCK); |
175 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
176 // ... there is no need for CTRL-C to interrupt something, don't let |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
177 // it set got_int when it was mapped. |
6491 | 178 if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) |
1086 | 179 ctrl_c_interrupts = FALSE; |
180 } | |
7 | 181 |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
182 /* |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
183 * Here we call gui_inchar() or mch_inchar(), the GUI or machine-dependent |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
184 * input function. The functionality they implement is like this: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
185 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
186 * while (not timed out) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
187 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
188 * handle-resize; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
189 * parse-queued-messages; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
190 * if (waited for 'updatetime') |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
191 * trigger-cursorhold; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
192 * ui_wait_for_chars_or_timer() |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
193 * if (character available) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
194 * break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
195 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
196 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
197 * ui_wait_for_chars_or_timer() does: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
198 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
199 * while (not timed out) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
200 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
201 * if (any-timer-triggered) |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
202 * invoke-timer-callback; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
203 * wait-for-character(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
204 * if (character available) |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
205 * break; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
206 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
207 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
208 * wait-for-character() does: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
209 * while (not timed out) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
210 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
211 * Wait for event; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
212 * if (something on channel) |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
213 * read/write channel; |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
214 * else if (resized) |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
215 * handle_resize(); |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
216 * else if (system event) |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
217 * deal-with-system-event; |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
218 * else if (character available) |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
27857
diff
changeset
|
219 * break; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
220 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
221 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
222 */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
223 |
7 | 224 #ifdef FEAT_GUI |
225 if (gui.in_use) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
226 retval = gui_inchar(buf, maxlen, wtime, tb_change_cnt); |
7 | 227 #endif |
228 #ifndef NO_CONSOLE | |
229 # ifdef FEAT_GUI | |
230 else | |
231 # endif | |
232 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); | |
233 #endif | |
234 | |
1086 | 235 if (wtime == -1 || wtime > 100L) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
236 // block SIGHUP et al. |
1086 | 237 (void)vim_handle_signal(SIGNAL_BLOCK); |
238 | |
7 | 239 ctrl_c_interrupts = TRUE; |
240 | |
170 | 241 #ifdef NO_CONSOLE_INPUT |
242 theend: | |
243 #endif | |
244 #ifdef FEAT_PROFILE | |
791 | 245 if (do_profiling == PROF_YES && wtime != 0) |
170 | 246 prof_inchar_exit(); |
247 #endif | |
7 | 248 return retval; |
249 } | |
250 | |
18896
4481f3b29fc5
patch 8.2.0009: VMS: terminal version doesn't build
Bram Moolenaar <Bram@vim.org>
parents:
18880
diff
changeset
|
251 #if defined(UNIX) || defined(VMS) || defined(FEAT_GUI) || defined(PROTO) |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
252 /* |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
253 * Common code for mch_inchar() and gui_inchar(): Wait for a while or |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
254 * indefinitely until characters are available, dealing with timers and |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
255 * messages on channels. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
256 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
257 * "buf" may be NULL if the available characters are not to be returned, only |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
258 * check if they are available. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
259 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
260 * Return the number of characters that are available. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
261 * If "wtime" == 0 do not wait for characters. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
262 * If "wtime" == n wait a short time for characters. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
263 * If "wtime" == -1 wait forever for characters. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
264 */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
265 int |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
266 inchar_loop( |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
267 char_u *buf, |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
268 int maxlen, |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
269 long wtime, // don't use "time", MIPS cannot handle it |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
270 int tb_change_cnt, |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
271 int (*wait_func)(long wtime, int *interrupted, int ignore_input), |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
272 int (*resize_func)(int check_only)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
273 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
274 int len; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
275 int interrupted = FALSE; |
15665
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
276 int did_call_wait_func = FALSE; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
277 int did_start_blocking = FALSE; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
278 long wait_time; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
279 long elapsed_time = 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
280 #ifdef ELAPSED_FUNC |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
281 elapsed_T start_tv; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
282 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
283 ELAPSED_INIT(start_tv); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
284 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
285 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
286 // repeat until we got a character or waited long enough |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
287 for (;;) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
288 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
289 // Check if window changed size while we were busy, perhaps the ":set |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
290 // columns=99" command was used. |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
291 if (resize_func != NULL) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
292 resize_func(FALSE); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
293 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
294 #ifdef MESSAGE_QUEUE |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
295 // Only process messages when waiting. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
296 if (wtime != 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
297 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
298 parse_queued_messages(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
299 // If input was put directly in typeahead buffer bail out here. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
300 if (typebuf_changed(tb_change_cnt)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
301 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
302 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
303 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
304 if (wtime < 0 && did_start_blocking) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
305 // blocking and already waited for p_ut |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
306 wait_time = -1; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
307 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
308 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
309 if (wtime >= 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
310 wait_time = wtime; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
311 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
312 // going to block after p_ut |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
313 wait_time = p_ut; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
314 #ifdef ELAPSED_FUNC |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
315 elapsed_time = ELAPSED_FUNC(start_tv); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
316 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
317 wait_time -= elapsed_time; |
15665
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
318 |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
319 // If the waiting time is now zero or less, we timed out. However, |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
320 // loop at least once to check for characters and events. Matters |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
321 // when "wtime" is zero. |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
322 if (wait_time <= 0 && did_call_wait_func) |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
323 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
324 if (wtime >= 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
325 // no character available within "wtime" |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
326 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
327 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
328 // No character available within 'updatetime'. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
329 did_start_blocking = TRUE; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
330 if (trigger_cursorhold() && maxlen >= 3 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
331 && !typebuf_changed(tb_change_cnt)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
332 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
333 // Put K_CURSORHOLD in the input buffer or return it. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
334 if (buf == NULL) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
335 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
336 char_u ibuf[3]; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
337 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
338 ibuf[0] = CSI; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
339 ibuf[1] = KS_EXTRA; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
340 ibuf[2] = (int)KE_CURSORHOLD; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
341 add_to_input_buf(ibuf, 3); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
342 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
343 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
344 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
345 buf[0] = K_SPECIAL; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
346 buf[1] = KS_EXTRA; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
347 buf[2] = (int)KE_CURSORHOLD; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
348 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
349 return 3; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
350 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
351 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
352 // There is no character available within 'updatetime' seconds: |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
353 // flush all the swap files to disk. Also done when |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
354 // interrupted by SIGWINCH. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
355 before_blocking(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
356 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
357 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
358 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
359 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
360 #ifdef FEAT_JOB_CHANNEL |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
361 if (wait_time < 0 || wait_time > 100L) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
362 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
363 // Checking if a job ended requires polling. Do this at least |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
364 // every 100 msec. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
365 if (has_pending_job()) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
366 wait_time = 100L; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
367 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
368 // If there is readahead then parse_queued_messages() timed out and |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
369 // we should call it again soon. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
370 if (channel_any_readahead()) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
371 wait_time = 10L; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
372 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
373 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
374 #ifdef FEAT_BEVAL_GUI |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
375 if (p_beval && wait_time > 100L) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
376 // The 'balloonexpr' may indirectly invoke a callback while waiting |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
377 // for a character, need to check often. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
378 wait_time = 100L; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
379 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
380 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
381 // Wait for a character to be typed or another event, such as the winch |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
382 // signal or an event on the monitored file descriptors. |
15665
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
383 did_call_wait_func = TRUE; |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
384 if (wait_func(wait_time, &interrupted, FALSE)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
385 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
386 // If input was put directly in typeahead buffer bail out here. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
387 if (typebuf_changed(tb_change_cnt)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
388 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
389 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
390 // We might have something to return now. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
391 if (buf == NULL) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
392 // "buf" is NULL, we were just waiting, not actually getting |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
393 // input. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
394 return input_available(); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
395 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
396 len = read_from_input_buf(buf, (long)maxlen); |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
397 if (len > 0) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
398 return len; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
399 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
400 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
401 // Timed out or interrupted with no character available. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
402 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
403 #ifndef ELAPSED_FUNC |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
404 // estimate the elapsed time |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
405 elapsed_time += wait_time; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
406 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
407 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
408 if ((resize_func != NULL && resize_func(TRUE)) |
15655
2202ab00e9f9
patch 8.1.0835: GUI build fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents:
15653
diff
changeset
|
409 #if defined(FEAT_CLIENTSERVER) && defined(UNIX) |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
410 || server_waiting() |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
411 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
412 #ifdef MESSAGE_QUEUE |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
413 || interrupted |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
414 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
415 || wait_time > 0 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
416 || (wtime < 0 && !did_start_blocking)) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
417 // no character available, but something to be done, keep going |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
418 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
419 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
420 // no character available or interrupted, return zero |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
421 break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
422 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
423 return 0; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
424 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
425 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
426 |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
427 #if defined(FEAT_TIMERS) || defined(PROTO) |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
428 /* |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
429 * Wait for a timer to fire or "wait_func" to return non-zero. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
430 * Returns OK when something was read. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
431 * Returns FAIL when it timed out or was interrupted. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
432 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
433 int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
434 ui_wait_for_chars_or_timer( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
435 long wtime, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
436 int (*wait_func)(long wtime, int *interrupted, int ignore_input), |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
437 int *interrupted, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
438 int ignore_input) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
439 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
440 int due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
441 long remaining = wtime; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
442 int tb_change_cnt = typebuf.tb_change_cnt; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
443 # ifdef FEAT_JOB_CHANNEL |
15506
8b508af36a80
patch 8.1.0761: default value for brief_wait is wrong
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
444 int brief_wait = FALSE; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
445 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
446 |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
447 // When waiting very briefly don't trigger timers. |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
448 if (wtime >= 0 && wtime < 10L) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
449 return wait_func(wtime, NULL, ignore_input); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
450 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
451 while (wtime < 0 || remaining > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
452 { |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
453 // Trigger timers and then get the time in wtime until the next one is |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
454 // due. Wait up to that time. |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
455 due_time = check_due_timer(); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
456 if (typebuf.tb_change_cnt != tb_change_cnt) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
457 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
458 // timer may have used feedkeys() |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
459 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
460 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
461 if (due_time <= 0 || (wtime > 0 && due_time > remaining)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
462 due_time = remaining; |
30719
71137f73c94d
patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents:
29109
diff
changeset
|
463 # if defined(FEAT_JOB_CHANNEL) || defined(FEAT_SOUND_CANBERRA) || defined(FEAT_SOUND_MACOSX) |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
464 if ((due_time < 0 || due_time > 10L) && ( |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
465 # if defined(FEAT_JOB_CHANNEL) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
466 ( |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
467 # if defined(FEAT_GUI) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
468 !gui.in_use && |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
469 # endif |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
470 (has_pending_job() || channel_any_readahead())) |
30719
71137f73c94d
patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents:
29109
diff
changeset
|
471 # if defined(FEAT_SOUND_CANBERRA) || defined(FEAT_SOUND_MACOSX) |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
472 || |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
473 # endif |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
474 # endif |
30719
71137f73c94d
patch 9.0.0694: no native sound support on Mac OS
Bram Moolenaar <Bram@vim.org>
parents:
29109
diff
changeset
|
475 # if defined(FEAT_SOUND_CANBERRA) || defined(FEAT_SOUND_MACOSX) |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
476 has_any_sound_callback() |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
477 # endif |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
478 )) |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
479 { |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
480 // There is a pending job or channel, should return soon in order |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
481 // to handle them ASAP. Do check for input briefly. |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
482 due_time = 10L; |
18021
e273e489acdf
patch 8.1.2006: build failure with huge features but without channel feature
Bram Moolenaar <Bram@vim.org>
parents:
17950
diff
changeset
|
483 # ifdef FEAT_JOB_CHANNEL |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
484 brief_wait = TRUE; |
18021
e273e489acdf
patch 8.1.2006: build failure with huge features but without channel feature
Bram Moolenaar <Bram@vim.org>
parents:
17950
diff
changeset
|
485 # endif |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
486 } |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
487 # endif |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
488 if (wait_func(due_time, interrupted, ignore_input)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
489 return OK; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
490 if ((interrupted != NULL && *interrupted) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
491 # ifdef FEAT_JOB_CHANNEL |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
492 || brief_wait |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
493 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
494 ) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
495 // Nothing available, but need to return so that side effects get |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
496 // handled, such as handling a message on a channel. |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
497 return FAIL; |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
498 if (wtime > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
499 remaining -= due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
500 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
501 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
502 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
503 #endif |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
504 |
7 | 505 /* |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
506 * Return non-zero if a character is available. |
7 | 507 */ |
508 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
509 ui_char_avail(void) |
7 | 510 { |
511 #ifdef FEAT_GUI | |
512 if (gui.in_use) | |
513 { | |
514 gui_mch_update(); | |
515 return input_available(); | |
516 } | |
517 #endif | |
518 #ifndef NO_CONSOLE | |
519 # ifdef NO_CONSOLE_INPUT | |
520 if (no_console_input()) | |
521 return 0; | |
522 # endif | |
523 return mch_char_avail(); | |
524 #else | |
525 return 0; | |
526 #endif | |
527 } | |
528 | |
529 /* | |
530 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we | |
531 * cancel the delay if a key is hit. | |
532 */ | |
533 void | |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
534 ui_delay(long msec_arg, int ignoreinput) |
7 | 535 { |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
536 long msec = msec_arg; |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
537 |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
538 #ifdef FEAT_EVAL |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
539 if (ui_delay_for_testing > 0) |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
540 msec = ui_delay_for_testing; |
18642
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
541 ch_log(NULL, "ui_delay(%ld)", msec); |
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
542 #endif |
7 | 543 #ifdef FEAT_GUI |
544 if (gui.in_use && !ignoreinput) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
545 gui_wait_for_chars(msec, typebuf.tb_change_cnt); |
7 | 546 else |
547 #endif | |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
20861
diff
changeset
|
548 mch_delay(msec, ignoreinput ? MCH_DELAY_IGNOREINPUT : 0); |
7 | 549 } |
550 | |
551 /* | |
552 * If the machine has job control, use it to suspend the program, | |
553 * otherwise fake it by starting a new shell. | |
554 * When running the GUI iconify the window. | |
555 */ | |
556 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
557 ui_suspend(void) |
7 | 558 { |
559 #ifdef FEAT_GUI | |
560 if (gui.in_use) | |
561 { | |
562 gui_mch_iconify(); | |
563 return; | |
564 } | |
565 #endif | |
566 mch_suspend(); | |
567 } | |
568 | |
20591
4411c2b96af9
patch 8.2.0849: BeOS code is not maintained and probably unused
Bram Moolenaar <Bram@vim.org>
parents:
19774
diff
changeset
|
569 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) |
7 | 570 /* |
571 * When the OS can't really suspend, call this function to start a shell. | |
572 * This is never called in the GUI. | |
573 */ | |
574 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
575 suspend_shell(void) |
7 | 576 { |
577 if (*p_sh == NUL) | |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26466
diff
changeset
|
578 emsg(_(e_shell_option_is_empty)); |
7 | 579 else |
580 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
581 msg_puts(_("new shell started\n")); |
7 | 582 do_shell(NULL, 0); |
583 } | |
584 } | |
585 #endif | |
586 | |
587 /* | |
588 * Try to get the current Vim shell size. Put the result in Rows and Columns. | |
589 * Use the new sizes as defaults for 'columns' and 'lines'. | |
590 * Return OK when size could be determined, FAIL otherwise. | |
591 */ | |
592 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
593 ui_get_shellsize(void) |
7 | 594 { |
595 int retval; | |
596 | |
597 #ifdef FEAT_GUI | |
598 if (gui.in_use) | |
599 retval = gui_get_shellsize(); | |
600 else | |
601 #endif | |
602 retval = mch_get_shellsize(); | |
603 | |
604 check_shellsize(); | |
605 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
606 // adjust the default for 'lines' and 'columns' |
7 | 607 if (retval == OK) |
608 { | |
609 set_number_default("lines", Rows); | |
610 set_number_default("columns", Columns); | |
611 } | |
612 return retval; | |
613 } | |
614 | |
615 /* | |
616 * Set the size of the Vim shell according to Rows and Columns, if possible. | |
617 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the | |
618 * new size. If this is not possible, it will adjust Rows and Columns. | |
619 */ | |
620 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
621 ui_set_shellsize( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
622 int mustset UNUSED) // set by the user |
7 | 623 { |
624 #ifdef FEAT_GUI | |
625 if (gui.in_use) | |
5106
c3a82208e143
updated for version 7.3.1296
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
626 gui_set_shellsize(mustset, TRUE, RESIZE_BOTH); |
7 | 627 else |
628 #endif | |
629 mch_set_shellsize(); | |
630 } | |
631 | |
632 /* | |
633 * Called when Rows and/or Columns changed. Adjust scroll region and mouse | |
634 * region. | |
635 */ | |
636 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
637 ui_new_shellsize(void) |
7 | 638 { |
639 if (full_screen && !exiting) | |
640 { | |
641 #ifdef FEAT_GUI | |
642 if (gui.in_use) | |
643 gui_new_shellsize(); | |
644 else | |
645 #endif | |
646 mch_new_shellsize(); | |
647 } | |
648 } | |
649 | |
16245
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16243
diff
changeset
|
650 #if ((defined(FEAT_EVAL) || defined(FEAT_TERMINAL)) \ |
16243
3b79a3029947
patch 8.1.1126: build failure with +terminal but without tgetent
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
651 && (defined(FEAT_GUI) \ |
16253
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
652 || defined(MSWIN) \ |
16243
3b79a3029947
patch 8.1.1126: build failure with +terminal but without tgetent
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
653 || (defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE)))) \ |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
654 || defined(PROTO) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
655 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
656 * Get the window position in pixels, if possible. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
657 * Return FAIL when not possible. |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
658 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
659 int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
660 ui_get_winpos(int *x, int *y, varnumber_T timeout UNUSED) |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
661 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
662 # ifdef FEAT_GUI |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
663 if (gui.in_use) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
664 return gui_mch_get_winpos(x, y); |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
665 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16253
diff
changeset
|
666 # if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL)) |
16253
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
667 return mch_get_winpos(x, y); |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
668 # else |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
669 # if defined(HAVE_TGETENT) && defined(FEAT_TERMRESPONSE) |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
670 return term_get_winpos(x, y, timeout); |
16253
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
671 # else |
16245
e0a6298bd70f
patch 8.1.1127: getwinpos() doesn't work in terminal on MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16243
diff
changeset
|
672 return FAIL; |
16253
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
673 # endif |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
674 # endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
675 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
676 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
677 |
7 | 678 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
679 ui_breakcheck(void) |
7 | 680 { |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
681 ui_breakcheck_force(FALSE); |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
682 } |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
683 |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
684 /* |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
685 * When "force" is true also check when the terminal is not in raw mode. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
686 * This is useful to read input on channels. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
687 */ |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
688 void |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
689 ui_breakcheck_force(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
690 { |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
691 static int recursive = FALSE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
692 int save_updating_screen = updating_screen; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
693 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
694 // We could be called recursively if stderr is redirected, calling |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
695 // fill_input_buf() calls settmode() when stdin isn't a tty. settmode() |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
696 // calls vgetorpeek() which calls ui_breakcheck() again. |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
697 if (recursive) |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
698 return; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
699 recursive = TRUE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
700 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
701 // We do not want gui_resize_shell() to redraw the screen here. |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
702 ++updating_screen; |
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
703 |
7 | 704 #ifdef FEAT_GUI |
705 if (gui.in_use) | |
706 gui_mch_update(); | |
707 else | |
708 #endif | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
709 mch_breakcheck(force); |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
710 |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
711 if (save_updating_screen) |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
712 updating_screen = TRUE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
713 else |
16835
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
714 after_updating_screen(FALSE); |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
715 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
716 recursive = FALSE; |
7 | 717 } |
718 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
719 ////////////////////////////////////////////////////////////////////////////// |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
720 // Functions that handle the input buffer. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
721 // This is used for any GUI version, and the unix terminal version. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
722 // |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
723 // For Unix, the input characters are buffered to be able to check for a |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
724 // CTRL-C. This should be done with signals, but I don't know how to do that |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
725 // in a portable way for a tty in RAW mode. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
726 // |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
727 // For the client-server code in the console the received keys are put in the |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
728 // input buffer. |
7 | 729 |
730 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
731 | |
732 /* | |
733 * Internal typeahead buffer. Includes extra space for long key code | |
734 * descriptions which would otherwise overflow. The buffer is considered full | |
735 * when only this extra space (or part of it) remains. | |
736 */ | |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
737 #if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER) |
7 | 738 /* |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
739 * NetBeans stuffs debugger commands into the input buffer. |
7 | 740 * This requires a larger buffer... |
741 * (Madsen) Go with this for remote input as well ... | |
742 */ | |
743 # define INBUFLEN 4096 | |
744 #else | |
745 # define INBUFLEN 250 | |
746 #endif | |
747 | |
748 static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN]; | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
749 static int inbufcount = 0; // number of chars in inbuf[] |
7 | 750 |
751 /* | |
752 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and | |
753 * trash_input_buf() are functions for manipulating the input buffer. These | |
754 * are used by the gui_* calls when a GUI is used to handle keyboard input. | |
755 */ | |
756 | |
757 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
758 vim_is_input_buf_full(void) |
7 | 759 { |
760 return (inbufcount >= INBUFLEN); | |
761 } | |
762 | |
763 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
764 vim_is_input_buf_empty(void) |
7 | 765 { |
766 return (inbufcount == 0); | |
767 } | |
768 | |
769 #if defined(FEAT_OLE) || defined(PROTO) | |
770 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
771 vim_free_in_input_buf(void) |
7 | 772 { |
773 return (INBUFLEN - inbufcount); | |
774 } | |
775 #endif | |
776 | |
575 | 777 #if defined(FEAT_GUI_GTK) || defined(PROTO) |
7 | 778 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
779 vim_used_in_input_buf(void) |
7 | 780 { |
781 return inbufcount; | |
782 } | |
783 #endif | |
784 | |
785 /* | |
786 * Return the current contents of the input buffer and make it empty. | |
787 * The returned pointer must be passed to set_input_buf() later. | |
788 */ | |
789 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
790 get_input_buf(void) |
7 | 791 { |
792 garray_T *gap; | |
793 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
794 // We use a growarray to store the data pointer and the length. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
795 gap = ALLOC_ONE(garray_T); |
7 | 796 if (gap != NULL) |
797 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
798 // Add one to avoid a zero size. |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16451
diff
changeset
|
799 gap->ga_data = alloc(inbufcount + 1); |
7 | 800 if (gap->ga_data != NULL) |
801 mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); | |
802 gap->ga_len = inbufcount; | |
803 } | |
804 trash_input_buf(); | |
805 return (char_u *)gap; | |
806 } | |
807 | |
808 /* | |
809 * Restore the input buffer with a pointer returned from get_input_buf(). | |
810 * The allocated memory is freed, this only works once! | |
24846
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
811 * When "overwrite" is FALSE input typed later is kept. |
7 | 812 */ |
813 void | |
24846
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
814 set_input_buf(char_u *p, int overwrite) |
7 | 815 { |
816 garray_T *gap = (garray_T *)p; | |
817 | |
818 if (gap != NULL) | |
819 { | |
820 if (gap->ga_data != NULL) | |
821 { | |
24846
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
822 if (overwrite || inbufcount + gap->ga_len >= INBUFLEN) |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
823 { |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
824 mch_memmove(inbuf, gap->ga_data, gap->ga_len); |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
825 inbufcount = gap->ga_len; |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
826 } |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
827 else |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
828 { |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
829 mch_memmove(inbuf + gap->ga_len, inbuf, inbufcount); |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
830 mch_memmove(inbuf, gap->ga_data, gap->ga_len); |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
831 inbufcount += gap->ga_len; |
fdc6a7769045
patch 8.2.2961: keys typed during a :normal command are discarded
Bram Moolenaar <Bram@vim.org>
parents:
24196
diff
changeset
|
832 } |
7 | 833 vim_free(gap->ga_data); |
834 } | |
835 vim_free(gap); | |
836 } | |
837 } | |
838 | |
839 /* | |
840 * Add the given bytes to the input buffer | |
841 * Special keys start with CSI. A real CSI must have been translated to | |
842 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation. | |
843 */ | |
844 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
845 add_to_input_buf(char_u *s, int len) |
7 | 846 { |
847 if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
848 return; // Shouldn't ever happen! |
7 | 849 |
850 while (len--) | |
851 inbuf[inbufcount++] = *s++; | |
852 } | |
853 | |
854 /* | |
855 * Add "str[len]" to the input buffer while escaping CSI bytes. | |
856 */ | |
857 void | |
858 add_to_input_buf_csi(char_u *str, int len) | |
859 { | |
860 int i; | |
861 char_u buf[2]; | |
862 | |
863 for (i = 0; i < len; ++i) | |
864 { | |
865 add_to_input_buf(str + i, 1); | |
866 if (str[i] == CSI) | |
867 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
868 // Turn CSI into K_CSI. |
7 | 869 buf[0] = KS_EXTRA; |
870 buf[1] = (int)KE_CSI; | |
871 add_to_input_buf(buf, 2); | |
872 } | |
873 } | |
874 } | |
875 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
876 /* |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
877 * Remove everything from the input buffer. Called when ^C is found. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
878 */ |
7 | 879 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
880 trash_input_buf(void) |
7 | 881 { |
882 inbufcount = 0; | |
883 } | |
884 | |
885 /* | |
886 * Read as much data from the input buffer as possible up to maxlen, and store | |
887 * it in buf. | |
888 */ | |
889 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
890 read_from_input_buf(char_u *buf, long maxlen) |
7 | 891 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
892 if (inbufcount == 0) // if the buffer is empty, fill it |
7 | 893 fill_input_buf(TRUE); |
894 if (maxlen > inbufcount) | |
895 maxlen = inbufcount; | |
896 mch_memmove(buf, inbuf, (size_t)maxlen); | |
897 inbufcount -= maxlen; | |
29109
c1c795a61545
patch 8.2.5075: clang gives an out of bounds warning
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
898 // check "maxlen" to avoid clang warning |
c1c795a61545
patch 8.2.5075: clang gives an out of bounds warning
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
899 if (inbufcount > 0 && maxlen > 0) |
7 | 900 mch_memmove(inbuf, inbuf + maxlen, (size_t)inbufcount); |
901 return (int)maxlen; | |
902 } | |
903 | |
904 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
905 fill_input_buf(int exit_on_error UNUSED) |
7 | 906 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
907 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 908 int len; |
909 int try; | |
910 static int did_read_something = FALSE; | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
911 static char_u *rest = NULL; // unconverted rest of previous read |
7 | 912 static int restlen = 0; |
913 int unconverted; | |
914 #endif | |
915 | |
916 #ifdef FEAT_GUI | |
294 | 917 if (gui.in_use |
918 # ifdef NO_CONSOLE_INPUT | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
919 // Don't use the GUI input when the window hasn't been opened yet. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
920 // We get here from ui_inchar() when we should try reading from stdin. |
294 | 921 && !no_console_input() |
922 # endif | |
923 ) | |
7 | 924 { |
925 gui_mch_update(); | |
926 return; | |
927 } | |
928 #endif | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
929 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 930 if (vim_is_input_buf_full()) |
931 return; | |
932 /* | |
933 * Fill_input_buf() is only called when we really need a character. | |
934 * If we can't get any, but there is some in the buffer, just return. | |
935 * If we can't get any, and there isn't any in the buffer, we give up and | |
936 * exit Vim. | |
937 */ | |
938 if (rest != NULL) | |
939 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
940 // Use remainder of previous call, starts with an invalid character |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
941 // that may become valid when reading more. |
7 | 942 if (restlen > INBUFLEN - inbufcount) |
943 unconverted = INBUFLEN - inbufcount; | |
944 else | |
945 unconverted = restlen; | |
946 mch_memmove(inbuf + inbufcount, rest, unconverted); | |
947 if (unconverted == restlen) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
948 VIM_CLEAR(rest); |
7 | 949 else |
950 { | |
951 restlen -= unconverted; | |
952 mch_memmove(rest, rest + unconverted, restlen); | |
953 } | |
954 inbufcount += unconverted; | |
955 } | |
956 else | |
957 unconverted = 0; | |
958 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
959 len = 0; // to avoid gcc warning |
7 | 960 for (try = 0; try < 100; ++try) |
961 { | |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
962 size_t readlen = (size_t)((INBUFLEN - inbufcount) |
19730
fe8ba2f82f59
patch 8.2.0421: interrupting with CTRL-C does not always work
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
963 / input_conv.vc_factor); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
964 # ifdef VMS |
13776
ef6de4674811
patch 8.0.1760: wrong number of arguments to vms_read()
Christian Brabandt <cb@256bit.org>
parents:
13758
diff
changeset
|
965 len = vms_read((char *)inbuf + inbufcount, readlen); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
966 # else |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
967 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); |
7 | 968 # endif |
31287
fa309d9af73c
patch 9.0.0977: it is not easy to see what client-server commands are doing
Bram Moolenaar <Bram@vim.org>
parents:
31103
diff
changeset
|
969 # ifdef FEAT_EVAL |
22065
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
970 if (len > 0) |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
971 { |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
972 inbuf[inbufcount + len] = NUL; |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
973 ch_log(NULL, "raw key input: \"%s\"", inbuf + inbufcount); |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
974 } |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
975 # endif |
169 | 976 |
7 | 977 if (len > 0 || got_int) |
978 break; | |
979 /* | |
980 * If reading stdin results in an error, continue reading stderr. | |
981 * This helps when using "foo | xargs vim". | |
982 */ | |
983 if (!did_read_something && !isatty(read_cmd_fd) && read_cmd_fd == 0) | |
984 { | |
985 int m = cur_tmode; | |
986 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
987 // We probably set the wrong file descriptor to raw mode. Switch |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
988 // back to cooked mode, use another descriptor and set the mode to |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
989 // what it was. |
7 | 990 settmode(TMODE_COOK); |
991 #ifdef HAVE_DUP | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
992 // Use stderr for stdin, also works for shell commands. |
7 | 993 close(0); |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
994 vim_ignored = dup(2); |
7 | 995 #else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
996 read_cmd_fd = 2; // read from stderr instead of stdin |
7 | 997 #endif |
998 settmode(m); | |
999 } | |
1000 if (!exit_on_error) | |
1001 return; | |
1002 } | |
1003 if (len <= 0 && !got_int) | |
1004 read_error_exit(); | |
1005 if (len > 0) | |
1006 did_read_something = TRUE; | |
1007 if (got_int) | |
1008 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1009 // Interrupted, pretend a CTRL-C was typed. |
7 | 1010 inbuf[0] = 3; |
1011 inbufcount = 1; | |
1012 } | |
1013 else | |
1014 { | |
1015 /* | |
1016 * May perform conversion on the input characters. | |
1017 * Include the unconverted rest of the previous call. | |
1018 * If there is an incomplete char at the end it is kept for the next | |
1019 * time, reading more bytes should make conversion possible. | |
1020 * Don't do this in the unlikely event that the input buffer is too | |
1021 * small ("rest" still contains more bytes). | |
1022 */ | |
1023 if (input_conv.vc_type != CONV_NONE) | |
1024 { | |
1025 inbufcount -= unconverted; | |
1026 len = convert_input_safe(inbuf + inbufcount, | |
1027 len + unconverted, INBUFLEN - inbufcount, | |
1028 rest == NULL ? &rest : NULL, &restlen); | |
1029 } | |
26727
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1030 while (len > 0) |
7 | 1031 { |
23479
39d62cdde492
patch 8.2.2282: length check mismatch with argument of strncmp()
Bram Moolenaar <Bram@vim.org>
parents:
23464
diff
changeset
|
1032 // If a CTRL-C was typed, remove it from the buffer and set |
26727
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1033 // got_int. Also recognize CTRL-C with modifyOtherKeys set, lower |
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1034 // and upper case, in two forms. |
19730
fe8ba2f82f59
patch 8.2.0421: interrupting with CTRL-C does not always work
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
1035 if (ctrl_c_interrupts && (inbuf[inbufcount] == 3 |
23479
39d62cdde492
patch 8.2.2282: length check mismatch with argument of strncmp()
Bram Moolenaar <Bram@vim.org>
parents:
23464
diff
changeset
|
1036 || (len >= 10 && STRNCMP(inbuf + inbufcount, |
23464
a0fc14114576
patch 8.2.2275: CTRL-C not recognized in Mintty
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
1037 "\033[27;5;99~", 10) == 0) |
26727
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1038 || (len >= 10 && STRNCMP(inbuf + inbufcount, |
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1039 "\033[27;5;67~", 10) == 0) |
23464
a0fc14114576
patch 8.2.2275: CTRL-C not recognized in Mintty
Bram Moolenaar <Bram@vim.org>
parents:
22065
diff
changeset
|
1040 || (len >= 7 && STRNCMP(inbuf + inbufcount, |
26727
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1041 "\033[99;5u", 7) == 0) |
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1042 || (len >= 7 && STRNCMP(inbuf + inbufcount, |
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1043 "\033[67;5u", 7) == 0))) |
7 | 1044 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1045 // remove everything typed before the CTRL-C |
26727
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1046 mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len)); |
7 | 1047 inbufcount = 0; |
1048 got_int = TRUE; | |
1049 } | |
26727
077277ee1626
patch 8.2.3892: when modifyOtherKeys is used CTRL-C is not recognized
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
1050 --len; |
7 | 1051 ++inbufcount; |
1052 } | |
1053 } | |
18880
18a4871332ce
patch 8.2.0001: #endif comments do reflect corresponding #ifdef
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
1054 #endif // UNIX || VMS || MACOS_X |
7 | 1055 } |
18880
18a4871332ce
patch 8.2.0001: #endif comments do reflect corresponding #ifdef
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
1056 #endif // USE_INPUT_BUF |
7 | 1057 |
1058 /* | |
1059 * Exit because of an input read error. | |
1060 */ | |
1061 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1062 read_error_exit(void) |
7 | 1063 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1064 if (silent_mode) // Normal way to exit for "ex -s" |
7 | 1065 getout(0); |
1066 STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); | |
1067 preserve_exit(); | |
1068 } | |
1069 | |
1070 #if defined(CURSOR_SHAPE) || defined(PROTO) | |
1071 /* | |
1072 * May update the shape of the cursor. | |
1073 */ | |
1074 void | |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1075 ui_cursor_shape_forced(int forced) |
7 | 1076 { |
1077 # ifdef FEAT_GUI | |
1078 if (gui.in_use) | |
1079 gui_update_cursor_later(); | |
36 | 1080 else |
7 | 1081 # endif |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1082 term_cursor_mode(forced); |
36 | 1083 |
7 | 1084 # ifdef MCH_CURSOR_SHAPE |
1085 mch_update_cursor(); | |
1086 # endif | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1087 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1088 # ifdef FEAT_CONCEAL |
25074
aa55d6d17625
patch 8.2.3074: popup_atcursor() uses wrong position with concealing
Bram Moolenaar <Bram@vim.org>
parents:
24846
diff
changeset
|
1089 conceal_check_cursor_line(FALSE); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1090 # endif |
7 | 1091 } |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1092 |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1093 void |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1094 ui_cursor_shape(void) |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1095 { |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1096 ui_cursor_shape_forced(FALSE); |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1097 } |
7 | 1098 #endif |
1099 | |
1100 /* | |
1101 * Check bounds for column number | |
1102 */ | |
1103 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1104 check_col(int col) |
7 | 1105 { |
1106 if (col < 0) | |
1107 return 0; | |
27426
41e0dcf38521
patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents:
26727
diff
changeset
|
1108 if (col >= screen_Columns) |
41e0dcf38521
patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents:
26727
diff
changeset
|
1109 return screen_Columns - 1; |
7 | 1110 return col; |
1111 } | |
1112 | |
1113 /* | |
1114 * Check bounds for row number | |
1115 */ | |
1116 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1117 check_row(int row) |
7 | 1118 { |
1119 if (row < 0) | |
1120 return 0; | |
27426
41e0dcf38521
patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents:
26727
diff
changeset
|
1121 if (row >= screen_Rows) |
41e0dcf38521
patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents:
26727
diff
changeset
|
1122 return screen_Rows - 1; |
7 | 1123 return row; |
1124 } | |
1125 | |
1126 /* | |
31103
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1127 * Return length of line "lnum" in screen cells for horizontal scrolling. |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1128 */ |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1129 long |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1130 scroll_line_len(linenr_T lnum) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1131 { |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1132 char_u *p = ml_get(lnum); |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1133 colnr_T col = 0; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1134 |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1135 if (*p != NUL) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1136 for (;;) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1137 { |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1138 int w = chartabsize(p, col); |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1139 MB_PTR_ADV(p); |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1140 if (*p == NUL) // don't count the last character |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1141 break; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1142 col += w; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1143 } |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1144 return col; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1145 } |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1146 |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1147 /* |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1148 * Find the longest visible line number. This is used for horizontal |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1149 * scrolling. If this is not possible (or not desired, by setting 'h' in |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1150 * "guioptions") then the current line number is returned. |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1151 */ |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1152 linenr_T |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1153 ui_find_longest_lnum(void) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1154 { |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1155 linenr_T ret = 0; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1156 |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1157 // Calculate maximum for horizontal scrollbar. Check for reasonable |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1158 // line numbers, topline and botline can be invalid when displaying is |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1159 // postponed. |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1160 if ( |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1161 # ifdef FEAT_GUI |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1162 (!gui.in_use || vim_strchr(p_go, GO_HORSCROLL) == NULL) && |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1163 # endif |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1164 curwin->w_topline <= curwin->w_cursor.lnum |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1165 && curwin->w_botline > curwin->w_cursor.lnum |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1166 && curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1167 { |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1168 linenr_T lnum; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1169 long n; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1170 long max = 0; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1171 |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1172 // Use maximum of all visible lines. Remember the lnum of the |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1173 // longest line, closest to the cursor line. Used when scrolling |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1174 // below. |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1175 for (lnum = curwin->w_topline; lnum < curwin->w_botline; ++lnum) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1176 { |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1177 n = scroll_line_len(lnum); |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1178 if (n > max) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1179 { |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1180 max = n; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1181 ret = lnum; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1182 } |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1183 else if (n == max && abs((int)(lnum - curwin->w_cursor.lnum)) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1184 < abs((int)(ret - curwin->w_cursor.lnum))) |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1185 ret = lnum; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1186 } |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1187 } |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1188 else |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1189 // Use cursor line only. |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1190 ret = curwin->w_cursor.lnum; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1191 |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1192 return ret; |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1193 } |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1194 |
33ca088dbd3e
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
30719
diff
changeset
|
1195 /* |
7 | 1196 * Called when focus changed. Used for the GUI or for systems where this can |
1197 * be done in the console (Win32). | |
1198 */ | |
1199 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1200 ui_focus_change( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1201 int in_focus) // TRUE if focus gained. |
7 | 1202 { |
1203 static time_t last_time = (time_t)0; | |
1204 int need_redraw = FALSE; | |
1205 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1206 // When activated: Check if any file was modified outside of Vim. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1207 // Only do this when not done within the last two seconds (could get |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1208 // several events in a row). |
7 | 1209 if (in_focus && last_time + 2 < time(NULL)) |
1210 { | |
1211 need_redraw = check_timestamps( | |
1212 # ifdef FEAT_GUI | |
1213 gui.in_use | |
1214 # else | |
1215 FALSE | |
1216 # endif | |
1217 ); | |
1218 last_time = time(NULL); | |
1219 } | |
1220 | |
26462
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1221 #ifdef FEAT_TERMINAL |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1222 term_focus_change(in_focus); |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1223 #endif |
3af56224dca6
patch 8.2.3761: focus change is not passed on to a terminal window
Bram Moolenaar <Bram@vim.org>
parents:
26336
diff
changeset
|
1224 |
7 | 1225 /* |
1226 * Fire the focus gained/lost autocommand. | |
1227 */ | |
1228 need_redraw |= apply_autocmds(in_focus ? EVENT_FOCUSGAINED | |
1229 : EVENT_FOCUSLOST, NULL, NULL, FALSE, curbuf); | |
1230 | |
1231 if (need_redraw) | |
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
|
1232 redraw_after_callback(TRUE, TRUE); |
26336
a2e6da79274d
patch 8.2.3699: the +title feature adds a lot of #ifdef but little code
Bram Moolenaar <Bram@vim.org>
parents:
25074
diff
changeset
|
1233 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1234 // File may have been changed from 'readonly' to 'noreadonly' |
7 | 1235 if (need_maketitle) |
1236 maketitle(); | |
1237 } | |
1238 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13373
diff
changeset
|
1239 #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
7 | 1240 /* |
1241 * Save current Input Method status to specified place. | |
1242 */ | |
1243 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1244 im_save_status(long *psave) |
7 | 1245 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1246 // Don't save when 'imdisable' is set or "xic" is NULL, IM is always |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1247 // disabled then (but might start later). |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1248 // Also don't save when inside a mapping, vgetc_im_active has not been set |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1249 // then. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1250 // And don't save when the keys were stuffed (e.g., for a "." command). |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1251 // And don't save when the GUI is running but our window doesn't have |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1252 // input focus (e.g., when a find dialog is open). |
7 | 1253 if (!p_imdisable && KeyTyped && !KeyStuffed |
1254 # ifdef FEAT_XIM | |
1255 && xic != NULL | |
1256 # endif | |
1257 # ifdef FEAT_GUI | |
1258 && (!gui.in_use || gui.in_focus) | |
1259 # endif | |
1260 ) | |
1261 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1262 // Do save when IM is on, or IM is off and saved status is on. |
7 | 1263 if (vgetc_im_active) |
1264 *psave = B_IMODE_IM; | |
1265 else if (*psave == B_IMODE_IM) | |
1266 *psave = B_IMODE_NONE; | |
1267 } | |
1268 } | |
1269 #endif |