aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/input.c
Commit message (Collapse)AuthorAge
...
* input: set input stream to blocking on exitJustin M. Keyes2015-05-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If stdin is non-blocking, many tools (e.g. cat(1), read(1)) which assume that stdin is blocking, will break in odd ways: read: read error: 0: Resource temporarily unavailable cat: -: Resource temporarily unavailable rm: error closing file libuv puts stdin in nonblocking mode, and leaves it that way at exit (this is apparently by design). So, before this commit, this always works (because the shell clobbers O_NONBLOCK): $ nvim --cmd q $ read ...but these forms do _not_ work: $ nvim --cmd q && read $ echo foo | nvim --cmd q && read $ nvim && read After this commit, all of the above forms work. Background: https://github.com/fish-shell/fish-shell/commit/437b4397b9cf273922ce7b414bf6626845f15ad0#diff-41f4d294430cd8c36538999d62681ae2 https://github.com/fish-shell/fish-shell/issues/176#issuecomment-15800155 - bash (and other shells: zsh, tcsh, fish), upon returning to the foreground, always sets fd 0 back to blocking mode. This practice only applies to stdin, _not_ stdout or stderr (in practice these fds may be affected anyways). - bash/zsh/tcsh/fish do _not_ restore the non-blocking status of stdin when _resuming a job_. - We do _not_ save/restore the original flags visible to fcntl(F_[SG]ETFL), because (counterintuitively) that isn't expected. Helped-by: oni-link <knil.ino@gmail.com> Closes #2086 Closes #2377 --- Note: The following implementation of stream_set_blocking() was discarded, because it resulted in a failed libuv assertion[1]: int stream_set_blocking(int fd, bool blocking) { uv_pipe_t stream; uv_pipe_init(uv_default_loop(), &stream, 0); uv_pipe_open(&stream, fd); int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking); uv_close((uv_handle_t *)&stream, NULL); return retval; } [1] .deps/build/src/libuv/src/unix/core.c:833: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
* Rename var eof as input_eof #2728Rui Abreu Ferreira2015-05-24
| | | | | - In Windows eof is a function, renamed the eof var in input.c to input_eof
* os/input.c: Eliminate conversion warning from gcc 5 #2617Björn Linse2015-05-09
|
* eval: Fix `jobwait()`Thiago de Arruda2015-04-11
| | | | | | - Properly save job event deferring state for recursive calls - Disable breakcheck while running. Breakcheck can invoke job callbacks in unexpected places.
* main: Simplify code that deals with early user inputThiago de Arruda2015-03-18
| | | | | | | | | A read stream will be started before the first ex command is processed. This stream will be used to read early user input before handling control over to the UI module. Which stdio stream will be used depends on which types of file descriptors are connected, and whether the "-" argument was passed.
* input: Escape utf8 sequences that contain CSI/K_SPECIALThiago de Arruda2015-02-18
|
* ui: Remove/adapt some old code for a big UI refactorThiago de Arruda2015-02-16
| | | | | | | | | | | | | - Remove abstract_ui global, now it is always active - Remove some terminal handling code - Remove unused functions - Remove HAVE_TGETENT/TERMINFO/TERMIOS/IOCTL #ifdefs - Remove tgetent/terminfo from version.c - Remove curses/terminfo dependencies - Only start/stop termcap when starting/exiting the program - msg_use_printf will return true if there are no attached UIs( messages will be written to stdout) - Remove `ex_winpos`(implement `:winpos` with `ex_ni`)
* input: Remove input_buffer_{save,restore}Thiago de Arruda2015-02-16
| | | | | | | The input buffer is only used for data that really came from another process and is only visible to os/input.c. Remove the input_buffer_{save,restore} functions, they are not necessary(Also can result in problems if data comes while the typeahead is saved).
* input: Fix handle_mouse_event functionThiago de Arruda2015-02-16
| | | | Ignore all keys that aren't prefixed with KS_EXTRA.
* input: Prefer keycodes in input_enqueue key translationThiago de Arruda2015-02-16
| | | | This is required to correctly handle certain keys such as <delete>
* input: Fix check for mouse coordinatesThiago de Arruda2015-01-15
| | | | Must check for EOF which will result in row/col being uninitialized.
* input: Read row/col position when processing mouse wheelThiago de Arruda2015-01-14
|
* input: Ignore invalid "<" key sequencesThiago de Arruda2015-01-13
| | | | | Ignoring invalid key sequences simplifies input handling in UIs. The only downside is having to use "<lt>" everytime a "<" is needed on functional tests.
* Revert "[WIP] "abstract_ui" fixes and improvements"Justin M. Keyes2015-01-12
|
* input: Ignore invalid "<" key sequencesThiago de Arruda2015-01-12
| | | | | Ignoring invalid key sequences simplifies input handling in UIs. The only downside is having to use "<lt>" everytime a "<" is needed on functional tests.
* Remove long_u: term: Enable -Wconversion.Eliseo Martínez2015-01-10
|
* input: Recognize mouse events for abstract_uiThiago de Arruda2014-12-10
|
* ui: Add abstract_ui termcap and split UI layerThiago de Arruda2014-12-08
| | | | | | | | | | | | | | | | | | This is how Nvim behaves when the "abstract_ui" termcap is activated: - No data is written/read to stdout/stdin by default. - Instead of sending data to stdout, ui_write will parse the termcap codes and invoke dispatch functions in the ui.c module. - The dispatch functions will forward the calls to all attached UI instances(each UI instance is an implementation of the UI layer and is registered with ui_attach). - Like with the "builtin_gui" termcap, "abstract_ui" does not contain any key sequences. Instead, vim key strings(<cr>, <esc>, etc) are parsed directly by input_enqueue and the translated strings are pushed to the input buffer. With this new input model, its not possible to send mouse events yet. Thats because mouse sequence parsing happens in term.c/check_termcodes which must return early when "abstract_ui" is activated.
* ui: Remove redundant ui.h includesThiago de Arruda2014-11-27
| | | | Also move read_error_exit to os/input.c
* ui: Remove ui_inchar/ui_char_availThiago de Arruda2014-11-27
| | | | | | | | | Also: - Remove NO_CONSOLE_INPUT/NO_CONSULE preprocessor conditionals - Remove ctrl_c_interrupts variable, check for mapped_ctrl_c directly in process_interrupts() - Move ui_inchar profiling to input_poll which is where Nvim blocks for input.
* input: Refactor to ensure user input has higher priorityThiago de Arruda2014-11-21
|
* event: Ensure the event loop has been cleaned up in event_teardownThiago de Arruda2014-11-02
| | | | | | | | | | - Add input_teardown/signal_teardown to take care of closing signal/stdin handles. - Call those functions in event_teardown, and ensure there are no active handles by entering an infinite loop when there are unclosed handles(think of this as an assertion that can't go unoticed on travis). - Move event_teardown call to the end of mch_exit. That is required because event_poll may still be called in that function.
* api: Add vim_input function and mark vim_feedkeys as deferredThiago de Arruda2014-10-29
| | | | | | | | The `vim_feedkeys` must be deferred because it can potentially free the buffer passed to `os_inchar`(which in turns calls `vim_feedkeys` indirectly). The new `vim_input` function can be used to emulate user input(Since it does not mess with the typeahead, it is safe to execute without deferring).
* input: Fix sizes of input/read buffersThiago de Arruda2014-10-29
| | | | | Input buffer must be bigger than read buffer to ensure it always has space for converted data.
* input/job: process ctrl+c and do conversion in the read callbackThiago de Arruda2014-10-29
| | | | | | | | | - Extract `process_interrupts` out of `convert_input` - Instead of waiting for os_breakcheck/os_inchar calls, call `convert_input` and `process_interrupts` directly from the read callback in input.c. - Remove the `settmode` calls from `job_wait`. Now that interrupts are processed in the event loop, there's no need to set the terminal to cooked which introduces other problems(ref 7.4.427)
* input: Fix conversion error in `convert_input()`Thiago de Arruda2014-10-28
| | | | | | | The `rbuffer_consumed` was being passed a consumed count from another buffer, causing integer overflow in `rbuffer_relocate`. Fixes #1343
* input: Fix ctrl+c handling in convert_inputThiago de Arruda2014-10-22
|
* input: Don't remove Ctrl+C from the input_bufferThiago de Arruda2014-10-21
|
* compilation: Add -Wconversion to more files and validate CONV_SOURCESThiago de Arruda2014-10-21
| | | | | | All files under the os, api and msgpack_rpc directories have -Wconversion automatically applied. CONV_SOURCES is also checked for missing files(when renaming, for example)
* event: Extract event_poll loops to `event_poll_until` macroThiago de Arruda2014-10-21
| | | | | | | A pattern that is becoming common across the project is to poll for events until a certain condition is true, optionally passing a timeout. To address this scenario, the event_poll_until macro was created and the job/channel/input modules were refactored to use it on their blocking functions.
* event: Remove automatic event deferallThiago de Arruda2014-10-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is how asynchronous events are currently handled by Nvim: - Libuv event loop is entered when Nvim blocks for user input(os_inchar is called) - Any event delivered by libuv that is not user input is queued for processing - The `K_EVENT` special key code is returned by os_inchar - `K_EVENT` is returned to a loop that is reading keys for the current Nvim mode, which will be handled by calling event_process() This approach has the advantage of integrating nicely with the current codebase, eg: vimscript code can be executed asynchronously with little surprises(Its the same as if the user typed a key). The problem with using keys to represent any event is that it also interferes with operators, and not every event needs or should do that. For example, consider this scenario: - A msgpack-rpc client calls vim_feedkeys("d") - Nvim processes K_EVENT, pushing "d" to the input queue - Nvim processes "d", entering operator-pending mode to wait for a motion - The client calls vim_feedkeys("w"), expecting Nvim to delete a word - Nvim processes K_EVENT, breaking out of operator-pending and pushing "w" - Nvim processes "w", moving a word This commit fixes the above problem by removing all automatic calls to `event_push`(which is what generates K_EVENT input). Right now this also breaks redrawing initiated by asynchronous events(and possibly other stuff too, Nvim is a complex state machine and we can't simply run vimscript code anywhere). In future commits the calls to `event_push` will be inserted only where it's absolutely necessary to run code in "key reading loops", such as when executing vimscript code or mutating editor data structures in ways that currently can only be done by the user.
* rstream: Add rbuffer_read_ptr/rbuffer_write_ptr functionsThiago de Arruda2014-10-19
| | | | | | | | | rbuffer_data was renamed to rbuffer_read_ptr, and it represents the next read position in a RBuffer instance. Similarly, rbuffer_write_ptr was added to represent the next write position. Also, rbuffer_data was being used for writing(in alloc_cb), replace that by rbuffer_write_ptr.
* ui: Refactor input buffer handlingThiago de Arruda2014-10-18
| | | | | All input buffer code was moved to os/input.c, and `inbuf` is now a `RBuffer` instance(which abstracts static buffer manipulation).
* rstream: Extract some RStream functionality to RBufferThiago de Arruda2014-10-18
| | | | | | | | RBuffer instances represent the internal buffer used by RStreams. This changes RStream constructor to receive RBuffer pointers and adds a set of RBuffer methods that expose the lower level buffer manipulation to consumers of the RStream API.
* api: Implement '--embedded-mode' command-line optionThiago de Arruda2014-08-28
| | | | | This option makes nvim run in "embedded mode", which creates an API channel via stdin/stdout and disables all terminal-related code
* events: Refactor how event deferral is handledThiago de Arruda2014-07-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Remove all *_set_defer methods and the 'defer' flag from rstream/jobs - Added {signal,rstream,job}_event_source functions. Each return a pointer that represent the event source for the object in question(For signals, a static pointer is returned) - Added a 'source' field to the Event struct, which is set to the appropriate value by the code that created the event. - Added a 'sources' parameter to `event_poll`. It should point to a NULL-terminated array of event sources that will be used to decide which events should be processed immediately - Added a 'source_override' parameter to `rstream_new`. This was required to use jobs as event sources of RStream instances(When "focusing" on a job, for example). - Extracted `process_from` static function from `event_process`. - Remove 'defer' parameter from `event_process`, which now operates only on deferred events. - Refactor `channel_send_call` to use the new lock mechanism What changed in a single sentence: Code that calls `event_poll` have to specify which event sources should NOT be deferred. This change was necessary for a number of reasons: - To fix a bug where due to race conditions, a client request could end in the deferred queue in the middle of a `channel_send_call` invocation, resulting in a deadlock since the client process would never receive a response, and channel_send_call would never return because the client would still be waiting for the response. - To handle "event locking" correctly in recursive `channel_send_call` invocations when the frames are waiting for responses from different clients. Not much of an issue now since there's only a python client, but could break things later. - To simplify the process of implementing synchronous functions that depend on asynchronous events.
* Use strict function prototypes #945Pavel Platto2014-07-14
| | | | | | | | | | | | | | | | | | | `-Wstrict-prototypes` warn if a function is declared or defined without specifying the argument types. This warning disallow function prototypes with empty parameter list. In C, a function declared with an empty parameter list accepts an arbitrary number of arguments when being called. This is for historic reasons; originally, C functions didn't have prototypes, as C evolved from B, a typeless language. When prototypes were added, the original typeless declarations were left in the language for backwards compatibility. Instead we should provide `void` in argument list to state that function doesn't have arguments. Also this warning disallow declaring type of the parameters after the parentheses because Neovim header generator produce no declarations for old-stlyle prototypes: it expects to find `{` after prototype.
* move ascii.h include out of vim.hBrandon Coleman2014-07-09
|
* event: Decouple user input checks from `event_poll`Thiago de Arruda2014-06-24
| | | | | | | | | | | | | | This was done to generalize the usage of `event_poll`, which will now return `true` only if a event has been processed/deferred before the timeout(if not -1). To do that, the `input_ready` calls have been extracted to the input.c module(the `event_poll` call has been surrounded by `input_ready` calls, resulting in the same behavior). The `input_start`/`input_stop` calls still present in `event_poll` are temporary: When the API becomes the only way to read user input, it will no longer be necessary to start/stop the input stream.
* events: Refactor how events are queued for processingThiago de Arruda2014-06-18
| | | | | | | | | | | | | | | | | | To make it possible reuse `event_poll` recursively and in other blocking function calls, this changes how deferred/immediate events are processed: - There are two queues in event.c, one for immediate events and another for deferred events. The queue used when pushing/processing events is determined with boolean arguments passed to `event_push`/`event_process` respectively. - Events pushed to the immediate queue are processed inside `event_poll` but after the `uv_run` call. This is required because libuv event loop does not support recursion, and processing events may result in other `event_poll` calls. - Events pushed to the deferred queue are processed later by calling `event_process(true)`. This is required to "trick" vim into treating all asynchronous events as special keypresses, which is the least obtrusive way of introducing asynchronicity into the editor. - RStream instances will now forward the `defer` flag to the `event_push` call.
* Add automatic generation of headersZyX2014-06-02
| | | | | | | | | | | | | | | | | - The 'stripdecls.py' script replaces declarations in all headers by includes to generated headers. `ag '#\s*if(?!ndef NEOVIM_).*((?!#\s*endif).*\n)*#ifdef INCLUDE_GENERATED'` was used for this. - Add and integrate gendeclarations.lua into the build system to generate the required includes. - Add -Wno-unused-function - Made a bunch of old-style definitions ANSI This adds a requirement: all type and structure definitions must be present before INCLUDE_GENERATED_DECLARATIONS-protected include. Warning: mch_expandpath (path.h.generated.h) was moved manually. So far it is the only exception.
* Move documentation from function declarations to definitionsZyX2014-06-02
| | | | Uses a perl script to move it (scripts/movedocs.pl)
* Introduce nvim namespace: Fix project-local includes.Eliseo Martínez2014-05-15
| | | | Prepend 'nvim/' in all project-local (non-system) includes.
* Introduce nvim namespace: Move files.Eliseo Martínez2014-05-15
Move files from src/ to src/nvim/. - src/nvim/ becomes the new root dir for nvim executable sources. - src/libnvim/ is planned to become root dir of the neovim library.