Merge #41114 from epithet/default-ruler-as-expression

This commit is contained in:
Justin M. Keyes
2026-08-04 06:51:34 -04:00
committed by GitHub
25 changed files with 347 additions and 342 deletions

View File

@@ -561,14 +561,14 @@ describe('API/win', function()
api.nvim_set_option_value('statusline', 'window-status', { win = 0 })
eq('window-status', api.nvim_get_option_value('statusline', { win = 0 }))
eq(
"%<%f %{%nvim_eval_statusline('%h%w%m%r', {'maxwidth': 30}).width > 0 ? '%h%w%m%r ' : ''%}%=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
"%<%f %{%nvim_eval_statusline('%h%w%m%r', {'maxwidth': 30}).width > 0 ? '%h%w%m%r ' : ''%}%=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &ruler ? &rulerformat : '' %}",
api.nvim_get_option_value('statusline', { scope = 'global' })
)
command('set modified')
command('enew') -- global-local: not preserved in new buffer
-- confirm local value was not copied
eq(
"%<%f %{%nvim_eval_statusline('%h%w%m%r', {'maxwidth': 30}).width > 0 ? '%h%w%m%r ' : ''%}%=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
"%<%f %{%nvim_eval_statusline('%h%w%m%r', {'maxwidth': 30}).width > 0 ? '%h%w%m%r ' : ''%}%=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &ruler ? &rulerformat : '' %}",
api.nvim_get_option_value('statusline', { win = 0 })
)
eq('', eval('&l:statusline'))
@@ -2337,7 +2337,7 @@ describe('API/win', function()
screen:expect([[
│^ |
~ │~ |*4
0,0-1 All |
0,0-1 All|
{5:-- TERMINAL --} |
]])
screen:detach()
@@ -2351,7 +2351,7 @@ describe('API/win', function()
screen:expect([[
^ │ |
~ │~ |*4
0,0-1 All |
0,0-1 All|
{5:-- TERMINAL --} |
]])
end)

View File

@@ -1507,7 +1507,7 @@ describe('completion', function()
{12:hello }{1: }|
{4:hullo }{1: }|
{4:heee }{1: }|
{5:-- INSERT --} 4,6 All |
{5:-- INSERT --} 4,6 All|
]])
end)

View File

@@ -429,7 +429,7 @@ describe('swapfile detection', function()
screen:expect([[
^ |
{1:~ }|*16
{19:W325: Ignoring swapfile from Nvim process }0,0-1 All |
{19:W325: Ignoring swapfile from Nvim process }0,0-1 All|
]])
eq(('\n' .. msg_expected):rep(3):sub(2), n.exec_capture('messages'))
command('bwipe!')

View File

@@ -386,7 +386,7 @@ describe('cmdline', function()
api.nvim_set_option_value('rulerformat', '%!TestRulerFn()', {})
screen:expect([[
^ |
10,20 30% |
10,20 30%|
]])
end)

View File

@@ -263,7 +263,7 @@ describe(':confirm command dialog', function()
fooba^r |
{1:~ }|*5
|
1,6 All |
1,6 All|
]])
eq('foo\n', read_file('Xconfirm_write_ro'))
@@ -377,7 +377,7 @@ describe(':confirm command dialog', function()
d |
{1:~ }|*2
|
1,1 All |
1,1 All|
]])
eq('a\nb\nc\nd\n', read_file('Xwrite_partial'))
os.remove('Xwrite_partial')

View File

