mirror of https://github.com/Hilbis/Hilbish
feat: add job.background and bg command
parent
43dc00c120
commit
7ac43aa2da
23
job.go
23
job.go
|
@ -112,6 +112,7 @@ func (j *job) lua() rt.Value {
|
||||||
"stop": {j.luaStop, 0, false},
|
"stop": {j.luaStop, 0, false},
|
||||||
"start": {j.luaStart, 0, false},
|
"start": {j.luaStart, 0, false},
|
||||||
"foreground": {j.luaForeground, 0, false},
|
"foreground": {j.luaForeground, 0, false},
|
||||||
|
"background": {j.luaBackground, 0, false},
|
||||||
}
|
}
|
||||||
luaJob := rt.NewTable()
|
luaJob := rt.NewTable()
|
||||||
util.SetExports(l, luaJob, jobFuncs)
|
util.SetExports(l, luaJob, jobFuncs)
|
||||||
|
@ -154,7 +155,14 @@ func (j *job) luaForeground(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
|
||||||
// lua code can run in other threads and goroutines, so this exists
|
// lua code can run in other threads and goroutines, so this exists
|
||||||
jobs.foreground = true
|
jobs.foreground = true
|
||||||
err := j.foreground()
|
// this is kinda funny
|
||||||
|
// background continues the process incase it got suspended
|
||||||
|
err := j.background()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = j.foreground()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -163,6 +171,19 @@ func (j *job) luaForeground(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.Next(), nil
|
return c.Next(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *job) luaBackground(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
|
if !j.running {
|
||||||
|
return nil, errors.New("job not running")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := j.background()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Next(), nil
|
||||||
|
}
|
||||||
|
|
||||||
type jobHandler struct {
|
type jobHandler struct {
|
||||||
jobs map[int]*job
|
jobs map[int]*job
|
||||||
latestID int
|
latestID int
|
||||||
|
|
10
job_unix.go
10
job_unix.go
|
@ -26,3 +26,13 @@ func (j *job) foreground() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *job) background() error {
|
||||||
|
proc := j.handle.Process
|
||||||
|
if proc == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
proc.Signal(syscall.SIGCONT)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -9,3 +9,7 @@ import (
|
||||||
func (j *job) foreground() error {
|
func (j *job) foreground() error {
|
||||||
return errors.New("not supported on windows")
|
return errors.New("not supported on windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *job) background() error {
|
||||||
|
return errors.New("not supported on windows")
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
local commander = require 'commander'
|
||||||
|
|
||||||
|
commander.register('bg', function()
|
||||||
|
local job = hilbish.jobs.last()
|
||||||
|
if not job then
|
||||||
|
print 'bg: no last job'
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local err = job.background()
|
||||||
|
if err then
|
||||||
|
print('bg: ' .. err)
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
end)
|
Loading…
Reference in New Issue