mirror of
https://github.com/neovim/neovim.git
synced 2025-09-10 21:38:19 +00:00
'guicursor': enabled=false if 'guicursor' is empty
Closes #6429 Closes #6430
This commit is contained in:
@@ -300,11 +300,11 @@ static void remote_ui_scroll(UI *ui, int count)
|
|||||||
push_call(ui, "scroll", args);
|
push_call(ui, "scroll", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remote_ui_cursor_style_set(UI *ui, Dictionary styles)
|
static void remote_ui_cursor_style_set(UI *ui, bool enabled, Dictionary data)
|
||||||
{
|
{
|
||||||
Array args = ARRAY_DICT_INIT;
|
Array args = ARRAY_DICT_INIT;
|
||||||
Object copy = copy_object(DICTIONARY_OBJ(styles));
|
ADD(args, BOOLEAN_OBJ(enabled));
|
||||||
ADD(args, copy);
|
ADD(args, copy_object(DICTIONARY_OBJ(data)));
|
||||||
push_call(ui, "cursor_style_set", args);
|
push_call(ui, "cursor_style_set", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,10 +89,8 @@ char_u *parse_shape_opt(int what)
|
|||||||
int found_ve = false; /* found "ve" flag */
|
int found_ve = false; /* found "ve" flag */
|
||||||
int round;
|
int round;
|
||||||
|
|
||||||
/*
|
// First round: check for errors; second round: do it for real.
|
||||||
* First round: check for errors; second round: do it for real.
|
for (round = 1; round <= 2; round++) {
|
||||||
*/
|
|
||||||
for (round = 1; round <= 2; ++round) {
|
|
||||||
// Repeat for all comma separated parts.
|
// Repeat for all comma separated parts.
|
||||||
modep = p_guicursor;
|
modep = p_guicursor;
|
||||||
if (*p_guicursor == NUL) {
|
if (*p_guicursor == NUL) {
|
||||||
|
@@ -84,6 +84,7 @@ typedef struct {
|
|||||||
} TUIData;
|
} TUIData;
|
||||||
|
|
||||||
static bool volatile got_winch = false;
|
static bool volatile got_winch = false;
|
||||||
|
static bool cursor_style_enabled = false;
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "tui/tui.c.generated.h"
|
# include "tui/tui.c.generated.h"
|
||||||
@@ -151,6 +152,7 @@ static void terminfo_start(UI *ui)
|
|||||||
// Set 't_Co' from the result of unibilium & fix_terminfo.
|
// Set 't_Co' from the result of unibilium & fix_terminfo.
|
||||||
t_colors = unibi_get_num(data->ut, unibi_max_colors);
|
t_colors = unibi_get_num(data->ut, unibi_max_colors);
|
||||||
// Enter alternate screen and clear
|
// Enter alternate screen and clear
|
||||||
|
// NOTE: Do this *before* changing terminal settings. #6433
|
||||||
unibi_out(ui, unibi_enter_ca_mode);
|
unibi_out(ui, unibi_enter_ca_mode);
|
||||||
unibi_out(ui, unibi_clear_screen);
|
unibi_out(ui, unibi_clear_screen);
|
||||||
// Enable bracketed paste
|
// Enable bracketed paste
|
||||||
@@ -437,11 +439,11 @@ static void tui_cursor_goto(UI *ui, int row, int col)
|
|||||||
CursorShape tui_cursor_decode_shape(const char *shape_str)
|
CursorShape tui_cursor_decode_shape(const char *shape_str)
|
||||||
{
|
{
|
||||||
CursorShape shape = 0;
|
CursorShape shape = 0;
|
||||||
if (strcmp(shape_str, "block") == 0) {
|
if (strequal(shape_str, "block")) {
|
||||||
shape = SHAPE_BLOCK;
|
shape = SHAPE_BLOCK;
|
||||||
} else if (strcmp(shape_str, "vertical") == 0) {
|
} else if (strequal(shape_str, "vertical")) {
|
||||||
shape = SHAPE_VER;
|
shape = SHAPE_VER;
|
||||||
} else if (strcmp(shape_str, "horizontal") == 0) {
|
} else if (strequal(shape_str, "horizontal")) {
|
||||||
shape = SHAPE_HOR;
|
shape = SHAPE_HOR;
|
||||||
} else {
|
} else {
|
||||||
EMSG2(_(e_invarg2), shape_str);
|
EMSG2(_(e_invarg2), shape_str);
|
||||||
@@ -454,40 +456,41 @@ static cursorentry_T decode_cursor_entry(Dictionary args)
|
|||||||
cursorentry_T r;
|
cursorentry_T r;
|
||||||
|
|
||||||
for (size_t i = 0; i < args.size; i++) {
|
for (size_t i = 0; i < args.size; i++) {
|
||||||
char *keyStr = args.items[i].key.data;
|
char *key = args.items[i].key.data;
|
||||||
Object value = args.items[i].value;
|
Object value = args.items[i].value;
|
||||||
|
|
||||||
if (strcmp(keyStr, "cursor_shape") == 0) {
|
if (strequal(key, "cursor_shape")) {
|
||||||
r.shape = tui_cursor_decode_shape(args.items[i].value.data.string.data);
|
r.shape = tui_cursor_decode_shape(args.items[i].value.data.string.data);
|
||||||
} else if (strcmp(keyStr, "blinkon") == 0) {
|
} else if (strequal(key, "blinkon")) {
|
||||||
r.blinkon = (int)value.data.integer;
|
r.blinkon = (int)value.data.integer;
|
||||||
} else if (strcmp(keyStr, "blinkoff") == 0) {
|
} else if (strequal(key, "blinkoff")) {
|
||||||
r.blinkoff = (int)value.data.integer;
|
r.blinkoff = (int)value.data.integer;
|
||||||
} else if (strcmp(keyStr, "hl_id") == 0) {
|
} else if (strequal(key, "hl_id")) {
|
||||||
r.id = (int)value.data.integer;
|
r.id = (int)value.data.integer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tui_cursor_style_set(UI *ui, Dictionary args)
|
static void tui_cursor_style_set(UI *ui, bool enabled, Dictionary args)
|
||||||
{
|
{
|
||||||
|
cursor_style_enabled = enabled;
|
||||||
|
if (!enabled) {
|
||||||
|
return; // Do not send cursor style control codes.
|
||||||
|
}
|
||||||
TUIData *data = ui->data;
|
TUIData *data = ui->data;
|
||||||
|
|
||||||
|
assert(args.size);
|
||||||
|
// Keys: as defined by `shape_table`.
|
||||||
for (size_t i = 0; i < args.size; i++) {
|
for (size_t i = 0; i < args.size; i++) {
|
||||||
char *mode_name = args.items[i].key.data;
|
char *mode_name = args.items[i].key.data;
|
||||||
const int mode_id = cursor_mode_str2int(mode_name);
|
const int mode_id = cursor_mode_str2int(mode_name);
|
||||||
|
assert(mode_id >= 0);
|
||||||
if (mode_id < 0) {
|
|
||||||
WLOG("Unknown mode '%s'", mode_name);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
cursorentry_T r = decode_cursor_entry(args.items[i].value.data.dictionary);
|
cursorentry_T r = decode_cursor_entry(args.items[i].value.data.dictionary);
|
||||||
r.full_name = mode_name;
|
r.full_name = mode_name;
|
||||||
data->cursor_shapes[mode_id] = r;
|
data->cursor_shapes[mode_id] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// force redraw
|
|
||||||
MouseMode cursor_mode = tui_mode2cursor(data->showing_mode);
|
MouseMode cursor_mode = tui_mode2cursor(data->showing_mode);
|
||||||
tui_set_cursor(ui, cursor_mode);
|
tui_set_cursor(ui, cursor_mode);
|
||||||
}
|
}
|
||||||
@@ -528,6 +531,9 @@ static void tui_mouse_off(UI *ui)
|
|||||||
/// @param mode one of SHAPE_XXX
|
/// @param mode one of SHAPE_XXX
|
||||||
static void tui_set_cursor(UI *ui, MouseMode mode)
|
static void tui_set_cursor(UI *ui, MouseMode mode)
|
||||||
{
|
{
|
||||||
|
if (!cursor_style_enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
TUIData *data = ui->data;
|
TUIData *data = ui->data;
|
||||||
cursorentry_T c = data->cursor_shapes[mode];
|
cursorentry_T c = data->cursor_shapes[mode];
|
||||||
int shape = c.shape;
|
int shape = c.shape;
|
||||||
@@ -536,17 +542,15 @@ static void tui_set_cursor(UI *ui, MouseMode mode)
|
|||||||
|
|
||||||
# define TMUX_WRAP(seq) (inside_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
|
# define TMUX_WRAP(seq) (inside_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
|
||||||
// Support changing cursor shape on some popular terminals.
|
// Support changing cursor shape on some popular terminals.
|
||||||
const char *term_prog = os_getenv("TERM_PROGRAM");
|
|
||||||
const char *vte_version = os_getenv("VTE_VERSION");
|
const char *vte_version = os_getenv("VTE_VERSION");
|
||||||
|
|
||||||
if ((term_prog && !strcmp(term_prog, "Konsole"))
|
if (os_getenv("KONSOLE_PROFILE_NAME") || os_getenv("KONSOLE_DBUS_SESSION")) {
|
||||||
|| os_getenv("KONSOLE_DBUS_SESSION") != NULL) {
|
|
||||||
// Konsole uses a proprietary escape code to set the cursor shape
|
// Konsole uses a proprietary escape code to set the cursor shape
|
||||||
// and does not support DECSCUSR.
|
// and does not support DECSCUSR.
|
||||||
switch (shape) {
|
switch (shape) {
|
||||||
case SHAPE_BLOCK: shape = 0; break;
|
case SHAPE_BLOCK: shape = 0; break;
|
||||||
case SHAPE_VER: shape = 1; break;
|
case SHAPE_VER: shape = 1; break;
|
||||||
case SHAPE_HOR: shape = 3; break;
|
case SHAPE_HOR: shape = 2; break;
|
||||||
default: WLOG("Unknown shape value %d", shape); break;
|
default: WLOG("Unknown shape value %d", shape); break;
|
||||||
}
|
}
|
||||||
data->params[0].i = shape;
|
data->params[0].i = shape;
|
||||||
@@ -1102,15 +1106,15 @@ static const char *tui_tk_ti_getstr(const char *name, const char *value,
|
|||||||
stty_erase = tui_get_stty_erase();
|
stty_erase = tui_get_stty_erase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(name, "key_backspace") == 0) {
|
if (strequal(name, "key_backspace")) {
|
||||||
ILOG("libtermkey:kbs=%s", value);
|
ILOG("libtermkey:kbs=%s", value);
|
||||||
if (stty_erase != NULL && stty_erase[0] != 0) {
|
if (stty_erase != NULL && stty_erase[0] != 0) {
|
||||||
return stty_erase;
|
return stty_erase;
|
||||||
}
|
}
|
||||||
} else if (strcmp(name, "key_dc") == 0) {
|
} else if (strequal(name, "key_dc")) {
|
||||||
ILOG("libtermkey:kdch1=%s", value);
|
ILOG("libtermkey:kdch1=%s", value);
|
||||||
// Vim: "If <BS> and <DEL> are now the same, redefine <DEL>."
|
// Vim: "If <BS> and <DEL> are now the same, redefine <DEL>."
|
||||||
if (stty_erase != NULL && value != NULL && strcmp(stty_erase, value) == 0) {
|
if (stty_erase != NULL && value != NULL && strequal(stty_erase, value)) {
|
||||||
return stty_erase[0] == DEL ? CTRL_H_STR : DEL_STR;
|
return stty_erase[0] == DEL ? CTRL_H_STR : DEL_STR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -381,7 +381,8 @@ void ui_cursor_goto(int new_row, int new_col)
|
|||||||
void ui_cursor_style_set(void)
|
void ui_cursor_style_set(void)
|
||||||
{
|
{
|
||||||
Dictionary style = cursor_shape_dict();
|
Dictionary style = cursor_shape_dict();
|
||||||
UI_CALL(cursor_style_set, style);
|
bool enabled = (*p_guicursor != NUL);
|
||||||
|
UI_CALL(cursor_style_set, enabled, style);
|
||||||
api_free_dictionary(style);
|
api_free_dictionary(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ struct ui_t {
|
|||||||
void (*clear)(UI *ui);
|
void (*clear)(UI *ui);
|
||||||
void (*eol_clear)(UI *ui);
|
void (*eol_clear)(UI *ui);
|
||||||
void (*cursor_goto)(UI *ui, int row, int col);
|
void (*cursor_goto)(UI *ui, int row, int col);
|
||||||
void (*cursor_style_set)(UI *ui, Dictionary cursor_shapes);
|
void (*cursor_style_set)(UI *ui, bool enabled, Dictionary cursor_styles);
|
||||||
void (*update_menu)(UI *ui);
|
void (*update_menu)(UI *ui);
|
||||||
void (*busy_start)(UI *ui);
|
void (*busy_start)(UI *ui);
|
||||||
void (*busy_stop)(UI *ui);
|
void (*busy_stop)(UI *ui);
|
||||||
|
@@ -60,7 +60,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
|
|||||||
rv->bridge.clear = ui_bridge_clear;
|
rv->bridge.clear = ui_bridge_clear;
|
||||||
rv->bridge.eol_clear = ui_bridge_eol_clear;
|
rv->bridge.eol_clear = ui_bridge_eol_clear;
|
||||||
rv->bridge.cursor_goto = ui_bridge_cursor_goto;
|
rv->bridge.cursor_goto = ui_bridge_cursor_goto;
|
||||||
rv->bridge.cursor_style_set = ui_bridge_cursor_styleset;
|
rv->bridge.cursor_style_set = ui_bridge_cursor_style_set;
|
||||||
rv->bridge.update_menu = ui_bridge_update_menu;
|
rv->bridge.update_menu = ui_bridge_update_menu;
|
||||||
rv->bridge.busy_start = ui_bridge_busy_start;
|
rv->bridge.busy_start = ui_bridge_busy_start;
|
||||||
rv->bridge.busy_stop = ui_bridge_busy_stop;
|
rv->bridge.busy_stop = ui_bridge_busy_stop;
|
||||||
@@ -180,19 +180,21 @@ static void ui_bridge_cursor_goto_event(void **argv)
|
|||||||
ui->cursor_goto(ui, PTR2INT(argv[1]), PTR2INT(argv[2]));
|
ui->cursor_goto(ui, PTR2INT(argv[1]), PTR2INT(argv[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ui_bridge_cursor_styleset(UI *b, Dictionary style)
|
static void ui_bridge_cursor_style_set(UI *b, bool enabled, Dictionary styles)
|
||||||
{
|
{
|
||||||
Object copy = copy_object(DICTIONARY_OBJ(style));
|
bool *enabledp = xmalloc(sizeof(*enabledp));
|
||||||
Object *pobj = xmalloc(sizeof(copy));
|
Object *stylesp = xmalloc(sizeof(*stylesp));
|
||||||
*pobj = copy;
|
*enabledp = enabled;
|
||||||
UI_CALL(b, cursor_styleset, 2, b, pobj);
|
*stylesp = copy_object(DICTIONARY_OBJ(styles));
|
||||||
|
UI_CALL(b, cursor_style_set, 3, b, enabledp, stylesp);
|
||||||
}
|
}
|
||||||
static void ui_bridge_cursor_styleset_event(void **argv)
|
static void ui_bridge_cursor_style_set_event(void **argv)
|
||||||
{
|
{
|
||||||
UI *ui = UI(argv[0]);
|
UI *ui = UI(argv[0]);
|
||||||
Object *styles = (Object *)argv[1];
|
bool *enabled = argv[1];
|
||||||
|
Object *styles = argv[2];
|
||||||
ui->cursor_style_set(ui, styles->data.dictionary);
|
ui->cursor_style_set(ui, *enabled, styles->data.dictionary);
|
||||||
|
xfree(enabled);
|
||||||
api_free_object(*styles);
|
api_free_object(*styles);
|
||||||
xfree(styles);
|
xfree(styles);
|
||||||
}
|
}
|
||||||
|
@@ -144,6 +144,7 @@ describe('ui/cursor', function()
|
|||||||
}
|
}
|
||||||
-- Default 'guicursor' published on startup.
|
-- Default 'guicursor' published on startup.
|
||||||
eq(expected_cursor_style, screen._cursor_style)
|
eq(expected_cursor_style, screen._cursor_style)
|
||||||
|
eq(true, screen._cursor_style_enabled)
|
||||||
eq('normal', screen.mode)
|
eq('normal', screen.mode)
|
||||||
|
|
||||||
-- Event is published ONLY if the cursor style changed.
|
-- Event is published ONLY if the cursor style changed.
|
||||||
|
@@ -345,7 +345,8 @@ function Screen:_handle_resize(width, height)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Screen:_handle_cursor_style_set(style)
|
function Screen:_handle_cursor_style_set(enabled, style)
|
||||||
|
self._cursor_style_enabled = enabled
|
||||||
self._cursor_style = style
|
self._cursor_style = style
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user