refactor: format tui.c with uncrustify (#15640)

This commit is contained in:
dundargoc 2021-09-14 10:36:08 +02:00 committed by GitHub
parent 5fd21b8d3e
commit 0771504488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 163 additions and 174 deletions

View File

@ -1,4 +1,4 @@
# Uncrustify-0.73.0-159-81b1bc77
# Uncrustify-0.73.0-162-ac9b0f48
#
# General options

View File

@ -4,47 +4,45 @@
// Terminal UI functions. Invoked (by ui_bridge.c) on the TUI thread.
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <limits.h>
#include <uv.h>
#include <unibilium.h>
#include <uv.h>
#if defined(HAVE_TERMIOS_H)
# include <termios.h>
#endif
#include "nvim/lib/kvec.h"
#include "nvim/ascii.h"
#include "nvim/vim.h"
#include "nvim/log.h"
#include "nvim/ui.h"
#include "nvim/highlight.h"
#include "nvim/map.h"
#include "nvim/main.h"
#include "nvim/memory.h"
#include "nvim/option.h"
#include "nvim/api/vim.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/event/loop.h"
#include "nvim/event/signal.h"
#include "nvim/highlight.h"
#include "nvim/lib/kvec.h"
#include "nvim/log.h"
#include "nvim/main.h"
#include "nvim/map.h"
#include "nvim/memory.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/signal.h"
#include "nvim/os/tty.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#ifdef WIN32
# include "nvim/os/os_win_console.h"
#endif
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/ui_bridge.h"
#include "nvim/ugrid.h"
#include "nvim/tui/input.h"
#include "nvim/tui/tui.h"
#include "nvim/tui/terminfo.h"
#include "nvim/cursor_shape.h"
#include "nvim/macros.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/tui/input.h"
#include "nvim/tui/terminfo.h"
#include "nvim/tui/tui.h"
#include "nvim/ugrid.h"
#include "nvim/ui_bridge.h"
// Space reserved in two output buffers to make the cursor normal or invisible
// when flushing. No existing terminal will require 32 bytes to do that.
@ -180,8 +178,7 @@ UI *tui_start(void)
return ui_bridge_attach(ui, tui_main, tui_scheduler);
}
static size_t unibi_pre_fmt_str(TUIData *data, unsigned int unibi_index,
char * buf, size_t len)
static size_t unibi_pre_fmt_str(TUIData *data, unsigned int unibi_index, char * buf, size_t len)
{
const char *str = unibi_get_str(data->ut, unibi_index);
if (!str) {
@ -802,8 +799,7 @@ safe_move:
ugrid_goto(grid, row, col);
}
static void clear_region(UI *ui, int top, int bot, int left, int right,
int attr_id)
static void clear_region(UI *ui, int top, int bot, int left, int right, int attr_id)
{
TUIData *data = ui->data;
UGrid *grid = &data->grid;
@ -1096,10 +1092,14 @@ static void tui_set_mode(UI *ui, ModeShape mode)
int shape;
switch (c.shape) {
default: abort(); break;
case SHAPE_BLOCK: shape = 1; break;
case SHAPE_HOR: shape = 3; break;
case SHAPE_VER: shape = 5; break;
default:
abort(); break;
case SHAPE_BLOCK:
shape = 1; break;
case SHAPE_HOR:
shape = 3; break;
case SHAPE_VER:
shape = 5; break;
}
UNIBI_SET_NUM_VAR(data->params[0], shape + (int)(c.blinkon == 0));
unibi_out_ext(ui, data->unibi_ext.set_cursor_style);
@ -1124,8 +1124,8 @@ static void tui_mode_change(UI *ui, String mode, Integer mode_idx)
}
static void tui_grid_scroll(UI *ui, Integer g, Integer startrow, // -V751
Integer endrow, Integer startcol, Integer endcol,
Integer rows, Integer cols FUNC_ATTR_UNUSED)
Integer endrow, Integer startcol, Integer endcol, Integer rows,
Integer cols FUNC_ATTR_UNUSED)
{
TUIData *data = ui->data;
UGrid *grid = &data->grid;
@ -1184,8 +1184,7 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer startrow, // -V751
}
}
static void tui_hl_attr_define(UI *ui, Integer id, HlAttrs attrs,
HlAttrs cterm_attrs, Array info)
static void tui_hl_attr_define(UI *ui, Integer id, HlAttrs attrs, HlAttrs cterm_attrs, Array info)
{
TUIData *data = ui->data;
kv_a(data->attrs, (size_t)id) = attrs;
@ -1201,8 +1200,7 @@ static void tui_visual_bell(UI *ui)
unibi_out(ui, unibi_flash_screen);
}
static void tui_default_colors_set(UI *ui, Integer rgb_fg, Integer rgb_bg,
Integer rgb_sp,
static void tui_default_colors_set(UI *ui, Integer rgb_fg, Integer rgb_bg, Integer rgb_sp,
Integer cterm_fg, Integer cterm_bg)
{
TUIData *data = ui->data;
@ -1379,9 +1377,8 @@ static void tui_option_set(UI *ui, String name, Object value)
}
}
static void tui_raw_line(UI *ui, Integer g, Integer linerow, Integer startcol,
Integer endcol, Integer clearcol, Integer clearattr,
LineFlags flags, const schar_T *chunk,
static void tui_raw_line(UI *ui, Integer g, Integer linerow, Integer startcol, Integer endcol,
Integer clearcol, Integer clearattr, LineFlags flags, const schar_T *chunk,
const sattr_T *attrs)
{
TUIData *data = ui->data;
@ -1561,8 +1558,7 @@ static void out(void *ctx, const char *str, size_t len)
data->bufpos += len;
}
static void unibi_set_if_empty(unibi_term *ut, enum unibi_string str,
const char *val)
static void unibi_set_if_empty(unibi_term *ut, enum unibi_string str, const char *val)
{
if (!unibi_get_str(ut, str)) {
unibi_set_str(ut, str, val);
@ -1596,9 +1592,8 @@ static int unibi_find_ext_bool(unibi_term *ut, const char *name)
/// Patches the terminfo records after loading from system or built-in db.
/// Several entries in terminfo are known to be deficient or outright wrong;
/// and several terminal emulators falsely announce incorrect terminal types.
static void patch_terminfo_bugs(TUIData *data, const char *term,
const char *colorterm, long vte_version,
long konsolev, bool iterm_env, bool nsterm)
static void patch_terminfo_bugs(TUIData *data, const char *term, const char *colorterm,
long vte_version, long konsolev, bool iterm_env, bool nsterm)
{
unibi_term *ut = data->ut;
const char *xterm_version = os_getenv("XTERM_VERSION");
@ -1875,7 +1870,8 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
// Konsole before version 18.07.70: set up a nonce profile. This has
// side-effects on temporary font resizing. #6798
data->unibi_ext.set_cursor_style = (int)unibi_add_ext_str(ut, "Ss",
TMUX_WRAP(tmux, "\x1b]50;CursorShape=%?"
TMUX_WRAP(tmux,
"\x1b]50;CursorShape=%?"
"%p1%{3}%<" "%t%{0}" // block
"%e%p1%{5}%<" "%t%{2}" // underline
"%e%{1}" // everything else is bar
@ -1895,9 +1891,8 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
/// This adds stuff that is not in standard terminfo as extended unibilium
/// capabilities.
static void augment_terminfo(TUIData *data, const char *term,
long vte_version,
long konsolev, bool iterm_env, bool nsterm)
static void augment_terminfo(TUIData *data, const char *term, long vte_version, long konsolev,
bool iterm_env, bool nsterm)
{
unibi_term *ut = data->ut;
bool xterm = terminfo_is_term_family(term, "xterm")
@ -1939,8 +1934,7 @@ static void augment_terminfo(TUIData *data, const char *term,
// terminfo describes strikethrough modes as rmxx/smxx with respect
// to the ECMA-48 strikeout/crossed-out attributes.
data->unibi_ext.enter_strikethrough_mode = (int)unibi_find_ext_str(
ut, "smxx");
data->unibi_ext.enter_strikethrough_mode = (int)unibi_find_ext_str(ut, "smxx");
// Dickey ncurses terminfo does not include the setrgbf and setrgbb
// capabilities, proposed by Rüdiger Sonderfeld on 2013-10-15. Adding
@ -1985,46 +1979,42 @@ static void augment_terminfo(TUIData *data, const char *term,
// FIXME: Bypassing tmux like this affects the cursor colour globally, in
// all panes, which is not particularly desirable. A better approach
// would use a tmux control sequence and an extra if(screen) test.
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
ut, NULL, TMUX_WRAP(tmux, "\033]Pl%p1%06x\033\\"));
data->unibi_ext.set_cursor_color =
(int)unibi_add_ext_str(ut, NULL, TMUX_WRAP(tmux, "\033]Pl%p1%06x\033\\"));
} else if ((xterm || rxvt || tmux || alacritty)
&& (vte_version == 0 || vte_version >= 3900)) {
// Supported in urxvt, newer VTE.
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
ut, "ext.set_cursor_color", "\033]12;#%p1%06x\007");
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(ut, "ext.set_cursor_color",
"\033]12;#%p1%06x\007");
}
if (-1 != data->unibi_ext.set_cursor_color) {
data->unibi_ext.reset_cursor_color = (int)unibi_add_ext_str(
ut, "ext.reset_cursor_color", "\x1b]112\x07");
data->unibi_ext.reset_cursor_color = (int)unibi_add_ext_str(ut, "ext.reset_cursor_color",
"\x1b]112\x07");
}
data->unibi_ext.save_title = (int)unibi_add_ext_str(
ut, "ext.save_title", "\x1b[22;0t");
data->unibi_ext.restore_title = (int)unibi_add_ext_str(
ut, "ext.restore_title", "\x1b[23;0t");
data->unibi_ext.save_title = (int)unibi_add_ext_str(ut, "ext.save_title", "\x1b[22;0t");
data->unibi_ext.restore_title = (int)unibi_add_ext_str(ut, "ext.restore_title", "\x1b[23;0t");
/// Terminals usually ignore unrecognized private modes, and there is no
/// known ambiguity with these. So we just set them unconditionally.
data->unibi_ext.enable_lr_margin = (int)unibi_add_ext_str(
ut, "ext.enable_lr_margin", "\x1b[?69h");
data->unibi_ext.disable_lr_margin = (int)unibi_add_ext_str(
ut, "ext.disable_lr_margin", "\x1b[?69l");
data->unibi_ext.enable_bracketed_paste = (int)unibi_add_ext_str(
ut, "ext.enable_bpaste", "\x1b[?2004h");
data->unibi_ext.disable_bracketed_paste = (int)unibi_add_ext_str(
ut, "ext.disable_bpaste", "\x1b[?2004l");
data->unibi_ext.enable_lr_margin =
(int)unibi_add_ext_str(ut, "ext.enable_lr_margin", "\x1b[?69h");
data->unibi_ext.disable_lr_margin = (int)unibi_add_ext_str(ut, "ext.disable_lr_margin",
"\x1b[?69l");
data->unibi_ext.enable_bracketed_paste = (int)unibi_add_ext_str(ut, "ext.enable_bpaste",
"\x1b[?2004h");
data->unibi_ext.disable_bracketed_paste = (int)unibi_add_ext_str(ut, "ext.disable_bpaste",
"\x1b[?2004l");
// For urxvt send BOTH xterm and old urxvt sequences. #8695
data->unibi_ext.enable_focus_reporting = (int)unibi_add_ext_str(
ut, "ext.enable_focus",
data->unibi_ext.enable_focus_reporting = (int)unibi_add_ext_str(ut, "ext.enable_focus",
rxvt ? "\x1b[?1004h\x1b]777;focus;on\x7" : "\x1b[?1004h");
data->unibi_ext.disable_focus_reporting = (int)unibi_add_ext_str(
ut, "ext.disable_focus",
data->unibi_ext.disable_focus_reporting = (int)unibi_add_ext_str(ut, "ext.disable_focus",
rxvt ? "\x1b[?1004l\x1b]777;focus;off\x7" : "\x1b[?1004l");
data->unibi_ext.enable_mouse = (int)unibi_add_ext_str(
ut, "ext.enable_mouse", "\x1b[?1002h\x1b[?1006h");
data->unibi_ext.disable_mouse = (int)unibi_add_ext_str(
ut, "ext.disable_mouse", "\x1b[?1002l\x1b[?1006l");
data->unibi_ext.enable_mouse = (int)unibi_add_ext_str(ut, "ext.enable_mouse",
"\x1b[?1002h\x1b[?1006h");
data->unibi_ext.disable_mouse = (int)unibi_add_ext_str(ut, "ext.disable_mouse",
"\x1b[?1002l\x1b[?1006l");
// Extended underline.
// terminfo will have Smulx for this (but no support for colors yet).
@ -2034,14 +2024,14 @@ static void augment_terminfo(TUIData *data, const char *term,
if (vte_version >= 5102
|| (ext_bool_Su != -1
&& unibi_get_ext_bool(ut, (size_t)ext_bool_Su))) {
data->unibi_ext.set_underline_style = (int)unibi_add_ext_str(
ut, "ext.set_underline_style", "\x1b[4:%p1%dm");
data->unibi_ext.set_underline_style = (int)unibi_add_ext_str(ut, "ext.set_underline_style",
"\x1b[4:%p1%dm");
}
}
if (data->unibi_ext.set_underline_style != -1) {
// Only support colon syntax. #9270
data->unibi_ext.set_underline_color = (int)unibi_add_ext_str(
ut, "ext.set_underline_color", "\x1b[58:2::%p1%d:%p2%d:%p3%dm");
data->unibi_ext.set_underline_color = (int)unibi_add_ext_str(ut, "ext.set_underline_color",
"\x1b[58:2::%p1%d:%p2%d:%p3%dm");
}
}
@ -2134,8 +2124,7 @@ static const char *tui_get_stty_erase(void)
/// libtermkey hook to override terminfo entries.
/// @see TermInput.tk_ti_hook_fn
static const char *tui_tk_ti_getstr(const char *name, const char *value,
void *data)
static const char *tui_tk_ti_getstr(const char *name, const char *value, void *data)
{
static const char *stty_erase = NULL;
if (stty_erase == NULL) {