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.
Issue #, if available:
Description of changes:
This PR aims to achieve the following:
Background:

Stage A:
This is the current status quo. The event loop writes directly to
stdout
andstderr
. What gets written are the ANSI code that gets interpreted by the terminal.Stage B:
An abstraction is implemented that substitutes
stdout
andstderr
. This abstraction also implementsstd::io::Write
, which enables it be a drop in replacement forstdout
andstderr
where they are used as output incrossterm::queue!
andcrossterm::execute!
. In this mode, the ANSI bytes written to this abstraction is then logged tostderr
andstdout
accordingly, thus preserving the UX.Stage C:
In this stage, the current event loop is instrumented to send structured events instead of ANSI bytes. To preserve the ability to go back to stage B (should we choose to), we shall gate this behind a flag:
The purpose of this stage is really to prepare us for the next stage when we swap out the old event loop with its successor (which is only capable to sending structured messages and does not have the option to write directly to stdout or stderr). Aside from the aforementioned instrumentation, we would also need to add enough logic in the UI abstraction layer to properly handle these events:
Stage D:
After validating / verifying the UI layer works as expected with the old event loop, at this stage we shall swap out the old event loop with the new event loop.
Stage E:
At this stage we would write another UI layer that speaks the same protocol and is more suitable for relevant use cases.