Compare commits

..

No commits in common. "7961a441ad4a281fe689b9b53732480911eaf40f" and "f2ee600c280097f336609fbd0e9e16d47a3be899" have entirely different histories.

15 changed files with 62 additions and 98 deletions

View File

@ -216,11 +216,10 @@ func completionHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface completions // #interface completions
// call(name, query, ctx, fields) -> completionGroups (table), prefix (string) // call(name, query, ctx, fields)
// Calls a completer function. This is mainly used to call // Calls a completer function. This is mainly used to call
// a command completer, which will have a `name` in the form // a command completer, which will have a `name` in the form
// of `command.name`, example: `command.git`. // of `command.name`, example: `command.git`
// You can check `doc completions` for info on the `completionGroups` return value.
// --- @param name string // --- @param name string
// --- @param query string // --- @param query string
// --- @param ctx string // --- @param ctx string
@ -265,7 +264,7 @@ func callLuaCompleter(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface completions // #interface completions
// files(query, ctx, fields) -> entries (table), prefix (string) // files(query, ctx, fields)
// Returns file completion candidates based on the provided query. // Returns file completion candidates based on the provided query.
// --- @param query string // --- @param query string
// --- @param ctx string // --- @param ctx string
@ -287,7 +286,7 @@ func luaFileComplete(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface completions // #interface completions
// bins(query, ctx, fields) -> entries (table), prefix (string) // bins(query, ctx, fields)
// Returns binary/executale completion candidates based on the provided query. // Returns binary/executale completion candidates based on the provided query.
// --- @param query string // --- @param query string
// --- @param ctx string // --- @param ctx string

View File

@ -21,11 +21,11 @@ Catches a hook with `name`. Runs the `cb` when it is thrown
### catchOnce(name, cb) ### catchOnce(name, cb)
Same as catch, but only runs the `cb` once and then removes the hook Same as catch, but only runs the `cb` once and then removes the hook
### hooks(name) -> table ### hooks(name) -> {}
Returns a table with hooks (callback functions) on the event with `name`. Returns a table with hooks (callback functions) on the event with `name`.
### release(name, catcher) ### release(name, catcher)
Removes the `catcher` for the event with `name`. Removes the `catcher` for the event with `name`
For this to work, `catcher` has to be the same function used to catch For this to work, `catcher` has to be the same function used to catch
an event, like one saved to a variable. an event, like one saved to a variable.

View File

@ -13,25 +13,25 @@ and other things, and acts an addition to the Lua standard library's
I/O and filesystem functions. I/O and filesystem functions.
## Functions ## Functions
### abs(path) -> string ### abs(path)
Gives an absolute version of `path`. Gives an absolute version of `path`.
### basename(path) -> string ### basename(path)
Gives the basename of `path`. For the rules, Gives the basename of `path`. For the rules,
see Go's filepath.Base see Go's filepath.Base
### cd(dir) ### cd(dir)
Changes directory to `dir` Changes directory to `dir`
### dir(path) -> string ### dir(path)
Returns the directory part of `path`. For the rules, see Go's Returns the directory part of `path`. For the rules, see Go's
filepath.Dir filepath.Dir
### glob(pattern) -> matches (table) ### glob(pattern)
Glob all files and directories that match the pattern. Glob all files and directories that match the pattern.
For the rules, see Go's filepath.Glob For the rules, see Go's filepath.Glob
### join(...) -> string ### join(...)
Takes paths and joins them together with the OS's Takes paths and joins them together with the OS's
directory separator (forward or backward slash). directory separator (forward or backward slash).

View File

@ -11,19 +11,18 @@ menu:
The completions interface deals with tab completions. The completions interface deals with tab completions.
## Functions ## Functions
### call(name, query, ctx, fields) -> completionGroups (table), prefix (string) ### call(name, query, ctx, fields)
Calls a completer function. This is mainly used to call Calls a completer function. This is mainly used to call
a command completer, which will have a `name` in the form a command completer, which will have a `name` in the form
of `command.name`, example: `command.git`. of `command.name`, example: `command.git`
You can check `doc completions` for info on the `completionGroups` return value.
### handler(line, pos) ### handler(line, pos)
The handler function is the callback for tab completion in Hilbish. The handler function is the callback for tab completion in Hilbish.
You can check the completions doc for more info. You can check the completions doc for more info.
### bins(query, ctx, fields) -> entries (table), prefix (string) ### bins(query, ctx, fields)
Returns binary/executale completion candidates based on the provided query. Returns binary/executale completion candidates based on the provided query.
### files(query, ctx, fields) -> entries (table), prefix (string) ### files(query, ctx, fields)
Returns file completion candidates based on the provided query. Returns file completion candidates based on the provided query.

View File

@ -12,10 +12,10 @@ The hilbish.editor interface provides functions to
directly interact with the line editor in use. directly interact with the line editor in use.
## Functions ## Functions
### getLine() -> string ### getLine()
Returns the current input line. Returns the current input line.
### getVimRegister(register) -> string ### getVimRegister(register)
Returns the text that is at the register. Returns the text that is at the register.
### insert(text) ### insert(text)

View File

@ -16,15 +16,12 @@ method of saving history.
### add(cmd) ### add(cmd)
Adds a command to the history. Adds a command to the history.
### all() -> table
Retrieves all history.
### clear() ### clear()
Deletes all commands from the history. Deletes all commands from the history.
### get(idx) ### get(idx)
Retrieves a command from the history based on the `idx`. Retrieves a command from the history based on the `idx`.
### size() -> number ### size()
Returns the amount of commands in the history. Returns the amount of commands in the history.

View File

@ -1,56 +1,44 @@
Hilbish has a pretty good completion system. It has a nice looking Hilbish has a pretty good completion system. It has a nice looking menu,
menu, with 2 types of menus: grid (like file completions) or with 2 types of menus: grid (like file completions) or list.
list.
Like most parts of Hilbish, it's made to be extensible and Like most parts of Hilbish, it's made to be extensible and customizable.
customizable. The default handler for completions in general can The default handler for completions in general can be overwritten to provide
be overwritten to provide more advanced completions if needed. more advanced completions if needed.
# Completion Handler # Completion Handler
By default, it provides 3 things: for the first argument, By default, it provides 3 things: for the first argument, binaries (with a
binaries (with a plain name requested to complete, those in plain name requested to complete, those in $PATH), files, or command
$PATH), files, or command completions. With the default completions. With the default completion handler, it will try to run a
completion handler, it will try to run a handler for the handler for the command or fallback to file completions.
command or fallback to file completions.
To overwrite it, just assign a function to To overwrite it, just assign a function to `hilbish.completion.handler`
`hilbish.completion.handler` like so: like so:
function hilbish.completion.handler(line, pos) function hilbish.completion.handler(line, pos)
-- do things -- do things
end end
It is passed 2 arguments, the entire line, and the current cursor position.
It is passed 2 arguments, the entire line, and the current The functions in the completion interface take 3 arguments: query, ctx,
cursor position. The functions in the completion interface and fields. The `query`, which what the user is currently trying to complete,
take 3 arguments: query, ctx, and fields. `ctx`, being just the entire line, and `fields` being a table of arguments.
It's just `ctx` split up, delimited by spaces.
- The `query`, which what the user is currently trying to complete It's expected to return 2 things: a table of completion groups, and a prefix.
- `ctx`, being just the entire line A completion group is defined as a table with 2 keys: `items` and `type`.
- `fields` being a table of arguments. It's just `ctx` split up, The `items` field is just a table of items to use for completions.
delimited by spaces. The `type` is for the completion menu type, being either `grid` or `list`.
It's expected to return 2 things: a table of completion groups, and
a prefix. A completion group is defined as a table with 2 keys:
`items` and `type`.
- The `items` field is just a table of items to use for completions.
- The `type` is for the completion menu type, being either `grid` or
`list`.
The prefix is what all the completions start with. It should be empty The prefix is what all the completions start with. It should be empty
if the user doesn't have a query. If the beginning of the completion if the user doesn't have a query. If the beginning of the completion
item does not match the prefix, it will be replaced and fixed item does not match the prefix, it will be replaced and fixed properly
properly in the line. It is case sensitive. in the line. It is case sensitive.
If you want to overwrite the functionality of the general completion If you want to overwrite the functionality of the general completion handler,
handler, or make your command completion have files as well or make your command completion have files as well (and filter them),
(and filter them), then there is the `files` function, which is then there is the `files` function, which is mentioned below.
mentioned below.
# Completion Interface # Completion Interface
## Functions ## Functions
- `files(query, ctx, fields)` -> table, prefix: get file completions, - `files(query, ctx, fields)` -> table, prefix: get file completions, based
based on the user's query. on the user's query.
- `bins(query, ctx, fields)` -> table, prefix: get binary/executable - `bins(query, ctx, fields)` -> table, prefix: get binary/executable
completions, based on user query. completions, based on user query.
- `call(scope, query, ctx, fields)` -> table, prefix: call a completion - `call(scope, query, ctx, fields)` -> table, prefix: call a completion handler
handler with `scope`, usually being in the form of `command.<name>` with `scope`, usually being in the form of `command.<name>`

View File

@ -68,7 +68,7 @@ func editorSetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface editor // #interface editor
// getVimRegister(register) -> string // getVimRegister(register)
// Returns the text that is at the register. // Returns the text that is at the register.
// --- @param register string // --- @param register string
func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
@ -87,7 +87,7 @@ func editorGetRegister(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// #interface editor // #interface editor
// getLine() -> string // getLine()
// Returns the current input line. // Returns the current input line.
func editorGetLine(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func editorGetLine(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
buf := lr.rl.GetLine() buf := lr.rl.GetLine()

View File

@ -17,7 +17,7 @@ function bait.catchOnce(name, cb) end
--- @returns table<function> --- @returns table<function>
function bait.hooks(name) end function bait.hooks(name) end
--- Removes the `catcher` for the event with `name`. --- Removes the `catcher` for the event with `name`
--- For this to work, `catcher` has to be the same function used to catch --- For this to work, `catcher` has to be the same function used to catch
--- an event, like one saved to a variable. --- an event, like one saved to a variable.
--- @param name string --- @param name string

View File

@ -4,12 +4,10 @@ local fs = {}
--- Gives an absolute version of `path`. --- Gives an absolute version of `path`.
--- @param path string --- @param path string
--- @returns string
function fs.abs(path) end function fs.abs(path) end
--- Gives the basename of `path`. For the rules, --- Gives the basename of `path`. For the rules,
--- see Go's filepath.Base --- see Go's filepath.Base
--- @returns string
function fs.basename(path) end function fs.basename(path) end
--- Changes directory to `dir` --- Changes directory to `dir`
@ -19,19 +17,16 @@ function fs.cd(dir) end
--- Returns the directory part of `path`. For the rules, see Go's --- Returns the directory part of `path`. For the rules, see Go's
--- filepath.Dir --- filepath.Dir
--- @param path string --- @param path string
--- @returns string
function fs.dir(path) end function fs.dir(path) end
--- Glob all files and directories that match the pattern. --- Glob all files and directories that match the pattern.
--- For the rules, see Go's filepath.Glob --- For the rules, see Go's filepath.Glob
--- @param pattern string --- @param pattern string
--- @returns table
function fs.glob(pattern) end function fs.glob(pattern) end
--- Takes paths and joins them together with the OS's --- Takes paths and joins them together with the OS's
--- directory separator (forward or backward slash). --- directory separator (forward or backward slash).
--- @vararg string --- @vararg any
--- @returns string
function fs.join(...) end function fs.join(...) end
--- Makes a directory called `name`. If `recursive` is true, it will create its parent directories. --- Makes a directory called `name`. If `recursive` is true, it will create its parent directories.

View File

@ -16,8 +16,7 @@ function hilbish.runner.setMode(cb) end
--- Calls a completer function. This is mainly used to call --- Calls a completer function. This is mainly used to call
--- a command completer, which will have a `name` in the form --- a command completer, which will have a `name` in the form
--- of `command.name`, example: `command.git`. --- of `command.name`, example: `command.git`
--- You can check `doc completions` for info on the `completionGroups` return value.
--- @param name string --- @param name string
--- @param query string --- @param query string
--- @param ctx string --- @param ctx string
@ -243,10 +242,6 @@ function hilbish.jobs.last() end
--- @param cmd string --- @param cmd string
function hilbish.history.add(cmd) end function hilbish.history.add(cmd) end
--- Retrieves all history.
--- @returns table
function hilbish.history.all() end
--- Deletes all commands from the history. --- Deletes all commands from the history.
function hilbish.history.clear() end function hilbish.history.clear() end

View File

@ -280,7 +280,7 @@ func (b *Bait) bcatchOnce(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
} }
// release(name, catcher) // release(name, catcher)
// Removes the `catcher` for the event with `name`. // Removes the `catcher` for the event with `name`
// For this to work, `catcher` has to be the same function used to catch // For this to work, `catcher` has to be the same function used to catch
// an event, like one saved to a variable. // an event, like one saved to a variable.
// --- @param name string // --- @param name string
@ -296,7 +296,7 @@ func (b *Bait) brelease(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.Next(), nil return c.Next(), nil
} }
// hooks(name) -> table // hooks(name) -> {}
// Returns a table with hooks (callback functions) on the event with `name`. // Returns a table with hooks (callback functions) on the event with `name`.
// --- @param name string // --- @param name string
// --- @returns table<function> // --- @returns table<function>

View File

@ -151,10 +151,9 @@ func freaddir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext1(t.Runtime, rt.TableValue(names)), nil return c.PushingNext1(t.Runtime, rt.TableValue(names)), nil
} }
// abs(path) -> string // abs(path)
// Gives an absolute version of `path`. // Gives an absolute version of `path`.
// --- @param path string // --- @param path string
// --- @returns string
func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
path, err := c.StringArg(0) path, err := c.StringArg(0)
if err != nil { if err != nil {
@ -170,10 +169,9 @@ func fabs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil return c.PushingNext1(t.Runtime, rt.StringValue(abspath)), nil
} }
// basename(path) -> string // basename(path)
// Gives the basename of `path`. For the rules, // Gives the basename of `path`. For the rules,
// see Go's filepath.Base // see Go's filepath.Base
// --- @returns string
func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fbasename(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
@ -186,11 +184,10 @@ func fbasename(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Base(path))), nil return c.PushingNext(t.Runtime, rt.StringValue(filepath.Base(path))), nil
} }
// dir(path) -> string // dir(path)
// Returns the directory part of `path`. For the rules, see Go's // Returns the directory part of `path`. For the rules, see Go's
// filepath.Dir // filepath.Dir
// --- @param path string // --- @param path string
// --- @returns string
func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fdir(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
@ -203,11 +200,10 @@ func fdir(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext(t.Runtime, rt.StringValue(filepath.Dir(path))), nil return c.PushingNext(t.Runtime, rt.StringValue(filepath.Dir(path))), nil
} }
// glob(pattern) -> matches (table) // glob(pattern)
// Glob all files and directories that match the pattern. // Glob all files and directories that match the pattern.
// For the rules, see Go's filepath.Glob // For the rules, see Go's filepath.Glob
// --- @param pattern string // --- @param pattern string
// --- @returns table
func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fglob(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
@ -231,11 +227,10 @@ func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil
} }
// join(...) -> string // join(...)
// Takes paths and joins them together with the OS's // Takes paths and joins them together with the OS's
// directory separator (forward or backward slash). // directory separator (forward or backward slash).
// --- @vararg string // --- @vararg any
// --- @returns string
func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
strs := make([]string, len(c.Etc())) strs := make([]string, len(c.Etc()))
for i, v := range c.Etc() { for i, v := range c.Etc() {

6
rl.go
View File

@ -263,7 +263,7 @@ func (lr *lineReader) luaAddHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error)
} }
// #interface history // #interface history
// size() -> number // size()
// Returns the amount of commands in the history. // Returns the amount of commands in the history.
// --- @returns number // --- @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) {
@ -288,10 +288,6 @@ func (lr *lineReader) luaGetHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error)
return c.PushingNext1(t.Runtime, rt.StringValue(cmd)), nil return c.PushingNext1(t.Runtime, rt.StringValue(cmd)), nil
} }
// #interface history
// all() -> table
// Retrieves all history.
// --- @returns table
func (lr *lineReader) luaAllHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { func (lr *lineReader) luaAllHistory(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
tbl := rt.NewTable() tbl := rt.NewTable()
size := lr.fileHist.Len() size := lr.fileHist.Len()

View File

@ -12,7 +12,7 @@ var (
// Version info // Version info
var ( var (
ver = "v2.1.0" ver = "v2.1.0"
releaseName = "Pansy" releaseName = "Hibiscus"
gitCommit string gitCommit string
gitBranch string gitBranch string
) )