From 9d8dff554be3954731f879be4d4f94aa52ec99d3 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Sun, 1 Sep 2024 19:50:55 -0700 Subject: [PATCH] Remove limits now that we have ^C. Use fixed version of fortio/terminal (#201) * remove limits now that we have ^c * Use fixed version of fortio/terminal --- eval/eval.go | 5 ----- go.mod | 2 +- go.sum | 4 ++-- main.go | 3 ++- main_test.txtar | 2 +- repl/repl.go | 4 ++-- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/eval/eval.go b/eval/eval.go index 1275df5b..51733541 100644 --- a/eval/eval.go +++ b/eval/eval.go @@ -802,7 +802,6 @@ func (s *State) evalForExpression(fe *ast.ForExpression) object.Object { // Other: condition or number of iterations for loop. var lastEval object.Object lastEval = object.NULL - count := 0 for { condition := s.evalInternal(fe.Condition) switch condition { @@ -825,10 +824,6 @@ func (s *State) evalForExpression(fe *ast.ForExpression) object.Object { return s.NewError("for condition is not a boolean nor integer nor assignment: " + condition.Inspect()) } } - count++ - if s.depth+count > s.MaxDepth { - return s.NewError("too many for loop iterations") - } } } diff --git a/go.mod b/go.mod index 10687b3d..de63b2cb 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( fortio.org/log v1.16.0 fortio.org/sets v1.2.0 fortio.org/struct2env v0.4.1 - fortio.org/terminal v0.8.0 + fortio.org/terminal v0.8.1 fortio.org/testscript v0.3.1 // only for tests fortio.org/version v1.0.4 github.com/rivo/uniseg v0.4.7 diff --git a/go.sum b/go.sum index 2fcdef1a..3876da83 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ fortio.org/struct2env v0.4.1 h1:rJludAMO5eBvpWplWEQNqoVDFZr4RWMQX7RUapgZyc0= fortio.org/struct2env v0.4.1/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= fortio.org/term v0.23.0-fortio-6 h1:pKrUX0tKOxyEhkhLV50oJYucTVx94rzFrXc24lIuLvk= fortio.org/term v0.23.0-fortio-6/go.mod h1:7buBfn81wEJUGWiVjFNiUE/vxWs5FdM9c7PyZpZRS30= -fortio.org/terminal v0.8.0 h1:NSaa/JQZ4lIK08QEfBExwuzNY/bXfkzZzpfuPB7MlEA= -fortio.org/terminal v0.8.0/go.mod h1:hRs4ZM5C06GyfLRD6JHD96yjJGgm1mXQH75Ze8CMLjw= +fortio.org/terminal v0.8.1 h1:atT8OyR+w65k3RgHjjUz1A7ar51SVxiSRFVpPNzZ4xM= +fortio.org/terminal v0.8.1/go.mod h1:4mFl6U7FmnQ+D/NZuxq05QDX/guBTwCRb2+DxTOj4Tg= fortio.org/testscript v0.3.1 h1:MmRO64AsmzaU1KlYMzAbotJIMKRGxD1XXssJnBRiMGQ= fortio.org/testscript v0.3.1/go.mod h1:7OJ+U4avooRNqc7p/VHKJadYgj9fA6+N0SbGU8FVWGs= fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U= diff --git a/main.go b/main.go index 2f8c4f79..7757fa76 100644 --- a/main.go +++ b/main.go @@ -67,7 +67,8 @@ func Main() (retcode int) { maxDepth := flag.Int("max-depth", eval.DefaultMaxDepth-1, "Maximum interpreter depth") maxLen := flag.Int("max-save-len", 4000, "Maximum len of saved identifiers, use 0 for unlimited") panicOk := flag.Bool("panic", false, "Don't catch panic - only for development/debugging") - maxDuration := flag.Duration("max-duration", eval.DefaultMaxDuration, "Maximum duration for a script to run. 0 for unlimited.") + // Use 0 (unlimited) as default now that you can ^C to stop a script. + maxDuration := flag.Duration("max-duration", 0, "Maximum duration for a script to run. 0 for unlimited.") cli.ArgsHelp = "*.gr files to interpret or `-` for stdin without prompt or no arguments for stdin repl..." cli.MaxArgs = -1 diff --git a/main_test.txtar b/main_test.txtar index fe08449d..e4ffcfff 100644 --- a/main_test.txtar +++ b/main_test.txtar @@ -23,7 +23,7 @@ stderr welcome !stderr 'rror' # no Errors or other case/singular/plural # syntax error non mode, stdout doesn't repeat errors -!grol -c 'foo' +!grol -no-auto -c 'foo' stderr 'Total 1 error' stderr 'identifier not found: foo' !stdout . diff --git a/repl/repl.go b/repl/repl.go index e2db1048..c67cb89a 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -253,8 +253,8 @@ func Interactive(options Options) int { //nolint:funlen // we do have quite a fe _ = AutoSave(s, options) return 0 } - if errors.Is(err, terminal.ErrInterrupted) { - log.Debugf("Interrupted error") + if errors.Is(err, terminal.ErrUserInterrupt) { + log.Debugf("^C from user") ctx, _ = term.ResetInterrupts(context.Background()) //nolint:fatcontext // we only get a new one after the previous one is done. continue }