aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/shell.c
Commit message (Collapse)AuthorAge
* out_data_decide_throttle(): timeout instead of hard limit.Justin M. Keyes2016-12-10
| | | | | | | Instead of managing max_visits, check the time every N visits. This avoids edge cases where max_visits is large but the chunk frequency slowed down, which would causing the "..." pulse to show for a very long time. It's more important to show output at reasonable intervals than to avoid calling os_hrtime().
* out_data_decide_throttle(): Avoid too-small final chunk.Justin M. Keyes2016-12-10
|
* os/shell: do_os_system(): Always show last chunk.Justin M. Keyes2016-12-10
| | | | | | | | | | | | | | | | | | | | | This ameliorates use-cases like: :!cat foo.txt :make where the user is interested in the last few lines of output. Try these shell-based ex-commands before/after this commit: :grep -r '' * :make :!yes :!grep -r '' * :!git grep '' :!cat foo :!echo foo :!while true; do date; done :!for i in `seq 1 20000`; do echo XXXXXXXXXX $i; done In all cases the last few lines of the command should always be shown, regardless of where throttling was triggered.
* os/shell: Throttle :! output, pulse "..." message.Justin M. Keyes2016-12-09
| | | | | | | | | | | | | | | | | | | | | | | | | | Periodically skip :! spam. This is a "cheat" that works for all UIs and greatly improves responsiveness when :! spams MB or GB of output: :!yes :!while true; do date; done :!git grep '' :grep -r '' * After ~10KB of data is seen from a single :! invocation, output will be skipped for ~1s and three dots "..." will pulse in the bottom-left. Thereafter the behavior alternates at every: * 10KB received * ~1s throttled This also avoids out-of-memory which could happen with large :! outputs. Note: This commit does not change the behavior of execute(':!foo'). execute(':!foo') returns the string ':!foo^M', it captures *only* Vim messages, *not* shell command output. Vim behaves the same way. Use system('foo') for capturing shell command output. Closes #1234 Helped-by: oni-link <knil.ino@gmail.com>
* shell_write_cb: Schedule error message. (#5670)Justin M. Keyes2016-11-26
| | | Closes #5558
* system('foo &', 'bar'): Show error, don't crash.Justin M. Keyes2016-10-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Closes #3529 Closes #5241 In Vim, :echo system('cat - &', 'foo') works because for both system() and :! Vim writes input to a temp file and uses shell syntax to redirect the file to the backgrounded `cat` (get_cmd_output() .. make_filter_cmd()). In Nvim, :echo system('cat - &', 'foo') fails because we write the input directly via pipes (shell.c:do_os_system()), but (per POSIX[1]) backgrounded process input stream is redirected from /dev/null (unless overridden by shell redirection; supported only by some shells [2]), so our writes are ignored, the process exits quickly, and if we are writing data larger than the buffer size we'll see EPIPE. This still works: :%w !tee > foo1358.txt & but this does not: :%w !tee foo1358.txt & though it *should* (why doesn't it?) because we still do the temp file dance in do_bang() .. do_filter(). [1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_03_02 [2] http://unix.stackexchange.com/a/71218
* event/multiqueue.c: Rename "queue" to "multiqueue".Justin M. Keyes2016-10-02
| | | | | | | | | | | | | | `lib/queue.h` implements a basic queue. `event/queue.c` implements a specialized data structure on top of lib/queue.h; it is not a "normal" queue. Rename the specialized multi-level queue implemented in event/queue.c to "multiqueue", to avoid confusion when reading the code. Before this change one can eventually notice that "macros (uppercase symbols) are for the normal queue, lowercase operations are for the multi-level queue", but that is unnecessary friction for new developers (or existing developers just visiting this part of the codebase).
* doc: minor comment tweaksJustin M. Keyes2016-09-28
|
* refactor: eliminate misc2.cJustin M. Keyes2016-09-13
| | | | | | | | | | move `call_shell` to misc1.c Move some fns to state.c Move some fns to option.c Move some fns to memline.c Move `vim_chdir*` fns to file_search.c Move some fns to new module, bytes.c Move some fns to fileio.c
* shell_escape: rename; refactorJustin M. Keyes2016-09-11
| | | | | | | | - rename to shell_xescape_xquote - move to os/shell.c - disallow NULL argument - eliminate casts, nesting - test: empty shellxquote/shellxescape
* system(): Respect 'sxe' and 'sxq' #2789Zhaosheng Pan2016-09-10
| | | | Fixes #2773
* stream: set data together with callbackBjörn Linse2016-08-20
|
* Merge #4646 from oni-link/fix.issue.4569.3Justin M. Keyes2016-06-26
|\ | | | | Fix for missing output (#4569, ...)
| * shell.c: Fix missing outputoni-link2016-05-15
| | | | | | | | | | | | | | | | | | | | | | | | The whole stream buffer is now put on screen at once instead of only data up to the last newline. This has some advantages: * RBuffer cannot wrap around, so we never forget to output second half of the buffer. * Stream data is not delayed anymore, because we don't have to wait for a newline. This works by remembering the last used screen column.
* | *: Rename main loop variable from loop to main_loopZyX2016-05-30
|/ | | | | | | | | | | | | | | | Current name is inappropriate for the following reasons: 1. It is often masked by local `loop` variables. 2. It cannot be searched for. There are many `loop` variables where `loop` is some local variable. There are many cases when “loop” word is used in a comment. 3. It is in any case bad idea to use a generic name as a name of the global variable. Best if global has module prefix: this is why it is in `main.h`: `main_loop` both stands for “a main loop” and “a loop defined in `main.*`”. Since I have no idea how to list every occurrence of this variable method used to rename it is “remove it from globals.h, try to compile, fix errors”. Thus if some occurrence was hidden under false `#if` branch it was not replaced.
* shell: Unquote &shell* options before using themZyX2016-01-11
|
* vim-patch:7.4.785Johan Klokkhammer Helsing2015-11-22
| | | | | | | | Problem: On some systems automatically adding the missing EOL causes problems. Setting 'binary' has too many side effects. Solution: Add the 'fixeol' option, default on. (Pavel Samarkin) https://github.com/vim/vim/commit/34d72d4b6c1a2b04a214d8a49b7d22c97bc7a8bc
* Windows: avoid "uv_" naming conflicts. #3225Seth Jackson2015-08-27
|
* eval: Fix jobwait() to process multiple jobs concurrentlyThiago de Arruda2015-08-13
| | | | | | | | | | | | | The new event processing architecture changed `jobwait()` semantics: Only one job is processed at time since process_wait only focuses on one queue. This fixes the problem with a few changes: - Allow the event queue polled by `process_wait` to be overriden by a new argument. - Allow the parent queue to be overriden with `queue_replace_parent` - Create a temporary queue that serves as the parent for all jobs passed to `jobwait()`
* rstream: Pass read count to read eventsThiago de Arruda2015-08-13
| | | | This is necessary to keep events in the same order received from the OS.
* event: Refactor async event processingThiago de Arruda2015-08-13
| | | | | | | | | | - Improve the implementation of deferred/immediate events. - Use the new queue module to change how/when events are queued/processed by giving a private queue to each emitter. - Immediate events(which only exist to break uv_run recursion) are now represented in the `loop->fast_events` queue. - Events pushed to child queues are propagated to the event loop main queue and processed as K_EVENT keys.
* process: Pass loop reference during initializationThiago de Arruda2015-08-13
| | | | | Change the API so that it is passed to {uv,pty}_process_init instead of `process_spawn`.
* shell.c: A full RBuffer with no NL can freeze shell output. #3156oni-link2015-08-11
| | | | | | | | | | | | | | | out_data_cb() can return without emptying the full RBuffer (no NL was seen). Because the shell output stream is stopped until space in the Rbuffer is freed up, no more shell output is written. To prevent this, output the full RBuffer when write_output() did not write anything. write_output() can also process the same RBuffer content more than once, if no NL was seen. To prevent NUL bytes from producing new lines (if lines are not written to a buffer), translate NUL to SOH(1). Fixes #2983
* job: Replace by a better process abstraction layerThiago de Arruda2015-07-17
| | | | | | | | | | | | | - New libuv/pty process abstraction with simplified API and no globals. - Remove nvim/os/job*. Jobs are now a concept that apply only to programs spawned by vimscript job* functions. - Refactor shell.c/channel.c to use the new module, which brings a number of advantages: - Simplified API, less code - No slots in the user job table are used - Not possible to acidentally receive data from vimscript - Implement job table in eval.c, which is now a hash table with unilimited job slots and unique job ids.
* rstream/wstream: Unify structures and simplify APIThiago de Arruda2015-07-17
| | | | | | | | | | | | | - Simplify RStream/WStream API and make it more consistent with libuv. - Move into the event loop layer(event subdirectory) - Remove uv_helpers module. - Simplify job/process internal modules/API. - Unify RStream and WStream into a single structure. This is necessary because libuv streams can be readable and writable at the same time(and because the uv_helpers.c hack to associate multiple streams with libuv handle was removed) - Make struct definition public, allowing more flexible/simple memory management by users of the module. - Adapt channel/job modules to cope with the changes.
* event loop: New abstraction layer with refactored time/signal APIThiago de Arruda2015-07-17
| | | | | | | | | | - Add event loop abstraction module under src/nvim/event. The src/nvim/event/loop module replaces src/nvim/os/event - Remove direct dependency on libuv signal/timer API and use the new abstraction instead. - Replace all references to uv_default_loop() by &loop.uv, a new global variable that wraps libuv main event loop but allows the event loop functions to be reused in other contexts.
* rbuffer: Reimplement as a ring buffer and decouple from rstreamThiago de Arruda2015-07-01
| | | | | | | | | | | | | | | | | | | | Extract the RBuffer class from rstream.c and reimplement it as a ring buffer, a more efficient version that doesn't need to relocate memory. The old rbuffer_read/rbuffer_write interfaces are kept for simple reading/writing, and the RBUFFER_UNTIL_{FULL,EMPTY} macros are introduced to hide wrapping logic when more control is required(such as passing the buffer pointer to a library function that writes directly to the pointer) Also add a basic infrastructure for writing helper C files that are only compiled in the unit test library, and use this to write unit tests for RBuffer which contains some macros that can't be accessed directly by luajit. Helped-by: oni-link <knil.ino@gmail.com> Reviewed-by: oni-link <knil.ino@gmail.com> Reviewed-by: Scott Prager <splinterofchaos@gmail.com> Reviewed-by: Justin M. Keyes <justinkz@gmail.com> Reviewed-by: Michael Reed <m.reed@mykolab.com>
* Fix warnings: shell.c: do_os_system(): Nonnull passed null: FP. #2923Eliseo Martínez2015-06-28
| | | | | | | | | | | | Problem : Argument with 'nonnull' attribute passed null @ 203. Diagnostic : False positive. Rationale : Problem is supposed to appear when argv[0] is NULL within do_os_system. But argv is being generated by shell_build_argv(), which implies argv[0] is the current value for 'shell' option. Now, option has a non-null default ($SHELL or "sh"), and, if set by the user, it can be empty, but not NULL. So, argv[0] can never be NULL. Resolution : Assert shell_build_argv() postcondition.
* unify jobstart, termopen, and system interfacesScott Prager2015-05-02
| | | | | | | | | | | | | | | | | For any of these functions, if {cmd} is a string, execute "&shell &shellcmdflag '{cmd}'", or simply {cmd} if it's a list. In termopen(), if the 'name' option is not supplied, try to guess using '{cmd}' (string) or {cmd}[0] (list). Simplify ex_terminal to use the string form of termopen(). termopen: get name from argument Convert list_to_argv to tv_to_argv. Helped-by: Björn Linse <@bfredl> Helped-by: oni-link <knil.ino@gmail.com> Helped-by: Thiago de Arruda <@tarruda>
* memory: Add `free` wrapper and refactor project to use itThiago de Arruda2015-04-13
| | | | | | We already use wrappers for allocation, the new `xfree` function is the equivalent for deallocation and provides a way to fully replace the malloc implementation used by Neovim.
* ui: Refactor so that busy state won't be the defaultThiago de Arruda2015-03-18
| | | | | | | | | | | Even though assuming nvim is busy most times is simpler, it has a problem: A lot of unnecessary busy_start/busy_stop notifications are sent to the UI. That's because in the majority of scenarios almost no time is spent between `event_poll` calls. This restores the normal behavior which is to call busy_start only when nvim is going to perform some task that can take a significant amount of time. Also improve the usage of buffering in the TUI when changing the cursor state.
* ui: Replace cursor_{on,off} by busy_{stop,start}Thiago de Arruda2015-03-15
| | | | | | | | | | | | | | | | | | | | | | | | Switching cursor off is only necessary in two occasions: - When redrawing to avoid terminal flickering - When the editor is busy The first can now be handled by the TUI, so most calls to ui_cursor_off can be removed from the core. So, before this commit it was only necessary to switch the cursor off to notify the user that nvim was running some long operation. Now the cursor_{on,off} functions have been replaced by busy_{stop,start} which can be handled in a UI-specific way(turning the cursor off or showing a busy indicator, for example). To make things even more simpler, nvim is always busy except when waiting for user input or other asynchronous events: It automatically switches to a non-busy state when the event loop is about to be entered for more than 100 milliseconds. `ui_busy_start` can be called when its not desired to change the busy state in the event loop (As its now done by functions that perform blocking shell invocations).
* job: Refactor process spawning and startup argumentsThiago de Arruda2015-02-23
| | | | | | | | - process spawning was decoupled from the rest of the job control logic. The goal is reusing it for spawning processes connected to pseudo terminal file descriptors. - job_start now receives a JobOptions structure containing all the startup options.
* refactor: Remove term modules and termcap optionsThiago de Arruda2015-02-21
| | | | | | | | | | | | | | | - Removed term.c, term.h and term_defs.h - Tests for T_* values were removed. screen.c was simplified as a consequence(the best strategy for drawing is implemented in the UI layer) - Redraw functions now call ui.c functions directly. Updates are flushed with `ui_flush()` - Removed all termcap options(they now return empty strings for compatibility) - &term/&ttybuiltin options return a constant value(nvim) - &t_Co is still available, but it mirrors t_colors directly - Remove cursor tracking from screen.c and the `screen_start` function. Now the UI is expected to maintain cursor state across any call, and reset it when resized. - Remove unused code
* shell: When executing command, use screen functions to display outputThiago de Arruda2015-01-13
| | | | | By calling ui_write directly, the internal screen isn't updated and invalid bytes aren't handled, which breaks the abstract UI model.
* Revert "[WIP] "abstract_ui" fixes and improvements"Justin M. Keyes2015-01-12
|
* shell: When executing command, use screen functions to display outputThiago de Arruda2015-01-12
| | | | | By calling ui_write directly, the internal screen isn't updated and invalid bytes aren't handled, which breaks the abstract UI model.
* coverity/74717: FP: NULL Pointer DereferenceJustin M. Keyes2014-12-23
| | | | | dynamic_buffer_ensure() allocates buf->data; add an assert to make this clear to coverity.
* coverity/74718: invalid FUNC_ATTR_NONNULL_ARGJustin M. Keyes2014-12-20
| | | | | | | - avoid null passed to ELOG format string - receive (char *) internally - modify identifier names for consistency - edit comments for concision and consistency
* shell: Fix shell command outputThiago de Arruda2014-12-06
| | | | | | | | | Shell command output was broken in @8a5a8db, which refactored nvim to no longer switch to cooked mode(linefeeds are processed differently). Fix the problem by refactoring write_output to accept to extra arguments that control the flushing behavior and where data will be written to: buffer or directly to the screen.
* term: Remove most calls to settmodeThiago de Arruda2014-12-02
| | | | | | Nvim now relies much less on setting terminal mode to cooked mode, remove most calls to settmode, except for those that happen on startup or when suspending. Eventually even those will be handled by the UI layer.
* shell: Use job_write_cb for closing stdinThiago de Arruda2014-11-10
| | | | | | | | | | Commit @45525853d352 removed usage of the `job_write_cb` for closing stdin due to a memory error, but that doesn't work anymore because `job_close_in` closes stdin immediately, possibly trimming input data before it is fully written. Since most memory issues with jobs have been fixed, re-add the `job_write_cb` call to ensure stdin is only closed when it should. Also add tests for scenarios where using the callback makes a difference.
* job/shell: Refactor os_call_shell/os_system to share codeThiago de Arruda2014-10-31
|
* shell: Rename dyn_buffer_t to DynamicBufferThiago de Arruda2014-10-31
| | | | To follow our coding conventions
* job: Let job_start callers to selectively ignore stdioThiago de Arruda2014-10-31
| | | | | | | | Passing NULL as the callback for stdout/stderr will result in job_start ignoring stdout/stderr, respectively. A 'writable' boolean argument was also added, and when false `job_start` will ignore stdin. Also, refactor os_system to allow passing NULL as the `output` argument.
* event: Remove direct calls to `uv_run` from job.c/shell.cThiago 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)
* 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.
* wstream/shell: Fix memory errors caused by os_systemThiago de Arruda2014-10-01
| | | | | | | | | | | | | | The os_system function uses a write callback to close the input stream when the write completes, but this causes a memory error because the callback is invoked right before the stream is freed by the caller. This fixes the problem by removing the callback set by os_system. Instead, it calls job_close_in immediately after writing(the stream will only close after the write completes). The 'pending' parameter was also removed from the 'write_cb' as it should be hidden by the wstream module. While the `wstream_set_write_cb` and `job_write_cb` are no longer used, they will remain in the codebase for future use.
* Remove unused arg 'defer' in 'job_start' #1000oni-link2014-07-29
| | | | | | | | | * With the changes in commit "events: Refactor how event deferral is handled" (2e4ea29d2c7b62eb8baf1c41cd43433e085dda0) the function argument 'defer' of 'job_start' and member variable 'defer' of 'struct job' can be removed. * Update/Fix the documentation for function 'job_start'.