ui: cleanup UI_CALL wrappers

remove pointless control chars in the text stream
This commit is contained in:
Björn Linse 2017-05-10 09:54:54 +02:00
parent c778311505
commit 7d6af9985c
10 changed files with 57 additions and 168 deletions

View File

@ -24,6 +24,7 @@
#include <inttypes.h>
#include "nvim/api/private/handle.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/vim.h"
@ -3001,13 +3002,13 @@ static bool ti_change(char_u *str, char_u **last)
return false;
}
/*
* Put current window title back (used after calling a shell)
*/
/// Set current window title
void resettitle(void)
{
ui_set_title((char *)lasttitle);
ui_set_icon((char *)lasticon);
ui_call_set_title(cstr_as_string((char *)lasttitle));
ui_call_set_icon(cstr_as_string((char *)lasticon));
ui_flush();
}
# if defined(EXITFREE)

View File

@ -6285,13 +6285,14 @@ static void ex_stop(exarg_T *eap)
autowrite_all();
}
ui_cursor_goto((int)Rows - 1, 0);
ui_putc('\n');
ui_linefeed();
ui_flush();
ui_call_suspend(); // call machine specific function
ui_flush();
ui_suspend(); /* call machine specific function */
maketitle();
resettitle(); /* force updating the title */
resettitle(); // force updating the title
redraw_later_clear();
ui_refresh(); /* may have resized window */
ui_refresh(); // may have resized window
}
}

View File

@ -1303,8 +1303,8 @@ static void handle_quickfix(mparm_T *paramp)
set_string_option_direct((char_u *)"ef", -1,
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');
if (qf_init(NULL, p_ef, p_efm, true, IObuff) < 0) {
ui_linefeed();
mch_exit(3);
}
TIME_MSG("reading errorfile");

View File

@ -247,7 +247,7 @@ ex_menu (
xfree(map_buf);
}
ui_update_menu();
ui_call_update_menu();
theend:
;

View File

@ -2536,9 +2536,9 @@ void vim_beep(unsigned val)
if (emsg_silent == 0) {
if (!((bo_flags & val) || (bo_flags & BO_ALL))) {
if (p_vb) {
ui_visual_bell();
ui_call_visual_bell();
} else {
ui_putc(BELL);
ui_call_bell();
}
}
@ -2691,7 +2691,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
if (p_verbose > 3) {
verbose_enter();
smsg(_("Calling shell to execute: \"%s\""), cmd == NULL ? p_sh : cmd);
ui_putc('\n');
ui_linefeed();
verbose_leave();
}

View File

@ -479,9 +479,9 @@ void setmouse(void)
checkfor = MOUSE_NORMAL; /* assume normal mode */
if (mouse_has(checkfor)) {
ui_mouse_on();
ui_call_mouse_on();
} else {
ui_mouse_off();
ui_call_mouse_off();
}
}

View File

@ -1952,15 +1952,7 @@ did_set_title (
{
if (starting != NO_SCREEN) {
maketitle();
if (icon) {
if (!p_icon) {
ui_set_icon(NULL);
}
} else {
if (!p_title) {
ui_set_title(NULL);
}
}
resettitle();
}
}
@ -3282,7 +3274,7 @@ did_set_string_option (
if (varp == &p_mouse) {
if (*p_mouse == NUL) {
ui_mouse_off();
ui_call_mouse_off();
} else {
setmouse(); // in case 'mouse' changed
}

View File

@ -5956,7 +5956,7 @@ void screen_fill(int start_row, int end_row, int start_col, int end_col, int c1,
col = off - LineOffset[row];
screen_stop_highlight();
ui_cursor_goto(row, col); // clear rest of this screen line
ui_eol_clear();
ui_call_eol_clear();
col = end_col - col;
while (col--) { /* clear chars in ScreenLines */
ScreenLines[off] = ' ';
@ -6345,10 +6345,10 @@ static void screenclear2(void)
LineWraps[i] = FALSE;
}
ui_clear(); // clear the display
clear_cmdline = FALSE;
mode_displayed = FALSE;
screen_cleared = TRUE; /* can use contents of ScreenLines now */
ui_call_clear(); // clear the display
clear_cmdline = false;
mode_displayed = false;
screen_cleared = true; // can use contents of ScreenLines now
win_rest_invalid(firstwin);
redraw_cmdline = TRUE;
@ -6647,7 +6647,7 @@ int screen_ins_lines (
}
}
ui_append_lines(line_count);
ui_call_scroll(-line_count);
return OK;
}
@ -6702,7 +6702,7 @@ int screen_del_lines (
}
}
ui_delete_lines(line_count);
ui_call_scroll(line_count);
return OK;
}

View File

@ -683,7 +683,7 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *data)
static int term_bell(void *data)
{
ui_putc('\x07');
ui_call_bell();
return 1;
}

View File

