diff options
author | Marco Hinz <mh.codebro+github@gmail.com> | 2017-07-14 00:08:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-14 00:08:15 +0200 |
commit | f746e38955f33dfdcc0dbdb40efaae82fb4b4c12 (patch) | |
tree | 59a3dcf2e14fa55860eb57d96a1badc510a5315c | |
parent | 8370373839cc4da8b781edc398d38c0a7cb42223 (diff) | |
parent | d40ca32095c4128152fdf380a3d65946bd080038 (diff) | |
download | rneovim-f746e38955f33dfdcc0dbdb40efaae82fb4b4c12.tar.gz rneovim-f746e38955f33dfdcc0dbdb40efaae82fb4b4c12.tar.bz2 rneovim-f746e38955f33dfdcc0dbdb40efaae82fb4b4c12.zip |
Merge pull request #7011 from mhinz/doc/jobcontrol-example
doc: rewrite job-control example
-rw-r--r-- | runtime/doc/job_control.txt | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/runtime/doc/job_control.txt b/runtime/doc/job_control.txt index da592d6eb0..edbc1bca81 100644 --- a/runtime/doc/job_control.txt +++ b/runtime/doc/job_control.txt @@ -102,36 +102,30 @@ function. Here's a more object-oriented version of the above: > let Shell = {} - function Shell.on_stdout(job_id, data) dict - call append(line('$'), self.get_name().' stdout: '.join(a:data)) + function Shell.on_stdout(_job_id, data, event) + call append(line('$'), + \ printf('[%s] %s: %s', a:event, self.name, join(a:data[:-2]))) endfunction - function Shell.on_stderr(job_id, data) dict - call append(line('$'), self.get_name().' stderr: '.join(a:data)) - endfunction - - function Shell.on_exit(job_id, data) dict - call append(line('$'), self.get_name().' exited') - endfunction + let Shell.on_stderr = function(Shell.on_stdout) - function Shell.get_name() dict - return 'shell '.self.name + function Shell.on_exit(job_id, _data, event) + let msg = printf('job %d ("%s") finished', a:job_id, self.name) + call append(line('$'), printf('[%s] BOOM!', a:event)) + call append(line('$'), printf('[%s] %s!', a:event, msg)) endfunction - function Shell.new(name, ...) dict - let instance = extend(copy(g:Shell), {'name': a:name}) - let argv = ['bash'] - if a:0 > 0 - let argv += ['-c', a:1] - endif - let instance.id = jobstart(argv, instance) - return instance + function Shell.new(name, cmd) + let object = extend(copy(g:Shell), {'name': a:name}) + let object.cmd = ['sh', '-c', a:cmd] + let object.id = jobstart(object.cmd, object) + $ + return object endfunction - let s1 = Shell.new('1') - let s2 = Shell.new('2', 'for i in {1..10}; do echo hello $i!; sleep 1; done') - - + let instance = Shell.new('bomb', + \ 'for i in $(seq 9 -1 1); do echo $i 1>&$((i % 2 + 1)); sleep 1; done') +< To send data to the job's stdin, one can use the |jobsend()| function, like this: > |