Skip to content

Commit 4fd9ee4

Browse files
committed
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)
1 parent 49d5ed5 commit 4fd9ee4

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/nvim/os/input.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
116116
return 0;
117117
}
118118

119-
convert_input();
120119
// Safe to convert rbuffer_read to int, it will never overflow since
121120
// we use relatively small buffers.
122121
return (int)rbuffer_read(input_buffer, (char *)buf, (size_t)maxlen);
@@ -132,8 +131,8 @@ bool os_char_avail(void)
132131
// In cooked mode we should get SIGINT, no need to check.
133132
void os_breakcheck(void)
134133
{
135-
if (curr_tmode == TMODE_RAW && input_poll(0))
136-
convert_input();
134+
if (curr_tmode == TMODE_RAW)
135+
input_poll(0);
137136
}
138137

139138
/// Test whether a file descriptor refers to a terminal.
@@ -220,6 +219,8 @@ static void read_cb(RStream *rstream, void *data, bool at_eof)
220219
}
221220
}
222221

222+
convert_input();
223+
process_interrupts();
223224
started_reading = true;
224225
}
225226

@@ -260,7 +261,10 @@ static void convert_input(void)
260261
// data points to memory allocated by `string_convert_ext`, free it.
261262
free(data);
262263
}
264+
}
263265

266+
static void process_interrupts(void)
267+
{
264268
if (!ctrl_c_interrupts) {
265269
return;
266270
}
@@ -299,10 +303,10 @@ static int push_event_key(uint8_t *buf, int maxlen)
299303
// Check if there's pending input
300304
static bool input_ready(void)
301305
{
302-
return typebuf_was_filled || // API call filled typeahead
303-
event_has_deferred() || // Events must be processed
306+
return typebuf_was_filled || // API call filled typeahead
307+
event_has_deferred() || // Events must be processed
304308
(!embedded_mode && (
305-
rstream_pending(read_stream) > 0 || // Stdin input
306-
eof)); // Stdin closed
309+
rbuffer_pending(input_buffer) > 0 || // Stdin input
310+
eof)); // Stdin closed
307311
}
308312

src/nvim/os/job.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "nvim/os/shell.h"
1616
#include "nvim/vim.h"
1717
#include "nvim/memory.h"
18-
#include "nvim/term.h"
1918

2019
#define EXIT_TIMEOUT 25
2120
#define MAX_RUNNING_JOBS 100
@@ -277,10 +276,6 @@ void job_stop(Job *job)
277276
/// is possible on some OS.
278277
int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
279278
{
280-
// switch to cooked so `got_int` will be set if the user interrupts
281-
int old_mode = cur_tmode;
282-
settmode(TMODE_COOK);
283-
284279
// Increase refcount to stop the job from being freed before we have a
285280
// chance to get the status.
286281
job->refcount++;
@@ -296,8 +291,6 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
296291
event_poll(0);
297292
}
298293

299-
settmode(old_mode);
300-
301294
if (!--job->refcount) {
302295
int status = (int) job->status;
303296
// Manually invoke close_cb to free the job resources

0 commit comments

Comments
 (0)