@ -132,24 +132,6 @@ bool ui_active(void)
return ui_count != 0;
}
void ui_suspend(void)
{
UI_CALL(suspend);
UI_CALL(flush);
}
void ui_set_title(char *title)
{
ui_call_set_title(cstr_as_string(title));
UI_CALL(flush);
}
void ui_set_icon(char *icon)
{
ui_call_set_icon(cstr_as_string(icon));
UI_CALL(flush);
}
void ui_event(char *name, Array args)
{
bool args_consumed = false;
@ -218,33 +200,23 @@ void ui_resize(int new_width, int new_height)
sr.bot = height - 1;
sr.left = 0;
sr.right = width - 1;
UI_CALL(resize, width, height);
ui_call_resize(width, height);
}
void ui_busy_start(void)
{
if (!(busy++)) {
UI_CALL(busy_start);
ui_call_busy_start();
}
}
void ui_busy_stop(void)
{
if (!(--busy)) {
UI_CALL(busy_stop);
ui_call_busy_stop();
}
}
void ui_mouse_on(void)
{
UI_CALL(mouse_on);
}
void ui_mouse_off(void)
{
UI_CALL(mouse_off);
}
void ui_attach_impl(UI *ui)
{
if (ui_count == MAX_UI_COUNT) {
@ -285,11 +257,6 @@ void ui_detach_impl(UI *ui)
}
}
void ui_clear(void)
{
UI_CALL(clear);
}
// Set scrolling region for window 'wp'.
// The region starts 'off' lines from the start of the window.
// Also set the vertical scroll region for a vertically split window. Always
@ -304,7 +271,7 @@ void ui_set_scroll_region(win_T *wp, int off)
sr.right = wp->w_wincol + wp->w_width - 1;
}
UI_CALL(set_scroll_region, sr.top, sr.bot, sr.left, sr.right);
ui_call_set_scroll_region(sr.top, sr.bot, sr.left, sr.right);
}
// Reset scrolling region to the whole screen.
@ -314,22 +281,7 @@ void ui_reset_scroll_region(void)
sr.bot = (int)Rows - 1;
sr.left = 0;
sr.right = (int)Columns - 1;
UI_CALL(set_scroll_region, sr.top, sr.bot, sr.left, sr.right);
}
void ui_append_lines(int count)
{
UI_CALL(scroll, -count);
}
void ui_delete_lines(int count)
{
UI_CALL(scroll, count);
}
void ui_eol_clear(void)
{
UI_CALL(eol_clear);
ui_call_set_scroll_region(sr.top, sr.bot, sr.left, sr.right);
}
void ui_start_highlight(int attr_code)
@ -354,23 +306,31 @@ void ui_stop_highlight(void)
set_highlight_args(current_attr_code);
}
void ui_visual_bell(void)
{
UI_CALL(visual_bell);
}
void ui_puts(uint8_t *str)
{
uint8_t *ptr = str;
uint8_t *p = str;
uint8_t c;
while ((c = *ptr)) {
while ((c = *p)) {
if (c < 0x20) {
parse_control_character(c);
ptr++;
} else {
send_output(&ptr);
abort();
}
size_t clen = (size_t)mb_ptr2len(p);
ui_call_put((String){ .data = (char *)p, .size = clen });
col++;
if (mb_ptr2cells(p) > 1) {
// double cell character, blank the next cell
ui_call_put((String)STRING_INIT);
col++;
}
if (utf_ambiguous_width(utf_ptr2char(p))) {
pending_cursor_update = true;
}
if (col >= width) {
ui_linefeed();
}
p += clen;
}
}
@ -398,11 +358,6 @@ void ui_mode_info_set(void)
api_free_array(style);
}
void ui_update_menu(void)
{
UI_CALL(update_menu);
}
int ui_current_row(void)
{
return row;
@ -415,47 +370,7 @@ int ui_current_col(void)
void ui_flush(void)
{
UI_CALL(flush);
}
static void send_output(uint8_t **ptr)
{
uint8_t *p = *ptr;
while (*p >= 0x20) {
size_t clen = (size_t)mb_ptr2len(p);
ui_call_put((String){.data = (char *)p, .size = clen});
col++;
if (mb_ptr2cells(p) > 1) {
// double cell character, blank the next cell
ui_call_put((String)STRING_INIT);
col++;
}
if (utf_ambiguous_width(utf_ptr2char(p))) {
pending_cursor_update = true;
}
if (col >= width) {
ui_linefeed();
}
p += clen;
}
*ptr = p;
}
static void parse_control_character(uint8_t c)
{
if (c == '\n') {
ui_linefeed();
} else if (c == '\r') {
ui_carriage_return();
} else if (c == '\b') {
ui_cursor_left();
} else if (c == Ctrl_L) {
ui_cursor_right();
} else if (c == Ctrl_G) {
UI_CALL(bell);
}
ui_call_flush();
}
static void set_highlight_args(int attr_code)
@ -513,43 +428,23 @@ end:
UI_CALL(highlight_set, (ui->rgb ? rgb_attrs : cterm_attrs));
}
static void ui_linefeed(void)
void ui_linefeed(void)
{
int new_col = 0;
int new_row = row;
if (new_row < sr.bot) {
new_row++;
} else {
UI_CALL(scroll, 1);
ui_call_scroll(1);
}
ui_cursor_goto(new_row, new_col);
}
static void ui_carriage_return(void)
{
int new_col = 0;
ui_cursor_goto(row, new_col);
}
static void ui_cursor_left(void)
{
int new_col = col - 1;
assert(new_col >= 0);
ui_cursor_goto(row, new_col);
}
static void ui_cursor_right(void)
{
int new_col = col + 1;
assert(new_col < width);
ui_cursor_goto(row, new_col);
}
static void flush_cursor_update(void)
{
if (pending_cursor_update) {
pending_cursor_update = false;
UI_CALL(cursor_goto, row, col);
ui_call_cursor_goto(row, col);
}
}