mirror of https://github.com/Hilbis/Hilbish
refactor!: rework docs and doc command (#218)
changes the actual file format of docs to markup since that's basically what we have been using in the first place. the docgen command has been modified to write markdown headings with the function name and yaml metadata for easy consumption by hugo for the website. all other docs have been moved to markdown as well this is the main reason this is a "breaking" change users will have to reinstall hilbish (task uninstall and task install) to remove the old plaintext docspull/220/head
parent
6525fa774e
commit
e5eefb1d2d
|
@ -2,13 +2,14 @@ name: Generate docs
|
|||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
gen:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v2
|
||||
- name: Run docgen
|
||||
run: go run cmd/docgen/docgen.go
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
*.exe
|
||||
hilbish
|
||||
!docs/api/hilbish
|
||||
docgen
|
||||
!cmd/docgen
|
||||
|
||||
.vim
|
||||
petals/
|
||||
|
|
45
aliases.go
45
aliases.go
|
@ -9,40 +9,40 @@ import (
|
|||
rt "github.com/arnodel/golua/runtime"
|
||||
)
|
||||
|
||||
var aliases *aliasHandler
|
||||
var aliases *aliasModule
|
||||
|
||||
type aliasHandler struct {
|
||||
type aliasModule struct {
|
||||
aliases map[string]string
|
||||
mu *sync.RWMutex
|
||||
}
|
||||
|
||||
// initialize aliases map
|
||||
func newAliases() *aliasHandler {
|
||||
return &aliasHandler{
|
||||
func newAliases() *aliasModule {
|
||||
return &aliasModule{
|
||||
aliases: make(map[string]string),
|
||||
mu: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
func (a *aliasHandler) Add(alias, cmd string) {
|
||||
func (a *aliasModule) Add(alias, cmd string) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
a.aliases[alias] = cmd
|
||||
}
|
||||
|
||||
func (a *aliasHandler) All() map[string]string {
|
||||
func (a *aliasModule) All() map[string]string {
|
||||
return a.aliases
|
||||
}
|
||||
|
||||
func (a *aliasHandler) Delete(alias string) {
|
||||
func (a *aliasModule) Delete(alias string) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
delete(a.aliases, alias)
|
||||
}
|
||||
|
||||
func (a *aliasHandler) Resolve(cmdstr string) string {
|
||||
func (a *aliasModule) Resolve(cmdstr string) string {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
|
||||
|
@ -66,7 +66,10 @@ func (a *aliasHandler) Resolve(cmdstr string) string {
|
|||
|
||||
// lua section
|
||||
|
||||
func (a *aliasHandler) Loader(rtm *rt.Runtime) *rt.Table {
|
||||
// #interface aliases
|
||||
// command aliasing
|
||||
// The alias interface deals with all command aliases in Hilbish.
|
||||
func (a *aliasModule) Loader(rtm *rt.Runtime) *rt.Table {
|
||||
// create a lua module with our functions
|
||||
hshaliasesLua := map[string]util.LuaExport{
|
||||
"add": util.LuaExport{hlalias, 2, false},
|
||||
|
@ -81,7 +84,17 @@ func (a *aliasHandler) Loader(rtm *rt.Runtime) *rt.Table {
|
|||
return mod
|
||||
}
|
||||
|
||||
func (a *aliasHandler) luaList(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
// #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
|
||||
// list()
|
||||
// Get a table of all aliases.
|
||||
func (a *aliasModule) luaList(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
aliasesList := rt.NewTable()
|
||||
for k, v := range a.All() {
|
||||
aliasesList.Set(rt.StringValue(k), rt.StringValue(v))
|
||||
|
@ -90,7 +103,11 @@ func (a *aliasHandler) luaList(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
return c.PushingNext1(t.Runtime, rt.TableValue(aliasesList)), nil
|
||||
}
|
||||
|
||||
func (a *aliasHandler) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
// #interface aliases
|
||||
// delete(name)
|
||||
// Removes an alias.
|
||||
// --- @param name string
|
||||
func (a *aliasModule) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
if err := c.Check1Arg(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -103,7 +120,11 @@ func (a *aliasHandler) luaDelete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
return c.Next(), nil
|
||||
}
|
||||
|
||||
func (a *aliasHandler) luaResolve(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
// #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) {
|
||||
if err := c.Check1Arg(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
44
api.go
44
api.go
|
@ -1,6 +1,14 @@
|
|||
// Here is the core api for the hilbi shell itself
|
||||
// Basically, stuff about the shell itself and other functions
|
||||
// go here.
|
||||
// the core Hilbish API
|
||||
// The Hilbish module includes the core API, containing
|
||||
// interfaces and functions which directly relate to shell functionality.
|
||||
// #field ver The version of Hilbish
|
||||
// #field user Username of the user
|
||||
// #field host Hostname of the machine
|
||||
// #field dataDir Directory for Hilbish data files, including the docs and default modules
|
||||
// #field interactive Is Hilbish in an interactive shell?
|
||||
// #field login Is Hilbish the login shell?
|
||||
// #field vimMode Current Vim input mode of Hilbish (will be nil if not in Vim input mode)
|
||||
// #field exitCode xit code of the last executed command
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -19,7 +27,6 @@ import (
|
|||
rt "github.com/arnodel/golua/runtime"
|
||||
"github.com/arnodel/golua/lib/packagelib"
|
||||
"github.com/maxlandon/readline"
|
||||
"github.com/blackfireio/osinfo"
|
||||
"mvdan.cc/sh/v3/interp"
|
||||
)
|
||||
|
||||
|
@ -114,20 +121,12 @@ 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.")
|
||||
|
||||
// hilbish.userDir table
|
||||
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")
|
||||
hshuser := userDirLoader(rtm)
|
||||
util.Document(hshuser, "User directories to store configs and/or modules.")
|
||||
mod.Set(rt.StringValue("userDir"), rt.TableValue(hshuser))
|
||||
|
||||
// hilbish.os table
|
||||
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")
|
||||
hshos := hshosLoader(rtm)
|
||||
util.Document(hshos, "OS info interface")
|
||||
mod.Set(rt.StringValue("os"), rt.TableValue(hshos))
|
||||
|
||||
|
@ -159,10 +158,10 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
|||
mod.Set(rt.StringValue("jobs"), rt.TableValue(jobModule))
|
||||
|
||||
// hilbish.timers table
|
||||
timers = newTimerHandler()
|
||||
timerModule := timers.loader(rtm)
|
||||
util.Document(timerModule, "Timer interface, for control of all intervals and timeouts.")
|
||||
mod.Set(rt.StringValue("timers"), rt.TableValue(timerModule))
|
||||
timers = newTimersModule()
|
||||
timersModule := timers.loader(rtm)
|
||||
util.Document(timersModule, "Timer interface, for control of all intervals and timeouts.")
|
||||
mod.Set(rt.StringValue("timers"), rt.TableValue(timersModule))
|
||||
|
||||
editorModule := editorLoader(rtm)
|
||||
util.Document(editorModule, "")
|
||||
|
@ -250,11 +249,12 @@ func hlcwd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
}
|
||||
|
||||
|
||||
// read(prompt?) -> input?
|
||||
// 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)
|
||||
// --- @param prompt string
|
||||
// --- @param prompt string|nil
|
||||
// --- @returns string|nil
|
||||
func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
luaprompt := c.Arg(0)
|
||||
if typ := luaprompt.Type(); typ != rt.StringType && typ != rt.NilType {
|
||||
|
@ -281,7 +281,7 @@ func hlread(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
}
|
||||
|
||||
/*
|
||||
prompt(str, typ?)
|
||||
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.
|
||||
|
@ -289,7 +289,7 @@ These will be formatted and replaced with the appropriate values.
|
|||
`%u` - Name of current user
|
||||
`%h` - Hostname of device
|
||||
--- @param str string
|
||||
--- @param typ string Type of prompt, being left or right. Left by default.
|
||||
--- @param typ string|nil Type of prompt, being left or right. Left by default.
|
||||
*/
|
||||
func hlprompt(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
err := c.Check1Arg()
|
||||
|
|
|
@ -9,26 +9,191 @@ import (
|
|||
"go/token"
|
||||
"strings"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type EmmyPiece struct {
|
||||
FuncName string
|
||||
Docs []string
|
||||
var header = `---
|
||||
title: %s %s
|
||||
description: %s
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
`
|
||||
|
||||
type emmyPiece struct {
|
||||
DocPiece *docPiece
|
||||
Annotations []string
|
||||
Params []string // we only need to know param name to put in function
|
||||
FuncName string
|
||||
}
|
||||
type DocPiece struct {
|
||||
|
||||
type module struct {
|
||||
Docs []docPiece
|
||||
Fields []docPiece
|
||||
Properties []docPiece
|
||||
ShortDescription string
|
||||
Description string
|
||||
ParentModule string
|
||||
HasInterfaces bool
|
||||
}
|
||||
|
||||
type docPiece struct {
|
||||
Doc []string
|
||||
FuncSig string
|
||||
FuncName string
|
||||
Interfacing string
|
||||
ParentModule string
|
||||
GoFuncName string
|
||||
IsInterface bool
|
||||
IsMember bool
|
||||
Fields []docPiece
|
||||
Properties []docPiece
|
||||
}
|
||||
|
||||
type tag struct {
|
||||
id string
|
||||
fields []string
|
||||
}
|
||||
|
||||
var docs = make(map[string]module)
|
||||
var interfaceDocs = make(map[string]module)
|
||||
var emmyDocs = make(map[string][]emmyPiece)
|
||||
var prefix = map[string]string{
|
||||
"main": "hl",
|
||||
"hilbish": "hl",
|
||||
"fs": "f",
|
||||
"commander": "c",
|
||||
"bait": "b",
|
||||
"terminal": "term",
|
||||
}
|
||||
|
||||
func getTagsAndDocs(docs string) (map[string][]tag, []string) {
|
||||
pts := strings.Split(docs, "\n")
|
||||
parts := []string{}
|
||||
tags := make(map[string][]tag)
|
||||
|
||||
for _, part := range pts {
|
||||
if strings.HasPrefix(part, "#") {
|
||||
tagParts := strings.Split(strings.TrimPrefix(part, "#"), " ")
|
||||
if tags[tagParts[0]] == nil {
|
||||
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 {
|
||||
parts = append(parts, part)
|
||||
}
|
||||
}
|
||||
|
||||
return tags, parts
|
||||
}
|
||||
|
||||
func docPieceTag(tagName string, tags map[string][]tag) []docPiece {
|
||||
dps := []docPiece{}
|
||||
for _, tag := range tags[tagName] {
|
||||
dps = append(dps, docPiece{
|
||||
FuncName: tag.id,
|
||||
Doc: tag.fields,
|
||||
})
|
||||
}
|
||||
|
||||
return dps
|
||||
}
|
||||
|
||||
func setupDoc(mod string, fun *doc.Func) *docPiece {
|
||||
docs := strings.TrimSpace(fun.Doc)
|
||||
inInterface := strings.HasPrefix(docs, "#interface")
|
||||
if (!strings.HasPrefix(fun.Name, prefix[mod]) && !inInterface) || (strings.ToLower(fun.Name) == "loader" && !inInterface) {
|
||||
return nil
|
||||
}
|
||||
|
||||
tags, parts := getTagsAndDocs(docs)
|
||||
|
||||
var interfaces string
|
||||
funcsig := parts[0]
|
||||
doc := parts[1:]
|
||||
funcName := strings.TrimPrefix(fun.Name, prefix[mod])
|
||||
funcdoc := []string{}
|
||||
|
||||
if inInterface {
|
||||
interfaces = tags["interface"][0].id
|
||||
funcName = interfaces + "." + strings.Split(funcsig, "(")[0]
|
||||
}
|
||||
em := emmyPiece{FuncName: funcName}
|
||||
|
||||
fields := docPieceTag("field", tags)
|
||||
properties := docPieceTag("property", tags)
|
||||
|
||||
for _, d := range doc {
|
||||
if strings.HasPrefix(d, "---") {
|
||||
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
||||
emmyLinePieces := strings.Split(emmyLine, " ")
|
||||
emmyType := emmyLinePieces[0]
|
||||
if emmyType == "@param" {
|
||||
em.Params = append(em.Params, emmyLinePieces[1])
|
||||
}
|
||||
if emmyType == "@vararg" {
|
||||
em.Params = append(em.Params, "...") // add vararg
|
||||
}
|
||||
em.Annotations = append(em.Annotations, d)
|
||||
} else {
|
||||
funcdoc = append(funcdoc, d)
|
||||
}
|
||||
}
|
||||
|
||||
var isMember bool
|
||||
if tags["member"] != nil {
|
||||
isMember = true
|
||||
}
|
||||
var parentMod string
|
||||
if inInterface {
|
||||
parentMod = mod
|
||||
}
|
||||
dps := &docPiece{
|
||||
Doc: funcdoc,
|
||||
FuncSig: funcsig,
|
||||
FuncName: funcName,
|
||||
Interfacing: interfaces,
|
||||
GoFuncName: strings.ToLower(fun.Name),
|
||||
IsInterface: inInterface,
|
||||
IsMember: isMember,
|
||||
ParentModule: parentMod,
|
||||
Fields: fields,
|
||||
Properties: properties,
|
||||
}
|
||||
if strings.HasSuffix(dps.GoFuncName, strings.ToLower("loader")) {
|
||||
dps.Doc = parts
|
||||
}
|
||||
em.DocPiece = dps
|
||||
|
||||
emmyDocs[mod] = append(emmyDocs[mod], em)
|
||||
return dps
|
||||
}
|
||||
|
||||
// feel free to clean this up
|
||||
// it works, dont really care about the code
|
||||
func main() {
|
||||
fset := token.NewFileSet()
|
||||
os.Mkdir("docs", 0777)
|
||||
os.Mkdir("docs/api", 0777)
|
||||
os.Mkdir("emmyLuaDocs", 0777)
|
||||
|
||||
|
||||
dirs := []string{"./"}
|
||||
filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
|
||||
|
@ -51,120 +216,172 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
prefix := map[string]string{
|
||||
"hilbish": "hl",
|
||||
"fs": "f",
|
||||
"commander": "c",
|
||||
"bait": "b",
|
||||
"terminal": "term",
|
||||
}
|
||||
docs := make(map[string][]DocPiece)
|
||||
emmyDocs := make(map[string][]EmmyPiece)
|
||||
|
||||
interfaceModules := make(map[string]*module)
|
||||
for l, f := range pkgs {
|
||||
p := doc.New(f, "./", doc.AllDecls)
|
||||
pieces := []docPiece{}
|
||||
mod := l
|
||||
if mod == "main" {
|
||||
mod = "hilbish"
|
||||
}
|
||||
var hasInterfaces bool
|
||||
for _, t := range p.Funcs {
|
||||
mod := l
|
||||
if strings.HasPrefix(t.Name, "hl") { mod = "hilbish" }
|
||||
if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" { continue }
|
||||
parts := strings.Split(strings.TrimSpace(t.Doc), "\n")
|
||||
funcsig := parts[0]
|
||||
doc := parts[1:]
|
||||
funcdoc := []string{}
|
||||
em := EmmyPiece{FuncName: strings.TrimPrefix(t.Name, prefix[mod])}
|
||||
for _, d := range doc {
|
||||
if strings.HasPrefix(d, "---") {
|
||||
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
||||
emmyLinePieces := strings.Split(emmyLine, " ")
|
||||
emmyType := emmyLinePieces[0]
|
||||
if emmyType == "@param" {
|
||||
em.Params = append(em.Params, emmyLinePieces[1])
|
||||
}
|
||||
if emmyType == "@vararg" {
|
||||
em.Params = append(em.Params, "...") // add vararg
|
||||
}
|
||||
em.Docs = append(em.Docs, d)
|
||||
} else {
|
||||
funcdoc = append(funcdoc, d)
|
||||
}
|
||||
piece := setupDoc(mod, t)
|
||||
if piece == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
dps := DocPiece{
|
||||
Doc: funcdoc,
|
||||
FuncSig: funcsig,
|
||||
FuncName: strings.TrimPrefix(t.Name, prefix[mod]),
|
||||
|
||||
pieces = append(pieces, *piece)
|
||||
if piece.IsInterface {
|
||||
hasInterfaces = true
|
||||
}
|
||||
|
||||
docs[mod] = append(docs[mod], dps)
|
||||
emmyDocs[mod] = append(emmyDocs[mod], em)
|
||||
}
|
||||
for _, t := range p.Types {
|
||||
for _, m := range t.Methods {
|
||||
if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue }
|
||||
parts := strings.Split(strings.TrimSpace(m.Doc), "\n")
|
||||
funcsig := parts[0]
|
||||
doc := parts[1:]
|
||||
funcdoc := []string{}
|
||||
em := EmmyPiece{FuncName: strings.TrimPrefix(m.Name, prefix[l])}
|
||||
for _, d := range doc {
|
||||
if strings.HasPrefix(d, "---") {
|
||||
emmyLine := strings.TrimSpace(strings.TrimPrefix(d, "---"))
|
||||
emmyLinePieces := strings.Split(emmyLine, " ")
|
||||
emmyType := emmyLinePieces[0]
|
||||
if emmyType == "@param" {
|
||||
em.Params = append(em.Params, emmyLinePieces[1])
|
||||
}
|
||||
if emmyType == "@vararg" {
|
||||
em.Params = append(em.Params, "...") // add vararg
|
||||
}
|
||||
em.Docs = append(em.Docs, d)
|
||||
} else {
|
||||
funcdoc = append(funcdoc, d)
|
||||
}
|
||||
}
|
||||
dps := DocPiece{
|
||||
Doc: funcdoc,
|
||||
FuncSig: funcsig,
|
||||
FuncName: strings.TrimPrefix(m.Name, prefix[l]),
|
||||
piece := setupDoc(mod, m)
|
||||
if piece == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
docs[l] = append(docs[l], dps)
|
||||
emmyDocs[l] = append(emmyDocs[l], em)
|
||||
pieces = append(pieces, *piece)
|
||||
if piece.IsInterface {
|
||||
hasInterfaces = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tags, descParts := getTagsAndDocs(strings.TrimSpace(p.Doc))
|
||||
shortDesc := descParts[0]
|
||||
desc := descParts[1:]
|
||||
filteredPieces := []docPiece{}
|
||||
for _, piece := range pieces {
|
||||
if !piece.IsInterface {
|
||||
filteredPieces = append(filteredPieces, piece)
|
||||
continue
|
||||
}
|
||||
|
||||
modname := piece.ParentModule + "." + piece.Interfacing
|
||||
if interfaceModules[modname] == nil {
|
||||
interfaceModules[modname] = &module{
|
||||
ParentModule: piece.ParentModule,
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasSuffix(piece.GoFuncName, strings.ToLower("loader")) {
|
||||
shortDesc := piece.Doc[0]
|
||||
desc := piece.Doc[1:]
|
||||
interfaceModules[modname].ShortDescription = shortDesc
|
||||
interfaceModules[modname].Description = strings.Join(desc, "\n")
|
||||
interfaceModules[modname].Fields = piece.Fields
|
||||
interfaceModules[modname].Properties = piece.Properties
|
||||
continue
|
||||
}
|
||||
interfaceModules[modname].Docs = append(interfaceModules[modname].Docs, piece)
|
||||
}
|
||||
|
||||
docs[mod] = module{
|
||||
Docs: filteredPieces,
|
||||
ShortDescription: shortDesc,
|
||||
Description: strings.Join(desc, "\n"),
|
||||
HasInterfaces: hasInterfaces,
|
||||
Properties: docPieceTag("property", tags),
|
||||
Fields: docPieceTag("field", tags),
|
||||
}
|
||||
}
|
||||
|
||||
for key, mod := range interfaceModules {
|
||||
docs[key] = *mod
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(docs) * 2)
|
||||
|
||||
for mod, v := range docs {
|
||||
if mod == "main" { continue }
|
||||
f, _ := os.Create("docs/" + mod + ".txt")
|
||||
for _, dps := range v {
|
||||
f.WriteString(dps.FuncSig + " > ")
|
||||
for _, doc := range dps.Doc {
|
||||
if !strings.HasPrefix(doc, "---") {
|
||||
f.WriteString(doc + "\n")
|
||||
}
|
||||
}
|
||||
f.WriteString("\n")
|
||||
docPath := "docs/api/" + mod + ".md"
|
||||
if v.HasInterfaces {
|
||||
os.Mkdir("docs/api/" + mod, 0777)
|
||||
os.Remove(docPath) // remove old doc path if it exists
|
||||
docPath = "docs/api/" + mod + "/_index.md"
|
||||
}
|
||||
}
|
||||
|
||||
for mod, v := range emmyDocs {
|
||||
if mod == "main" { continue }
|
||||
f, _ := os.Create("emmyLuaDocs/" + mod + ".lua")
|
||||
f.WriteString("--- @meta\n\nlocal " + mod + " = {}\n\n")
|
||||
for _, em := range v {
|
||||
var funcdocs []string
|
||||
for _, dps := range docs[mod] {
|
||||
if dps.FuncName == em.FuncName {
|
||||
funcdocs = dps.Doc
|
||||
}
|
||||
}
|
||||
f.WriteString("--- " + strings.Join(funcdocs, "\n--- ") + "\n")
|
||||
if len(em.Docs) != 0 {
|
||||
f.WriteString(strings.Join(em.Docs, "\n") + "\n")
|
||||
}
|
||||
f.WriteString("function " + mod + "." + em.FuncName + "(" + strings.Join(em.Params, ", ") + ") end\n\n")
|
||||
if v.ParentModule != "" {
|
||||
docPath = "docs/api/" + v.ParentModule + "/" + mod + ".md"
|
||||
}
|
||||
f.WriteString("return " + mod + "\n")
|
||||
|
||||
go func(modname, docPath string, modu module) {
|
||||
defer wg.Done()
|
||||
modOrIface := "Module"
|
||||
if modu.ParentModule != "" {
|
||||
modOrIface = "Interface"
|
||||
}
|
||||
|
||||
f, _ := os.Create(docPath)
|
||||
f.WriteString(fmt.Sprintf(header, modOrIface, modname, modu.ShortDescription))
|
||||
f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n", modu.Description))
|
||||
if len(modu.Fields) != 0 {
|
||||
f.WriteString("## Interface fields\n")
|
||||
for _, dps := range modu.Fields {
|
||||
f.WriteString(fmt.Sprintf("- `%s`: ", dps.FuncName))
|
||||
f.WriteString(strings.Join(dps.Doc, " "))
|
||||
f.WriteString("\n")
|
||||
}
|
||||
f.WriteString("\n")
|
||||
}
|
||||
if len(modu.Properties) != 0 {
|
||||
f.WriteString("## Object properties\n")
|
||||
for _, dps := range modu.Properties {
|
||||
f.WriteString(fmt.Sprintf("- `%s`: ", dps.FuncName))
|
||||
f.WriteString(strings.Join(dps.Doc, " "))
|
||||
f.WriteString("\n")
|
||||
}
|
||||
f.WriteString("\n")
|
||||
}
|
||||
if len(modu.Docs) != 0 {
|
||||
f.WriteString("## Functions\n")
|
||||
}
|
||||
for _, dps := range modu.Docs {
|
||||
f.WriteString(fmt.Sprintf("### %s\n", dps.FuncSig))
|
||||
for _, doc := range dps.Doc {
|
||||
if !strings.HasPrefix(doc, "---") {
|
||||
f.WriteString(doc + "\n")
|
||||
}
|
||||
}
|
||||
f.WriteString("\n")
|
||||
}
|
||||
}(mod, docPath, v)
|
||||
|
||||
go func(md, modname string, modu module) {
|
||||
defer wg.Done()
|
||||
|
||||
if modu.ParentModule != "" {
|
||||
return
|
||||
}
|
||||
|
||||
ff, _ := os.Create("emmyLuaDocs/" + modname + ".lua")
|
||||
ff.WriteString("--- @meta\n\nlocal " + modname + " = {}\n\n")
|
||||
for _, em := range emmyDocs[modname] {
|
||||
if strings.HasSuffix(em.DocPiece.GoFuncName, strings.ToLower("loader")) {
|
||||
continue
|
||||
}
|
||||
|
||||
dps := em.DocPiece
|
||||
funcdocs := dps.Doc
|
||||
ff.WriteString("--- " + strings.Join(funcdocs, "\n--- ") + "\n")
|
||||
if len(em.Annotations) != 0 {
|
||||
ff.WriteString(strings.Join(em.Annotations, "\n") + "\n")
|
||||
}
|
||||
accessor := "."
|
||||
if dps.IsMember {
|
||||
accessor = ":"
|
||||
}
|
||||
signature := strings.Split(dps.FuncSig, " ->")[0]
|
||||
var intrface string
|
||||
if dps.IsInterface {
|
||||
intrface = "." + dps.Interfacing
|
||||
}
|
||||
ff.WriteString("function " + modname + intrface + accessor + signature + " end\n\n")
|
||||
}
|
||||
ff.WriteString("return " + modname + "\n")
|
||||
}(mod, mod, v)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
|
19
complete.go
19
complete.go
|
@ -172,6 +172,9 @@ func escapeFilename(fname string) string {
|
|||
return escapeReplaer.Replace(fname)
|
||||
}
|
||||
|
||||
// #interface completions
|
||||
// tab completions
|
||||
// The completions interface deals with tab completions.
|
||||
func completionLoader(rtm *rt.Runtime) *rt.Table {
|
||||
exports := map[string]util.LuaExport{
|
||||
"files": {luaFileComplete, 3, false},
|
||||
|
@ -186,11 +189,19 @@ func completionLoader(rtm *rt.Runtime) *rt.Table {
|
|||
return mod
|
||||
}
|
||||
|
||||
// left as a shim, might doc in the same way as hilbish functions
|
||||
// #interface completions
|
||||
// handler(line, pos)
|
||||
// The handler function is the callback for tab completion in Hilbish.
|
||||
// You can check the completions doc for more info.
|
||||
func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
return c.Next(), nil
|
||||
}
|
||||
|
||||
// #interface completions
|
||||
// call(name, query, ctx, fields)
|
||||
// Calls a completer function. This is mainly used to call
|
||||
// a command completer, which will have a `name` in the form
|
||||
// of `command.name`, example: `command.git`
|
||||
func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
if err := c.CheckNArgs(4); err != nil {
|
||||
return nil, err
|
||||
|
@ -230,6 +241,9 @@ func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
return c.PushingNext1(t.Runtime, completerReturn), nil
|
||||
}
|
||||
|
||||
// #interface completions
|
||||
// files(query, ctx, fields)
|
||||
// Returns file completion candidates based on the provided query.
|
||||
func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
query, ctx, fds, err := getCompleteParams(t, c)
|
||||
if err != nil {
|
||||
|
@ -246,6 +260,9 @@ func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
return c.PushingNext(t.Runtime, rt.TableValue(luaComps), rt.StringValue(pfx)), nil
|
||||
}
|
||||
|
||||
// #interface completions
|
||||
// bins(query, ctx, fields)
|
||||
// Returns binary/executale completion candidates based on the provided query.
|
||||
func luaBinaryComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
query, ctx, fds, err := getCompleteParams(t, c)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
title: API
|
||||
layout: doc
|
||||
weight: -50
|
||||
menu: docs
|
||||
---
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: Module bait
|
||||
description: the event emitter
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
Bait is the event emitter for Hilbish. Why name it bait? Why not.
|
||||
It throws hooks that you can catch. 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 thrown by Hilbish, see doc hooks.
|
||||
|
||||
## Functions
|
||||
### catch(name, cb)
|
||||
Catches a hook with `name`. Runs the `cb` when it is thrown
|
||||
|
||||
### catchOnce(name, cb)
|
||||
Same as catch, but only runs the `cb` once and then removes the hook
|
||||
|
||||
### hooks(name) -> {cb, cb...}
|
||||
Returns a table with hooks on the event with `name`.
|
||||
|
||||
### release(name, catcher)
|
||||
Removes the `catcher` for the event with `name`
|
||||
For this to work, `catcher` has to be the same function used to catch
|
||||
an event, like one saved to a variable.
|
||||
|
||||
### throw(name, ...args)
|
||||
Throws a hook with `name` with the provided `args`
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
title: Module commander
|
||||
description: library for custom commands
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
Commander is a library for writing custom commands in Lua.
|
||||
|
||||
## Functions
|
||||
### deregister(name)
|
||||
Deregisters any command registered with `name`
|
||||
|
||||
### register(name, cb)
|
||||
Register a command with `name` that runs `cb` when ran
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
---
|
||||
title: Module fs
|
||||
description: filesystem interaction and functionality library
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
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.
|
||||
|
||||
## Functions
|
||||
### abs(path)
|
||||
Gives an absolute version of `path`.
|
||||
|
||||
### basename(path)
|
||||
Gives the basename of `path`. For the rules,
|
||||
see Go's filepath.Base
|
||||
|
||||
### cd(dir)
|
||||
Changes directory to `dir`
|
||||
|
||||
### dir(path)
|
||||
Returns the directory part of `path`. For the rules, see Go's
|
||||
filepath.Dir
|
||||
|
||||
### glob(pattern)
|
||||
Glob all files and directories that match the pattern.
|
||||
For the rules, see Go's filepath.Glob
|
||||
|
||||
### join(paths...)
|
||||
Takes paths and joins them together with the OS's
|
||||
directory separator (forward or backward slash).
|
||||
|
||||
### mkdir(name, recursive)
|
||||
Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
||||
|
||||
### readdir(dir)
|
||||
Returns a table of files in `dir`
|
||||
|
||||
### stat(path)
|
||||
Returns info about `path`
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
---
|
||||
title: Module hilbish
|
||||
description: the core Hilbish API
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
The Hilbish module includes the core API, containing
|
||||
interfaces and functions which directly relate to shell functionality.
|
||||
|
||||
## Interface fields
|
||||
- `ver`: The version of Hilbish
|
||||
- `user`: Username of the user
|
||||
- `host`: Hostname of the machine
|
||||
- `dataDir`: Directory for Hilbish data files, including the docs and default modules
|
||||
- `interactive`: Is Hilbish in an interactive shell?
|
||||
- `login`: Is Hilbish the login shell?
|
||||
- `vimMode`: Current Vim input mode of Hilbish (will be nil if not in Vim input mode)
|
||||
- `exitCode`: xit code of the last executed command
|
||||
|
||||
## 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
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
title: Interface hilbish.aliases
|
||||
description: command aliasing
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## 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.
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
title: Interface hilbish.completions
|
||||
description: tab completions
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
The completions interface deals with tab completions.
|
||||
|
||||
## Functions
|
||||
### call(name, query, ctx, fields)
|
||||
Calls a completer function. This is mainly used to call
|
||||
a command completer, which will have a `name` in the form
|
||||
of `command.name`, example: `command.git`
|
||||
|
||||
### handler(line, pos)
|
||||
The handler function is the callback for tab completion in Hilbish.
|
||||
You can check the completions doc for more info.
|
||||
|
||||
### bins(query, ctx, fields)
|
||||
Returns binary/executale completion candidates based on the provided query.
|
||||
|
||||
### files(query, ctx, fields)
|
||||
Returns file completion candidates based on the provided query.
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: Interface hilbish.editor
|
||||
description: interactions for Hilbish's line reader
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
The hilbish.editor interface provides functions to
|
||||
directly interact with the line editor in use.
|
||||
|
||||
## Functions
|
||||
### getLine()
|
||||
Returns the current input line.
|
||||
|
||||
### getVimRegister(register)
|
||||
Returns the text that is at the register.
|
||||
|
||||
### insert(text)
|
||||
Inserts text into the line.
|
||||
|
||||
### setVimRegister(register, text)
|
||||
Sets the vim register at `register` to hold the passed text.
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
title: Interface hilbish.history
|
||||
description: command history
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## 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.
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
---
|
||||
title: Interface hilbish.jobs
|
||||
description: background job management
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
Manage interactive jobs in Hilbish via Lua.
|
||||
|
||||
Jobs are the name of background tasks/commands. A job can be started via
|
||||
interactive usage or with the functions defined below for use in external runners.
|
||||
|
||||
## Object properties
|
||||
- `cmd`: The user entered command string for the job.
|
||||
- `running`: Whether the job is running or not.
|
||||
- `id`: The ID of the job in the job table
|
||||
- `pid`: The Process ID
|
||||
- `exitCode`: The last exit code of the job.
|
||||
- `stdout`: The standard output of the job. This just means the normal logs of the process.
|
||||
- `stderr`: The standard error stream of the process. This (usually) includes error messages of the job.
|
||||
|
||||
## Functions
|
||||
### background()
|
||||
Puts a job in the background. This acts the same as initially running a job.
|
||||
|
||||
### foreground()
|
||||
Puts a job in the foreground. This will cause it to run like it was
|
||||
executed normally and wait for it to complete.
|
||||
|
||||
### start()
|
||||
Starts running the job.
|
||||
|
||||
### stop()
|
||||
Stops the job from running.
|
||||
|
||||
### add(cmdstr, args, execPath)
|
||||
Adds a new job to the job table. Note that this does not immediately run it.
|
||||
|
||||
### all()
|
||||
Returns a table of all job objects.
|
||||
|
||||
### disown(id)
|
||||
Disowns a job. This deletes it from the job table.
|
||||
|
||||
### get(id)
|
||||
Get a job object via its ID.
|
||||
|
||||
### last() -> Job
|
||||
Returns the last added job from the table.
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
title: Interface hilbish.os
|
||||
description: OS Info
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
The `os` interface provides simple text information properties about
|
||||
the current OS on the systen. This mainly includes the name and
|
||||
version.
|
||||
|
||||
## Interface fields
|
||||
- `family`: Family name of the current OS
|
||||
- `name`: Pretty name of the current OS
|
||||
- `version`: Version of the current OS
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
title: Interface hilbish.runner
|
||||
description: interactive command runner customization
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
The runner interface contains functions that allow the user to change
|
||||
how Hilbish interprets interactive input.
|
||||
Users can add and change the default runner for interactive input to any
|
||||
language or script of their choosing. A good example is using it to
|
||||
write command in Fennel.
|
||||
|
||||
## Functions
|
||||
### setMode(cb)
|
||||
This is the same as the `hilbish.runnerMode` function. It takes a callback,
|
||||
which will be used to execute all interactive input.
|
||||
In normal cases, neither callbacks should be overrided by the user,
|
||||
as the higher level functions listed below this will handle it.
|
||||
|
||||
### lua(cmd)
|
||||
Evaluates `cmd` as Lua input. This is the same as using `dofile`
|
||||
or `load`, but is appropriated for the runner interface.
|
||||
|
||||
### sh(cmd)
|
||||
Runs a command in Hilbish's shell script interpreter.
|
||||
This is the equivalent of using `source`.
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: Interface hilbish.timers
|
||||
description: timeout and interval API
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## 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.
|
||||
|
||||
## Object properties
|
||||
- `type`: What type of timer it is
|
||||
- `running`: If the timer is running
|
||||
- `duration`: The duration in milliseconds that the timer will run
|
||||
|
||||
## Functions
|
||||
### start()
|
||||
Starts a timer.
|
||||
|
||||
### stop()
|
||||
Stops a timer.
|
||||
|
||||
### create(type, time, callback)
|
||||
Creates a timer that runs based on the specified `time` in milliseconds.
|
||||
The `type` can either be interval (value of 0) or timeout (value of 1).
|
||||
|
||||
### get(id)
|
||||
Retrieves a timer via its ID.
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: Interface hilbish.userDir
|
||||
description: user-related directories
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## 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.
|
||||
|
||||
## Interface fields
|
||||
- `config`: The user's config directory
|
||||
- `data`: The user's directory for program data
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
title: Module terminal
|
||||
description: low level terminal library
|
||||
layout: doc
|
||||
menu:
|
||||
docs:
|
||||
parent: "API"
|
||||
---
|
||||
|
||||
## Introduction
|
||||
The terminal library is a simple and lower level library for certain terminal interactions.
|
||||
|
||||
## Functions
|
||||
### restoreState()
|
||||
Restores the last saved state of the terminal
|
||||
|
||||
### saveState()
|
||||
Saves the current state of the terminal
|
||||
|
||||
### setRaw()
|
||||
Puts the terminal in raw mode
|
||||
|
||||
### size()
|
||||
Gets the dimensions of the terminal. Returns a table with `width` and `height`
|
||||
Note: this is not the size in relation to the dimensions of the display
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
catch(name, cb) > Catches a hook with `name`. Runs the `cb` when it is thrown
|
||||
|
||||
catchOnce(name, cb) > Same as catch, but only runs the `cb` once and then removes the hook
|
||||
|
||||
hooks(name) -> {cb, cb...} > Returns a table with hooks on the event with `name`.
|
||||
|
||||
release(name, catcher) > Removes the `catcher` for the event with `name`
|
||||
For this to work, `catcher` has to be the same function used to catch
|
||||
an event, like one saved to a variable.
|
||||
|
||||
throw(name, ...args) > Throws a hook with `name` with the provided `args`
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
deregister(name) > Deregisters any command registered with `name`
|
||||
|
||||
register(name, cb) > Register a command with `name` that runs `cb` when ran
|
||||
|
22
docs/fs.txt
22
docs/fs.txt
|
@ -1,22 +0,0 @@
|
|||
abs(path) > Gives an absolute version of `path`.
|
||||
|
||||
basename(path) > Gives the basename of `path`. For the rules,
|
||||
see Go's filepath.Base
|
||||
|
||||
cd(dir) > Changes directory to `dir`
|
||||
|
||||
dir(path) > Returns the directory part of `path`. For the rules, see Go's
|
||||
filepath.Dir
|
||||
|
||||
glob(pattern) > Glob all files and directories that match the pattern.
|
||||
For the rules, see Go's filepath.Glob
|
||||
|
||||
join(paths...) > Takes paths and joins them together with the OS's
|
||||
directory separator (forward or backward slash).
|
||||
|
||||
mkdir(name, recursive) > Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
|
||||
|
||||
readdir(dir) > Returns a table of files in `dir`
|
||||
|
||||
stat(path) > Returns info about `path`
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
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,9 +0,0 @@
|
|||
restoreState() > Restores the last saved state of the terminal
|
||||
|
||||
saveState() > Saves the current state of the terminal
|
||||
|
||||
setRaw() > Puts the terminal in raw mode
|
||||
|
||||
size() > Gets the dimensions of the terminal. Returns a table with `width` and `height`
|
||||
Note: this is not the size in relation to the dimensions of the display
|
||||
|
16
editor.go
16
editor.go
|
@ -6,6 +6,10 @@ import (
|
|||
rt "github.com/arnodel/golua/runtime"
|
||||
)
|
||||
|
||||
// #interface editor
|
||||
// interactions for Hilbish's line reader
|
||||
// The hilbish.editor interface provides functions to
|
||||
// directly interact with the line editor in use.
|
||||
func editorLoader(rtm *rt.Runtime) *rt.Table {
|
||||
exports := map[string]util.LuaExport{
|
||||
"insert": {editorInsert, 1, false},
|
||||
|
@ -20,6 +24,9 @@ func editorLoader(rtm *rt.Runtime) *rt.Table {
|
|||
return mod
|
||||
}
|
||||
|
||||
// #interface editor
|
||||
// insert(text)
|
||||
// Inserts text into the line.
|
||||
func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
if err := c.Check1Arg(); err != nil {
|
||||
return nil, err
|
||||
|
@ -35,6 +42,9 @@ func editorInsert(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
return c.Next(), nil
|
||||
}
|
||||
|
||||
// #interface editor
|
||||
|