Mercurial > vim
annotate src/ui.c @ 22361:00f2eebe74d9 v8.2.1729
patch 8.2.1729: endless loop when ":normal" feeds popup window filter
Commit: https://github.com/vim/vim/commit/189832bf661168df7ebd428e4088737718775fbd
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Sep 23 12:29:11 2020 +0200
patch 8.2.1729: endless loop when ":normal" feeds popup window filter
Problem: Endless loop when ":normal" feeds popup window filter.
Solution: Add the ex_normal_busy_done flag.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 23 Sep 2020 12:30:04 +0200 |
parents | d8b95a9cdaaa |
children | a0fc14114576 |
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 | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
21 ui_write(char_u *s, int len) |
7 | 22 { |
23 #ifdef FEAT_GUI | |
24 if (gui.in_use && !gui.dying && !gui.starting) | |
25 { | |
26 gui_write(s, len); | |
27 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
|
28 gui_wait_for_chars(p_wd, typebuf.tb_change_cnt); |
7 | 29 return; |
30 } | |
31 #endif | |
32 #ifndef NO_CONSOLE | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
33 // Don't output anything in silent mode ("ex -s") unless 'verbose' set |
7 | 34 if (!(silent_mode && p_verbose == 0)) |
35 { | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
36 #if !defined(MSWIN) |
7 | 37 char_u *tofree = NULL; |
38 | |
39 if (output_conv.vc_type != CONV_NONE) | |
40 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
41 // Convert characters from 'encoding' to 'termencoding'. |
7 | 42 tofree = string_convert(&output_conv, s, &len); |
43 if (tofree != NULL) | |
44 s = tofree; | |
45 } | |
46 #endif | |
47 | |
48 mch_write(s, len); | |
49 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
50 # if !defined(MSWIN) |
7 | 51 if (output_conv.vc_type != CONV_NONE) |
52 vim_free(tofree); | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
53 # endif |
7 | 54 } |
55 #endif | |
56 } | |
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(UNIX) || defined(VMS) || defined(PROTO) || defined(MSWIN) |
7 | 59 /* |
60 * When executing an external program, there may be some typed characters that | |
61 * are not consumed by it. Give them back to ui_inchar() and they are stored | |
62 * here for the next call. | |
63 */ | |
64 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
|
65 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
|
66 static int ta_len; // length of ta_str when it's not NULL |
7 | 67 |
68 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
69 ui_inchar_undo(char_u *s, int len) |
7 | 70 { |
71 char_u *new; | |
72 int newlen; | |
73 | |
74 newlen = len; | |
75 if (ta_str != NULL) | |
76 newlen += ta_len - ta_off; | |
77 new = alloc(newlen); | |
78 if (new != NULL) | |
79 { | |
80 if (ta_str != NULL) | |
81 { | |
82 mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off)); | |
83 mch_memmove(new + ta_len - ta_off, s, (size_t)len); | |
84 vim_free(ta_str); | |
85 } | |
86 else | |
87 mch_memmove(new, s, (size_t)len); | |
88 ta_str = new; | |
89 ta_len = newlen; | |
90 ta_off = 0; | |
91 } | |
92 } | |
93 #endif | |
94 | |
95 /* | |
3877 | 96 * ui_inchar(): low level input function. |
7 | 97 * Get characters from the keyboard. |
98 * Return the number of characters that are available. | |
99 * If "wtime" == 0 do not wait for characters. | |
100 * If "wtime" == -1 wait forever for characters. | |
101 * If "wtime" > 0 wait "wtime" milliseconds for a character. | |
102 * | |
103 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
104 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
105 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL | |
106 * otherwise. | |
107 */ | |
108 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
109 ui_inchar( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
110 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
111 int maxlen, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
112 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
|
113 int tb_change_cnt) |
7 | 114 { |
115 int retval = 0; | |
116 | |
117 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS)) | |
118 /* | |
119 * Use the typeahead if there is any. | |
120 */ | |
121 if (ta_str != NULL) | |
122 { | |
123 if (maxlen >= ta_len - ta_off) | |
124 { | |
125 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
|
126 VIM_CLEAR(ta_str); |
7 | 127 return ta_len; |
128 } | |
129 mch_memmove(buf, ta_str + ta_off, (size_t)maxlen); | |
130 ta_off += maxlen; | |
131 return maxlen; | |
132 } | |
133 #endif | |
134 | |
170 | 135 #ifdef FEAT_PROFILE |
791 | 136 if (do_profiling == PROF_YES && wtime != 0) |
170 | 137 prof_inchar_enter(); |
138 #endif | |
139 | |
7 | 140 #ifdef NO_CONSOLE_INPUT |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
141 // 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
|
142 // 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
|
143 // 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
|
144 // this very often we probably got stuck, exit Vim. |
7 | 145 if (no_console_input()) |
146 { | |
147 static int count = 0; | |
148 | |
149 # 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
|
150 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); |
228 | 151 if (retval > 0 || typebuf_changed(tb_change_cnt) || wtime >= 0) |
170 | 152 goto theend; |
7 | 153 # endif |
154 if (wtime == -1 && ++count == 1000) | |
155 read_error_exit(); | |
156 buf[0] = CAR; | |
170 | 157 retval = 1; |
158 goto theend; | |
7 | 159 } |
160 #endif | |
161 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
162 // If we are going to wait for some time or block... |
1086 | 163 if (wtime == -1 || wtime > 100L) |
164 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
165 // ... allow signals to kill us. |
1086 | 166 (void)vim_handle_signal(SIGNAL_UNBLOCK); |
167 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
168 // ... 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
|
169 // it set got_int when it was mapped. |
6491 | 170 if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) |
1086 | 171 ctrl_c_interrupts = FALSE; |
172 } | |
7 | 173 |
15653
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
174 /* |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
175 * 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
|
176 * 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
|
177 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
178 * 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
|
179 * { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
180 * 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
|
181 * 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
|
182 * 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
|
183 * 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
|
184 * 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
|
185 * 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
|
186 * break; |
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 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
189 * 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
|
190 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
191 * 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
|
192 * { |
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 (any-timer-triggered) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
194 * invoke-timer-callback; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
195 * 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
|
196 * 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
|
197 * break; |
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 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
200 * 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
|
201 * 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
|
202 * { |
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 event; |
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 (something on channel) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
205 * read/write channel; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
206 * else if (resized) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
207 * 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
|
208 * else if (system event) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
209 * deal-with-system-event; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
210 * else 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
|
211 * break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
212 * } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
213 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
214 */ |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
215 |
7 | 216 #ifdef FEAT_GUI |
217 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
|
218 retval = gui_inchar(buf, maxlen, wtime, tb_change_cnt); |
7 | 219 #endif |
220 #ifndef NO_CONSOLE | |
221 # ifdef FEAT_GUI | |
222 else | |
223 # endif | |
224 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); | |
225 #endif | |
226 | |
1086 | 227 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
|
228 // block SIGHUP et al. |
1086 | 229 (void)vim_handle_signal(SIGNAL_BLOCK); |
230 | |
7 | 231 ctrl_c_interrupts = TRUE; |
232 | |
170 | 233 #ifdef NO_CONSOLE_INPUT |
234 theend: | |
235 #endif | |
236 #ifdef FEAT_PROFILE | |
791 | 237 if (do_profiling == PROF_YES && wtime != 0) |
170 | 238 prof_inchar_exit(); |
239 #endif | |
7 | 240 return retval; |
241 } | |
242 | |
18896
4481f3b29fc5
patch 8.2.0009: VMS: terminal version doesn't build
Bram Moolenaar <Bram@vim.org>
parents:
18880
diff
changeset
|
243 #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
|
244 /* |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
245 * 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
|
246 * 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
|
247 * 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
|
248 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
249 * "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
|
250 * 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
|
251 * |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
252 * 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
|
253 * 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
|
254 * 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
|
255 * 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
|
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 int |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 #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
|
273 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
|
274 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
275 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
|
276 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
277 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
278 // 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
|
279 for (;;) |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
280 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
281 // 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
|
282 // 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
|
283 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
|
284 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
|
285 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
286 #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
|
287 // 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
|
288 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
|
289 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
290 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
|
291 // 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
|
292 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
|
293 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
|
294 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
295 #endif |
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 && 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
|
297 // 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
|
298 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
|
299 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
300 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
301 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
|
302 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
|
303 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
304 // 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
|
305 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
|
306 #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
|
307 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
|
308 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
309 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
|
310 |
31367ce5aac7
patch 8.1.0840: getchar(0) never returns a character in the terminal
Bram Moolenaar <Bram@vim.org>
parents:
15655
diff
changeset
|
311 // 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
|
312 // 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
|
313 // 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
|
314 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
|
315 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
316 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
|
317 // 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
|
318 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
|
319 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
320 // 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
|
321 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
|
322 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
|
323 && !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
|
324 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
325 // 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
|
326 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
|
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 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
|
329 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 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
|
334 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
335 else |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
336 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
337 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
|
338 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
|
339 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
|
340 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
341 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
|
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 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
344 // 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
|
345 // 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
|
346 // 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
|
347 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
|
348 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
349 } |
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 #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
|
353 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
|
354 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
355 // 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
|
356 // 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
|
357 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
|
358 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
|
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 // 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
|
361 // 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
|
362 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
|
363 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
|
364 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
365 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
366 #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
|
367 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
|
368 // 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
|
369 // 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
|
370 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
|
371 #endif |
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 // 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
|
374 // 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
|
375 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
|
376 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
|
377 { |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
378 // 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
|
379 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
|
380 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
|
381 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
382 // 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
|
383 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
|
384 // "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
|
385 // input. |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
386 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
|
387 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
392 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
393 // 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
|
394 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
395 #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
|
396 // 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
|
397 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
|
398 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
399 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
400 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
|
401 #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
|
402 || 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
|
403 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
404 #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
|
405 || interrupted |
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 || 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
|
408 || (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
|
409 // 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
|
410 continue; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
411 |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
412 // 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
|
413 break; |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
414 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
415 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
|
416 } |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
417 #endif |
59a1ff689b4d
patch 8.1.0834: GUI may wait too long before dealing with messages
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
418 |
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
|
419 #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
|
420 /* |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
421 * 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
|
422 * 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
|
423 * 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
|
424 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
425 int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
426 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
|
427 long wtime, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
428 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
|
429 int *interrupted, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
430 int ignore_input) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
431 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
432 int due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
433 long remaining = wtime; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
434 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
|
435 # 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
|
436 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
|
437 # 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
|
438 |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
439 // 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
|
440 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
|
441 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
|
442 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
443 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
|
444 { |
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 // 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
|
446 // 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
|
447 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
|
448 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
|
449 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
450 // 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
|
451 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
452 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
453 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
|
454 due_time = remaining; |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
455 # if defined(FEAT_JOB_CHANNEL) || defined(FEAT_SOUND_CANBERRA) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
456 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
|
457 # 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
|
458 ( |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
459 # 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
|
460 !gui.in_use && |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
461 # endif |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
462 (has_pending_job() || channel_any_readahead())) |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
463 # ifdef FEAT_SOUND_CANBERRA |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
464 || |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
465 # 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
|
466 # endif |
17708
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
467 # ifdef FEAT_SOUND_CANBERRA |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
468 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
|
469 # endif |
10696f279e20
patch 8.1.1851: crash when sound_playfile() callback plays sound
Bram Moolenaar <Bram@vim.org>
parents:
17580
diff
changeset
|
470 )) |
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
|
471 { |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
472 // 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
|
473 // 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
|
474 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
|
475 # 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
|
476 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
|
477 # 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
|
478 } |
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 # endif |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 # 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
|
484 || 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
|
485 # 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
|
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 // 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
|
488 // 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
|
489 return FAIL; |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
490 if (wtime > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
491 remaining -= due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
492 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
493 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
494 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
495 #endif |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
496 |
7 | 497 /* |
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
|
498 * Return non-zero if a character is available. |
7 | 499 */ |
500 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
501 ui_char_avail(void) |
7 | 502 { |
503 #ifdef FEAT_GUI | |
504 if (gui.in_use) | |
505 { | |
506 gui_mch_update(); | |
507 return input_available(); | |
508 } | |
509 #endif | |
510 #ifndef NO_CONSOLE | |
511 # ifdef NO_CONSOLE_INPUT | |
512 if (no_console_input()) | |
513 return 0; | |
514 # endif | |
515 return mch_char_avail(); | |
516 #else | |
517 return 0; | |
518 #endif | |
519 } | |
520 | |
521 /* | |
522 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we | |
523 * cancel the delay if a key is hit. | |
524 */ | |
525 void | |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
526 ui_delay(long msec_arg, int ignoreinput) |
7 | 527 { |
20861
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
528 long msec = msec_arg; |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
529 |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
530 #ifdef FEAT_EVAL |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
531 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
|
532 msec = ui_delay_for_testing; |
1725bb56178a
patch 8.2.0982: insufficient testing for reading/writing files
Bram Moolenaar <Bram@vim.org>
parents:
20591
diff
changeset
|
533 #endif |
18642
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
534 #ifdef FEAT_JOB_CHANNEL |
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
535 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
|
536 #endif |
7 | 537 #ifdef FEAT_GUI |
538 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
|
539 gui_wait_for_chars(msec, typebuf.tb_change_cnt); |
7 | 540 else |
541 #endif | |
21927
88070e222e82
patch 8.2.1513: cannot interrupt shell used for filename expansion
Bram Moolenaar <Bram@vim.org>
parents:
20861
diff
changeset
|
542 mch_delay(msec, ignoreinput ? MCH_DELAY_IGNOREINPUT : 0); |
7 | 543 } |
544 | |
545 /* | |
546 * If the machine has job control, use it to suspend the program, | |
547 * otherwise fake it by starting a new shell. | |
548 * When running the GUI iconify the window. | |
549 */ | |
550 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
551 ui_suspend(void) |
7 | 552 { |
553 #ifdef FEAT_GUI | |
554 if (gui.in_use) | |
555 { | |
556 gui_mch_iconify(); | |
557 return; | |
558 } | |
559 #endif | |
560 mch_suspend(); | |
561 } | |
562 | |
20591
4411c2b96af9
patch 8.2.0849: BeOS code is not maintained and probably unused
Bram Moolenaar <Bram@vim.org>
parents:
19774
diff
changeset
|
563 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) |
7 | 564 /* |
565 * When the OS can't really suspend, call this function to start a shell. | |
566 * This is never called in the GUI. | |
567 */ | |
568 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
569 suspend_shell(void) |
7 | 570 { |
571 if (*p_sh == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15404
diff
changeset
|
572 emsg(_(e_shellempty)); |
7 | 573 else |
574 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
575 msg_puts(_("new shell started\n")); |
7 | 576 do_shell(NULL, 0); |
577 } | |
578 } | |
579 #endif | |
580 | |
581 /* | |
582 * Try to get the current Vim shell size. Put the result in Rows and Columns. | |
583 * Use the new sizes as defaults for 'columns' and 'lines'. | |
584 * Return OK when size could be determined, FAIL otherwise. | |
585 */ | |
586 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
587 ui_get_shellsize(void) |
7 | 588 { |
589 int retval; | |
590 | |
591 #ifdef FEAT_GUI | |
592 if (gui.in_use) | |
593 retval = gui_get_shellsize(); | |
594 else | |
595 #endif | |
596 retval = mch_get_shellsize(); | |
597 | |
598 check_shellsize(); | |
599 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
600 // adjust the default for 'lines' and 'columns' |
7 | 601 if (retval == OK) |
602 { | |
603 set_number_default("lines", Rows); | |
604 set_number_default("columns", Columns); | |
605 } | |
606 return retval; | |
607 } | |
608 | |
609 /* | |
610 * Set the size of the Vim shell according to Rows and Columns, if possible. | |
611 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the | |
612 * new size. If this is not possible, it will adjust Rows and Columns. | |
613 */ | |
614 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
615 ui_set_shellsize( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
616 int mustset UNUSED) // set by the user |
7 | 617 { |
618 #ifdef FEAT_GUI | |
619 if (gui.in_use) | |
5106
c3a82208e143
updated for version 7.3.1296
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
620 gui_set_shellsize(mustset, TRUE, RESIZE_BOTH); |
7 | 621 else |
622 #endif | |
623 mch_set_shellsize(); | |
624 } | |
625 | |
626 /* | |
627 * Called when Rows and/or Columns changed. Adjust scroll region and mouse | |
628 * region. | |
629 */ | |
630 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
631 ui_new_shellsize(void) |
7 | 632 { |
633 if (full_screen && !exiting) | |
634 { | |
635 #ifdef FEAT_GUI | |
636 if (gui.in_use) | |
637 gui_new_shellsize(); | |
638 else | |
639 #endif | |
640 mch_new_shellsize(); | |
641 } | |
642 } | |
643 | |
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
|
644 #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
|
645 && (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
|
646 || defined(MSWIN) \ |
16243
3b79a3029947
patch 8.1.1126: build failure with +terminal but without tgetent
Bram Moolenaar <Bram@vim.org>
parents:
16241
diff
changeset
|
647 || (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
|
648 || defined(PROTO) |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
649 /* |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
650 * 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
|
651 * 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
|
652 */ |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
653 int |
18139
59bc3cd42cf5
patch 8.1.2064: MS-Windows: compiler warnings for unused arguments
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
654 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
|
655 { |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
656 # 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
|
657 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
|
658 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
|
659 # 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
|
660 # 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
|
661 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
|
662 # else |
f28ef3d27f91
patch 8.1.1131: getwinpos() does not work in the MS-Windows console
Bram Moolenaar <Bram@vim.org>
parents:
16245
diff
changeset
|
663 # 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
|
664 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
|
665 # 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
|
666 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
|
667 # endif |
16241
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
668 # endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
669 } |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
670 #endif |
c1698187c482
patch 8.1.1125: libvterm does not handle the window position report
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
671 |
7 | 672 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
673 ui_breakcheck(void) |
7 | 674 { |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
675 ui_breakcheck_force(FALSE); |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
676 } |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
677 |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
678 /* |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
679 * 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
|
680 * 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
|
681 */ |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
682 void |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
683 ui_breakcheck_force(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
684 { |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
685 static int recursive = FALSE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
686 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
|
687 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
688 // 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
|
689 // 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
|
690 // 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
|
691 if (recursive) |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
692 return; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
693 recursive = TRUE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
694 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
695 // 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
|
696 ++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
|
697 |
7 | 698 #ifdef FEAT_GUI |
699 if (gui.in_use) | |
700 gui_mch_update(); | |
701 else | |
702 #endif | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
703 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
|
704 |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
705 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
|
706 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
|
707 else |
16835
7cade95272c4
patch 8.1.1419: listener callbacks may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
708 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
|
709 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
710 recursive = FALSE; |
7 | 711 } |
712 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
713 ////////////////////////////////////////////////////////////////////////////// |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
714 // 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
|
715 // 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
|
716 // |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
717 // 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
|
718 // 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
|
719 // 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
|
720 // |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
721 // 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
|
722 // input buffer. |
7 | 723 |
724 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
725 | |
726 /* | |
727 * Internal typeahead buffer. Includes extra space for long key code | |
728 * descriptions which would otherwise overflow. The buffer is considered full | |
729 * when only this extra space (or part of it) remains. | |
730 */ | |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
731 #if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER) |
7 | 732 /* |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
733 * NetBeans stuffs debugger commands into the input buffer. |
7 | 734 * This requires a larger buffer... |
735 * (Madsen) Go with this for remote input as well ... | |
736 */ | |
737 # define INBUFLEN 4096 | |
738 #else | |
739 # define INBUFLEN 250 | |
740 #endif | |
741 | |
742 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
|
743 static int inbufcount = 0; // number of chars in inbuf[] |
7 | 744 |
745 /* | |
746 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and | |
747 * trash_input_buf() are functions for manipulating the input buffer. These | |
748 * are used by the gui_* calls when a GUI is used to handle keyboard input. | |
749 */ | |
750 | |
751 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
752 vim_is_input_buf_full(void) |
7 | 753 { |
754 return (inbufcount >= INBUFLEN); | |
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_empty(void) |
7 | 759 { |
760 return (inbufcount == 0); | |
761 } | |
762 | |
763 #if defined(FEAT_OLE) || defined(PROTO) | |
764 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
765 vim_free_in_input_buf(void) |
7 | 766 { |
767 return (INBUFLEN - inbufcount); | |
768 } | |
769 #endif | |
770 | |
575 | 771 #if defined(FEAT_GUI_GTK) || defined(PROTO) |
7 | 772 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
773 vim_used_in_input_buf(void) |
7 | 774 { |
775 return inbufcount; | |
776 } | |
777 #endif | |
778 | |
779 /* | |
780 * Return the current contents of the input buffer and make it empty. | |
781 * The returned pointer must be passed to set_input_buf() later. | |
782 */ | |
783 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
784 get_input_buf(void) |
7 | 785 { |
786 garray_T *gap; | |
787 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
788 // 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
|
789 gap = ALLOC_ONE(garray_T); |
7 | 790 if (gap != NULL) |
791 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
792 // 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
|
793 gap->ga_data = alloc(inbufcount + 1); |
7 | 794 if (gap->ga_data != NULL) |
795 mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); | |
796 gap->ga_len = inbufcount; | |
797 } | |
798 trash_input_buf(); | |
799 return (char_u *)gap; | |
800 } | |
801 | |
802 /* | |
803 * Restore the input buffer with a pointer returned from get_input_buf(). | |
804 * The allocated memory is freed, this only works once! | |
805 */ | |
806 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
807 set_input_buf(char_u *p) |
7 | 808 { |
809 garray_T *gap = (garray_T *)p; | |
810 | |
811 if (gap != NULL) | |
812 { | |
813 if (gap->ga_data != NULL) | |
814 { | |
815 mch_memmove(inbuf, gap->ga_data, gap->ga_len); | |
816 inbufcount = gap->ga_len; | |
817 vim_free(gap->ga_data); | |
818 } | |
819 vim_free(gap); | |
820 } | |
821 } | |
822 | |
823 /* | |
824 * Add the given bytes to the input buffer | |
825 * Special keys start with CSI. A real CSI must have been translated to | |
826 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation. | |
827 */ | |
828 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
829 add_to_input_buf(char_u *s, int len) |
7 | 830 { |
831 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
|
832 return; // Shouldn't ever happen! |
7 | 833 |
834 while (len--) | |
835 inbuf[inbufcount++] = *s++; | |
836 } | |
837 | |
838 /* | |
839 * Add "str[len]" to the input buffer while escaping CSI bytes. | |
840 */ | |
841 void | |
842 add_to_input_buf_csi(char_u *str, int len) | |
843 { | |
844 int i; | |
845 char_u buf[2]; | |
846 | |
847 for (i = 0; i < len; ++i) | |
848 { | |
849 add_to_input_buf(str + i, 1); | |
850 if (str[i] == CSI) | |
851 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
852 // Turn CSI into K_CSI. |
7 | 853 buf[0] = KS_EXTRA; |
854 buf[1] = (int)KE_CSI; | |
855 add_to_input_buf(buf, 2); | |
856 } | |
857 } | |
858 } | |
859 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
860 /* |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
861 * 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
|
862 */ |
7 | 863 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
864 trash_input_buf(void) |
7 | 865 { |
866 inbufcount = 0; | |
867 } | |
868 | |
869 /* | |
870 * Read as much data from the input buffer as possible up to maxlen, and store | |
871 * it in buf. | |
872 */ | |
873 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
874 read_from_input_buf(char_u *buf, long maxlen) |
7 | 875 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
876 if (inbufcount == 0) // if the buffer is empty, fill it |
7 | 877 fill_input_buf(TRUE); |
878 if (maxlen > inbufcount) | |
879 maxlen = inbufcount; | |
880 mch_memmove(buf, inbuf, (size_t)maxlen); | |
881 inbufcount -= maxlen; | |
882 if (inbufcount) | |
883 mch_memmove(inbuf, inbuf + maxlen, (size_t)inbufcount); | |
884 return (int)maxlen; | |
885 } | |
886 | |
887 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
888 fill_input_buf(int exit_on_error UNUSED) |
7 | 889 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
890 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 891 int len; |
892 int try; | |
893 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
|
894 static char_u *rest = NULL; // unconverted rest of previous read |
7 | 895 static int restlen = 0; |
896 int unconverted; | |
897 #endif | |
898 | |
899 #ifdef FEAT_GUI | |
294 | 900 if (gui.in_use |
901 # ifdef NO_CONSOLE_INPUT | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
902 // 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
|
903 // We get here from ui_inchar() when we should try reading from stdin. |
294 | 904 && !no_console_input() |
905 # endif | |
906 ) | |
7 | 907 { |
908 gui_mch_update(); | |
909 return; | |
910 } | |
911 #endif | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
912 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 913 if (vim_is_input_buf_full()) |
914 return; | |
915 /* | |
916 * Fill_input_buf() is only called when we really need a character. | |
917 * If we can't get any, but there is some in the buffer, just return. | |
918 * If we can't get any, and there isn't any in the buffer, we give up and | |
919 * exit Vim. | |
920 */ | |
921 if (rest != NULL) | |
922 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
923 // 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
|
924 // that may become valid when reading more. |
7 | 925 if (restlen > INBUFLEN - inbufcount) |
926 unconverted = INBUFLEN - inbufcount; | |
927 else | |
928 unconverted = restlen; | |
929 mch_memmove(inbuf + inbufcount, rest, unconverted); | |
930 if (unconverted == restlen) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
931 VIM_CLEAR(rest); |
7 | 932 else |
933 { | |
934 restlen -= unconverted; | |
935 mch_memmove(rest, rest + unconverted, restlen); | |
936 } | |
937 inbufcount += unconverted; | |
938 } | |
939 else | |
940 unconverted = 0; | |
941 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
942 len = 0; // to avoid gcc warning |
7 | 943 for (try = 0; try < 100; ++try) |
944 { | |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
945 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
|
946 / input_conv.vc_factor); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
947 # ifdef VMS |
13776
ef6de4674811
patch 8.0.1760: wrong number of arguments to vms_read()
Christian Brabandt <cb@256bit.org>
parents:
13758
diff
changeset
|
948 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
|
949 # else |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
950 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); |
7 | 951 # endif |
22065
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
952 # ifdef FEAT_JOB_CHANNEL |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
953 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
|
954 { |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
955 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
|
956 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
|
957 } |
d8b95a9cdaaa
patch 8.2.1582: the channel log does not show typed text
Bram Moolenaar <Bram@vim.org>
parents:
21927
diff
changeset
|
958 # endif |
169 | 959 |
7 | 960 if (len > 0 || got_int) |
961 break; | |
962 /* | |
963 * If reading stdin results in an error, continue reading stderr. | |
964 * This helps when using "foo | xargs vim". | |
965 */ | |
966 if (!did_read_something && !isatty(read_cmd_fd) && read_cmd_fd == 0) | |
967 { | |
968 int m = cur_tmode; | |
969 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
970 // 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
|
971 // 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
|
972 // what it was. |
7 | 973 settmode(TMODE_COOK); |
974 #ifdef HAVE_DUP | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
975 // Use stderr for stdin, also works for shell commands. |
7 | 976 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
|
977 vim_ignored = dup(2); |
7 | 978 #else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
979 read_cmd_fd = 2; // read from stderr instead of stdin |
7 | 980 #endif |
981 settmode(m); | |
982 } | |
983 if (!exit_on_error) | |
984 return; | |
985 } | |
986 if (len <= 0 && !got_int) | |
987 read_error_exit(); | |
988 if (len > 0) | |
989 did_read_something = TRUE; | |
990 if (got_int) | |
991 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
992 // Interrupted, pretend a CTRL-C was typed. |
7 | 993 inbuf[0] = 3; |
994 inbufcount = 1; | |
995 } | |
996 else | |
997 { | |
998 /* | |
999 * May perform conversion on the input characters. | |
1000 * Include the unconverted rest of the previous call. | |
1001 * If there is an incomplete char at the end it is kept for the next | |
1002 * time, reading more bytes should make conversion possible. | |
1003 * Don't do this in the unlikely event that the input buffer is too | |
1004 * small ("rest" still contains more bytes). | |
1005 */ | |
1006 if (input_conv.vc_type != CONV_NONE) | |
1007 { | |
1008 inbufcount -= unconverted; | |
1009 len = convert_input_safe(inbuf + inbufcount, | |
1010 len + unconverted, INBUFLEN - inbufcount, | |
1011 rest == NULL ? &rest : NULL, &restlen); | |
1012 } | |
1013 while (len-- > 0) | |
1014 { | |
1015 /* | |
19730
fe8ba2f82f59
patch 8.2.0421: interrupting with CTRL-C does not always work
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
1016 * If a CTRL-C was typed, remove it from the buffer and set |
fe8ba2f82f59
patch 8.2.0421: interrupting with CTRL-C does not always work
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
1017 * got_int. Also recognize CTRL-C with modifyOtherKeys set. |
7 | 1018 */ |
19730
fe8ba2f82f59
patch 8.2.0421: interrupting with CTRL-C does not always work
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
1019 if (ctrl_c_interrupts && (inbuf[inbufcount] == 3 |
fe8ba2f82f59
patch 8.2.0421: interrupting with CTRL-C does not always work
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
1020 || (len >= 9 && STRNCMP(inbuf + inbufcount, |
19750
aa674de6d813
patch 8.2.0431: some compilers don't support using e for Esc
Bram Moolenaar <Bram@vim.org>
parents:
19738
diff
changeset
|
1021 "\033[27;5;99~", 10) == 0))) |
7 | 1022 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1023 // remove everything typed before the CTRL-C |
7 | 1024 mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len + 1)); |
1025 inbufcount = 0; | |
1026 got_int = TRUE; | |
1027 } | |
1028 ++inbufcount; | |
1029 } | |
1030 } | |
18880
18a4871332ce
patch 8.2.0001: #endif comments do reflect corresponding #ifdef
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
1031 #endif // UNIX || VMS || MACOS_X |
7 | 1032 } |
18880
18a4871332ce
patch 8.2.0001: #endif comments do reflect corresponding #ifdef
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
1033 #endif // USE_INPUT_BUF |
7 | 1034 |
1035 /* | |
1036 * Exit because of an input read error. | |
1037 */ | |
1038 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1039 read_error_exit(void) |
7 | 1040 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1041 if (silent_mode) // Normal way to exit for "ex -s" |
7 | 1042 getout(0); |
1043 STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); | |
1044 preserve_exit(); | |
1045 } | |
1046 | |
1047 #if defined(CURSOR_SHAPE) || defined(PROTO) | |
1048 /* | |
1049 * May update the shape of the cursor. | |
1050 */ | |
1051 void | |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1052 ui_cursor_shape_forced(int forced) |
7 | 1053 { |
1054 # ifdef FEAT_GUI | |
1055 if (gui.in_use) | |
1056 gui_update_cursor_later(); | |
36 | 1057 else |
7 | 1058 # endif |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1059 term_cursor_mode(forced); |
36 | 1060 |
7 | 1061 # ifdef MCH_CURSOR_SHAPE |
1062 mch_update_cursor(); | |
1063 # 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
|
1064 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1065 # ifdef FEAT_CONCEAL |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13776
diff
changeset
|
1066 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1067 # endif |
7 | 1068 } |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1069 |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1070 void |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1071 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
|
1072 { |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1073 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
|
1074 } |
7 | 1075 #endif |
1076 | |
1077 /* | |
1078 * Check bounds for column number | |
1079 */ | |
1080 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1081 check_col(int col) |
7 | 1082 { |
1083 if (col < 0) | |
1084 return 0; | |
1085 if (col >= (int)screen_Columns) | |
1086 return (int)screen_Columns - 1; | |
1087 return col; | |
1088 } | |
1089 | |
1090 /* | |
1091 * Check bounds for row number | |
1092 */ | |
1093 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1094 check_row(int row) |
7 | 1095 { |
1096 if (row < 0) | |
1097 return 0; | |
1098 if (row >= (int)screen_Rows) | |
1099 return (int)screen_Rows - 1; | |
1100 return row; | |
1101 } | |
1102 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15665
diff
changeset
|
1103 #if defined(FEAT_GUI) || defined(MSWIN) || defined(PROTO) |
7 | 1104 /* |
1105 * Called when focus changed. Used for the GUI or for systems where this can | |
1106 * be done in the console (Win32). | |
1107 */ | |
1108 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1109 ui_focus_change( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1110 int in_focus) // TRUE if focus gained. |
7 | 1111 { |
1112 static time_t last_time = (time_t)0; | |
1113 int need_redraw = FALSE; | |
1114 | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1115 // 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
|
1116 // 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
|
1117 // several events in a row). |
7 | 1118 if (in_focus && last_time + 2 < time(NULL)) |
1119 { | |
1120 need_redraw = check_timestamps( | |
1121 # ifdef FEAT_GUI | |
1122 gui.in_use | |
1123 # else | |
1124 FALSE | |
1125 # endif | |
1126 ); | |
1127 last_time = time(NULL); | |
1128 } | |
1129 | |
1130 /* | |
1131 * Fire the focus gained/lost autocommand. | |
1132 */ | |
1133 need_redraw |= apply_autocmds(in_focus ? EVENT_FOCUSGAINED | |
1134 : EVENT_FOCUSLOST, NULL, NULL, FALSE, curbuf); | |
1135 | |
1136 if (need_redraw) | |
1137 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1138 // Something was executed, make sure the cursor is put back where it |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1139 // belongs. |
7 | 1140 need_wait_return = FALSE; |
1141 | |
1142 if (State & CMDLINE) | |
1143 redrawcmdline(); | |
1144 else if (State == HITRETURN || State == SETWSIZE || State == ASKMORE | |
1145 || State == EXTERNCMD || State == CONFIRM || exmode_active) | |
1146 repeat_message(); | |
1147 else if ((State & NORMAL) || (State & INSERT)) | |
1148 { | |
1149 if (must_redraw != 0) | |
1150 update_screen(0); | |
1151 setcursor(); | |
1152 } | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1153 cursor_on(); // redrawing may have switched it off |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
1154 out_flush_cursor(FALSE, TRUE); |
7 | 1155 # ifdef FEAT_GUI |
1156 if (gui.in_use) | |
1157 gui_update_scrollbars(FALSE); | |
1158 # endif | |
1159 } | |
1160 #ifdef FEAT_TITLE | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1161 // File may have been changed from 'readonly' to 'noreadonly' |
7 | 1162 if (need_maketitle) |
1163 maketitle(); | |
1164 #endif | |
1165 } | |
1166 #endif | |
1167 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13373
diff
changeset
|
1168 #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
7 | 1169 /* |
1170 * Save current Input Method status to specified place. | |
1171 */ | |
1172 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1173 im_save_status(long *psave) |
7 | 1174 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1175 // 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
|
1176 // 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
|
1177 // 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
|
1178 // then. |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1179 // 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
|
1180 // 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
|
1181 // input focus (e.g., when a find dialog is open). |
7 | 1182 if (!p_imdisable && KeyTyped && !KeyStuffed |
1183 # ifdef FEAT_XIM | |
1184 && xic != NULL | |
1185 # endif | |
1186 # ifdef FEAT_GUI | |
1187 && (!gui.in_use || gui.in_focus) | |
1188 # endif | |
1189 ) | |
1190 { | |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1191 // Do save when IM is on, or IM is off and saved status is on. |
7 | 1192 if (vgetc_im_active) |
1193 *psave = B_IMODE_IM; | |
1194 else if (*psave == B_IMODE_IM) | |
1195 *psave = B_IMODE_NONE; | |
1196 } | |
1197 } | |
1198 #endif |