From 08e29515133ee4c43e169a15378e4fb96c507163 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 10 Jul 2022 20:34:00 -0400 Subject: [PATCH 01/11] feat: add raw input hook (closes #180) --- CHANGELOG.md | 1 + lua.go | 4 ++++ readline/instance.go | 2 ++ readline/readline.go | 1 + 4 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3ab22b..42812d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ will be ran on startup - Message of the day on startup (`hilbish.motd`), mainly intended as quick small news pieces for releases. It is printed by default. To disable it, set `hilbish.opts.motd` to false. +- `hilbish.rawInput` hook for input from the readline library ### Changed - **Breaking Change:** Upgraded to Lua 5.4. diff --git a/lua.go b/lua.go index 8f3c0fb..d7eb823 100644 --- a/lua.go +++ b/lua.go @@ -48,6 +48,10 @@ func luaInit() { } }) + lr.rl.RawInputCallback = func(r []rune) { + hooks.Em.Emit("hilbish.rawInput", string(r)) + } + // Add more paths that Lua can require from err := util.DoString(l, "package.path = package.path .. " + requirePaths) if err != nil { diff --git a/readline/instance.go b/readline/instance.go index f04811e..fcd8379 100644 --- a/readline/instance.go +++ b/readline/instance.go @@ -198,6 +198,8 @@ type Instance struct { ViModeCallback func(ViMode) ViActionCallback func(ViAction, []string) + + RawInputCallback func([]rune) // called on all input } // NewInstance is used to create a readline instance and initialise it with sane defaults. diff --git a/readline/readline.go b/readline/readline.go index c00fda9..50d04b9 100644 --- a/readline/readline.go +++ b/readline/readline.go @@ -94,6 +94,7 @@ func (rl *Instance) Readline() (string, error) { rl.skipStdinRead = false r := []rune(string(b)) + rl.RawInputCallback(r[:i]) if isMultiline(r[:i]) || len(rl.multiline) > 0 { rl.multiline = append(rl.multiline, b[:i]...) From b65acca9037a5d687a2bfa769c9f8929fbb50543 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 10 Jul 2022 22:07:01 -0400 Subject: [PATCH 02/11] fix: initialize line reader before lua init --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index ce1a7f3..9e3068a 100644 --- a/main.go +++ b/main.go @@ -116,8 +116,8 @@ func main() { } go handleSignals() - luaInit() lr = newLineReader("", false) + luaInit() // If user's config doesn't exixt, if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath { // Read default from current directory From 2b480e50e69eb959485dd624efd60302ee383111 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 10:08:23 -0400 Subject: [PATCH 03/11] feat: print tracebacks for errors --- lua.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua.go b/lua.go index d7eb823..92ece05 100644 --- a/lua.go +++ b/lua.go @@ -12,12 +12,16 @@ import ( rt "github.com/arnodel/golua/runtime" "github.com/arnodel/golua/lib" + "github.com/arnodel/golua/lib/debuglib" ) var minimalconf = `hilbish.prompt '& '` func luaInit() { l = rt.New(os.Stdout) + l.PushContext(rt.RuntimeContextDef{ + MessageHandler: debuglib.Traceback, + }) lib.LoadAll(l) lib.LoadLibs(l, hilbishLoader) From e185a3268540c50681941115edc187aa3156760e Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 14:10:29 -0400 Subject: [PATCH 04/11] fix: expand tilde in dataDir on windows --- vars_windows.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vars_windows.go b/vars_windows.go index a257baf..78f459d 100644 --- a/vars_windows.go +++ b/vars_windows.go @@ -2,13 +2,17 @@ package main +import ( + "hilbish/util" +) + // String vars that are free to be changed at compile time var ( requirePaths = commonRequirePaths + `.. ';' .. hilbish.userDir.config .. '\\Hilbish\\libs\\?\\init.lua;' .. hilbish.userDir.config .. '\\Hilbish\\libs\\?\\?.lua;' .. hilbish.userDir.config .. '\\Hilbish\\libs\\?.lua;'` - dataDir = "~\\Appdata\\Roaming\\Hilbish" // ~ and \ gonna cry? + dataDir = util.ExpandHome("~\\Appdata\\Roaming\\Hilbish") // ~ and \ gonna cry? preloadPath = dataDir + "\\nature\\init.lua" sampleConfPath = dataDir + "\\hilbishrc.lua" // Path to default/sample config defaultConfDir = "" From be8bdef9c895a6a04da476a39e665380cad86278 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 14:18:23 -0400 Subject: [PATCH 05/11] style: use single line import instead of list syntax --- vars_windows.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vars_windows.go b/vars_windows.go index 78f459d..403941f 100644 --- a/vars_windows.go +++ b/vars_windows.go @@ -2,9 +2,7 @@ package main -import ( - "hilbish/util" -) +import "hilbish/util" // String vars that are free to be changed at compile time var ( From dd9aa4b6ea58b9cd6dde5e4a178edb9184f68e76 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:04:18 -0400 Subject: [PATCH 06/11] fix: enable vt input for windows --- init_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init_windows.go b/init_windows.go index ee17a6b..0d74ba9 100644 --- a/init_windows.go +++ b/init_windows.go @@ -7,5 +7,5 @@ import "golang.org/x/sys/windows" func init() { var mode uint32 windows.GetConsoleMode(windows.Stdout, &mode) - windows.SetConsoleMode(windows.Stdout, mode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) + windows.SetConsoleMode(windows.Stdout, mode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.ENABLE_VIRTUAL_TERMINAL_INPUT) } From 990256006166c8be5e27d9c0ce4068cfa0d8a8bf Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:11:06 -0400 Subject: [PATCH 07/11] fix: set vt in on stdin --- init_windows.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/init_windows.go b/init_windows.go index 0d74ba9..825069d 100644 --- a/init_windows.go +++ b/init_windows.go @@ -5,7 +5,13 @@ package main import "golang.org/x/sys/windows" func init() { - var mode uint32 - windows.GetConsoleMode(windows.Stdout, &mode) - windows.SetConsoleMode(windows.Stdout, mode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.ENABLE_VIRTUAL_TERMINAL_INPUT) + // vt output (escape codes) + var outMode uint32 + windows.GetConsoleMode(windows.Stdout, &outMode) + windows.SetConsoleMode(windows.Stdout, outMode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) + + // vt input + var inMode uint32 + windows.GetConsoleMode(windows.Stdin, &inMode) + windows.SetConsoleMode(windows.Stdin, inMode | windows.ENABLE_VIRTUAL_TERMINAL_INPUT) } From dd9bdca5e05bea8ba5623b400b1dd82963fbc7f3 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:35:33 -0400 Subject: [PATCH 08/11] fix(readline): only call raw input callback if not nil --- readline/readline.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readline/readline.go b/readline/readline.go index 50d04b9..731e297 100644 --- a/readline/readline.go +++ b/readline/readline.go @@ -94,7 +94,9 @@ func (rl *Instance) Readline() (string, error) { rl.skipStdinRead = false r := []rune(string(b)) - rl.RawInputCallback(r[:i]) + if rl.RawInputCallback != nil { + rl.RawInputCallback(r[:i]) + } if isMultiline(r[:i]) || len(rl.multiline) > 0 { rl.multiline = append(rl.multiline, b[:i]...) From 083c2664386ddcb5eb699e3738e53b9063b678fb Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:38:07 -0400 Subject: [PATCH 09/11] feat(golibs/fs): add join function to join path elements --- golibs/fs/fs.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index 88a04c5..5b12e73 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -1,6 +1,7 @@ package fs import ( + "fmt" "path/filepath" "strconv" "os" @@ -27,6 +28,7 @@ func loaderFunc(rtm *rt.Runtime) (rt.Value, func()) { "basename": util.LuaExport{fbasename, 1, false}, "dir": util.LuaExport{fdir, 1, false}, "glob": util.LuaExport{fglob, 1, false}, + "join": util.LuaExport{fjoin, 0, true}, } mod := rt.NewTable() util.SetExports(rtm, mod, exports) @@ -216,3 +218,21 @@ func fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil } + +// join(paths...) +// Takes paths and joins them together with the OS's +// directory separator (forward or backward slash). +func fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { + strs := make([]string, len(c.Etc())) + for i, v := range c.Etc() { + if v.Type() != rt.StringType { + // +2; go indexes of 0 and first arg from above + return nil, fmt.Errorf("bad argument #%d to run (expected string, got %s)", i + 1, v.TypeName()) + } + strs[i] = v.AsString() + } + + res := filepath.Join(strs...) + + return c.PushingNext(t.Runtime, rt.StringValue(res)), nil +} From c8c30e9861d23e730e71a68f928df54b65807614 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 13 Jul 2022 15:46:18 -0400 Subject: [PATCH 10/11] docs: update changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42812d4..997d3de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ having and using multiple runners. - `fs.basename(path)` gets the basename of path - `fs.dir(path)` gets the directory part of path - `fs.glob(pattern)` globs files and directories based on patterns + - `fs.join(dirs...)` joins directories by OS dir separator - .. and 2 properties - `fs.pathSep` is the separator for filesystem paths and directories - `fs.pathListSep` is the separator for $PATH env entries @@ -66,6 +67,7 @@ will be ran on startup small news pieces for releases. It is printed by default. To disable it, set `hilbish.opts.motd` to false. - `hilbish.rawInput` hook for input from the readline library +- Completion of files in quotes ### Changed - **Breaking Change:** Upgraded to Lua 5.4. @@ -122,6 +124,14 @@ for explanation. Lua `job.stop` function. - Jobs are always started in sh exec handler now instead of only successful start. - SIGTERM is handled properly now, which means stopping jobs and timers. +- Fix panic on trailing newline on pasted multiline text. +- Completions will no longer be refreshed if the prompt refreshes while the +menu is open. +- Print error on search fail instead of panicking +- Windows related fixes: + - `hilbish.dataDir` now has tilde (`~`) expanded. + - Arrow keys now work on Windows terminals. + - Escape codes now work. ## [1.2.0] - 2022-03-17 ### Added From f7806f54798812854fad0ae60f28083c9cead402 Mon Sep 17 00:00:00 2001 From: TorchedSammy Date: Wed, 13 Jul 2022 19:46:40 +0000 Subject: [PATCH 11/11] docs: [ci] generate new docs --- docs/fs.txt | 3 +++ emmyLuaDocs/fs.lua | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/docs/fs.txt b/docs/fs.txt index c3d173e..8372afd 100644 --- a/docs/fs.txt +++ b/docs/fs.txt @@ -11,6 +11,9 @@ filepath.Dir glob(pattern) > Glob all files and directories that match the pattern. For the rules, see Go's filepath.Glob +join(paths...) > Takes paths and joins them together with the OS's +directory separator (forward or backward slash). + mkdir(name, recursive) > Makes a directory called `name`. If `recursive` is true, it will create its parent directories. readdir(dir) > Returns a table of files in `dir` diff --git a/emmyLuaDocs/fs.lua b/emmyLuaDocs/fs.lua index 5fbfb2b..14e7be4 100644 --- a/emmyLuaDocs/fs.lua +++ b/emmyLuaDocs/fs.lua @@ -22,6 +22,10 @@ function fs.dir() end --- For the rules, see Go's filepath.Glob function fs.glob() end +--- Takes paths and joins them together with the OS's +--- directory separator (forward or backward slash). +function fs.join() end + --- Makes a directory called `name`. If `recursive` is true, it will create its parent directories. --- @param name string --- @param recursive boolean