Repository navigation
Add an &on-finish callback, and time out the terminal queries - #15
Open
cognominal wants to merge 2 commits into
Open
cognominal wants to merge 2 commits into
cognominal wants to merge 2 commits into
Conversation
read-input awaited the cursor position and terminal size queries with no time limit, so a terminal that does not answer \e[6n (or answers slowly) left the prompt without an input field forever. query-terminal, detect-cursor-pos and detect-terminal-size take an optional :timeout; on timeout the Promise is kept with Str (Empty for the detect methods). The query record stays active so that a late answer is consumed by its own query, not taken as the answer to a later one. CLIInput gets a query-timeout attribute (1 second) and read-input sends both queries before waiting, falling back to the first column of an 80-column terminal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Enter always ended input, with no way for the caller to validate or rewrite the buffer first. &on-finish, if given, is called with the buffer contents on the finish action and returns True to finish, False to ignore the request, or a string that replaces the buffer contents while editing goes on. A REPL can use it to finish only complete statements, or, as the irak REPL of rak does, to show a rewritten submission on a first Enter and run it on a second. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cognominal
added a commit
to cognominal/pr-drafts
that referenced
this pull request
Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two commits on
RawTerminalInput.rakumod, both inCLIInput.read-input.1.
&on-finish. A caller can now look at the buffer when the user pressesEnter, and keep editing instead of returning. A REPL can use it to rewrite or
annotate a line before it runs, or to ask for a second Enter.
Without
&on-finishthe behavior is unchanged.2. Query timeout.
read-inputasks the terminal for the cursor position andthe screen size, then waits without a limit. A terminal or pty that never
answers hangs the prompt forever.
A late answer stays matched to its own query record, so it is consumed and
never mistaken for typed input or another query's answer.
Evidence
&on-finish, before: Enter always returns the buffer.After: with
-> $b { $b eq 'x' ?? True !! 'x' }, typingabcEntershows
xin the field; a second Enter returnsx.\e[6n,prompthangs.After: the prompt appears after 1 s with an 80-column field; a terminal
that answers sees no delay, since both queries are now in flight at once.
zef test .: all tests pass, before and after.mybefore undeclared variables and colors the line, a second Enter within a
second runs it. Tested there in a pty and with
t/02-rakudo/repl.t.Merge Danger
Door: two-way
Both changes are additive; reverting them restores the old behavior.
Blast Radius: small
Callers that pass no
&on-finishsee no change. The timeout only affectsterminals that do not answer within 1 s; they get default sizes instead of a
hang.
$.query-timeoutis configurable at construction.🤖 Generated with Claude Code