mirror of https://github.com/Hilbis/Hilbish
refactor: remove doc prop related code
should very very slightly improve startup. it's dead, obsolete, and unused code now anyways with the docs refactorcommander-stdout
parent
e4d87afab3
commit
78c95de784
41
api.go
41
api.go
|
@ -109,70 +109,59 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
}
|
}
|
||||||
|
|
||||||
util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(getVersion()), "Hilbish version")
|
util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(getVersion()))
|
||||||
util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username), "Username of user")
|
util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username))
|
||||||
util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host), "Host name of the machine")
|
util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host))
|
||||||
util.SetFieldProtected(fakeMod, mod, "home", rt.StringValue(curuser.HomeDir), "Home directory of the user")
|
util.SetFieldProtected(fakeMod, mod, "home", rt.StringValue(curuser.HomeDir))
|
||||||
util.SetFieldProtected(fakeMod, mod, "dataDir", rt.StringValue(dataDir), "Directory for Hilbish's data files")
|
util.SetFieldProtected(fakeMod, mod, "dataDir", rt.StringValue(dataDir))
|
||||||
util.SetFieldProtected(fakeMod, mod, "interactive", rt.BoolValue(interactive), "If this is an interactive shell")
|
util.SetFieldProtected(fakeMod, mod, "interactive", rt.BoolValue(interactive))
|
||||||
util.SetFieldProtected(fakeMod, mod, "login", rt.BoolValue(login), "Whether this is a login shell")
|
util.SetFieldProtected(fakeMod, mod, "login", rt.BoolValue(login))
|
||||||
util.SetFieldProtected(fakeMod, mod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
util.SetFieldProtected(fakeMod, mod, "vimMode", rt.NilValue)
|
||||||
util.SetFieldProtected(fakeMod, mod, "exitCode", rt.IntValue(0), "Exit code of last exected command")
|
util.SetFieldProtected(fakeMod, mod, "exitCode", rt.IntValue(0))
|
||||||
util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
|
||||||
|
|
||||||
// hilbish.userDir table
|
// hilbish.userDir table
|
||||||
hshuser := userDirLoader(rtm)
|
hshuser := userDirLoader(rtm)
|
||||||
util.Document(hshuser, "User directories to store configs and/or modules.")
|
|
||||||
mod.Set(rt.StringValue("userDir"), rt.TableValue(hshuser))
|
mod.Set(rt.StringValue("userDir"), rt.TableValue(hshuser))
|
||||||
|
|
||||||
// hilbish.os table
|
// hilbish.os table
|
||||||
hshos := hshosLoader(rtm)
|
hshos := hshosLoader(rtm)
|
||||||
util.Document(hshos, "OS info interface")
|
|
||||||
mod.Set(rt.StringValue("os"), rt.TableValue(hshos))
|
mod.Set(rt.StringValue("os"), rt.TableValue(hshos))
|
||||||
|
|
||||||
// hilbish.aliases table
|
// hilbish.aliases table
|
||||||
aliases = newAliases()
|
aliases = newAliases()
|
||||||
aliasesModule := aliases.Loader(rtm)
|
aliasesModule := aliases.Loader(rtm)
|
||||||
util.Document(aliasesModule, "Alias inferface for Hilbish.")
|
|
||||||
mod.Set(rt.StringValue("aliases"), rt.TableValue(aliasesModule))
|
mod.Set(rt.StringValue("aliases"), rt.TableValue(aliasesModule))
|
||||||
|
|
||||||
// hilbish.history table
|
// hilbish.history table
|
||||||
historyModule := lr.Loader(rtm)
|
historyModule := lr.Loader(rtm)
|
||||||
mod.Set(rt.StringValue("history"), rt.TableValue(historyModule))
|
mod.Set(rt.StringValue("history"), rt.TableValue(historyModule))
|
||||||
util.Document(historyModule, "History interface for Hilbish.")
|
|
||||||
|
|
||||||
// hilbish.completion table
|
// hilbish.completion table
|
||||||
hshcomp := completionLoader(rtm)
|
hshcomp := completionLoader(rtm)
|
||||||
util.Document(hshcomp, "Completions interface for Hilbish.")
|
|
||||||
mod.Set(rt.StringValue("completion"), rt.TableValue(hshcomp))
|
mod.Set(rt.StringValue("completion"), rt.TableValue(hshcomp))
|
||||||
|
|
||||||
// hilbish.runner table
|
// hilbish.runner table
|
||||||
runnerModule := runnerModeLoader(rtm)
|
runnerModule := runnerModeLoader(rtm)
|
||||||
util.Document(runnerModule, "Runner/exec interface for Hilbish.")
|
|
||||||
mod.Set(rt.StringValue("runner"), rt.TableValue(runnerModule))
|
mod.Set(rt.StringValue("runner"), rt.TableValue(runnerModule))
|
||||||
|
|
||||||
// hilbish.jobs table
|
// hilbish.jobs table
|
||||||
jobs = newJobHandler()
|
jobs = newJobHandler()
|
||||||
jobModule := jobs.loader(rtm)
|
jobModule := jobs.loader(rtm)
|
||||||
util.Document(jobModule, "(Background) job interface.")
|
|
||||||
mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule))
|
mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule))
|
||||||
|
|
||||||
// hilbish.timers table
|
// hilbish.timers table
|
||||||
timers = newTimersModule()
|
timers = newTimersModule()
|
||||||
timersModule := timers.loader(rtm)
|
timersModule := timers.loader(rtm)
|
||||||
util.Document(timersModule, "Timer interface, for control of all intervals and timeouts.")
|
|
||||||
mod.Set(rt.StringValue("timers"), rt.TableValue(timersModule))
|
mod.Set(rt.StringValue("timers"), rt.TableValue(timersModule))
|
||||||
|
|
||||||
editorModule := editorLoader(rtm)
|
editorModule := editorLoader(rtm)
|
||||||
util.Document(editorModule, "")
|
|
||||||
mod.Set(rt.StringValue("editor"), rt.TableValue(editorModule))
|
mod.Set(rt.StringValue("editor"), rt.TableValue(editorModule))
|
||||||
|
|
||||||
versionModule := rt.NewTable()
|
versionModule := rt.NewTable()
|
||||||
util.SetField(rtm, versionModule, "branch", rt.StringValue(gitBranch), "Git branch Hilbish was compiled from")
|
util.SetField(rtm, versionModule, "branch", rt.StringValue(gitBranch))
|
||||||
util.SetField(rtm, versionModule, "full", rt.StringValue(getVersion()), "Full version info, including release name")
|
util.SetField(rtm, versionModule, "full", rt.StringValue(getVersion()))
|
||||||
util.SetField(rtm, versionModule, "commit", rt.StringValue(gitCommit), "Git commit Hilbish was compiled from")
|
util.SetField(rtm, versionModule, "commit", rt.StringValue(gitCommit))
|
||||||
util.SetField(rtm, versionModule, "release", rt.StringValue(releaseName), "Release name")
|
util.SetField(rtm, versionModule, "release", rt.StringValue(releaseName))
|
||||||
util.Document(versionModule, "Version info interface.")
|
|
||||||
mod.Set(rt.StringValue("version"), rt.TableValue(versionModule))
|
mod.Set(rt.StringValue("version"), rt.TableValue(versionModule))
|
||||||
|
|
||||||
return rt.TableValue(fakeMod), nil
|
return rt.TableValue(fakeMod), nil
|
||||||
|
@ -187,12 +176,12 @@ func getenv(key, fallback string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setVimMode(mode string) {
|
func setVimMode(mode string) {
|
||||||
util.SetField(l, hshMod, "vimMode", rt.StringValue(mode), "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
util.SetField(l, hshMod, "vimMode", rt.StringValue(mode))
|
||||||
hooks.Emit("hilbish.vimMode", mode)
|
hooks.Emit("hilbish.vimMode", mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func unsetVimMode() {
|
func unsetVimMode() {
|
||||||
util.SetField(l, hshMod, "vimMode", rt.NilValue, "Current Vim mode of Hilbish (nil if not in Vim mode)")
|
util.SetField(l, hshMod, "vimMode", rt.NilValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// run(cmd, returnOut) -> exitCode, stdout, stderr
|
// run(cmd, returnOut) -> exitCode, stdout, stderr
|
||||||
|
|
2
exec.go
2
exec.go
|
@ -552,7 +552,7 @@ func splitInput(input string) ([]string, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdFinish(code uint8, cmdstr string, private bool) {
|
func cmdFinish(code uint8, cmdstr string, private bool) {
|
||||||
util.SetField(l, hshMod, "exitCode", rt.IntValue(int64(code)), "Exit code of last exected command")
|
util.SetField(l, hshMod, "exitCode", rt.IntValue(int64(code)))
|
||||||
// using AsValue (to convert to lua type) on an interface which is an int
|
// using AsValue (to convert to lua type) on an interface which is an int
|
||||||
// results in it being unknown in lua .... ????
|
// results in it being unknown in lua .... ????
|
||||||
// so we allow the hook handler to take lua runtime Values
|
// so we allow the hook handler to take lua runtime Values
|
||||||
|
|
|
@ -204,15 +204,6 @@ func (b *Bait) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
util.SetExports(rtm, mod, exports)
|
util.SetExports(rtm, mod, exports)
|
||||||
|
|
||||||
util.Document(mod,
|
|
||||||
`Bait is the event emitter for Hilbish. Why name it bait?
|
|
||||||
Because it throws hooks that you can catch (emits events
|
|
||||||
that you can listen to) and because why not, fun naming
|
|
||||||
is fun. This is what you will use if you want to listen
|
|
||||||
in on hooks to know when certain things have happened,
|
|
||||||
like when you've changed directory, a command has
|
|
||||||
failed, etc. To find all available hooks, see doc hooks.`)
|
|
||||||
|
|
||||||
return rt.TableValue(mod), nil
|
return rt.TableValue(mod), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ func (c *Commander) loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
}
|
}
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
util.SetExports(rtm, mod, exports)
|
util.SetExports(rtm, mod, exports)
|
||||||
util.Document(mod, "Commander is Hilbish's custom command library, a way to write commands in Lua.")
|
|
||||||
|
|
||||||
return rt.TableValue(mod), nil
|
return rt.TableValue(mod), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,6 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
mod.Set(rt.StringValue("pathSep"), rt.StringValue(string(os.PathSeparator)))
|
mod.Set(rt.StringValue("pathSep"), rt.StringValue(string(os.PathSeparator)))
|
||||||
mod.Set(rt.StringValue("pathListSep"), rt.StringValue(string(os.PathListSeparator)))
|
mod.Set(rt.StringValue("pathListSep"), rt.StringValue(string(os.PathListSeparator)))
|
||||||
|
|
||||||
util.Document(mod, `The fs module provides easy and simple access to
|
|
||||||
filesystem functions and other things, and acts an
|
|
||||||
addition to the Lua standard library's I/O and filesystem functions.`)
|
|
||||||
|
|
||||||
return rt.TableValue(mod), nil
|
return rt.TableValue(mod), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
|
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
util.SetExports(rtm, mod, exports)
|
util.SetExports(rtm, mod, exports)
|
||||||
util.Document(mod, "The terminal library is a simple and lower level library for certain terminal interactions.")
|
|
||||||
|
|
||||||
return rt.TableValue(mod), nil
|
return rt.TableValue(mod), nil
|
||||||
}
|
}
|
||||||
|
|
6
os.go
6
os.go
|
@ -19,9 +19,9 @@ func hshosLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
info, _ := osinfo.GetOSInfo()
|
info, _ := osinfo.GetOSInfo()
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
|
|
||||||
util.SetField(rtm, mod, "family", rt.StringValue(info.Family), "Family name of the current OS")
|
util.SetField(rtm, mod, "family", rt.StringValue(info.Family))
|
||||||
util.SetField(rtm, mod, "name", rt.StringValue(info.Name), "Pretty name of the current OS")
|
util.SetField(rtm, mod, "name", rt.StringValue(info.Name))
|
||||||
util.SetField(rtm, mod, "version", rt.StringValue(info.Version), "Version of the current OS")
|
util.SetField(rtm, mod, "version", rt.StringValue(info.Version))
|
||||||
|
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ import (
|
||||||
func userDirLoader(rtm *rt.Runtime) *rt.Table {
|
func userDirLoader(rtm *rt.Runtime) *rt.Table {
|
||||||
mod := rt.NewTable()
|
mod := rt.NewTable()
|
||||||
|
|
||||||
util.SetField(rtm, mod, "config", rt.StringValue(confDir), "User's config directory")
|
util.SetField(rtm, mod, "config", rt.StringValue(confDir))
|
||||||
util.SetField(rtm, mod, "data", rt.StringValue(userDataDir), "XDG data directory")
|
util.SetField(rtm, mod, "data", rt.StringValue(userDataDir))
|
||||||
|
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
39
util/util.go
39
util/util.go
|
@ -10,53 +10,18 @@ import (
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Document adds a documentation string to a module.
|
|
||||||
// It is accessible via the __doc metatable.
|
|
||||||
func Document(module *rt.Table, doc string) {
|
|
||||||
mt := module.Metatable()
|
|
||||||
|
|
||||||
if mt == nil {
|
|
||||||
mt = rt.NewTable()
|
|
||||||
module.SetMetatable(mt)
|
|
||||||
}
|
|
||||||
|
|
||||||
mt.Set(rt.StringValue("__doc"), rt.StringValue(doc))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetField sets a field in a table, adding docs for it.
|
// SetField sets a field in a table, adding docs for it.
|
||||||
// It is accessible via the __docProp metatable. It is a table of the names of the fields.
|
// It is accessible via the __docProp metatable. It is a table of the names of the fields.
|
||||||
func SetField(rtm *rt.Runtime, module *rt.Table, field string, value rt.Value, doc string) {
|
func SetField(rtm *rt.Runtime, module *rt.Table, field string, value rt.Value) {
|
||||||
// TODO: ^ rtm isnt needed, i should remove it
|
// TODO: ^ rtm isnt needed, i should remove it
|
||||||
SetFieldDoc(module, field, doc)
|
|
||||||
module.Set(rt.StringValue(field), value)
|
module.Set(rt.StringValue(field), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFieldDoc sets the __docProp metatable for a field on the
|
|
||||||
// module.
|
|
||||||
func SetFieldDoc(module *rt.Table, field, doc string) {
|
|
||||||
mt := module.Metatable()
|
|
||||||
|
|
||||||
if mt == nil {
|
|
||||||
mt = rt.NewTable()
|
|
||||||
module.SetMetatable(mt)
|
|
||||||
}
|
|
||||||
|
|
||||||
docProp := mt.Get(rt.StringValue("__docProp"))
|
|
||||||
if docProp == rt.NilValue {
|
|
||||||
docPropTbl := rt.NewTable()
|
|
||||||
mt.Set(rt.StringValue("__docProp"), rt.TableValue(docPropTbl))
|
|
||||||
docProp = mt.Get(rt.StringValue("__docProp"))
|
|
||||||
}
|
|
||||||
|
|
||||||
docProp.AsTable().Set(rt.StringValue(field), rt.StringValue(doc))
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetFieldProtected sets a field in a protected table. A protected table
|
// SetFieldProtected sets a field in a protected table. A protected table
|
||||||
// is one which has a metatable proxy to ensure no overrides happen to it.
|
// is one which has a metatable proxy to ensure no overrides happen to it.
|
||||||
// It sets the field in the table and sets the __docProp metatable on the
|
// It sets the field in the table and sets the __docProp metatable on the
|
||||||
// user facing table.
|
// user facing table.
|
||||||
func SetFieldProtected(module, realModule *rt.Table, field string, value rt.Value, doc string) {
|
func SetFieldProtected(module, realModule *rt.Table, field string, value rt.Value) {
|
||||||
SetFieldDoc(module, field, doc)
|
|
||||||
realModule.Set(rt.StringValue(field), value)
|
realModule.Set(rt.StringValue(field), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue