Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] screen_puts_len: Ignore control chars. #4376

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/nvim/ex_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,20 +1104,11 @@ static void do_filter(
}
read_linecount = curbuf->b_ml.ml_line_count;

/*
* When call_shell() fails wait_return() is called to give the user a
* chance to read the error messages. Otherwise errors are ignored, so you
* can see the error messages from the command that appear on stdout; use
* 'u' to fix the text
* Switch to cooked mode when not redirecting stdin, avoids that something
* like ":r !cat" hangs.
* Pass on the kShellDoOut flag when the output is being redirected.
*/
if (call_shell(
cmd_buf,
kShellOptFilter | shell_flags,
NULL
)) {
// When call_shell() fails wait_return() is called to give the user a
// chance to read the error messages. Otherwise errors are ignored, so you
// can see the error messages from the command that appear on stdout.
// Pass on the kShellDoOut flag when the output is being redirected.
if (call_shell(cmd_buf, kShellOptFilter | shell_flags, NULL)) {
redraw_later_clear();
wait_return(FALSE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5975,7 +5975,7 @@ static void ex_stop(exarg_T *eap)
autowrite_all();
}
ui_cursor_goto((int)Rows - 1, 0);
ui_putc('\n');
ui_putc('\n', true);
ui_flush();
ui_suspend(); /* call machine specific function */
maketitle();
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ static void handle_quickfix(mparm_T *paramp)
paramp->use_ef, OPT_FREE, SID_CARG);
vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef);
if (qf_init(NULL, p_ef, p_efm, TRUE, IObuff) < 0) {
ui_putc('\n');
ui_putc('\n', true);
mch_exit(3);
}
TIME_MSG("reading errorfile");
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/misc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,7 @@ void vim_beep(unsigned val)
if (p_vb) {
ui_visual_bell();
} else {
ui_putc(BELL);
ui_putc(BELL, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nvim/misc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
verbose_enter();
smsg(_("Calling shell to execute: \"%s\""),
cmd == NULL ? p_sh : cmd);
ui_putc('\n');
ui_putc('\n', true);
verbose_leave();
}

Expand Down
8 changes: 2 additions & 6 deletions src/nvim/os/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,10 @@ static void read_input(DynamicBuffer *buf)

if (len == l) {
// Finished a line, add a NL, unless this line should not have one.
// FIXME need to make this more readable
if (lnum != curbuf->b_op_end.lnum
|| (!curbuf->b_p_bin
&& curbuf->b_p_fixeol)
|| (!curbuf->b_p_bin && curbuf->b_p_fixeol)
|| (lnum != curbuf->b_no_eol_lnum
&& (lnum !=
curbuf->b_ml.ml_line_count
|| curbuf->b_p_eol))) {
&& (lnum != curbuf->b_ml.ml_line_count || curbuf->b_p_eol))) {
dynamic_buffer_ensure(buf, buf->len + 1);
buf->data[buf->len++] = NL;
}
Expand Down
12 changes: 6 additions & 6 deletions src/nvim/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4209,9 +4209,9 @@ win_line (
if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
screen_row -
1] + (Columns - 1)]) > 1) {
ui_putc(' ');
ui_putc(' ', false);
} else {
ui_putc(ScreenLines[LineOffset[screen_row - 1] + (Columns - 1)]);
ui_putc(ScreenLines[LineOffset[screen_row - 1] + (Columns - 1)], false);
}
/* force a redraw of the first char on the next line */
ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
Expand Down Expand Up @@ -5797,12 +5797,12 @@ static void screen_char(unsigned off, int row, int col)

// Convert UTF-8 character to bytes and write it.
buf[utfc_char2bytes(off, buf)] = NUL;
ui_puts(buf);
ui_puts(buf, false);
} else {
ui_putc(ScreenLines[off]);
ui_putc(ScreenLines[off], false);
// double-byte character in single-width cell
if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) {
ui_putc(ScreenLines2[off]);
ui_putc(ScreenLines2[off], false);
}
}
}
Expand All @@ -5829,7 +5829,7 @@ static void screen_char_2(unsigned off, int row, int col)
/* Output the first byte normally (positions the cursor), then write the
* second byte directly. */
screen_char(off, row, col);
ui_putc(ScreenLines[off + 1]);
ui_putc(ScreenLines[off + 1], false);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data)

static int term_bell(void *data)
{
ui_putc('\x07');
ui_putc(BELL, true);
return 1;
}

Expand Down
34 changes: 25 additions & 9 deletions src/nvim/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,33 @@ void ui_visual_bell(void)
UI_CALL(visual_bell);
}

void ui_puts(uint8_t *str)
void ui_puts(uint8_t *str, bool control)
{
uint8_t *ptr = str;
uint8_t c;

while ((c = *ptr)) {
if (c < 0x20) {
parse_control_character(c);
if (control) {
parse_control_character(c);
} // else, advance `ptr` to skip to next byte.
ptr++;
} else {
send_output(&ptr);
}
if (p_wd) {
UI_CALL(flush); // For testing/'writedelay' we flush each time.
assert(p_wd >= 0
&& (sizeof(long) <= sizeof(uint64_t) || p_wd <= UINT64_MAX));
os_microdelay((uint64_t)p_wd);
}
}
}

void ui_putc(uint8_t c)
void ui_putc(uint8_t c, bool control)
{
uint8_t buf[2] = {c, 0};
ui_puts(buf);
ui_puts(buf, control);
}

void ui_cursor_goto(int new_row, int new_col)
Expand Down Expand Up @@ -373,16 +381,24 @@ static void send_output(uint8_t **ptr)

static void parse_control_character(uint8_t c)
{
if (c == '\n') {
switch (c) {
case '\n':
ui_linefeed();
} else if (c == '\r') {
break;
case '\r':
ui_carriage_return();
} else if (c == '\b') {
break;
case '\b':
ui_cursor_left();
} else if (c == Ctrl_L) {
break;
case Ctrl_L:
ui_cursor_right();
} else if (c == Ctrl_G) {
break;
case Ctrl_G:
UI_CALL(bell);
break;
default:
break;
}
}

Expand Down