diff --git a/docs/hooks/command.txt b/docs/hooks/command.txt new file mode 100644 index 0000000..f97f7e3 --- /dev/null +++ b/docs/hooks/command.txt @@ -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. diff --git a/docs/hooks/index.txt b/docs/hooks/index.txt new file mode 100644 index 0000000..53897ac --- /dev/null +++ b/docs/hooks/index.txt @@ -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: ++ -> > + +`` 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`. diff --git a/docs/hooks/signal.txt b/docs/hooks/signal.txt new file mode 100644 index 0000000..829a423 --- /dev/null +++ b/docs/hooks/signal.txt @@ -0,0 +1,3 @@ ++ `signal.sigint` > Sent when Hilbish receives SIGINT (used to Ctrl-C). + ++ `signal.resize` > Sent when the terminal is resized. diff --git a/preload.lua b/preload.lua index d7d8813..e5e9311 100644 --- a/preload.lua +++ b/preload.lua @@ -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//.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 +Usage: doc
[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, ', '))