mirror of https://github.com/Hilbis/Hilbish
parent
d3bd47963d
commit
972c6e44b3
42
main.go
42
main.go
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
_ "bufio"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
_ "os/exec"
|
||||
|
@ -23,7 +23,7 @@ import (
|
|||
|
||||
)
|
||||
|
||||
const version = "0.1.0"
|
||||
const version = "0.1.1"
|
||||
var l *lua.LState
|
||||
var prompt string
|
||||
var commands = map[string]bool{}
|
||||
|
@ -125,11 +125,44 @@ func main() {
|
|||
default:
|
||||
err := execCommand(cmdString)
|
||||
if err != nil {
|
||||
if syntax.IsIncomplete(err) {
|
||||
sb := &strings.Builder{}
|
||||
for {
|
||||
done := StartMultiline(cmdString, sb)
|
||||
if done {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||
if sb.String() == "" { sb.WriteString(prev + "\n") }
|
||||
|
||||
fmt.Printf("... ")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
cont, err := reader.ReadString('\n')
|
||||
if err == io.EOF {
|
||||
fmt.Println("")
|
||||
return true
|
||||
}
|
||||
|
||||
sb.WriteString(cont)
|
||||
|
||||
err = execCommand(sb.String())
|
||||
if err != nil && syntax.IsIncomplete(err) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func splitInput(input string) []string {
|
||||
quoted := false
|
||||
|
@ -161,10 +194,7 @@ func splitInput(input string) []string {
|
|||
func execCommand(cmd string) error {
|
||||
file, err := syntax.NewParser().Parse(strings.NewReader(cmd), "")
|
||||
if err != nil {
|
||||
if syntax.IsIncomplete(err) {
|
||||
fmt.Println("incomplete input")
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
runner, _ := interp.New(
|
||||
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
|
||||
|
|
Loading…
Reference in New Issue