Add support for job control

This commit adds support for job control (running processes
asynchronously from plugins) with the JobStart, JobSend, and JobStop
functions (copying neovim's job control).

This commit also makes the linter plugin work asynchronously, so the
editor won't be frozen while the linter checks your code for errors.
This commit is contained in:
Zachary Yedidia
2016-06-15 11:19:00 -04:00
parent ceb5760d6d
commit d2277a376a
6 changed files with 118 additions and 15 deletions

View File

@@ -52,6 +52,9 @@ var (
// This is the currently open tab
// It's just an index to the tab in the tabs array
curTab int
jobs chan JobFunction
events chan tcell.Event
)
// LoadInput loads the file input for the editor
@@ -245,14 +248,33 @@ func main() {
L.SetGlobal("MakeCommand", luar.New(L, MakeCommand))
L.SetGlobal("CurView", luar.New(L, CurView))
L.SetGlobal("JobStart", luar.New(L, JobStart))
L.SetGlobal("JobSend", luar.New(L, JobSend))
L.SetGlobal("JobStop", luar.New(L, JobStop))
LoadPlugins()
jobs = make(chan JobFunction, 100)
events = make(chan tcell.Event)
go func() {
for {
events <- screen.PollEvent()
}
}()
for {
// Display everything
RedrawAll()
// Wait for the user's action
event := screen.PollEvent()
var event tcell.Event
select {
case f := <-jobs:
f.function(f.output, f.args...)
continue
case event = <-events:
}
if TabbarHandleMouseEvent(event) {
continue
}