Skip to content

Commit

Permalink
fix ~ avoid panic if running on early windows without ANSI escape con…
Browse files Browse the repository at this point in the history
…sole support

.# Discussion

Versions of Windows prior to one of the v1511 Windows 10 builds (likely
10.0.10586.589; released on 2016-09-13) do not have built-in console
interpretation of ANSI escapes. After Win10 v1511, ANSI escape interpretation
is available, when enabled via `SetConsoleMode()` (see [4]). Earlier versions
(back through Windows 7 to XP) *do* have 8-bit color available via the Console
API, but it's more cumbersome to access (especially from the `rust` realm)[5].

Pre-ANSI escape color may be too cumbersome to use, but the majority of
`pastel` has usefulness even if not displayed in color. "colorcheck" and "pick"
are obvious sub-commands which are unusable without some color support and so
both are disabled with an error message. "format" and "list" are modified to
only display non-colorized output. "paint", a judgement call about error vs
un-colorized, is left operational but without colorized output.

[1] [MS ~ Release Blog Post](https://devblogs.microsoft.com/commandline/24-bit-color-in-the-windows-console) @@ <https://archive.is/6UTBA>
[2] [Reddit ~ Win 10 ANSI Escapes](https://www.reddit.com/r/Windows10/comments/44czox/windows_10_v1511_adds_support_for_ansi_escape) @@ <https://archive.is/7l6tz>
[3] [MS TechNet Win 10 Versions](https://docs.microsoft.com/en-us/windows/release-information/) @@ <https://archive.is/sv3LN>
[4] [`ansi-term` ~ enable ANSI](https://github.com/rivy/rust.ansi-term/blob/ff7eba98d55ad609c7fcc8c7bb0859b37c7545cc/src/windows.rs#L25-L57)
[5] [rust-users ~ Windows color](https://users.rust-lang.org/t/colored-terminal-output/24604/12) @@ <https://web.archive.org/web/20190905231230/https://users.rust-lang.org/t/colored-terminal-output/24604/12>
  • Loading branch information
rivy authored and sharkdp committed Oct 8, 2019
1 parent b366456 commit 57bea78
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ features = ["suggestions", "color", "wrap_help"]

[build-dependencies]
clap = "2"
output_vt100 = "0.1"

[[bin]]
name = "pastel"
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ pub fn build_cli() -> App<'static, 'static> {
.value_name("mode")
.help("Specify the terminal color mode: 24bit, 8bit, off, *auto*")
.possible_values(&["24bit", "8bit", "off", "auto"])
.default_value("auto")
.default_value(if output_vt100::try_init().is_ok() {"auto"} else {"off"})
.hide_possible_values(true)
.hide_default_value(true)
)
Expand Down
4 changes: 0 additions & 4 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ fn run() -> Result<ExitCode> {

let interactive_mode = atty::is(Stream::Stdout);

if interactive_mode {
output_vt100::init();
}

let color_mode = if global_matches.is_present("force-color") {
Some(ansi::Mode::TrueColor)
} else {
Expand Down

0 comments on commit 57bea78

Please sign in to comment.