2019-05-19 19:57:45 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
2021-11-07 14:28:11 -07:00
|
|
|
local feed = helpers.feed
|
2019-05-19 19:57:45 -07:00
|
|
|
local source = helpers.source
|
|
|
|
local clear = helpers.clear
|
2021-11-07 14:28:11 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
|
|
|
local meths = helpers.meths
|
|
|
|
local eq = helpers.eq
|
2019-05-19 19:57:45 -07:00
|
|
|
|
|
|
|
describe('prompt buffer', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(25, 10)
|
|
|
|
screen:attach()
|
|
|
|
source([[
|
2023-02-21 02:43:53 -07:00
|
|
|
set laststatus=0 nohidden
|
|
|
|
|
2019-05-19 19:57:45 -07:00
|
|
|
func TextEntered(text)
|
|
|
|
if a:text == "exit"
|
2023-02-21 02:43:53 -07:00
|
|
|
" Reset &modified to allow the buffer to be closed.
|
2019-05-24 21:15:01 -07:00
|
|
|
set nomodified
|
2019-05-19 19:57:45 -07:00
|
|
|
stopinsert
|
|
|
|
close
|
|
|
|
else
|
2023-02-21 02:43:53 -07:00
|
|
|
" Add the output above the current prompt.
|
2019-05-19 19:57:45 -07:00
|
|
|
call append(line("$") - 1, 'Command: "' . a:text . '"')
|
2023-02-21 02:43:53 -07:00
|
|
|
" Reset &modified to allow the buffer to be closed.
|
2022-05-21 14:07:34 -07:00
|
|
|
set nomodified
|
2019-05-19 19:57:45 -07:00
|
|
|
call timer_start(20, {id -> TimerFunc(a:text)})
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func TimerFunc(text)
|
2023-02-21 02:43:53 -07:00
|
|
|
" Add the output above the current prompt.
|
2019-05-19 19:57:45 -07:00
|
|
|
call append(line("$") - 1, 'Result: "' . a:text .'"')
|
2023-02-21 02:43:53 -07:00
|
|
|
" Reset &modified to allow the buffer to be closed.
|
|
|
|
set nomodified
|
2019-05-19 19:57:45 -07:00
|
|
|
endfunc
|
2021-11-25 15:53:14 -07:00
|
|
|
|
|
|
|
func SwitchWindows()
|
2022-05-21 14:07:34 -07:00
|
|
|
call timer_start(0, {-> execute("wincmd p", "")})
|
2021-11-25 15:53:14 -07:00
|
|
|
endfunc
|
2019-05-19 19:57:45 -07:00
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
call setline(1, "other buffer")
|
|
|
|
set nomodified
|
|
|
|
new
|
|
|
|
set buftype=prompt
|
|
|
|
call prompt_setcallback(bufnr(''), function("TextEntered"))
|
|
|
|
eval bufnr("")->prompt_setprompt("cmd: ")
|
|
|
|
startinsert
|
|
|
|
]])
|
2019-05-19 19:57:45 -07:00
|
|
|
screen:expect([[
|
2023-02-21 02:43:53 -07:00
|
|
|
cmd: ^ |
|
2019-05-19 19:57:45 -07:00
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
[Prompt] [+] |
|
2019-05-19 19:57:45 -07:00
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
-- INSERT -- |
|
2019-05-19 19:57:45 -07:00
|
|
|
]])
|
2023-02-21 02:43:53 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
screen:detach()
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- oldtest: Test_prompt_basic()
|
|
|
|
it('works', function()
|
2019-05-19 19:57:45 -07:00
|
|
|
feed("hello\n")
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: hello |
|
2019-05-19 19:57:45 -07:00
|
|
|
Command: "hello" |
|
|
|
|
Result: "hello" |
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: ^ |
|
2023-02-21 02:43:53 -07:00
|
|
|
[Prompt] |
|
2019-05-19 19:57:45 -07:00
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
-- INSERT -- |
|
2019-05-19 19:57:45 -07:00
|
|
|
]])
|
|
|
|
feed("exit\n")
|
|
|
|
screen:expect([[
|
|
|
|
^other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
-- oldtest: Test_prompt_editing()
|
2019-05-22 09:47:56 -07:00
|
|
|
it('editing', function()
|
|
|
|
feed("hello<BS><BS>")
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: hel^ |
|
2019-05-22 09:47:56 -07:00
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2019-05-24 21:15:01 -07:00
|
|
|
[Prompt] [+] |
|
2019-05-22 09:47:56 -07:00
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
-- INSERT -- |
|
2019-05-22 09:47:56 -07:00
|
|
|
]])
|
|
|
|
feed("<Left><Left><Left><BS>-")
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: -^hel |
|
2019-05-22 09:47:56 -07:00
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2019-05-24 21:15:01 -07:00
|
|
|
[Prompt] [+] |
|
2019-05-22 09:47:56 -07:00
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
-- INSERT -- |
|
2019-05-22 09:47:56 -07:00
|
|
|
]])
|
2021-11-07 06:12:17 -07:00
|
|
|
feed("<C-O>lz")
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: -hz^el |
|
2021-11-07 06:12:17 -07:00
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
[Prompt] [+] |
|
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
-- INSERT -- |
|
2021-11-07 06:12:17 -07:00
|
|
|
]])
|
2019-05-22 09:47:56 -07:00
|
|
|
feed("<End>x")
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: -hzelx^ |
|
2019-05-22 09:47:56 -07:00
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2019-05-24 21:15:01 -07:00
|
|
|
[Prompt] [+] |
|
2019-05-22 09:47:56 -07:00
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
2023-02-21 02:43:53 -07:00
|
|
|
-- INSERT -- |
|
2019-05-22 09:47:56 -07:00
|
|
|
]])
|
|
|
|
feed("<C-U>exit\n")
|
|
|
|
screen:expect([[
|
|
|
|
^other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
-- oldtest: Test_prompt_switch_windows()
|
2021-11-25 15:53:14 -07:00
|
|
|
it('switch windows', function()
|
|
|
|
feed("<C-O>:call SwitchWindows()<CR>")
|
2022-05-21 14:07:34 -07:00
|
|
|
screen:expect{grid=[[
|
|
|
|
cmd: |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
[Prompt] [+] |
|
|
|
|
^other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
]]}
|
|
|
|
feed("<C-O>:call SwitchWindows()<CR>")
|
2021-11-25 15:53:14 -07:00
|
|
|
screen:expect([[
|
|
|
|
cmd: ^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
[Prompt] [+] |
|
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
-- INSERT -- |
|
|
|
|
]])
|
|
|
|
feed("<Esc>")
|
|
|
|
screen:expect([[
|
|
|
|
cmd:^ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
[Prompt] [+] |
|
|
|
|
other buffer |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
-- oldtest: Test_prompt_while_writing_to_hidden_buffer()
|
2021-11-07 14:28:11 -07:00
|
|
|
it('keeps insert mode after aucmd_restbuf in callback', function()
|
|
|
|
source [[
|
|
|
|
let s:buf = nvim_create_buf(1, 1)
|
|
|
|
call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])})
|
|
|
|
]]
|
|
|
|
poke_eventloop()
|
|
|
|
eq({ mode = "i", blocking = false }, meths.get_mode())
|
|
|
|
end)
|
2019-05-19 19:57:45 -07:00
|
|
|
end)
|