Compare commits

..

7 Commits

Author SHA1 Message Date
TorchedSammy 51b1219003
feat(bait): add catchOnce function 2021-12-04 17:59:19 -04:00
TorchedSammy dd45766bae
style: dont redeclare function param, just assign 2021-12-04 17:56:45 -04:00
TorchedSammy 144e158473
chore: remove unused function param 2021-12-04 17:56:11 -04:00
TorchedSammy dedb8cbf76
chore: make typ a local 2021-12-04 17:54:04 -04:00
TorchedSammy 284d4e01a3
chore: rename f to fname in subdoc map (doesnt redefine f) 2021-12-04 17:53:34 -04:00
TorchedSammy 3d36786cc7
chore: remove redundant returns 2021-12-04 17:53:10 -04:00
TorchedSammy 074c5f6766
fix: require lunacolors in preload 2021-12-04 17:50:04 -04:00
3 changed files with 17 additions and 15 deletions

View File

@ -38,6 +38,7 @@ failed, etc. To find all available hooks, see doc hooks.`)
L.SetField(mod, "throw", luar.New(L, b.bthrow)) L.SetField(mod, "throw", luar.New(L, b.bthrow))
L.SetField(mod, "catch", luar.New(L, b.bcatch)) L.SetField(mod, "catch", luar.New(L, b.bcatch))
L.SetField(mod, "catchOnce", luar.New(L, b.bcatchOnce))
L.Push(mod) L.Push(mod)
@ -55,3 +56,9 @@ func (b *Bait) bthrow(name string, args ...interface{}) {
func (b *Bait) bcatch(name string, catcher func(...interface{})) { func (b *Bait) bcatch(name string, catcher func(...interface{})) {
b.Em.On(name, catcher) b.Em.On(name, catcher)
} }
// catchOnce(name, cb)
// Same as catch, but only runs the `cb` once and then removes the hook
func (b *Bait) bcatchOnce(name string, catcher func(...interface{})) {
b.Em.Once(name, catcher)
}

View File

@ -5,11 +5,11 @@ local lunacolors = require 'lunacolors'
local ansikit = {} local ansikit = {}
ansikit.clear = function(scrollback) ansikit.clear = function(scrollback)
typ = (scrollback and 3 or 2) local typ = (scrollback and 3 or 2)
return ansikit.printCSI(typ, 'J') return ansikit.printCSI(typ, 'J')
end end
ansikit.clearFromPos = function(scrollback) ansikit.clearFromPos = function()
return ansikit.printCSI(0, 'J') return ansikit.printCSI(0, 'J')
end end
@ -79,7 +79,7 @@ end
ansikit.link = function(url, text) ansikit.link = function(url, text)
if not url then error 'ansikit: missing url for hyperlink' end if not url then error 'ansikit: missing url for hyperlink' end
local text = (text and text or 'link') text = (text and text or 'link')
return lunacolors.blue('\27]8;;' .. url .. '\27\\' .. text .. '\27]8;;\27\\\n') return lunacolors.blue('\27]8;;' .. url .. '\27\\' .. text .. '\27]8;;\27\\\n')
end end

View File

@ -1,9 +1,9 @@
-- The preload file initializes everything else for our shell -- The preload file initializes everything else for our shell
local fs = require 'fs'
local commander = require 'commander'
local bait = require 'bait' local bait = require 'bait'
require 'succulent' -- Function additions local commander = require 'commander'
local fs = require 'fs'
local lunacolors = require 'lunacolors'
local _ require 'succulent' -- Function additions
local oldDir = hilbish.cwd() local oldDir = hilbish.cwd()
local shlvl = tonumber(os.getenv 'SHLVL') local shlvl = tonumber(os.getenv 'SHLVL')
@ -37,8 +37,6 @@ commander.register('cd', function (args)
end end
fs.cd(hilbish.home) fs.cd(hilbish.home)
bait.throw('cd', hilbish.home) bait.throw('cd', hilbish.home)
return
end) end)
commander.register('exit', function() commander.register('exit', function()
@ -74,8 +72,8 @@ These are the global Hilbish functions that are always available and not part of
return return
end end
funcdocs = f:read '*a' funcdocs = f:read '*a'
local subdocs = table.map(fs.readdir(moddocPath), function(f) local subdocs = table.map(fs.readdir(moddocPath), function(fname)
return lunacolors.underline(lunacolors.blue(string.gsub(f, '.txt', ''))) return lunacolors.underline(lunacolors.blue(string.gsub(fname, '.txt', '')))
end) end)
if subdocName == 'index' then if subdocName == 'index' then
funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ') funcdocs = funcdocs .. '\nSubdocs: ' .. table.concat(subdocs, ', ')
@ -135,8 +133,6 @@ A section is a module or a literal section and a subdoc is a subsection for it.
Available sections: ]] Available sections: ]]
print(table.concat(modules, ', ')) print(table.concat(modules, ', '))
return
end) end)
do do
@ -207,7 +203,6 @@ to get a list of recent directories, use {green}{underline}cdr list{reset}]])
end end
fs.cd(recentDirs[index]) fs.cd(recentDirs[index])
return
end) end)
-- Hook handles -- Hook handles