Compare commits

..

6 Commits

Author SHA1 Message Date
TorchedSammy 1eed4cc7ee
fix: add back empty string in command line split
this fixes file completion in normal usage without
using quotes. it basically cut out the space at the
end which prevented normal usage without adding an
additional space or using quotes for file
completion
2022-08-30 23:38:46 -04:00
TorchedSammy c13889592f
fix: pass alias expanded string to sh runner (fixes #201)
i have no idea why it didnt before, it *shouldnt*
introduce any problems and fixes this one.
2022-08-30 23:10:47 -04:00
TorchedSammy 2e192be2e1
refactor: setup autocd opt in a better way
with the previous commit allowing users to override
hilbish.runner.sh and it being ran by hilbish, the
code for the autocd opt can just override that
function and do the autocd functionality instead
of reimplementing a hybrid runner.

this means that if any other custom runner wants
autocd functionality they can have it with the sh runner
2022-08-30 23:08:22 -04:00
TorchedSammy c96605e79c
feat: allow hilbish.runner.sh to be overridden 2022-08-30 23:07:24 -04:00
TorchedSammy a1ce2ecba6
fix(readline): correct function to count len of prompt to accomodate east asian characters 2022-08-30 22:37:21 -04:00
TorchedSammy a1410ae7ad
fix: set prompt to normal after ctrl d exit
this prevents the prompt being stuck at the multiline
prompt instead of normal prompt after exiting
via the ctrl d bind
2022-08-30 21:52:07 -04:00
5 changed files with 22 additions and 16 deletions

View File

@ -27,6 +27,9 @@ func splitQuote(str string) []string {
sb.WriteRune(r) sb.WriteRune(r)
} }
} }
if strings.HasSuffix(str, " ") {
split = append(split, "")
}
if sb.Len() > 0 { if sb.Len() > 0 {
split = append(split, sb.String()) split = append(split, sb.String())

17
exec.go
View File

@ -101,7 +101,7 @@ func runInput(input string, priv bool) {
cmdFinish(0, input, priv) cmdFinish(0, input, priv)
return return
} }
input, exitCode, cont, err = handleSh(input) input, exitCode, cont, err = handleSh(cmdString)
case "hybridRev": case "hybridRev":
_, _, _, err = handleSh(input) _, _, _, err = handleSh(input)
if err == nil { if err == nil {
@ -112,7 +112,7 @@ func runInput(input string, priv bool) {
case "lua": case "lua":
input, exitCode, err = handleLua(cmdString) input, exitCode, err = handleLua(cmdString)
case "sh": case "sh":
input, exitCode, cont, err = handleSh(input) input, exitCode, cont, err = handleSh(cmdString)
} }
} else { } else {
// can only be a string or function so // can only be a string or function so
@ -152,6 +152,7 @@ func reprompt(input string) (string, error) {
for { for {
in, err := continuePrompt(strings.TrimSuffix(input, "\\")) in, err := continuePrompt(strings.TrimSuffix(input, "\\"))
if err != nil { if err != nil {
lr.SetPrompt(fmtPrompt(prompt))
return input, err return input, err
} }
@ -220,7 +221,17 @@ func handleLua(cmdString string) (string, uint8, error) {
return cmdString, 125, err return cmdString, 125, err
} }
func handleSh(cmdString string) (string, uint8, bool, error) { func handleSh(cmdString string) (input string, exitCode uint8, cont bool, runErr error) {
shRunner := hshMod.Get(rt.StringValue("runner")).AsTable().Get(rt.StringValue("sh"))
var err error
input, exitCode, cont, runErr, err = runLuaRunner(shRunner, cmdString)
if err != nil {
runErr = err
}
return
}
func execSh(cmdString string) (string, uint8, bool, error) {
_, _, err := execCommand(cmdString, true) _, _, err := execCommand(cmdString, true)
if err != nil { if err != nil {
// If input is incomplete, start multiline prompting // If input is incomplete, start multiline prompting

View File

@ -1,13 +1,8 @@
local fs = require 'fs' local fs = require 'fs'
function cdHandle(inp) local oldShRunner = hilbish.runner.sh
local res = hilbish.runner.lua(inp) function hilbish.runner.sh(input)
local res = oldShRunner(input)
if not res.err then
return res
end
res = hilbish.runner.sh(inp)
if res.exit ~= 0 and hilbish.opts.autocd then if res.exit ~= 0 and hilbish.opts.autocd then
local ok, stat = pcall(fs.stat, res.input) local ok, stat = pcall(fs.stat, res.input)
@ -21,5 +16,3 @@ function cdHandle(inp)
return res return res
end end
hilbish.runner.setMode(cdHandle)

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
ansi "github.com/acarl005/stripansi" ansi "github.com/acarl005/stripansi"
"github.com/rivo/uniseg"
) )
// SetPrompt will define the readline prompt string. // SetPrompt will define the readline prompt string.
@ -209,7 +208,7 @@ func (rl *Instance) colorizeVimPrompt(p []rune) (cp []rune) {
// getting its real-printed length. // getting its real-printed length.
func getRealLength(s string) (l int) { func getRealLength(s string) (l int) {
stripped := ansi.Strip(s) stripped := ansi.Strip(s)
return uniseg.GraphemeClusterCount(stripped) return getWidth([]rune(stripped))
} }
func (rl *Instance) echoRightPrompt() { func (rl *Instance) echoRightPrompt() {

View File

@ -28,7 +28,7 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return nil, err return nil, err
} }
input, exitCode, cont, err := handleSh(cmd) input, exitCode, cont, err := execSh(cmd)
var luaErr rt.Value = rt.NilValue var luaErr rt.Value = rt.NilValue
if err != nil { if err != nil {
luaErr = rt.StringValue(err.Error()) luaErr = rt.StringValue(err.Error())