Fix terminal formatting after cog run
with an interactive TTY
#2424
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.
#2419 changed how we handle attaching stdin to a container. If stdin is interactive (eg the actual
os.Stdin
, not a file or pipe) and a TTY we'd set the terminal to raw mode after attaching, and restore to the previous state once detached from the container. This allowscog run
to behave correctly when running interactive shells like/bin/bash
or a REPL likepython
.This PR fixes an issue where the terminal wasn't restored which led to strange behavior like incorrect alignment on the shell prompt. Now instead of restoring in a goroutine which may not complete in time, it's restored in a defer on the main goroutine.