mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
Merge pull request #12531 from BK1603/autoread-tui
Autoread now works in TUI too. The checktimestamp test is run at most once every 2 seconds not to poll too much and also because it doesn't make sense on some filesystems. A solution based on filesystem notifications should arrive soon.
This commit is contained in:
commit
bd5f0e9695
@ -129,6 +129,25 @@ function! s:check_performance() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:get_tmux_option(option) abort
|
||||
let cmd = 'tmux show-option -qvg '.a:option " try global scope
|
||||
let out = system(cmd)
|
||||
let val = substitute(out, '\v(\s|\r|\n)', '', 'g')
|
||||
if v:shell_error
|
||||
call health#report_error('command failed: '.cmd."\n".out)
|
||||
return 'error'
|
||||
elseif empty(val)
|
||||
let cmd = 'tmux show-option -qvgs '.a:option " try session scope
|
||||
let out = system(cmd)
|
||||
let val = substitute(out, '\v(\s|\r|\n)', '', 'g')
|
||||
if v:shell_error
|
||||
call health#report_error('command failed: '.cmd."\n".out)
|
||||
return 'error'
|
||||
endif
|
||||
endif
|
||||
return val
|
||||
endfunction
|
||||
|
||||
function! s:check_tmux() abort
|
||||
if empty($TMUX) || !executable('tmux')
|
||||
return
|
||||
@ -136,20 +155,31 @@ function! s:check_tmux() abort
|
||||
call health#report_start('tmux')
|
||||
|
||||
" check escape-time
|
||||
let suggestions = ["Set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10",
|
||||
let suggestions = ["set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10",
|
||||
\ s:suggest_faq]
|
||||
let cmd = 'tmux show-option -qvgs escape-time'
|
||||
let out = system(cmd)
|
||||
let tmux_esc_time = substitute(out, '\v(\s|\r|\n)', '', 'g')
|
||||
if v:shell_error
|
||||
call health#report_error('command failed: '.cmd."\n".out)
|
||||
elseif empty(tmux_esc_time)
|
||||
call health#report_error('escape-time is not set', suggestions)
|
||||
elseif tmux_esc_time > 300
|
||||
call health#report_error(
|
||||
\ 'escape-time ('.tmux_esc_time.') is higher than 300ms', suggestions)
|
||||
else
|
||||
call health#report_ok('escape-time: '.tmux_esc_time.'ms')
|
||||
let tmux_esc_time = s:get_tmux_option('escape-time')
|
||||
if tmux_esc_time !=# 'error'
|
||||
if empty(tmux_esc_time)
|
||||
call health#report_error('`escape-time` is not set', suggestions)
|
||||
elseif tmux_esc_time > 300
|
||||
call health#report_error(
|
||||
\ '`escape-time` ('.tmux_esc_time.') is higher than 300ms', suggestions)
|
||||
else
|
||||
call health#report_ok('escape-time: '.tmux_esc_time)
|
||||
endif
|
||||
endif
|
||||
|
||||
" check focus-events
|
||||
let suggestions = ["(tmux 1.9+ only) Set `focus-events` in ~/.tmux.conf:\nset-option -g focus-events on"]
|
||||
let tmux_focus_events = s:get_tmux_option('focus-events')
|
||||
call health#report_info('Checking stuff')
|
||||
if tmux_focus_events !=# 'error'
|
||||
if empty(tmux_focus_events) || tmux_focus_events !=# 'on'
|
||||
call health#report_warn(
|
||||
\ "`focus-events` is not enabled. |'autoread'| may not work.", suggestions)
|
||||
else
|
||||
call health#report_ok('focus-events: '.tmux_focus_events)
|
||||
endif
|
||||
endif
|
||||
|
||||
" check default-terminal and $TERM
|
||||
@ -203,9 +233,9 @@ function! s:check_terminal() abort
|
||||
call health#report_error('command failed: '.cmd."\n".out)
|
||||
else
|
||||
call health#report_info('key_backspace (kbs) terminfo entry: '
|
||||
\ .(empty(kbs_entry) ? '? (not found)' : kbs_entry))
|
||||
\ .(empty(kbs_entry) ? '? (not found)' : kbs_entry))
|
||||
call health#report_info('key_dc (kdch1) terminfo entry: '
|
||||
\ .(empty(kbs_entry) ? '? (not found)' : kdch1_entry))
|
||||
\ .(empty(kbs_entry) ? '? (not found)' : kdch1_entry))
|
||||
endif
|
||||
for env_var in ['XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY']
|
||||
if exists('$'.env_var)
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/aucmd.h"
|
||||
#include "nvim/eval.h"
|
||||
#include "nvim/ex_getln.h"
|
||||
#include "nvim/buffer.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "aucmd.c.generated.h"
|
||||
@ -50,12 +52,47 @@ void aucmd_schedule_focusgained(bool gained)
|
||||
static void do_autocmd_focusgained(bool gained)
|
||||
{
|
||||
static bool recursive = false;
|
||||
static Timestamp last_time = (time_t)0;
|
||||
bool need_redraw = false;
|
||||
|
||||
if (recursive) {
|
||||
return; // disallow recursion
|
||||
}
|
||||
recursive = true;
|
||||
apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
|
||||
NULL, NULL, false, curbuf);
|
||||
need_redraw |= apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
|
||||
NULL, NULL, false, curbuf);
|
||||
|
||||
// When activated: Check if any file was modified outside of Vim.
|
||||
// Only do this when not done within the last two seconds as:
|
||||
// 1. Some filesystems have modification time granularity in seconds. Fat32
|
||||
// has a granularity of 2 seconds.
|
||||
// 2. We could get multiple notifications in a row.
|
||||
if (gained && last_time + (Timestamp)2000 < os_now()) {
|
||||
need_redraw = check_timestamps(true);
|
||||
last_time = os_now();
|
||||
}
|
||||
|
||||
if (need_redraw) {
|
||||
// Something was executed, make sure the cursor is put back where it
|
||||
// belongs.
|
||||
need_wait_return = false;
|
||||
|
||||
if (State & CMDLINE) {
|
||||
redrawcmdline();
|
||||
} else if ((State & NORMAL) || (State & INSERT)) {
|
||||
if (must_redraw != 0) {
|
||||
update_screen(0);
|
||||
}
|
||||
|
||||
setcursor();
|
||||
}
|
||||
|
||||
ui_flush();
|
||||
}
|
||||
|
||||
if (need_maketitle) {
|
||||
maketitle();
|
||||
}
|
||||
|
||||
recursive = false;
|
||||
}
|
||||
|
58
test/functional/autoread/focus_spec.lua
Normal file
58
test/functional/autoread/focus_spec.lua
Normal file
@ -0,0 +1,58 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local thelpers = require('test.functional.terminal.helpers')
|
||||
local lfs = require('lfs')
|
||||
local clear = helpers.clear
|
||||
local nvim_prog = helpers.nvim_prog
|
||||
local feed_command = helpers.feed_command
|
||||
local feed_data = thelpers.feed_data
|
||||
|
||||
if helpers.pending_win32(pending) then return end
|
||||
|
||||
describe('autoread TUI FocusGained/FocusLost', function()
|
||||
local screen
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
screen = thelpers.screen_setup(0, '["'..nvim_prog
|
||||
..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler"]')
|
||||
end)
|
||||
|
||||
it('external file change', function()
|
||||
local path = 'xtest-foo'
|
||||
local expected_addition = [[
|
||||
line 1
|
||||
line 2
|
||||
line 3
|
||||
line 4
|
||||
]]
|
||||
|
||||
helpers.write_file(path, '')
|
||||
lfs.touch(path, os.time() - 10)
|
||||
feed_command('edit '..path)
|
||||
feed_data('\027[O')
|
||||
|
||||
screen:expect{grid=[[
|
||||
{1: } |
|
||||
{4:~ }|
|
||||
{4:~ }|
|
||||
{4:~ }|
|
||||
{5:xtest-foo }|
|
||||
:edit xtest-foo |
|
||||
{3:-- TERMINAL --} |
|
||||
]]}
|
||||
|
||||
helpers.write_file(path, expected_addition)
|
||||
|
||||
feed_data('\027[I')
|
||||
|
||||
screen:expect{grid=[[
|
||||
{1:l}ine 1 |
|
||||
line 2 |
|
||||
line 3 |
|
||||
line 4 |
|
||||
{5:xtest-foo }|
|
||||
"xtest-foo" 4L, 28C |
|
||||
{3:-- TERMINAL --} |
|
||||
]]}
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue
Block a user