Skip to content

Commit

Permalink
Remove limits now that we have ^C. Use fixed version of fortio/termin…
Browse files Browse the repository at this point in the history
…al (#201)

* remove limits now that we have ^c

* Use fixed version of fortio/terminal
  • Loading branch information
ldemailly authored Sep 2, 2024
1 parent bee7902 commit 9d8dff5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 12 deletions.
5 changes: 0 additions & 5 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main_test.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
4 changes: 2 additions & 2 deletions repl/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9d8dff5

Please sign in to comment.