mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Add plugin function JobSpawn
This commit is contained in:
@@ -40,15 +40,20 @@ func (f *CallbackFile) Write(data []byte) (int, error) {
|
|||||||
return f.Writer.Write(data)
|
return f.Writer.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// JobStart starts a process in the background with the given callbacks
|
// JobStart starts a shell command in the background with the given callbacks
|
||||||
// It returns an *exec.Cmd as the job id
|
// It returns an *exec.Cmd as the job id
|
||||||
func JobStart(cmd string, onStdout, onStderr, onExit string, userargs ...string) *exec.Cmd {
|
func JobStart(cmd string, onStdout, onStderr, onExit string, userargs ...string) *exec.Cmd {
|
||||||
split := strings.Split(cmd, " ")
|
split := strings.Split(cmd, " ")
|
||||||
args := split[1:]
|
cmdArgs := split[1:]
|
||||||
cmdName := split[0]
|
cmdName := split[0]
|
||||||
|
return JobSpawn(cmdName, cmdArgs, onStdout, onStderr, onExit, userargs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// JobSpawn starts a process with args in the background with the given callbacks
|
||||||
|
// It returns an *exec.Cmd as the job id
|
||||||
|
func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit string, userargs ...string) *exec.Cmd {
|
||||||
// Set up everything correctly if the functions have been provided
|
// Set up everything correctly if the functions have been provided
|
||||||
proc := exec.Command(cmdName, args...)
|
proc := exec.Command(cmdName, cmdArgs...)
|
||||||
var outbuf bytes.Buffer
|
var outbuf bytes.Buffer
|
||||||
if onStdout != "" {
|
if onStdout != "" {
|
||||||
proc.Stdout = &CallbackFile{&outbuf, LuaFunctionJob(onStdout), userargs}
|
proc.Stdout = &CallbackFile{&outbuf, LuaFunctionJob(onStdout), userargs}
|
||||||
|
|||||||
@@ -340,6 +340,7 @@ func main() {
|
|||||||
|
|
||||||
// Used for asynchronous jobs
|
// Used for asynchronous jobs
|
||||||
L.SetGlobal("JobStart", luar.New(L, JobStart))
|
L.SetGlobal("JobStart", luar.New(L, JobStart))
|
||||||
|
L.SetGlobal("JobSpawn", luar.New(L, JobSpawn))
|
||||||
L.SetGlobal("JobSend", luar.New(L, JobSend))
|
L.SetGlobal("JobSend", luar.New(L, JobSend))
|
||||||
L.SetGlobal("JobStop", luar.New(L, JobStop))
|
L.SetGlobal("JobStop", luar.New(L, JobStop))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user