'guicursor': Disable by default for unknown terminals.

User can still set guicursor explicitly in init.vim.

Closes #5990
Closes #6403
This commit is contained in:
Justin M. Keyes
2017-04-04 02:37:43 +02:00
parent 3ccd59ee82
commit e348e256f3
5 changed files with 33 additions and 14 deletions

View File

@@ -2796,7 +2796,7 @@ A jump table for the options with a short description can be found at |Q_op|.
-blinkwait175-blinkoff150-blinkon175") -blinkwait175-blinkoff150-blinkon175")
global global
Configures the cursor style for each mode. Works in the GUI and some Configures the cursor style for each mode. Works in the GUI and some
terminals. Empty means "non-blinking block cursor in all modes": > terminals. Unset to disable: >
:set guicursor= :set guicursor=
< <
With tmux you might need this in ~/.tmux.conf (see terminal-overrides With tmux you might need this in ~/.tmux.conf (see terminal-overrides

View File

@@ -283,7 +283,7 @@ int main(int argc, char **argv)
cmdline_row = (int)(Rows - p_ch); cmdline_row = (int)(Rows - p_ch);
msg_row = cmdline_row; msg_row = cmdline_row;
screenalloc(false); /* allocate screen buffers */ screenalloc(false); /* allocate screen buffers */
set_init_2(); set_init_2(params.headless);
TIME_MSG("inits 2"); TIME_MSG("inits 2");
msg_scroll = TRUE; msg_scroll = TRUE;

View File

@@ -939,11 +939,8 @@ void free_all_options(void)
#endif #endif
/* /// Initialize the options, part two: After getting Rows and Columns.
* Initialize the options, part two: After getting Rows and Columns and void set_init_2(bool headless)
* setting 'term'.
*/
void set_init_2(void)
{ {
int idx; int idx;
@@ -966,8 +963,12 @@ void set_init_2(void)
p_window = Rows - 1; p_window = Rows - 1;
} }
set_number_default("window", Rows - 1); set_number_default("window", Rows - 1);
parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */ if (!headless && !os_term_is_nice()) {
(void)parse_printoptions(); /* parse 'printoptions' default value */ set_string_option_direct((char_u *)"guicursor", -1, (char_u *)"",
OPT_GLOBAL, SID_NONE);
}
parse_shape_opt(SHAPE_CURSOR); // set cursor shapes from 'guicursor'
(void)parse_printoptions(); // parse 'printoptions' default value
} }
/* /*
@@ -2842,9 +2843,10 @@ did_set_string_option (
} }
} }
/* 'guicursor' */ // 'guicursor'
else if (varp == &p_guicursor) else if (varp == &p_guicursor) {
errmsg = parse_shape_opt(SHAPE_CURSOR); errmsg = parse_shape_opt(SHAPE_CURSOR);
}
else if (varp == &p_popt) else if (varp == &p_popt)
errmsg = parse_printoptions(); errmsg = parse_printoptions();

View File

@@ -889,3 +889,17 @@ bool os_setenv_append_path(const char *fname)
} }
return false; return false;
} }
/// Returns true if the terminal can be assumed to silently ignore unknown
/// control codes.
bool os_term_is_nice(void)
{
#if defined(__APPLE__) || defined(WIN32)
return true;
#else
const char *vte_version = os_getenv("VTE_VERSION");
return (vte_version && atoi(vte_version) >= 3900)
|| NULL != os_getenv("KONSOLE_PROFILE_NAME")
|| NULL != os_getenv("KONSOLE_DBUS_SESSION");
#endif
}

View File

@@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear, meths = helpers.clear, helpers.meths local clear, meths = helpers.clear, helpers.meths
local eq = helpers.eq local eq = helpers.eq
local command = helpers.command local command = helpers.command
local wait = helpers.wait
describe('ui/cursor', function() describe('ui/cursor', function()
local screen local screen
@@ -18,7 +19,7 @@ describe('ui/cursor', function()
end) end)
it("'guicursor' is published as a UI event", function() it("'guicursor' is published as a UI event", function()
command('redraw') wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
local expected_cursor_style = { local expected_cursor_style = {
cmdline_hover = { cmdline_hover = {
@@ -149,13 +150,13 @@ describe('ui/cursor', function()
-- Event is published ONLY if the cursor style changed. -- Event is published ONLY if the cursor style changed.
screen._cursor_style = nil screen._cursor_style = nil
command('redraw') wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
eq(nil, screen._cursor_style) eq(nil, screen._cursor_style)
-- Change the cursor style. -- Change the cursor style.
meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42')
command('redraw') wait()
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
eq('vertical', screen._cursor_style.normal.cursor_shape) eq('vertical', screen._cursor_style.normal.cursor_shape)
eq('horizontal', screen._cursor_style.visual_select.cursor_shape) eq('horizontal', screen._cursor_style.visual_select.cursor_shape)
@@ -171,6 +172,8 @@ describe('ui/cursor', function()
meths.set_option('guicursor', '') meths.set_option('guicursor', '')
command('redraw') command('redraw')
screen:expect('', nil, nil, nil, true) -- Tickle the event-loop. screen:expect('', nil, nil, nil, true) -- Tickle the event-loop.
-- Empty 'guicursor' sets enabled=false.
eq(false, screen._cursor_style_enabled)
for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert', for _, m in ipairs({ 'cmdline_insert', 'cmdline_normal', 'cmdline_replace', 'insert',
'showmatch', 'normal', 'replace', 'visual', 'showmatch', 'normal', 'replace', 'visual',
'visual_select', }) do 'visual_select', }) do