@@ -249,7 +249,7 @@ describe('linebreak', function()
{17:foo}^ │{1:~ }|
xxxxxxxxxxxxxxxxxxxx│{1:~ }|
{1:~ }│{1:~ }|*2
{5:-- VISUAL BLOCK --} 2x4 2,4 All |
{5:-- VISUAL BLOCK --} 2x4 2,4 All|
]])
-- TAB as end char: 'linebreak' shouldn't break Visual block hl
@@ -264,7 +264,7 @@ describe('linebreak', function()
f{17:oo12345}bar |
f^o{17:o }bar |
{1:~ }|*2
{5:-- VISUAL BLOCK --} 3x7 3,2 All |
{5:-- VISUAL BLOCK --} 3x7 3,2 All|
]])
feed('<Esc>:setlocal linebreak<CR>gv')
screen:expect_unchanged(true)
@@ -281,7 +281,7 @@ describe('linebreak', function()
f{17:oo123456}bar |
f^o{17:o<ffff>}bar |
{1:~ }|*2
{5:-- VISUAL BLOCK --} 3x8 3,2 All |
{5:-- VISUAL BLOCK --} 3x8 3,2 All|
]])
feed('<Esc>:setlocal linebreak<CR>gv')
screen:expect_unchanged(true)
@@ -303,7 +303,7 @@ describe('linebreak', function()
xx{17:xx}foo: {17:x}xxxxx |
xx{17:xx}bar: ^xxxxxx |
{1:~ }|*2
{5:-- VISUAL BLOCK --} 3x8 3,5-10 All |
{5:-- VISUAL BLOCK --} 3x8 3,5-10 All|
]])
feed('<Esc>:setlocal linebreak<CR>gv')
screen:expect_unchanged(true)

View File

@@ -158,7 +158,7 @@ describe('normal', function()
^4 |
5 |
6 |
40 more lines 5,1 %8 |
40 more lines 5,1 %8|
]])
end)
end)

View File

@@ -31,7 +31,7 @@ it('scrolling with laststatus=0 and :botright split', function()
98 |
99 |
^100 |
100,1 Bot |
100,1 Bot|
]])
end)

View File

@@ -853,7 +853,7 @@ describe('TUI :restart', function()
screen:expect([[
^ |
~ |*4
0,0-1 All |
0,0-1 All|
{5:-- TERMINAL --} |
]])
@@ -865,7 +865,7 @@ describe('TUI :restart', function()
0002;<control>;Cc;0;BN;;;;;N;START OF TEXT;;;; |
0003;<control>;Cc;0;BN;;;;;N;END OF TEXT;;;; |
0004;<control>;Cc;0;BN;;;;;N;END OF TRANSMISSION;;|
TRIGGERED: 1 1,1 Top |
TRIGGERED: 1 1,1 Top|
{5:-- TERMINAL --} |
]])

View File

@@ -423,7 +423,7 @@ describe(':terminal window', function()
cool line 8 |
cool line 9 |
cool line 10 |
{5:-- TERMINAL --} 6,1 Bot |
{5:-- TERMINAL --} 6,1 Bot|
]])
command('call nvim_win_set_cursor(0, [1, 0])')
screen:expect_unchanged()
@@ -436,7 +436,7 @@ describe(':terminal window', function()
cool line 8 |
cool line 9 |
cool line 10 |
{5:-- TERMINAL --} 7,5 Bot |
{5:-- TERMINAL --} 7,5 Bot|
]])
-- Check topline correct after leaving terminal mode.
-- The new cursor position is one column left of the terminal's actual cursor position.
@@ -448,7 +448,7 @@ describe(':terminal window', function()
cool line 8 |
cool line 9 |
cool line 10 |
7,4 Bot |
7,4 Bot|
]])
end)

View File

