annotate src/ui.c @ 27492:4789f29c9595

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