mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "754a63c74b55467ed7995923726ef81c25941161" and "802f444ba6ebb7e1e642d25762c89da7090f8f04" have entirely different histories.
754a63c74b
...
802f444ba6
7
api.go
7
api.go
|
@ -107,16 +107,11 @@ Check out the {blue}{bold}guide{reset} command to get started.
|
||||||
util.Document(L, hshcomp, "Completions interface for Hilbish.")
|
util.Document(L, hshcomp, "Completions interface for Hilbish.")
|
||||||
L.SetField(mod, "completion", hshcomp)
|
L.SetField(mod, "completion", hshcomp)
|
||||||
|
|
||||||
// hilbish.runner table
|
|
||||||
runnerModule := runnerModeLoader(L)
|
runnerModule := runnerModeLoader(L)
|
||||||
util.Document(L, runnerModule, "Runner/exec interface for Hilbish.")
|
util.Document(L, runnerModule, "Runner/exec interface for Hilbish.")
|
||||||
L.SetField(mod, "runner", runnerModule)
|
L.SetField(mod, "runner", runnerModule)
|
||||||
|
|
||||||
// hilbish.jobs table
|
|
||||||
jobs = newJobHandler()
|
jobs = newJobHandler()
|
||||||
jobModule := jobs.loader(L)
|
|
||||||
util.Document(L, jobModule, "(Background) job interface.")
|
|
||||||
L.SetField(mod, "jobs", jobModule)
|
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
|
@ -259,7 +254,7 @@ func hlmlprompt(L *lua.LState) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// alias(cmd, orig)
|
// alias(cmd, orig)
|
||||||
// Sets an alias of `cmd` to `orig`
|
// Sets an alias of `orig` to `cmd`
|
||||||
// --- @param cmd string
|
// --- @param cmd string
|
||||||
// --- @param orig string
|
// --- @param orig string
|
||||||
func hlalias(L *lua.LState) int {
|
func hlalias(L *lua.LState) int {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
alias(cmd, orig) > Sets an alias of `cmd` to `orig`
|
alias(cmd, orig) > Sets an alias of `orig` to `cmd`
|
||||||
|
|
||||||
appendPath(dir) > Appends `dir` to $PATH
|
appendPath(dir) > Appends `dir` to $PATH
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
local hilbish = {}
|
local hilbish = {}
|
||||||
|
|
||||||
--- Sets an alias of `cmd` to `orig`
|
--- Sets an alias of `orig` to `cmd`
|
||||||
--- @param cmd string
|
--- @param cmd string
|
||||||
--- @param orig string
|
--- @param orig string
|
||||||
function hilbish.alias(cmd, orig) end
|
function hilbish.alias(cmd, orig) end
|
||||||
|
|
1
exec.go
1
exec.go
|
@ -262,7 +262,6 @@ func execCommand(cmd string) error {
|
||||||
|
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
job := jobs.getLatest()
|
job := jobs.getLatest()
|
||||||
job.setHandle(cmd.Process)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if bg {
|
if bg {
|
||||||
job.start(cmd.Process.Pid)
|
job.start(cmd.Process.Pid)
|
||||||
|
|
63
job.go
63
job.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
|
@ -15,7 +14,6 @@ type job struct {
|
||||||
id int
|
id int
|
||||||
pid int
|
pid int
|
||||||
exitCode int
|
exitCode int
|
||||||
proc *os.Process
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *job) start(pid int) {
|
func (j *job) start(pid int) {
|
||||||
|
@ -24,27 +22,15 @@ func (j *job) start(pid int) {
|
||||||
hooks.Em.Emit("job.start", j.lua())
|
hooks.Em.Emit("job.start", j.lua())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *job) stop() {
|
|
||||||
// finish will be called in exec handle
|
|
||||||
j.proc.Kill()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *job) finish() {
|
func (j *job) finish() {
|
||||||
j.running = false
|
j.running = false
|
||||||
hooks.Em.Emit("job.done", j.lua())
|
hooks.Em.Emit("job.done", j.lua())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *job) setHandle(handle *os.Process) {
|
|
||||||
j.proc = handle
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *job) lua() *lua.LTable {
|
func (j *job) lua() *lua.LTable {
|
||||||
// returns lua table for job
|
// returns lua table for job
|
||||||
// because userdata is gross
|
// because userdata is gross
|
||||||
jobFuncs := map[string]lua.LGFunction{
|
luaJob := l.NewTable()
|
||||||
"stop": j.luaStop,
|
|
||||||
}
|
|
||||||
luaJob := l.SetFuncs(l.NewTable(), jobFuncs)
|
|
||||||
|
|
||||||
l.SetField(luaJob, "cmd", lua.LString(j.cmd))
|
l.SetField(luaJob, "cmd", lua.LString(j.cmd))
|
||||||
l.SetField(luaJob, "running", lua.LBool(j.running))
|
l.SetField(luaJob, "running", lua.LBool(j.running))
|
||||||
|
@ -55,14 +41,6 @@ func (j *job) lua() *lua.LTable {
|
||||||
return luaJob
|
return luaJob
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *job) luaStop(L *lua.LState) int {
|
|
||||||
if j.running {
|
|
||||||
j.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
type jobHandler struct {
|
type jobHandler struct {
|
||||||
jobs map[int]*job
|
jobs map[int]*job
|
||||||
latestID int
|
latestID int
|
||||||
|
@ -95,42 +73,3 @@ func (j *jobHandler) getLatest() *job {
|
||||||
|
|
||||||
return j.jobs[j.latestID]
|
return j.jobs[j.latestID]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (j *jobHandler) loader(L *lua.LState) *lua.LTable {
|
|
||||||
jobFuncs := map[string]lua.LGFunction{
|
|
||||||
"all": j.luaAllJobs,
|
|
||||||
"get": j.luaGetJob,
|
|
||||||
}
|
|
||||||
|
|
||||||
luaJob := l.SetFuncs(l.NewTable(), jobFuncs)
|
|
||||||
|
|
||||||
return luaJob
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *jobHandler) luaGetJob(L *lua.LState) int {
|
|
||||||
j.mu.RLock()
|
|
||||||
defer j.mu.RUnlock()
|
|
||||||
|
|
||||||
jobID := L.CheckInt(1)
|
|
||||||
job := j.jobs[jobID]
|
|
||||||
if job != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
L.Push(job.lua())
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *jobHandler) luaAllJobs(L *lua.LState) int {
|
|
||||||
j.mu.RLock()
|
|
||||||
defer j.mu.RUnlock()
|
|
||||||
|
|
||||||
jobTbl := L.NewTable()
|
|
||||||
for id, job := range j.jobs {
|
|
||||||
jobTbl.Insert(id, job.lua())
|
|
||||||
}
|
|
||||||
|
|
||||||
L.Push(jobTbl)
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue