mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "2ee506f9583f00b33cfd8ae74540ec9a4841e9f7" and "bb8045dd38f71614c82ea70eef3f7d1e633f8f06" have entirely different histories.
2ee506f958
...
bb8045dd38
|
@ -1,6 +1,5 @@
|
||||||
*.exe
|
*.exe
|
||||||
hilbish
|
hilbish
|
||||||
!docs/api/hilbish
|
|
||||||
docgen
|
docgen
|
||||||
|
|
||||||
.vim
|
.vim
|
||||||
|
|
15
aliases.go
15
aliases.go
|
@ -84,13 +84,6 @@ func (a *aliasModule) Loader(rtm *rt.Runtime) *rt.Table {
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface aliases
|
|
||||||
// add(alias, cmd)
|
|
||||||
// This is an alias (ha) for the `hilbish.alias` function.
|
|
||||||
// --- @param alias string
|
|
||||||
// --- @param cmd string
|
|
||||||
func _hlalias() {}
|
|
||||||
|
|
||||||
// #interface aliases
|
// #interface aliases
|
||||||
// list()
|
// list()
|
||||||
// Get a table of all aliases.
|
// Get a table of all aliases.
|
||||||
|
@ -103,10 +96,6 @@ func (a *aliasModule) luaList(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.PushingNext1(t.Runtime, rt.TableValue(aliasesList)), nil
|
return c.PushingNext1(t.Runtime, rt.TableValue(aliasesList)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface aliases
|
|
||||||
// delete(name)
|
|
||||||
// Removes an alias.
|
|
||||||
// --- @param name string
|
|
||||||
func (a *aliasModule) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (a *aliasModule) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
if err := c.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -120,10 +109,6 @@ func (a *aliasModule) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.Next(), nil
|
return c.Next(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface aliases
|
|
||||||
// resolve(alias)
|
|
||||||
// Tries to resolve an alias to its command.
|
|
||||||
// --- @param alias string
|
|
||||||
func (a *aliasModule) luaResolve(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (a *aliasModule) luaResolve(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
if err := c.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
13
api.go
13
api.go
|
@ -19,6 +19,7 @@ import (
|
||||||
rt "github.com/arnodel/golua/runtime"
|
rt "github.com/arnodel/golua/runtime"
|
||||||
"github.com/arnodel/golua/lib/packagelib"
|
"github.com/arnodel/golua/lib/packagelib"
|
||||||
"github.com/maxlandon/readline"
|
"github.com/maxlandon/readline"
|
||||||
|
"github.com/blackfireio/osinfo"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -113,12 +114,20 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
||||||
util.Document(fakeMod, "Hilbish's core API, containing submodules and functions which relate to the shell itself.")
|
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 := rt.NewTable()
|
||||||
|
|
||||||
|
util.SetField(rtm, hshuser, "config", rt.StringValue(confDir), "User's config directory")
|
||||||
|
util.SetField(rtm, hshuser, "data", rt.StringValue(userDataDir), "XDG data directory")
|
||||||
util.Document(hshuser, "User directories to store configs and/or modules.")
|
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 := rt.NewTable()
|
||||||
|
info, _ := osinfo.GetOSInfo()
|
||||||
|
|
||||||
|
util.SetField(rtm, hshos, "family", rt.StringValue(info.Family), "Family name of the current OS")
|
||||||
|
util.SetField(rtm, hshos, "name", rt.StringValue(info.Name), "Pretty name of the current OS")
|
||||||
|
util.SetField(rtm, hshos, "version", rt.StringValue(info.Version), "Version of the current OS")
|
||||||
util.Document(hshos, "OS info interface")
|
util.Document(hshos, "OS info interface")
|
||||||
mod.Set(rt.StringValue("os"), rt.TableValue(hshos))
|
mod.Set(rt.StringValue("os"), rt.TableValue(hshos))
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ type emmyPiece struct {
|
||||||
|
|
||||||
type module struct {
|
type module struct {
|
||||||
Docs []docPiece
|
Docs []docPiece
|
||||||
Properties []docPiece
|
|
||||||
ShortDescription string
|
ShortDescription string
|
||||||
Description string
|
Description string
|
||||||
ParentModule string
|
ParentModule string
|
||||||
|
@ -45,12 +44,6 @@ type docPiece struct {
|
||||||
GoFuncName string
|
GoFuncName string
|
||||||
IsInterface bool
|
IsInterface bool
|
||||||
IsMember bool
|
IsMember bool
|
||||||
Properties []docPiece
|
|
||||||
}
|
|
||||||
|
|
||||||
type tag struct {
|
|
||||||
id string
|
|
||||||
fields []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var docs = make(map[string]module)
|
var docs = make(map[string]module)
|
||||||
|
@ -74,31 +67,11 @@ func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||||
|
|
||||||
pts := strings.Split(docs, "\n")
|
pts := strings.Split(docs, "\n")
|
||||||
parts := []string{}
|
parts := []string{}
|
||||||
tags := make(map[string][]tag)
|
tags := make(map[string][]string)
|
||||||
for _, part := range pts {
|
for _, part := range pts {
|
||||||
if strings.HasPrefix(part, "#") {
|
if strings.HasPrefix(part, "#") {
|
||||||
tagParts := strings.Split(strings.TrimPrefix(part, "#"), " ")
|
tagParts := strings.Split(strings.TrimPrefix(part, "#"), " ")
|
||||||
if tags[tagParts[0]] == nil {
|
tags[tagParts[0]] = tagParts[1:]
|
||||||
var id string
|
|
||||||
if len(tagParts) > 1 {
|
|
||||||
id = tagParts[1]
|
|
||||||
}
|
|
||||||
tags[tagParts[0]] = []tag{
|
|
||||||
{id: id},
|
|
||||||
}
|
|
||||||
if len(tagParts) >= 2 {
|
|
||||||
tags[tagParts[0]][0].fields = tagParts[2:]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fleds := []string{}
|
|
||||||
if len(tagParts) >= 2 {
|
|
||||||
fleds = tagParts[2:]
|
|
||||||
}
|
|
||||||
tags[tagParts[0]] = append(tags[tagParts[0]], tag{
|
|
||||||
id: tagParts[1],
|
|
||||||
fields: fleds,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
parts = append(parts, part)
|
parts = append(parts, part)
|
||||||
}
|
}
|
||||||
|
@ -111,20 +84,11 @@ func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||||
funcdoc := []string{}
|
funcdoc := []string{}
|
||||||
|
|
||||||
if inInterface {
|
if inInterface {
|
||||||
interfaces = tags["interface"][0].id
|
interfaces = tags["interface"][0]
|
||||||
funcName = interfaces + "." + strings.Split(funcsig, "(")[0]
|
funcName = interfaces + "." + strings.Split(funcsig, "(")[0]
|
||||||
}
|
}
|
||||||
em := emmyPiece{FuncName: funcName}
|
em := emmyPiece{FuncName: funcName}
|
||||||
|
|
||||||
// manage properties
|
|
||||||
properties := []docPiece{}
|
|
||||||
for _, tag := range tags["property"] {
|
|
||||||
properties = append(properties, docPiece{
|
|
||||||
FuncName: tag.id,
|
|
||||||
Doc: tag.fields,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, d := range doc {
|
for _, d := range doc {
|
||||||
if strings.HasPrefix(d, "---") {
|
if strings.HasPrefix(d, "---") {
|
||||||
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
||||||
|
@ -159,7 +123,6 @@ func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||||
IsInterface: inInterface,
|
IsInterface: inInterface,
|
||||||
IsMember: isMember,
|
IsMember: isMember,
|
||||||
ParentModule: parentMod,
|
ParentModule: parentMod,
|
||||||
Properties: properties,
|
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(dps.GoFuncName, strings.ToLower("loader")) {
|
if strings.HasSuffix(dps.GoFuncName, strings.ToLower("loader")) {
|
||||||
dps.Doc = parts
|
dps.Doc = parts
|
||||||
|
@ -253,7 +216,6 @@ func main() {
|
||||||
desc := piece.Doc[1:]
|
desc := piece.Doc[1:]
|
||||||
interfaceModules[modname].ShortDescription = shortDesc
|
interfaceModules[modname].ShortDescription = shortDesc
|
||||||
interfaceModules[modname].Description = strings.Join(desc, "\n")
|
interfaceModules[modname].Description = strings.Join(desc, "\n")
|
||||||
interfaceModules[modname].Properties = piece.Properties
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
interfaceModules[modname].Docs = append(interfaceModules[modname].Docs, piece)
|
interfaceModules[modname].Docs = append(interfaceModules[modname].Docs, piece)
|
||||||
|
@ -294,18 +256,7 @@ func main() {
|
||||||
|
|
||||||
f, _ := os.Create(docPath)
|
f, _ := os.Create(docPath)
|
||||||
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
||||||
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n", modu.Description))
|
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n## Functions\n", modu.Description))
|
||||||
if len(modu.Properties) != 0 {
|
|
||||||
f.WriteString("## Properties\n")
|
|
||||||
for _, dps := range modu.Properties {
|
|
||||||
f.WriteString(fmt.Sprintf("- `%s`: ", dps.FuncName))
|
|
||||||
f.WriteString(strings.Join(dps.Doc, " "))
|
|
||||||
f.WriteString("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(modu.Docs) != 0 {
|
|
||||||
f.WriteString("## Functions\n")
|
|
||||||
}
|
|
||||||
for _, dps := range modu.Docs {
|
for _, dps := range modu.Docs {
|
||||||
f.WriteString(fmt.Sprintf("### %s\n", dps.FuncSig))
|
f.WriteString(fmt.Sprintf("### %s\n", dps.FuncSig))
|
||||||
for _, doc := range dps.Doc {
|
for _, doc := range dps.Doc {
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
---
|
|
||||||
name: Module hilbish
|
|
||||||
description: the core Hilbish API
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The Hilbish module includes the core API, containing
|
|
||||||
interfaces and functions which directly relate to shell functionality.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
### alias(cmd, orig)
|
|
||||||
Sets an alias of `cmd` to `orig`
|
|
||||||
|
|
||||||
### appendPath(dir)
|
|
||||||
Appends `dir` to $PATH
|
|
||||||
|
|
||||||
### complete(scope, cb)
|
|
||||||
Registers a completion handler for `scope`.
|
|
||||||
A `scope` is currently only expected to be `command.<cmd>`,
|
|
||||||
replacing <cmd> with the name of the command (for example `command.git`).
|
|
||||||
`cb` must be a function that returns a table of "completion groups."
|
|
||||||
Check `doc completions` for more information.
|
|
||||||
|
|
||||||
### cwd()
|
|
||||||
Returns the current directory of the shell
|
|
||||||
|
|
||||||
### exec(cmd)
|
|
||||||
Replaces running hilbish with `cmd`
|
|
||||||
|
|
||||||
### goro(fn)
|
|
||||||
Puts `fn` in a goroutine
|
|
||||||
|
|
||||||
### highlighter(line)
|
|
||||||
Line highlighter handler. This is mainly for syntax highlighting, but in
|
|
||||||
reality could set the input of the prompt to *display* anything. The
|
|
||||||
callback is passed the current line and is expected to return a line that
|
|
||||||
will be used as the input display.
|
|
||||||
|
|
||||||
### hinter(line, pos)
|
|
||||||
The command line hint handler. It gets called on every key insert to
|
|
||||||
determine what text to use as an inline hint. It is passed the current
|
|
||||||
line and cursor position. It is expected to return a string which is used
|
|
||||||
as the text for the hint. This is by default a shim. To set hints,
|
|
||||||
override this function with your custom handler.
|
|
||||||
|
|
||||||
### inputMode(mode)
|
|
||||||
Sets the input mode for Hilbish's line reader. Accepts either emacs or vim
|
|
||||||
|
|
||||||
### interval(cb, time)
|
|
||||||
Runs the `cb` function every `time` milliseconds.
|
|
||||||
Returns a `timer` object (see `doc timers`).
|
|
||||||
|
|
||||||
### multiprompt(str)
|
|
||||||
Changes the continued line prompt to `str`
|
|
||||||
|
|
||||||
### prependPath(dir)
|
|
||||||
Prepends `dir` to $PATH
|
|
||||||
|
|
||||||
### prompt(str, typ)
|
|
||||||
Changes the shell prompt to `str`
|
|
||||||
There are a few verbs that can be used in the prompt text.
|
|
||||||
These will be formatted and replaced with the appropriate values.
|
|
||||||
`%d` - Current working directory
|
|
||||||
`%u` - Name of current user
|
|
||||||
`%h` - Hostname of device
|
|
||||||
|
|
||||||
### read(prompt) -> input
|
|
||||||
Read input from the user, using Hilbish's line editor/input reader.
|
|
||||||
This is a separate instance from the one Hilbish actually uses.
|
|
||||||
Returns `input`, will be nil if ctrl + d is pressed, or an error occurs (which shouldn't happen)
|
|
||||||
|
|
||||||
### run(cmd, returnOut) -> exitCode, stdout, stderr
|
|
||||||
Runs `cmd` in Hilbish's sh interpreter.
|
|
||||||
If returnOut is true, the outputs of `cmd` will be returned as the 2nd and
|
|
||||||
3rd values instead of being outputted to the terminal.
|
|
||||||
|
|
||||||
### runnerMode(mode)
|
|
||||||
Sets the execution/runner mode for interactive Hilbish. This determines whether
|
|
||||||
Hilbish wll try to run input as Lua and/or sh or only do one of either.
|
|
||||||
Accepted values for mode are hybrid (the default), hybridRev (sh first then Lua),
|
|
||||||
sh, and lua. It also accepts a function, to which if it is passed one
|
|
||||||
will call it to execute user input instead.
|
|
||||||
|
|
||||||
### timeout(cb, time)
|
|
||||||
Runs the `cb` function after `time` in milliseconds
|
|
||||||
Returns a `timer` object (see `doc timers`).
|
|
||||||
|
|
||||||
### which(name)
|
|
||||||
Checks if `name` is a valid command
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
---
|
|
||||||
name: Interface hilbish.aliases
|
|
||||||
description: command aliasing
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The alias interface deals with all command aliases in Hilbish.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
### add(alias, cmd)
|
|
||||||
This is an alias (ha) for the `hilbish.alias` function.
|
|
||||||
|
|
||||||
### delete(name)
|
|
||||||
Removes an alias.
|
|
||||||
|
|
||||||
### list()
|
|
||||||
Get a table of all aliases.
|
|
||||||
|
|
||||||
### resolve(alias)
|
|
||||||
Tries to resolve an alias to its command.
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
---
|
|
||||||
name: Interface hilbish.completions
|
|
||||||
description: tab completions
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The completions interface deals with tab completions.
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
---
|
|
||||||
name: Interface hilbish.history
|
|
||||||
description: command history
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The history interface deals with command history.
|
|
||||||
This includes the ability to override functions to change the main
|
|
||||||
method of saving history.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
### add(cmd)
|
|
||||||
Adds a command to the history.
|
|
||||||
|
|
||||||
### clear()
|
|
||||||
Deletes all commands from the history.
|
|
||||||
|
|
||||||
### get(idx)
|
|
||||||
Retrieves a command from the history based on the `idx`.
|
|
||||||
|
|
||||||
### size()
|
|
||||||
Returns the amount of commands in the history.
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
---
|
|
||||||
name: Interface hilbish.os
|
|
||||||
description: OS Info
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The `os` interface provides simple text information properties about
|
|
||||||
the current OS on the systen. This mainly includes the name and
|
|
||||||
version.
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
- `family`: Family name of the current OS
|
|
||||||
- `name`: Pretty name of the current OS
|
|
||||||
- `version`: Version of the current OS
|
|
|
@ -1,15 +0,0 @@
|
||||||
---
|
|
||||||
name: Interface hilbish.timers
|
|
||||||
description: timeout and interval API
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
The timers interface si one to easily set timeouts and intervals
|
|
||||||
to run functions after a certain time or repeatedly without using
|
|
||||||
odd tricks.
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
### stop()
|
|
||||||
Stops a timer.
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
---
|
|
||||||
name: Interface hilbish.userDir
|
|
||||||
description: user-related directories
|
|
||||||
layout: apidoc
|
|
||||||
---
|
|
||||||
|
|
||||||
## Introduction
|
|
||||||
This interface just contains properties to know about certain user directories.
|
|
||||||
It is equivalent to XDG on Linux and gets the user's preferred directories
|
|
||||||
for configs and data.
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
- `config`: The user's config directory
|
|
||||||
- `data`: The user's directory for program data
|
|
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
local hilbish = {}
|
local hilbish = {}
|
||||||
|
|
||||||
--- This is an alias (ha) for the `hilbish.alias` function.
|
|
||||||
--- @param alias string
|
|
||||||
--- @param cmd string
|
|
||||||
function hilbish.aliases.add(alias, cmd) end
|
|
||||||
|
|
||||||
--- Sets an alias of `cmd` to `orig`
|
--- Sets an alias of `cmd` to `orig`
|
||||||
--- @param cmd string
|
--- @param cmd string
|
||||||
--- @param orig string
|
--- @param orig string
|
||||||
|
@ -116,30 +111,7 @@ function hilbish.which(name) end
|
||||||
--- Stops a timer.
|
--- Stops a timer.
|
||||||
function hilbish.timers:stop() end
|
function hilbish.timers:stop() end
|
||||||
|
|
||||||
--- Removes an alias.
|
|
||||||
--- @param name string
|
|
||||||
function hilbish.aliases.delete(name) end
|
|
||||||
|
|
||||||
--- Get a table of all aliases.
|
--- Get a table of all aliases.
|
||||||
function hilbish.aliases.list() end
|
function hilbish.aliases.list() end
|
||||||
|
|
||||||
--- Tries to resolve an alias to its command.
|
|
||||||
--- @param alias string
|
|
||||||
function hilbish.aliases.resolve(alias) end
|
|
||||||
|
|
||||||
--- Adds a command to the history.
|
|
||||||
--- @param cmd string
|
|
||||||
function hilbish.history.add(cmd) end
|
|
||||||
|
|
||||||
--- Deletes all commands from the history.
|
|
||||||
function hilbish.history.clear() end
|
|
||||||
|
|
||||||
--- Retrieves a command from the history based on the `idx`.
|
|
||||||
--- @param idx number
|
|
||||||
function hilbish.history.get(idx) end
|
|
||||||
|
|
||||||
--- Returns the amount of commands in the history.
|
|
||||||
--- @returns number
|
|
||||||
function hilbish.history.size() end
|
|
||||||
|
|
||||||
return hilbish
|
return hilbish
|
||||||
|
|
27
os.go
27
os.go
|
@ -1,27 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"hilbish/util"
|
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
|
||||||
"github.com/blackfireio/osinfo"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #interface os
|
|
||||||
// OS Info
|
|
||||||
// The `os` interface provides simple text information properties about
|
|
||||||
// the current OS on the systen. This mainly includes the name and
|
|
||||||
// version.
|
|
||||||
// #property family Family name of the current OS
|
|
||||||
// #property name Pretty name of the current OS
|
|
||||||
// #property version Version of the current OS
|
|
||||||
func hshosLoader(rtm *rt.Runtime) *rt.Table {
|
|
||||||
info, _ := osinfo.GetOSInfo()
|
|
||||||
mod := rt.NewTable()
|
|
||||||
|
|
||||||
util.SetField(rtm, mod, "family", rt.StringValue(info.Family), "Family name of the current OS")
|
|
||||||
util.SetField(rtm, mod, "name", rt.StringValue(info.Name), "Pretty name of the current OS")
|
|
||||||
util.SetField(rtm, mod, "version", rt.StringValue(info.Version), "Version of the current OS")
|
|
||||||
|
|
||||||
return mod
|
|
||||||
}
|
|
15
rl.go
15
rl.go
|
@ -245,10 +245,6 @@ func (lr *lineReader) Loader(rtm *rt.Runtime) *rt.Table {
|
||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface history
|
|
||||||
// add(cmd)
|
|
||||||
// Adds a command to the history.
|
|
||||||
// --- @param cmd string
|
|
||||||
func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
if err := c.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -262,18 +258,10 @@ func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error)
|
||||||
return c.Next(), nil
|
return c.Next(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface history
|
|
||||||
// size()
|
|
||||||
// Returns the amount of commands in the history.
|
|
||||||
// --- @returns number
|
|
||||||
func (lr *lineReader) luaSize(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (lr *lineReader) luaSize(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
return c.PushingNext1(t.Runtime, rt.IntValue(int64(lr.fileHist.Len()))), nil
|
return c.PushingNext1(t.Runtime, rt.IntValue(int64(lr.fileHist.Len()))), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface history
|
|
||||||
// get(idx)
|
|
||||||
// Retrieves a command from the history based on the `idx`.
|
|
||||||
// --- @param idx number
|
|
||||||
func (lr *lineReader) luaGetHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (lr *lineReader) luaGetHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
if err := c.Check1Arg(); err != nil {
|
if err := c.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -300,9 +288,6 @@ func (lr *lineReader) luaAllHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error)
|
||||||
return c.PushingNext1(t.Runtime, rt.TableValue(tbl)), nil
|
return c.PushingNext1(t.Runtime, rt.TableValue(tbl)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface history
|
|
||||||
// clear()
|
|
||||||
// Deletes all commands from the history.
|
|
||||||
func (lr *lineReader) luaClearHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
func (lr *lineReader) luaClearHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
lr.fileHist.clear()
|
lr.fileHist.clear()
|
||||||
return c.Next(), nil
|
return c.Next(), nil
|
||||||
|
|
23
userdir.go
23
userdir.go
|
@ -1,23 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"hilbish/util"
|
|
||||||
|
|
||||||
rt "github.com/arnodel/golua/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
// #interface userDir
|
|
||||||
// user-related directories
|
|
||||||
// This interface just contains properties to know about certain user directories.
|
|
||||||
// It is equivalent to XDG on Linux and gets the user's preferred directories
|
|
||||||
// for configs and data.
|
|
||||||
// #property config The user's config directory
|
|
||||||
// #property data The user's directory for program data
|
|
||||||
func userDirLoader(rtm *rt.Runtime) *rt.Table {
|
|
||||||
mod := rt.NewTable()
|
|
||||||
|
|
||||||
util.SetField(rtm, mod, "config", rt.StringValue(confDir), "User's config directory")
|
|
||||||
util.SetField(rtm, mod, "data", rt.StringValue(userDataDir), "XDG data directory")
|
|
||||||
|
|
||||||
return mod
|
|
||||||
}
|
|
Loading…
Reference in New Issue