1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-04-27 12:32:45 +02:00

#18 Updated REPL multiline

This commit is contained in:
Tim Voronov 2018-09-23 02:28:26 -04:00
parent 23b97c95b9
commit 33b51f626c
2 changed files with 19 additions and 7 deletions

View File

@ -28,6 +28,7 @@ func Repl(version string, opts Options) {
defer rl.Close() defer rl.Close()
var commands []string var commands []string
var multiline bool
timer := NewTimer() timer := NewTimer()
@ -44,16 +45,25 @@ func Repl(version string, opts Options) {
continue continue
} }
if strings.HasSuffix(line, "\\") { if strings.HasPrefix(line, "%") {
commands = append(commands, line[:len(line)-1]) line = line[1:]
multiline = !multiline
}
if multiline {
commands = append(commands, line)
continue continue
} }
commands = append(commands, line) commands = append(commands, line)
query := strings.Join(commands, "\n") query := strings.TrimSpace(strings.Join(commands, "\n"))
commands = make([]string, 0, 10) commands = make([]string, 0, 10)
if query == "" {
continue
}
program, err := ferret.Compile(query) program, err := ferret.Compile(query)
if err != nil { if err != nil {

View File

@ -83,10 +83,12 @@ func main() {
cdpConn, cdpConn,
} }
// check whether the app is getting a query via standard input stat, _ := os.Stdin.Stat()
std := bufio.NewReader(os.Stdin)
if (stat.Mode() & os.ModeCharDevice) == 0 {
// check whether the app is getting a query via standard input
std := bufio.NewReader(os.Stdin)
if std.Size() > 0 {
b, err := ioutil.ReadAll(std) b, err := ioutil.ReadAll(std)
if err != nil { if err != nil {