Skip to content
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

Add friendlier Windows set/restore console API #89

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

twpayne
Copy link
Contributor

@twpayne twpayne commented Sep 17, 2022

The existing EnableWindowsANSIConsole/RestoreWindowsConsole functions have a number of limitations:

  • They are only defined when termenv is built on Windows, and so require the user to use build tags, i.e. multiple source files, to control whether or not they are called and are not shown on https://pkg.go.dev/github.com/muesli/termenv by default.
  • They are hardcoded to set the console mode of stdout, and so fail if stdout is not a terminal, e.g. when redirecting the output to a file or when run in a Go test.

This commit adds a EnableVirtualTerminalProcessing function with a different API (to avoid breaking backwards compatibility) that is safe to call on all platforms, takes an io.Writer as an argument (for output flexibility). See the comments in the function for more details.

Replaces #88.
Refs #86 (and this PR will probably need updating).

@muesli
Copy link
Owner

muesli commented Sep 20, 2022

Nice work, @twpayne! The change looks good, but as you already realized will need a rebase for #86, which has just landed in master. Since this has been a bigger merge, I'll happily offer to do the rebase here if you prefer me to do that. Just let me know!

@twpayne twpayne force-pushed the windows-console-api branch 3 times, most recently from 700a110 to 09de4e1 Compare September 20, 2022 22:13
@twpayne
Copy link
Contributor Author

twpayne commented Sep 20, 2022

Thanks! I've rebased the PR, but I might have missed something. Please do review.

The CI failure on macOS looks like it's due to some kind of GitHub rate limiting and doesn't seem to be related to this PR. On my M1 Mac, the tests pass.

@twpayne
Copy link
Contributor Author

twpayne commented Sep 20, 2022

The GitHub rate limiting might be fixed by #91.

@twpayne
Copy link
Contributor Author

twpayne commented Sep 20, 2022

Rebasing on #91 fixes the macOS/GitHub rate limiting issue. Merging #91 before this PR will preserve a clean git history.

The existing EnableWindowsANSIConsole/RestoreWindowsConsole functions
have a number of limitations:
* They are only defined when termenv is built on Windows, and so require
  the user to use build tags, i.e. multiple source files, to control
  whether or not they are called and are not shown on
  https://pkg.go.dev/github.com/muesli/termenv by default.
* They are hardcoded to set the console mode of stdout, and so fail if
  stdout is not a terminal, e.g. when redirecting the output to a file
  or when run in a Go test.

This commit adds a EnableVirtualTerminalProcessing function with a
different API (to avoid breaking backwards compatibility) that is safe
to call on all platforms, takes an io.Writer as an argument (for output
flexibility). See the comments in the function for more details.
@muesli muesli added the enhancement New feature or request label Sep 21, 2022
@muesli muesli merged commit c2e45bf into muesli:master Sep 21, 2022
@muesli
Copy link
Owner

muesli commented Sep 22, 2022

Thank you, @twpayne!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants