diff --git a/repl/repl.go b/repl/repl.go index 5423900250..4a48f80504 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -41,6 +41,8 @@ type REPL struct { cancelMu sync.Mutex cancelFunc context.CancelFunc + lineBuf string + enableSuggestions bool } @@ -201,6 +203,13 @@ func (r *REPL) evalWithFluxError(t string) ([]interpreter.SideEffect, *libflux.F // executeLine processes a line of input. // If the input evaluates to a valid value, that value is returned. func (r *REPL) executeLine(t string) (*libflux.FluxError, error) { + t = r.lineBuf + t + if strings.HasSuffix(t, "\\") { + r.lineBuf = t[:len(t)-1] + "\n" + return nil, nil + } + r.lineBuf = "" + ses, fluxError, err := r.evalWithFluxError(t) if err != nil { return fluxError, err diff --git a/repl/repl_test.go b/repl/repl_test.go new file mode 100644 index 0000000000..1081883bc3 --- /dev/null +++ b/repl/repl_test.go @@ -0,0 +1,27 @@ +package repl + +import ( + "context" + "testing" + + "github.com/influxdata/flux/fluxinit" + "github.com/stretchr/testify/require" +) + +func TestReplNewLine(t *testing.T) { + ctx := context.TODO() + fluxinit.FluxInit() + + r := New(ctx) + errI, err := r.executeLine(`import "sampledata"`) + require.Nil(t, errI) + require.Nil(t, err) + + errI, err = r.executeLine(`sampledata.int() \`) + require.Nil(t, errI) + require.Nil(t, err) + + errI, err = r.executeLine(`|> sum()`) + require.Nil(t, errI) + require.Nil(t, err) +}