mirror of
https://github.com/neovim/neovim.git
synced 2025-10-15 14:26:07 +00:00
api: Refactor write_msg to use separate out/err buffers
This commit is contained in:
@@ -512,23 +512,24 @@ void vim_unsubscribe(uint64_t channel_id, String event)
|
|||||||
/// `emsg` instead of `msg` to print each line)
|
/// `emsg` instead of `msg` to print each line)
|
||||||
static void write_msg(String message, bool to_err)
|
static void write_msg(String message, bool to_err)
|
||||||
{
|
{
|
||||||
static int pos = 0;
|
static int out_pos = 0, err_pos = 0;
|
||||||
static char line_buf[LINE_BUFFER_SIZE];
|
static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE];
|
||||||
|
|
||||||
|
#define PUSH_CHAR(i, pos, line_buf, msg) \
|
||||||
|
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \
|
||||||
|
line_buf[pos] = NUL; \
|
||||||
|
msg((uint8_t *)line_buf); \
|
||||||
|
pos = 0; \
|
||||||
|
continue; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
line_buf[pos++] = message.data[i];
|
||||||
|
|
||||||
for (uint32_t i = 0; i < message.size; i++) {
|
for (uint32_t i = 0; i < message.size; i++) {
|
||||||
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) {
|
|
||||||
// Flush line
|
|
||||||
line_buf[pos] = NUL;
|
|
||||||
if (to_err) {
|
if (to_err) {
|
||||||
emsg((uint8_t *)line_buf);
|
PUSH_CHAR(i, err_pos, err_line_buf, emsg);
|
||||||
} else {
|
} else {
|
||||||
msg((uint8_t *)line_buf);
|
PUSH_CHAR(i, out_pos, out_line_buf, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
line_buf[pos++] = message.data[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user