The input buffer is a simple char_u
array:
static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN];
The variable
inbufcount
has the number of characters stored in the input buffer. If
inbufcount == 0
, the input buffer is empty and
vim_is_input_buf_empty()
returns
TRUE
.
Functions to manipulate the
input buffer are
-
vim_is_input_buf_full()
-
vim_is_input_buf_empty()
-
add_to_input_buf()
-
trash_input_buf()
These functions are used by gui_*
calls when the keyboard input is handled by a GUI.
Further interesting functions seem to be get_input_buf()
and set_input_buf()
.
The input buffer does not only store (keyboard-) characters. For example, when vim gets focus (Windows:
_OnSetFocus()
, a special byte-tripplet is inserted into the input buffer:
CSI
,
KS_EXTRA
,
KE_FOCUSGAINED
.
TODO: What is the relationship to the typeahead buffer (
typebuf_T
)?
Adds the given bytes to the input buffer.
In a Windows-GUI VIM, this functions is (among others?) called from
_OnChar()
(which itself is called after receiving a
WM_CHAR
notification in the Windows Procedure
_WndProc()
).
Returns true if inbufcount == 0
(which indicates that the input buffer is empty).
trash_input_buf()
trash_input_buf()
is called when
ctrl-C is pressed (and
ctrl_c_interrupts
is
TRUE
?) (but see also the handling of
VK_CANCEL
in
process_message()
)
The function erases the entire input buffer.
inchar_loop()
Common code for mch_inchar()
and gui_inchar()
: Wait for a while or indefinitely until characters are available, dealing with timers and messages on channels.
buf
may be NULL if the available characters are not to be returned, only check if they are available.
Return the number of characters that are available.
If wtime == 0
do not wait for characters.
If wtime == n
wait a short time for characters.
If wtime == -1
wait forever for characters.
The parameter wait_func
is a function pointer. In a GUI compilation, wait_func
seems to be point to gui_wait_for_chars_or_timer()
.
Compare with the similarly sounding function
inchar()
.
ui_wait_for_chars_or_timer()
Wait for a timer to fire or wait_func
(a function pointer) to return non-zero.
Returns OK
when something was read.
Returns FAIL
when it timed out or was interrupted.
The function is only defined if at least one of the macros FEAT_TIMERS
or PROTO
is defined.