mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 14:47:16 +09:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user