comparison runtime/doc/channel.txt @ 20753:661eb972cb22

Update runtime files Commit: https://github.com/vim/vim/commit/acc224064033e5cea21ef7f1eefb356ca06ff11d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 7 21:07:18 2020 +0200 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 Jun 2020 21:15:04 +0200
parents e373843e2980
children 21fb2a3ad3ca
comparison
equal deleted inserted replaced
20752:47b5de84b7f7 20753:661eb972cb22
1 *channel.txt* For Vim version 8.2. Last change: 2019 Dec 07 1 *channel.txt* For Vim version 8.2. Last change: 2020 Jun 01
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
1233 - Use a normal buffer and handle all possible commands yourself. 1233 - Use a normal buffer and handle all possible commands yourself.
1234 This will be complicated, since there are so many possible commands. 1234 This will be complicated, since there are so many possible commands.
1235 - Use a terminal window. This works well if what you type goes directly to 1235 - Use a terminal window. This works well if what you type goes directly to
1236 the job and the job output is directly displayed in the window. 1236 the job and the job output is directly displayed in the window.
1237 See |terminal-window|. 1237 See |terminal-window|.
1238 - Use a prompt window. This works well when entering a line for the job in Vim 1238 - Use a window with a prompt buffer. This works well when entering a line for
1239 while displaying (possibly filtered) output from the job. 1239 the job in Vim while displaying (possibly filtered) output from the job.
1240 1240
1241 A prompt buffer is created by setting 'buftype' to "prompt". You would 1241 A prompt buffer is created by setting 'buftype' to "prompt". You would
1242 normally only do that in a newly created buffer. 1242 normally only do that in a newly created buffer.
1243 1243
1244 The user can edit and enter one line of text at the very last line of the 1244 The user can edit and enter one line of text at the very last line of the
1268 1268
1269 Any command that starts Insert mode, such as "a", "i", "A" and "I", will move 1269 Any command that starts Insert mode, such as "a", "i", "A" and "I", will move
1270 the cursor to the last line. "A" will move to the end of the line, "I" to the 1270 the cursor to the last line. "A" will move to the end of the line, "I" to the
1271 start of the line. 1271 start of the line.
1272 1272
1273 Here is an example for Unix. It starts a shell in the background and prompts
1274 for the next shell command. Output from the shell is displayed above the
1275 prompt. >
1276
1277 " Create a channel log so we can see what happens.
1278 call ch_logfile('logfile', 'w')
1279
1280 " Function handling a line of text has been typed.
1281 func TextEntered(text)
1282 " Send the text to a shell with Enter appended.
1283 call ch_sendraw(g:shell_job, a:text .. "\n")
1284 endfunc
1285
1286 " Function handling output from the shell: Added above the prompt.
1287 func GotOutput(channel, msg)
1288 call append(line("$") - 1, "- " . a:msg)
1289 endfunc
1290
1291 " Function handling the shell exist: close the window.
1292 func JobExit(job, status)
1293 quit!
1294 endfunc
1295
1296 " Start a shell in the background.
1297 let shell_job = job_start(["/bin/sh"], #{
1298 \ out_cb: function('GotOutput'),
1299 \ err_cb: function('GotOutput'),
1300 \ exit_cb: function('JobExit'),
1301 \ })
1302 let shell_ch = job_getchannel(shell_job)
1303
1304 new
1305 set buftype=prompt
1306 let buf = bufnr('')
1307 call prompt_setcallback(buf, function("TextEntered"))
1308 eval prompt_setprompt(buf, "shell command: ")
1309
1310 " start accepting shell commands
1311 startinsert
1312 <
1313
1273 1314
1274 vim:tw=78:ts=8:noet:ft=help:norl: 1315 vim:tw=78:ts=8:noet:ft=help:norl: