mirror of
https://github.com/MontFerret/ferret.git
synced 2025-01-16 03:21:03 +02:00
#18 Updated REPL multiline
This commit is contained in:
parent
23b97c95b9
commit
33b51f626c
@ -28,6 +28,7 @@ func Repl(version string, opts Options) {
|
||||
defer rl.Close()
|
||||
|
||||
var commands []string
|
||||
var multiline bool
|
||||
|
||||
timer := NewTimer()
|
||||
|
||||
@ -44,16 +45,25 @@ func Repl(version string, opts Options) {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasSuffix(line, "\\") {
|
||||
commands = append(commands, line[:len(line)-1])
|
||||
if strings.HasPrefix(line, "%") {
|
||||
line = line[1:]
|
||||
|
||||
multiline = !multiline
|
||||
}
|
||||
|
||||
if multiline {
|
||||
commands = append(commands, line)
|
||||
continue
|
||||
}
|
||||
|
||||
commands = append(commands, line)
|
||||
query := strings.Join(commands, "\n")
|
||||
|
||||
query := strings.TrimSpace(strings.Join(commands, "\n"))
|
||||
commands = make([]string, 0, 10)
|
||||
|
||||
if query == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
program, err := ferret.Compile(query)
|
||||
|
||||
if err != nil {
|
||||
|
@ -83,10 +83,12 @@ func main() {
|
||||
cdpConn,
|
||||
}
|
||||
|
||||
// check whether the app is getting a query via standard input
|
||||
std := bufio.NewReader(os.Stdin)
|
||||
stat, _ := os.Stdin.Stat()
|
||||
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user