Compare commits

...

4 Commits

Author SHA1 Message Date
sammyette e4833bdba9
feat: add command.preexec hook
it provides 2 arguments: what the user typed, and the command hilbish
will execute.
2021-10-14 08:51:29 -04:00
sammyette 63061e3a52
fix(bait): allow more than 1 argment for catch callback 2021-10-13 23:41:20 -04:00
sammyette 4596159b8f
feat: add command.precmd hook 2021-10-13 22:53:09 -04:00
sammyette 9eabe5323d
fix: throw command.exit with 0 code if input is nothing 2021-10-13 22:51:38 -04:00
4 changed files with 7 additions and 2 deletions

View File

@ -30,6 +30,6 @@ func (b *Bait) throw(name string, args ...interface{}) {
b.Em.Emit(name, args...)
}
func (b *Bait) catch(name string, catcher func(interface{})) {
func (b *Bait) catch(name string, catcher func(...interface{})) {
b.Em.On(name, catcher)
}

View File

@ -184,7 +184,10 @@ input:
}
input = strings.TrimSpace(input)
if len(input) == 0 { continue }
if len(input) == 0 {
hooks.Em.Emit("command.exit", 0)
continue
}
if strings.HasSuffix(input, "\\") {
for {

1
rl.go
View File

@ -22,6 +22,7 @@ func NewLineReader(prompt string) *LineReader {
}
func (lr *LineReader) Read() (string, error) {
hooks.Em.Emit("command.precmd", nil)
return readline.String(lr.Prompt)
}

View File

@ -31,6 +31,7 @@ func RunInput(input string) {
continue
}
}
hooks.Em.Emit("command.preexec", input, cmdString)
// First try to load input, essentially compiling to bytecode
fn, err := l.LoadString(cmdString)