Ignore terminal echo before the command line in typescripts - #245
Merged
Merged
Conversation
script records everything on the pty, including tab-completion listings, history recall, and redrawn prompts. _help50 dropped only the first line as the command, so after tab-completing a command with no output, the leftover echo was treated as its output and passed to _helpless. Now drop everything through the first line that ends with the command as recorded in history, joining backslash continuations and their PS2 prompts; fall back to dropping the first logical line if the command isn't found.
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.
Found while testing the codespace integration (cs50/codespace#196).
Problem.
scriptrecords everything on the pty, including readline's tab-completion listing and the redrawn prompt, history recall, and Ctrl-R._help50treated only the first line of the typescript as the command line, so aftergrep zzz ind<Tab><Tab>oor.py(a command with no output), the leftoverindex.html indoor.pyplus the redrawn prompt were passed to_helplessas the command's output. In plain cli this is invisible because the default_helplessis silent; in the codespace it showed a help50 button whose message was that junk.Fix. Drop everything through the first line that ends with the executed command as recorded by history, joining backslash continuations (and stripping their
PS2prompts) along the way. Only what follows is treated as output. If no such line is found, fall back to dropping the first logical line, as before.Testing. Drove an interactive login shell under a pty with a fake
_helplessthat logs its argument:grep zzz indoor.py(no match):_helplessno longer calledcat \+nothere2: payload iscat: nothere2: No such file or directory, no>prompt1s,make hello.c,python baz.py: helpers unchangedmake smokepasses