feat: add fuzzy opt for fuzzy history searching

fuzzy-history-search
sammyette 2023-07-10 00:03:31 -04:00
parent 4593a2006c
commit b98239ac82
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 15 additions and 6 deletions

2
lua.go
View File

@ -68,7 +68,7 @@ func luaInit() {
} }
// Add more paths that Lua can require from // Add more paths that Lua can require from
err := util.DoString(l, "package.path = package.path .. " + requirePaths) _, err := util.DoString(l, "package.path = package.path .. " + requirePaths)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Could not add Hilbish require paths! Libraries will be missing. This shouldn't happen.") fmt.Fprintln(os.Stderr, "Could not add Hilbish require paths! Libraries will be missing. This shouldn't happen.")
} }

View File

@ -16,7 +16,7 @@ setmetatable(hilbish.opts, {
local function setupOpt(name, default) local function setupOpt(name, default)
opts[name] = default opts[name] = default
require('nature.opts.' .. name) pcall(require, 'nature.opts.' .. name)
end end
local defaultOpts = { local defaultOpts = {
@ -25,7 +25,8 @@ local defaultOpts = {
greeting = string.format([[Welcome to {magenta}Hilbish{reset}, {cyan}%s{reset}. greeting = string.format([[Welcome to {magenta}Hilbish{reset}, {cyan}%s{reset}.
The nice lil shell for {blue}Lua{reset} fanatics! The nice lil shell for {blue}Lua{reset} fanatics!
]], hilbish.user), ]], hilbish.user),
motd = true motd = true,
fuzzy = false
} }
for optsName, default in pairs(defaultOpts) do for optsName, default in pairs(defaultOpts) do

7
rl.go
View File

@ -25,7 +25,14 @@ func newLineReader(prompt string, noHist bool) *lineReader {
rl: rl, rl: rl,
} }
regexSearcher := rl.Searcher
rl.Searcher = func(needle string, haystack []string) []string { rl.Searcher = func(needle string, haystack []string) []string {
fz, _ := util.DoString(l, "return hilbish.opts.fuzzy")
fuzz, ok := fz.TryBool()
if !fuzz || !ok {
return regexSearcher(needle, haystack)
}
matches := fuzzy.Find(needle, haystack) matches := fuzzy.Find(needle, haystack)
suggs := make([]string, 0) suggs := make([]string, 0)

View File

@ -26,13 +26,14 @@ func SetFieldProtected(module, realModule *rt.Table, field string, value rt.Valu
} }
// DoString runs the code string in the Lua runtime. // DoString runs the code string in the Lua runtime.
func DoString(rtm *rt.Runtime, code string) error { func DoString(rtm *rt.Runtime, code string) (rt.Value, error) {
chunk, err := rtm.CompileAndLoadLuaChunk("<string>", []byte(code), rt.TableValue(rtm.GlobalEnv())) chunk, err := rtm.CompileAndLoadLuaChunk("<string>", []byte(code), rt.TableValue(rtm.GlobalEnv()))
var ret rt.Value
if chunk != nil { if chunk != nil {
_, err = rt.Call1(rtm.MainThread(), rt.FunctionValue(chunk)) ret, err = rt.Call1(rtm.MainThread(), rt.FunctionValue(chunk))
} }
return err return ret, err
} }
// DoFile runs the contents of the file in the Lua runtime. // DoFile runs the contents of the file in the Lua runtime.