@@ -27,7 +27,8 @@ M.nvim_set = (
'set shortmess+=IS background=light noswapfile noautoindent startofline'
.. ' laststatus=1 undodir=. directory=. viewdir=. backupdir=.'
.. " belloff= wildoptions-=pum joinspaces noshowcmd noruler nomore redrawdebug=invalid shada=!,'100,<50,s10,h"
.. [[ statusline=%<%f\ %{%nvim_eval_statusline('%h%w%m%r',\ {'maxwidth':\ 30}).width\ >\ 0\ ?\ '%h%w%m%r\ '\ :\ ''%}%=%{%\ &showcmdloc\ ==\ 'statusline'\ ?\ '%-10.S\ '\ :\ ''\ %}%{%\ exists('b:keymap_name')\ ?\ '<'..b:keymap_name..'>\ '\ :\ ''\ %}%{%\ &ruler\ ?\ (\ &rulerformat\ ==\ ''\ ?\ '%-14.(%l,%c%V%)\ %P'\ :\ &rulerformat\ )\ :\ ''\ %}]]
.. [[ statusline=%<%f\ %{%nvim_eval_statusline('%h%w%m%r',\ {'maxwidth':\ 30}).width\ >\ 0\ ?\ '%h%w%m%r\ '\ :\ ''%}%=%{%\ &showcmdloc\ ==\ 'statusline'\ ?\ '%-10.S\ '\ :\ ''\ %}%{%\ exists('b:keymap_name')\ ?\ '<'..b:keymap_name..'>\ '\ :\ ''\ %}%{%\ &ruler\ ?\ &rulerformat\ :\ ''\ %}]]
.. ' rulerformat=%18(%l,%c%V%=%P%)'
)
M.nvim_argv = {
M.nvim_prog,

View File

@@ -3578,7 +3578,7 @@ describe('float window', function()
|
{0:~ }|*5
## grid 3
1,1 All |
1,1 All|
## grid 4
{1:^aaa aab }|
{1:abb acc }|
@@ -3597,7 +3597,7 @@ describe('float window', function()
{0:~ }{1:abb acc }{0: }|
{0:~ }{2:~ }{0: }|
{0:~ }|*3
1,1 All |
1,1 All|
]],
}
end
@@ -3613,7 +3613,7 @@ describe('float window', function()
|
{0:~ }|*5
## grid 3
1,5 All |
1,5 All|
## grid 4
{1:aaa ^aab }|
{1:abb acc }|
@@ -3632,7 +3632,7 @@ describe('float window', function()
{0:~ }{1:abb acc }{0: }|
{0:~ }{2:~ }{0: }|
{0:~ }|*3
1,5 All |
1,5 All|
]],
}
end
@@ -3692,7 +3692,7 @@ describe('float window', function()
|
{0:~ }|*7
## grid 3
0,0-1 All |
0,0-1 All|
## grid 4
{1: }|
{2:~ }|*2
@@ -3716,7 +3716,7 @@ describe('float window', function()
{1: } {1:^ } |
{2:~ }{0: }{2:~ }{0: }|*2
{0:~ }|*5
0,0-1 All |
0,0-1 All|
]],
}
end

View File

@@ -936,7 +936,7 @@ describe('ui/ext_messages', function()
end)
it("supports 'showcmd' and 'ruler(format)'", function()
command('set showcmd ruler')
command('set showcmd ruler rulerformat=%12(%l,%c%V%=%P%)')
command('hi link MsgArea ErrorMsg')
screen:expect({
grid = [[
@@ -1890,25 +1890,11 @@ describe('ui/builtin messages', function()
end)
it('supports ruler with laststatus=0', function()
command('set ruler laststatus=0')
command('set laststatus=0 ruler rulerformat=%-15(%c%V\\ %p%%%)')
screen:expect([[
^ |
{1:~ }|*5
0,0-1 All |
]])
command('hi MsgArea guibg=#333333')
screen:expect([[
^ |
{1:~ }|*5
{101: 0,0-1 All }|
]])
command('set rulerformat=%15(%c%V\\ %p%%%)')
screen:expect([[
^ |
{1:~ }|*5
{101: 0,0-1 100% }|
0-1 100% |
]])
-- Ruler is cleared when it is no longer drawn.
@@ -1916,7 +1902,21 @@ describe('ui/builtin messages', function()
screen:expect([[
^ |
{1:~ }|*5
{101: }|
|
]])
command('set ruler rulerformat&')
screen:expect([[
^ |
{1:~ }|*5
0,0-1 All|
]])
command('hi MsgArea guibg=#333333')
screen:expect([[
^ |
{1:~ }|*5
{101: 0,0-1 All}|
]])
end)

View File

@@ -303,35 +303,35 @@ describe('multibyte rendering', function()
screen:expect([[
^🏳️‍⚧️ |
{1:~ }|*4
1,1 All |
1,1 All|
]])
feed('a word<esc>')
screen:expect([[
🏳️‍⚧️ wor^d |
{1:~ }|*4
1,21-7 All |
1,21-7 All|
]])
feed('0')
screen:expect([[
^🏳️‍⚧️ word |
{1:~ }|*4
1,1 All |
1,1 All|
]])
feed('l')
screen:expect([[
🏳️‍⚧️^ word |
{1:~ }|*4
1,17-3 All |
1,17-3 All|
]])
feed('h')
screen:expect([[
^🏳️‍⚧️ word |
{1:~ }|*4
1,1 All |
1,1 All|
]])
feed('o❤ variant selected<esc>')
@@ -339,7 +339,7 @@ describe('multibyte rendering', function()
🏳️‍⚧️ word |
❤️ variant selecte^d |
{1:~ }|*3
2,23-19 All |
2,23-19 All|
]])
feed('0')
@@ -347,7 +347,7 @@ describe('multibyte rendering', function()
🏳️‍⚧️ word |
^❤️ variant selected |
{1:~ }|*3
2,1 All |
2,1 All|
]])
feed('l')
@@ -355,7 +355,7 @@ describe('multibyte rendering', function()
🏳️‍⚧️ word |
❤️^ variant selected |
{1:~ }|*3
2,7-3 All |
2,7-3 All|
]])
feed('h')
@@ -363,7 +363,7 @@ describe('multibyte rendering', function()
🏳️‍⚧️ word |
^❤️ variant selected |
{1:~ }|*3
2,1 All |
2,1 All|
]])
-- without selector: single width (note column 18 and not 19)
@@ -373,7 +373,7 @@ describe('multibyte rendering', function()
❤️ variant selected |
❤ variant selecte^d |
{1:~ }|*2
3,20-18 All |
3,20-18 All|
]])
end)
end)

