Mercurial > vim
comparison src/testdir/test_prompt_buffer.vim @ 14019:dc67449d648c v8.1.0027
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
commit https://github.com/vim/vim/commit/f273245f6433d5d43a5671306b520a3230c35787
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 3 14:47:35 2018 +0200
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Problem: Difficult to make a plugin that feeds a line to a job.
Solution: Add the nitial code for the "prompt" buftype.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 03 Jun 2018 15:00:07 +0200 |
parents | |
children | 945d343d3024 |
comparison
equal
deleted
inserted
replaced
14018:c3064aaf53fb | 14019:dc67449d648c |
---|---|
1 " Tests for setting 'buftype' to "prompt" | |
2 | |
3 if !has('channel') | |
4 finish | |
5 endif | |
6 | |
7 source shared.vim | |
8 source screendump.vim | |
9 | |
10 func Test_prompt_basic() | |
11 " We need to use a terminal window to be able to feed keys without leaving | |
12 " Insert mode. | |
13 if !has('terminal') | |
14 call assert_report('no terminal') | |
15 return | |
16 endif | |
17 call writefile([ | |
18 \ 'func TextEntered(text)', | |
19 \ ' if a:text == "exit"', | |
20 \ ' stopinsert', | |
21 \ ' close', | |
22 \ ' else', | |
23 \ ' " Add the output above the current prompt.', | |
24 \ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")', | |
25 \ ' " Reset &modified to allow the buffer to be closed.', | |
26 \ ' set nomodified', | |
27 \ ' call timer_start(20, {id -> TimerFunc(a:text)})', | |
28 \ ' endif', | |
29 \ 'endfunc', | |
30 \ '', | |
31 \ 'func TimerFunc(text)', | |
32 \ ' " Add the output above the current prompt.', | |
33 \ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")', | |
34 \ 'endfunc', | |
35 \ '', | |
36 \ 'call setline(1, "other buffer")', | |
37 \ 'new', | |
38 \ 'set buftype=prompt', | |
39 \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', | |
40 \ 'startinsert', | |
41 \ ], 'Xpromptscript') | |
42 let buf = RunVimInTerminal('-S Xpromptscript', {}) | |
43 call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) | |
44 | |
45 call term_sendkeys(buf, "hello\<CR>") | |
46 call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))}) | |
47 call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))}) | |
48 call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))}) | |
49 | |
50 call term_sendkeys(buf, "exit\<CR>") | |
51 call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) | |
52 | |
53 call StopVimInTerminal(buf) | |
54 call delete('Xpromptscript') | |
55 endfunc |