docs: document available bait hooks

dev
TorchedSammy 2021-11-22 16:36:32 -05:00
parent c61b428d67
commit 52a6eb2125
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 49 additions and 8 deletions

View File

@ -0,0 +1,7 @@
+ `command.exit` -> code, cmdStr > Thrown when a command exits.
`code` is the exit code of the command, and `cmdStr` is the command that was run.
+ `command.not-found` -> cmdStr > Thrown when a command is not found.
+ `command.no-perm` -> cmdStr > Thrown when Hilbish attempts to execute a file but
has no permission.

View File

@ -0,0 +1,8 @@
Here is listed all scopes for bait hooks. If a hook is related to a command,
it will have the `command` scope, as example.
Here is the format for a doc for a hook:
+ <hook name> -> <args> > <description>
`<args>` just means the arguments of the hook. If a hook doc has the format
of `arg...`, it means the hook can take/recieve any number of `arg`.

View File

@ -0,0 +1,3 @@
+ `signal.sigint` > Sent when Hilbish receives SIGINT (used to Ctrl-C).
+ `signal.resize` > Sent when the terminal is resized.

View File

@ -50,18 +50,40 @@ commander.register('doc', function(args)
local globalDesc = [[
These are the global Hilbish functions that are always available and not part of a module.]]
if #args > 0 then
local mod = table.concat(args, ' '):gsub('^%s*(.-)%s*$', '%1')
local mod = args[1]
local f = io.open(moddocPath .. mod .. '.txt', 'rb')
if not f then
local funcdocs = nil
if not f then
-- assume subdir
-- dataDir/docs/<mod>/<mod>.txt
moddocPath = moddocPath .. mod .. '/'
local subdocName = args[2]
if not subdocName then
subdocName = 'index'
end
f = io.open(moddocPath .. subdocName .. '.txt', 'rb')
funcdocs = f:read '*a'
local subdocs = table.map(fs.readdir(moddocPath), function(f)
return lunacolors.underline(lunacolors.blue(string.gsub(f, '.txt', '')))
end)
if subdocName == 'index' then
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ')
end
end
if not f then
print('Could not find docs for module named ' .. mod .. '.')
return 1
end
local desc = (mod == 'global' and globalDesc or getmetatable(require(mod)).__doc)
local funcdocs = f:read '*a'
local desc = ''
local ok = pcall(require, mod)
if ok then
desc = (mod == 'global' and globalDesc or getmetatable(require(mod)).__doc) .. '\n\n'
end
local backtickOccurence = 0
print(desc .. '\n\n' .. lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function()
print(desc .. lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function()
backtickOccurence = backtickOccurence + 1
if backtickOccurence % 2 == 0 then
return '{reset}'
@ -74,16 +96,17 @@ These are the global Hilbish functions that are always available and not part of
return
end
local modules = table.map(fs.readdir(moddocPath), function(f)
return lunacolors.underline(lunacolors.blue(f:sub(1, -5)))
return lunacolors.underline(lunacolors.blue(string.gsub(f, '.txt', '')))
end)
io.write [[
Welcome to Hilbish's doc tool! Here you can find documentation for builtin
functions and other things.
Usage: doc <module>
Usage: doc <section> [subdoc]
A section is a module or a literal section and a subdoc is a subsection for it.
Available modules: ]]
Available sections: ]]
print(table.concat(modules, ', '))