View File

@@ -366,7 +366,7 @@ local function screen_tests(linegrid)
0123^456 |
789 |
{1:~ }|*11
1,5 All |
1,5 All|
]])
end)
end)

View File

@@ -346,7 +346,7 @@ describe('global statusline', function()
screen:expect([[
^ |
{1:~ }|*14
0,0-1 All |
0,0-1 All|
]])
command('set laststatus=3')
@@ -402,7 +402,7 @@ describe('global statusline', function()
{2:< 0,0-1 All <-1 All <}│{1:~ }|
│{1:~ }|
{1:~ }│{1:~ }|*4
0,0-1 All |
0,0-1 All|
]])
command('set laststatus=3')
@@ -816,7 +816,7 @@ describe('statusline', function()
{1:~}{15:^ }{1: }|
{1:~ }|*4
{2:[No Name] 0,0-1 All}|
0,0-1 All |
0,0-1 All|
]])
api.nvim_win_close(win, true)
screen:expect([[
@@ -1142,7 +1142,7 @@ describe('default statusline', function()
"%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}",
"%{% &busy > 0 ? '◐ ' : '' %}",
"%{% luaeval('(package.loaded[''vim.diagnostic''] and next(vim.diagnostic.count()) and vim.diagnostic.status() .. '' '') or '''' ') %}",
"%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}",
"%{% &ruler ? &rulerformat : '' %}",
})
exec_lua("vim.o.statusline = ''")
@@ -1295,6 +1295,48 @@ describe('default statusline', function()
end)
end)
describe('default rulerformat', function()
local screen
before_each(function()
clear()
screen = Screen.new(60, 16)
command('set ruler')
end)
it('setting rulerformat to empty string sets default rulerformat', function()
exec_lua("vim.o.rulerformat = 'hjkl'")
eq('hjkl', eval('&rulerformat'))
screen:expect([[
^ |
{1:~ }|*14
hjkl |
]])
local default_rulerformat = '%18(%l,%c%V%= %P%)%<'
exec_lua("vim.o.rulerformat = ''")
eq(default_rulerformat, eval('&rulerformat'))
screen:expect([[
^ |
{1:~ }|*14
0,0-1 All|
]])
-- Reset to default if there's an error.
command('set rulerformat=%{a%}')
eq(default_rulerformat, eval('&rulerformat'))
eq(default_rulerformat, eval('&g:rulerformat'))
eq(default_rulerformat, eval('&l:rulerformat'))
command('redrawstatus') -- like Vim, rulerformat isn't immediately redrawn after an error
screen:expect([[
^ |
{1:~ }|*14
{9:E121: Undefined variable: a} 0,0-1 All|
]])
end)
end)
describe("'statusline' in floatwin", function()
local screen
before_each(function()