libterm: Use Windows Console API to color texts. #14013
Closed
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.
This patch adds the coloring function on Windows console to libterm.
Fixes #13400, and makes working on MSYS slightly more pleasant.
Quick Notes
trait TerminalOps<T>
fromTerminal<T>
.struct WindowsConsole<T>
along withTerminal<T>
, both implementsTerminalOps<T>
.term::Terminal::new
is nowterm::new_terminal
, returns~TerminalOps<T>
.WindowsConsole<T>
, is in the modulewindows
.:Send
to deal with libsyntax, which packs Terminal into a RefCell. I couldn't come up with any smarter fix.I had to remove
Terminal::unwrap()
to implementDrop
onWindowsConsole<T>
, thus it lose the way to manually destroy itself. I suppose it's okay, since I couldn't find any use of it in the tree.Also, it will not be possible to access the members of
Terminal<T>
, such as TermInfo. It's still possible to see terminfo by callingterm::terminfo::parser::compiled::parse
, though.As this is Windows-only improvement, I'm not sure about breaking change is acceptable. I can consider more humble way to do this, if it doesn't pay.