diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-03-08 21:35:07 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-03-08 21:35:07 +0000 |
commit | 1588bc8ebee22f2855f27273fc2234fff370f86c (patch) | |
tree | 7ef17f0d3739007a97fbe09daa1f96757a8ac8f2 /runtime/doc/channel.txt | |
parent | ed0c62e7b16b62655824df28cdd6bd75aadbb8fc (diff) |
Update runtime files
Diffstat (limited to 'runtime/doc/channel.txt')
-rw-r--r-- | runtime/doc/channel.txt | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/runtime/doc/channel.txt b/runtime/doc/channel.txt index 0e95cd233d..2182ae6974 100644 --- a/runtime/doc/channel.txt +++ b/runtime/doc/channel.txt @@ -1,4 +1,4 @@ -*channel.txt* For Vim version 8.2. Last change: 2021 Nov 28 +*channel.txt* For Vim version 8.2. Last change: 2022 Feb 27 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1288,18 +1288,18 @@ prompt. > " Create a channel log so we can see what happens. call ch_logfile('logfile', 'w') - " Function handling a line of text has been typed. + " Function handling a line of text that has been typed. func TextEntered(text) " Send the text to a shell with Enter appended. call ch_sendraw(g:shell_job, a:text .. "\n") endfunc - " Function handling output from the shell: Added above the prompt. + " Function handling output from the shell: Add it above the prompt. func GotOutput(channel, msg) call append(line("$") - 1, "- " .. a:msg) endfunc - " Function handling the shell exist: close the window. + " Function handling the shell exits: close the window. func JobExit(job, status) quit! endfunc @@ -1310,7 +1310,6 @@ prompt. > \ err_cb: function('GotOutput'), \ exit_cb: function('JobExit'), \ }) - let shell_ch = job_getchannel(shell_job) new set buftype=prompt @@ -1321,6 +1320,46 @@ prompt. > " start accepting shell commands startinsert < +The same in |Vim9| script: > + + vim9script + + # Create a channel log so we can see what happens. + ch_logfile('logfile', 'w') + + var shell_job: job + + # Function handling a line of text that has been typed. + def TextEntered(text: string) + # Send the text to a shell with Enter appended. + ch_sendraw(shell_job, text .. "\n") + enddef + + # Function handling output from the shell: Add it above the prompt. + def GotOutput(channel: channel, msg: string) + append(line("$") - 1, "- " .. msg) + enddef + + # Function handling the shell exits: close the window. + def JobExit(job: job, status: number) + quit! + enddef + + # Start a shell in the background. + shell_job = job_start(["/bin/sh"], { + out_cb: GotOutput, + err_cb: GotOutput, + exit_cb: JobExit, + }) + + new + set buftype=prompt + var buf = bufnr('') + prompt_setcallback(buf, TextEntered) + prompt_setprompt(buf, "shell command: ") + + # start accepting shell commands + startinsert vim:tw=78:ts=8:noet:ft=help:norl: |