mirror of https://github.com/Hilbis/Hilbish
refactor(minor): reduce the amount of module renaming
parent
a29eddb1bf
commit
e0cf87d272
16
lua.go
16
lua.go
|
@ -2,12 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
hooks "hilbish/golibs/bait"
|
"hilbish/golibs/bait"
|
||||||
cmds "hilbish/golibs/commander"
|
"hilbish/golibs/commander"
|
||||||
lfs "hilbish/golibs/fs"
|
lfs "hilbish/golibs/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
lua "github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
|
|
||||||
var minimalconf = `
|
var minimalconf = `
|
||||||
|
@ -32,9 +32,9 @@ func LuaInit(confpath string) {
|
||||||
// Add fs module to Lua
|
// Add fs module to Lua
|
||||||
l.PreloadModule("fs", lfs.Loader)
|
l.PreloadModule("fs", lfs.Loader)
|
||||||
|
|
||||||
commander := cmds.New()
|
cmds := commander.New()
|
||||||
// When a command from Lua is added, register it for use
|
// When a command from Lua is added, register it for use
|
||||||
commander.Events.On("commandRegister",
|
cmds.Events.On("commandRegister",
|
||||||
func(cmdName string, cmd *lua.LFunction) {
|
func(cmdName string, cmd *lua.LFunction) {
|
||||||
commands[cmdName] = true
|
commands[cmdName] = true
|
||||||
l.SetField(
|
l.SetField(
|
||||||
|
@ -44,10 +44,10 @@ func LuaInit(confpath string) {
|
||||||
cmd)
|
cmd)
|
||||||
})
|
})
|
||||||
|
|
||||||
l.PreloadModule("commander", commander.Loader)
|
l.PreloadModule("commander", cmds.Loader)
|
||||||
|
|
||||||
bait = hooks.New()
|
hooks = bait.New()
|
||||||
l.PreloadModule("bait", bait.Loader)
|
l.PreloadModule("bait", hooks.Loader)
|
||||||
|
|
||||||
// Add more paths that Lua can require from
|
// Add more paths that Lua can require from
|
||||||
l.DoString(`package.path = package.path
|
l.DoString(`package.path = package.path
|
||||||
|
|
4
main.go
4
main.go
|
@ -8,7 +8,7 @@ import (
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
hooks "hilbish/golibs/bait"
|
"hilbish/golibs/bait"
|
||||||
|
|
||||||
"github.com/akamensky/argparse"
|
"github.com/akamensky/argparse"
|
||||||
"github.com/bobappleyard/readline"
|
"github.com/bobappleyard/readline"
|
||||||
|
@ -28,7 +28,7 @@ var (
|
||||||
commands = map[string]bool{}
|
commands = map[string]bool{}
|
||||||
aliases = map[string]string{}
|
aliases = map[string]string{}
|
||||||
|
|
||||||
bait hooks.Bait
|
hooks bait.Bait
|
||||||
homedir string
|
homedir string
|
||||||
running bool
|
running bool
|
||||||
interactive bool
|
interactive bool
|
||||||
|
|
10
shell.go
10
shell.go
|
@ -23,7 +23,7 @@ func RunInput(input string) {
|
||||||
// If it succeeds, add to history and prompt again
|
// If it succeeds, add to history and prompt again
|
||||||
HandleHistory(input)
|
HandleHistory(input)
|
||||||
|
|
||||||
bait.Em.Emit("command.exit", 0)
|
hooks.Em.Emit("command.exit", 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,22 +71,22 @@ func RunInput(input string) {
|
||||||
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
|
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
|
||||||
continue
|
continue
|
||||||
} else if code, ok := interp.IsExitStatus(err); ok {
|
} else if code, ok := interp.IsExitStatus(err); ok {
|
||||||
bait.Em.Emit("command.exit", code)
|
hooks.Em.Emit("command.exit", code)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
bait.Em.Emit("command.exit", 1)
|
hooks.Em.Emit("command.exit", 1)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if code, ok := interp.IsExitStatus(err); ok {
|
if code, ok := interp.IsExitStatus(err); ok {
|
||||||
bait.Em.Emit("command.exit", code)
|
hooks.Em.Emit("command.exit", code)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bait.Em.Emit("command.exit", 0)
|
hooks.Em.Emit("command.exit", 0)
|
||||||
}
|
}
|
||||||
HandleHistory(cmdString)
|
HandleHistory(cmdString)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue