diff --git a/docs/features/runner-mode.md b/docs/features/runner-mode.md index 0f7a8dd..ec804c1 100644 --- a/docs/features/runner-mode.md +++ b/docs/features/runner-mode.md @@ -33,19 +33,6 @@ needs to run interactive input. For more detail, see the [API documentation](../ The `hilbish.runner` interface is an alternative to using `hilbish.runnerMode` and also provides the shell script and Lua runner functions that Hilbish itself uses. -A runner function is expected to return a table with the following values: -- `exitCode` (number): Exit code of the command -- `input` (string): The text input of the user. This is used by Hilbish to append extra input, in case -more is requested. -- `err` (string): A string that represents an error from the runner. -This should only be set when, for example, there is a syntax error. -It can be set to a few special values for Hilbish to throw the right -hooks and have a better looking message. - - `: not-found` will throw a `command.not-found` hook - based on what `` is. - - `: not-executable` will throw a `command.not-executable` hook. -- `continue` (boolean): Whether Hilbish should prompt the user for no input - ## Functions These are the "low level" functions for the `hilbish.runner` interface. diff --git a/exec.go b/exec.go index e581893..357c143 100644 --- a/exec.go +++ b/exec.go @@ -138,15 +138,15 @@ func runInput(input string, priv bool) { } if cont { - input, err = reprompt(input, newline) + input, err = continuePrompt(input, newline) if err == nil { goto rerun } else if err == io.EOF { - return + lr.SetPrompt(fmtPrompt(prompt)) } } - if err != nil { + if err != nil && err != io.EOF { if exErr, ok := isExecError(err); ok { hooks.Emit("command." + exErr.typ, exErr.cmd) } else { diff --git a/main.go b/main.go index 7bb8014..1bddfc4 100644 --- a/main.go +++ b/main.go @@ -258,9 +258,12 @@ func continuePrompt(prev string, newline bool) (string, error) { return "", err } - if newline || strings.HasSuffix(cont, "\\") { - // a newline will get trimmed when this input is passed on, so we add 2 - cont = cont + "\n\n" + if newline { + cont = "\n" + cont + } + + if strings.HasSuffix(cont, "\\") { + cont = strings.TrimSuffix(cont, "\\") + "\n" } return prev + cont, nil diff --git a/runnermode.go b/runnermode.go index c6752f3..fb8bcf4 100644 --- a/runnermode.go +++ b/runnermode.go @@ -21,16 +21,18 @@ A runner is passed the input and has to return a table with these values. All are not required, only the useful ones the runner needs to return. (So if there isn't an error, just omit `err`.) -- `exitCode` (number): A numerical code to indicate the exit result. -- `input` (string): The user input. This will be used to add -to the history. -- `err` (string): A string to indicate an interal error for the runner. -It can be set to a few special values for Hilbish to throw the right hooks and have a better looking message: - -`[command]: not-found` will throw a command.not-found hook based on what `[command]` is. - -`[command]: not-executable` will throw a command.not-executable hook. -- `continue` (boolean): Whether to prompt the user for more input. +- `exitCode` (number): Exit code of the command +- `input` (string): The text input of the user. This is used by Hilbish to append extra input, in case +more is requested. +- `err` (string): A string that represents an error from the runner. +This should only be set when, for example, there is a syntax error. +It can be set to a few special values for Hilbish to throw the right +hooks and have a better looking message. + - `: not-found` will throw a `command.not-found` hook + based on what `` is. + - `: not-executable` will throw a `command.not-executable` hook. +- `continue` (boolean): Whether Hilbish should prompt the user for no input +- `newline` (boolean): Whether a newline should be added at the end of `input`. Here is a simple example of a fennel runner. It falls back to shell script if fennel eval has an error.