comparison runtime/doc/channel.txt @ 28010:c968191a8557

Update runtime files Commit: https://github.com/vim/vim/commit/1588bc8ebee22f2855f27273fc2234fff370f86c Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 8 21:35:07 2022 +0000 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Tue, 08 Mar 2022 22:45:09 +0100
parents d19b7aee1925
children 85b07a942518
comparison
equal deleted inserted replaced
28009:3bffa026c6d9 28010:c968191a8557
1 *channel.txt* For Vim version 8.2. Last change: 2021 Nov 28 1 *channel.txt* For Vim version 8.2. Last change: 2022 Feb 27
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
1286 prompt. > 1286 prompt. >
1287 1287
1288 " Create a channel log so we can see what happens. 1288 " Create a channel log so we can see what happens.
1289 call ch_logfile('logfile', 'w') 1289 call ch_logfile('logfile', 'w')
1290 1290
1291 " Function handling a line of text has been typed. 1291 " Function handling a line of text that has been typed.
1292 func TextEntered(text) 1292 func TextEntered(text)
1293 " Send the text to a shell with Enter appended. 1293 " Send the text to a shell with Enter appended.
1294 call ch_sendraw(g:shell_job, a:text .. "\n") 1294 call ch_sendraw(g:shell_job, a:text .. "\n")
1295 endfunc 1295 endfunc
1296 1296
1297 " Function handling output from the shell: Added above the prompt. 1297 " Function handling output from the shell: Add it above the prompt.
1298 func GotOutput(channel, msg) 1298 func GotOutput(channel, msg)
1299 call append(line("$") - 1, "- " .. a:msg) 1299 call append(line("$") - 1, "- " .. a:msg)
1300 endfunc 1300 endfunc
1301 1301
1302 " Function handling the shell exist: close the window. 1302 " Function handling the shell exits: close the window.
1303 func JobExit(job, status) 1303 func JobExit(job, status)
1304 quit! 1304 quit!
1305 endfunc 1305 endfunc
1306 1306
1307 " Start a shell in the background. 1307 " Start a shell in the background.
1308 let shell_job = job_start(["/bin/sh"], #{ 1308 let shell_job = job_start(["/bin/sh"], #{
1309 \ out_cb: function('GotOutput'), 1309 \ out_cb: function('GotOutput'),
1310 \ err_cb: function('GotOutput'), 1310 \ err_cb: function('GotOutput'),
1311 \ exit_cb: function('JobExit'), 1311 \ exit_cb: function('JobExit'),
1312 \ }) 1312 \ })
1313 let shell_ch = job_getchannel(shell_job)
1314 1313
1315 new 1314 new
1316 set buftype=prompt 1315 set buftype=prompt
1317 let buf = bufnr('') 1316 let buf = bufnr('')
1318 call prompt_setcallback(buf, function("TextEntered")) 1317 call prompt_setcallback(buf, function("TextEntered"))
1319 eval prompt_setprompt(buf, "shell command: ") 1318 eval prompt_setprompt(buf, "shell command: ")
1320 1319
1321 " start accepting shell commands 1320 " start accepting shell commands
1322 startinsert 1321 startinsert
1323 < 1322 <
1323 The same in |Vim9| script: >
1324
1325 vim9script
1326
1327 # Create a channel log so we can see what happens.
1328 ch_logfile('logfile', 'w')
1329
1330 var shell_job: job
1331
1332 # Function handling a line of text that has been typed.
1333 def TextEntered(text: string)
1334 # Send the text to a shell with Enter appended.
1335 ch_sendraw(shell_job, text .. "\n")
1336 enddef
1337
1338 # Function handling output from the shell: Add it above the prompt.
1339 def GotOutput(channel: channel, msg: string)
1340 append(line("$") - 1, "- " .. msg)
1341 enddef
1342
1343 # Function handling the shell exits: close the window.
1344 def JobExit(job: job, status: number)
1345 quit!
1346 enddef
1347
1348 # Start a shell in the background.
1349 shell_job = job_start(["/bin/sh"], {
1350 out_cb: GotOutput,
1351 err_cb: GotOutput,
1352 exit_cb: JobExit,
1353 })
1354
1355 new
1356 set buftype=prompt
1357 var buf = bufnr('')
1358 prompt_setcallback(buf, TextEntered)
1359 prompt_setprompt(buf, "shell command: ")
1360
1361 # start accepting shell commands
1362 startinsert
1324 1363
1325 1364
1326 vim:tw=78:ts=8:noet:ft=help:norl: 1365 vim:tw=78:ts=8:noet:ft=help:norl: