input/job: process ctrl+c and do conversion in the read callback

- 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)
This commit is contained in:
Thiago de Arruda
2014-10-29 17:30:45 -03:00
parent 49d5ed5591
commit 4fd9ee4a6b
2 changed files with 11 additions and 14 deletions

View File

@@ -116,7 +116,6 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
return 0; return 0;
} }
convert_input();
// Safe to convert rbuffer_read to int, it will never overflow since // Safe to convert rbuffer_read to int, it will never overflow since
// we use relatively small buffers. // we use relatively small buffers.
return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen); return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
@@ -132,8 +131,8 @@ bool os_char_avail(void)
// In cooked mode we should get SIGINT, no need to check. // In cooked mode we should get SIGINT, no need to check.
void os_breakcheck(void) void os_breakcheck(void)
{ {
if (curr_tmode == TMODE_RAW && input_poll(0)) if (curr_tmode == TMODE_RAW)
convert_input(); input_poll(0);
} }
/// Test whether a file descriptor refers to a terminal. /// Test whether a file descriptor refers to a terminal.
@@ -220,6 +219,8 @@ static void read_cb(RStream *rstream, void *data, bool at_eof)
} }
} }
convert_input();
process_interrupts();
started_reading = true; started_reading = true;
} }
@@ -260,7 +261,10 @@ static void convert_input(void)
// data points to memory allocated by `string_convert_ext`, free it. // data points to memory allocated by `string_convert_ext`, free it.
free(data); free(data);
} }
}
static void process_interrupts(void)
{
if (!ctrl_c_interrupts) { if (!ctrl_c_interrupts) {
return; return;
} }
@@ -299,10 +303,10 @@ static int push_event_key(uint8_t *buf, int maxlen)
// Check if there's pending input // Check if there's pending input
static bool input_ready(void) static bool input_ready(void)
{ {
return typebuf_was_filled || // API call filled typeahead return typebuf_was_filled || // API call filled typeahead
event_has_deferred() || // Events must be processed event_has_deferred() || // Events must be processed
(!embedded_mode && ( (!embedded_mode && (
rstream_pending(read_stream) > 0 || // Stdin input rbuffer_pending(input_buffer) > 0 || // Stdin input
eof)); // Stdin closed eof)); // Stdin closed
} }

View File

@@ -15,7 +15,6 @@
#include "nvim/os/shell.h" #include "nvim/os/shell.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/term.h"
#define EXIT_TIMEOUT 25 #define EXIT_TIMEOUT 25
#define MAX_RUNNING_JOBS 100 #define MAX_RUNNING_JOBS 100
@@ -277,10 +276,6 @@ void job_stop(Job *job)
/// is possible on some OS. /// is possible on some OS.
int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
{ {
// switch to cooked so `got_int` will be set if the user interrupts
int old_mode = cur_tmode;
settmode(TMODE_COOK);
// Increase refcount to stop the job from being freed before we have a // Increase refcount to stop the job from being freed before we have a
// chance to get the status. // chance to get the status.
job->refcount++; job->refcount++;
@@ -296,8 +291,6 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
event_poll(0); event_poll(0);
} }
settmode(old_mode);
if (!--job->refcount) { if (!--job->refcount) {
int status = (int) job->status; int status = (int) job->status;
// Manually invoke close_cb to free the job resources // Manually invoke close_cb to free the job resources