Skip to content

libterm: Use Windows Console API to color texts. #14013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

libterm: Use Windows Console API to color texts. #14013

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented May 7, 2014

This patch adds the coloring function on Windows console to libterm.
Fixes #13400, and makes working on MSYS slightly more pleasant.

Quick Notes

  • Extract trait TerminalOps<T> from Terminal<T>.
  • Add struct WindowsConsole<T> along with Terminal<T>, both implements TerminalOps<T>.
  • term::Terminal::new is now term::new_terminal, returns ~TerminalOps<T>.
  • Windows-specific code, including WindowsConsole<T>, is in the module windows.
  • It will assume it's running on terminal that understands ASCII if $TERM is "xterm". Attempts to not break rxvt.exe.
  • It spams :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 implement Drop on WindowsConsole<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 calling term::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.

@klutzy
Copy link
Contributor

klutzy commented May 7, 2014

(There is similar patch on #13401 by @cmr.)

I think #13400 is about providing wrapper for low-level apis like SetConsoleScreenBufferSize. But I don't object closing it since I don't think we need them in near future.

@ghost
Copy link
Author

ghost commented May 7, 2014

Oh, okay. Should I close this?

@emberian
Copy link
Member

emberian commented May 7, 2014

Good to know that our implementations converged (more or less). Thanks for working on this, sorry I've been slacking with that other PR :(

@adrientetar
Copy link
Contributor

~ was removed from the language.

I guess the question is which one of these patches works best.

@ghost
Copy link
Author

ghost commented May 7, 2014

I'd go for @cmr's one, which is more organized and has better documentation.
It's amusing to see we both took essentially same approach. Nice work! :)

@ghost ghost closed this May 7, 2014
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

term: windows console handling is incomplete
3 participants