api: allow open non-current buffer as terminal (+ xmas bonus)

vim.api.nvim_chan_send(vim.api.nvim_open_term(0), io.open("/path/to/smile.cat", "r"):read("*a"))
This commit is contained in:
Björn Linse
2020-12-20 16:52:01 +01:00
parent 097ec71bd8
commit ed08936987
8 changed files with 236 additions and 26 deletions

View File

@@ -2087,4 +2087,67 @@ describe('API', function()
eq("", meths.exec("messages", true))
end)
end)
describe('nvim_open_term', function()
local screen
before_each(function()
clear()
screen = Screen.new(100, 35)
screen:attach()
screen:set_default_attr_ids({
[0] = {bold=true, foreground=Screen.colors.Blue},
[1] = {background = Screen.colors.Plum1};
[2] = {background = tonumber('0xffff40'), bg_indexed = true};
[3] = {background = Screen.colors.Plum1, fg_indexed = true, foreground = tonumber('0x00e000')};
[4] = {bold = true, reverse = true, background = Screen.colors.Plum1};
})
end)
it('can batch process sequences', function()
local b = meths.create_buf(true,true)
meths.open_win(b, false, {width=79, height=31, row=1, col=1, relative='editor'})
local t = meths.open_term(b, {})
meths.chan_send(t, io.open("test/functional/fixtures/smile2.cat", "r"):read("*a"))
screen:expect{grid=[[
^ |
{0:~}{1::smile }{0: }|
{0:~}{1: }{2:oooo$$$$$$$$$$$$oooo}{1: }{0: }|
{0:~}{1: }{2:oo$$$$$$$$$$$$$$$$$$$$$$$$o}{1: }{0: }|
{0:~}{1: }{2:oo$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o}{1: }{2:o$}{1: }{2:$$}{1: }{2:o$}{1: }{0: }|
{0:~}{1: }{2:o}{1: }{2:$}{1: }{2:oo}{1: }{2:o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o}{1: }{2:$$}{1: }{2:$$}{1: }{2:$$o$}{1: }{0: }|
{0:~}{1: }{2:oo}{1: }{2:$}{1: }{2:$}{1: "}{2:$}{1: }{2:o$$$$$$$$$}{1: }{2:$$$$$$$$$$$$$}{1: }{2:$$$$$$$$$o}{1: }{2:$$$o$$o$}{1: }{0: }|
{0:~}{1: "}{2:$$$$$$o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$}{1:" }{2:$$$}{1: }{0: }|
{0:~}{1: }{2:$$$o}{1: "}{2:$$}{1:""}{2:$$$$$$}{1:"""" }{2:o$$$}{1: }{0: }|
{0:~}{1: }{2:$$$$o}{1: }{2:o$$$}{1:" }{0: }|
{0:~}{1: "}{2:$$$$o}{1: }{2:o$$$$$$o}{1:"}{2:$$$$o}{1: }{2:o$$$$}{1: }{0: }|
{0:~}{1: "}{2:$$$$$oo}{1: ""}{2:$$$$o$$$$$o}{1: }{2:o$$$$}{1:"" }{0: }|
{0:~}{1: ""}{2:$$$$$oooo}{1: "}{2:$$$o$$$$$$$$$}{1:""" }{0: }|
{0:~}{1: ""}{2:$$$$$$$oo}{1: }{2:$$$$$$$$$$}{1: }{0: }|
{0:~}{1: """"}{2:$$$$$$$$$$$}{1: }{0: }|
{0:~}{1: }{2:$$$$$$$$$$$$}{1: }{0: }|
{0:~}{1: }{2:$$$$$$$$$$}{1:" }{0: }|
{0:~}{1: "}{2:$$$}{1:"""" }{0: }|
{0:~}{1: }{0: }|
{0:~}{3:Press ENTER or type command to continue}{1: }{0: }|
{0:~}{4:term://~/config2/docs/pres//32693:vim --clean +smile 29,39 All}{0: }|
{0:~}{1::call nvim__screenshot("smile2.cat") }{0: }|
{0:~ }|
{0:~ }|
|
]]}
end)
end)
end)