Bug 1716518 - Upgrade termcolor to v1.1.2.

This removes wincolor.

Differential Revision: https://phabricator.services.mozilla.com/D117883

Depends on D117882
This commit is contained in:
Mike Hommey 2021-06-15 09:26:20 +00:00
parent e0d8e3cd3a
commit cee64b9959
14 changed files with 577 additions and 642 deletions

16
Cargo.lock generated
View File

@ -5041,11 +5041,11 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.0.5" version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [ dependencies = [
"wincolor", "winapi-util",
] ]
[[package]] [[package]]
@ -5865,16 +5865,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "wincolor"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"
dependencies = [
"winapi",
"winapi-util",
]
[[package]] [[package]]
name = "wineventlog" name = "wineventlog"
version = "0.1.0" version = "0.1.0"

View File

@ -1 +1 @@
{"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"6aa6756345334b141f6ecc768420d0f4b38617b521dc470640a819ec50c733f2","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"91f15c930f170ad8199d603315228fdb16ee865ea8f04f5156af5d45fd1eb430","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","src/lib.rs":"d2096632374fe044540abe35a36d23c37a19eb1153bc589b96729081504f23b9"},"package":"96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"} {"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"8d7cf2f58e13533f446cfe1d0c045461974d05d675c1dbda029d912a491d7271","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"5818a900b5f23ed13e824479c4739e3afe7929a5a08e0dcfdf2cc61ba019d986","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","rustfmt.toml":"1ca600239a27401c4a43f363cf3f38183a212affc1f31bff3ae93234bbaec228","src/lib.rs":"5aa9530c1de59aa0f19b035270f87e10397ef37eba317366b9504058364f1d78"},"package":"2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"}

View File

@ -11,8 +11,9 @@
# will likely look very different (and much more reasonable) # will likely look very different (and much more reasonable)
[package] [package]
edition = "2018"
name = "termcolor" name = "termcolor"
version = "1.0.5" version = "1.1.2"
authors = ["Andrew Gallant <jamslam@gmail.com>"] authors = ["Andrew Gallant <jamslam@gmail.com>"]
exclude = ["/.travis.yml", "/appveyor.yml", "/ci/**"] exclude = ["/.travis.yml", "/appveyor.yml", "/ci/**"]
description = "A simple cross platform library for writing colored text to a terminal.\n" description = "A simple cross platform library for writing colored text to a terminal.\n"
@ -26,5 +27,7 @@ repository = "https://github.com/BurntSushi/termcolor"
[lib] [lib]
name = "termcolor" name = "termcolor"
bench = false bench = false
[target."cfg(windows)".dependencies.wincolor]
version = "1" [dev-dependencies]
[target."cfg(windows)".dependencies.winapi-util]
version = "0.1.3"

View File

@ -6,8 +6,7 @@ by interacting with the Windows console. Several convenient abstractions
are provided for use in single-threaded or multi-threaded command line are provided for use in single-threaded or multi-threaded command line
applications. applications.
[![Linux build status](https://api.travis-ci.org/BurntSushi/termcolor.png)](https://travis-ci.org/BurntSushi/termcolor) [![Build status](https://github.com/BurntSushi/termcolor/workflows/ci/badge.svg)](https://github.com/BurntSushi/termcolor/actions)
[![Windows build status](https://ci.appveyor.com/api/projects/status/github/BurntSushi/termcolor?svg=true)](https://ci.appveyor.com/project/BurntSushi/termcolor)
[![](https://img.shields.io/crates/v/termcolor.svg)](https://crates.io/crates/termcolor) [![](https://img.shields.io/crates/v/termcolor.svg)](https://crates.io/crates/termcolor)
Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org). Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
@ -22,13 +21,7 @@ Add this to your `Cargo.toml`:
```toml ```toml
[dependencies] [dependencies]
termcolor = "1" termcolor = "1.1"
```
and this to your crate root:
```rust
extern crate termcolor;
``` ```
### Organization ### Organization
@ -58,12 +51,14 @@ except it is augmented with methods for coloring by the `WriteColor` trait.
For example, to write some green text: For example, to write some green text:
```rust ```rust
use std::io::Write; use std::io::{self, Write};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
let mut stdout = StandardStream::stdout(ColorChoice::Always); fn write_green() -> io::Result<()> {
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?; let mut stdout = StandardStream::stdout(ColorChoice::Always);
writeln!(&mut stdout, "green text!")?; stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
writeln!(&mut stdout, "green text!")
}
``` ```
### Example: using `BufferWriter` ### Example: using `BufferWriter`
@ -75,12 +70,46 @@ implements `io::Write` and `termcolor::WriteColor`.
This example shows how to print some green text to stderr. This example shows how to print some green text to stderr.
```rust ```rust
use std::io::Write; use std::io::{self, Write};
use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor}; use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor};
let mut bufwtr = BufferWriter::stderr(ColorChoice::Always); fn write_green() -> io::Result<()> {
let mut buffer = bufwtr.buffer(); let mut bufwtr = BufferWriter::stderr(ColorChoice::Always);
buffer.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?; let mut buffer = bufwtr.buffer();
writeln!(&mut buffer, "green text!")?; buffer.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
bufwtr.print(&buffer)?; writeln!(&mut buffer, "green text!")?;
bufwtr.print(&buffer)
}
``` ```
### Automatic color selection
When building a writer with termcolor, the caller must provide a
[`ColorChoice`](https://docs.rs/termcolor/1.0.5/termcolor/enum.ColorChoice.html)
selection. When the color choice is `Auto`, termcolor will attempt to determine
whether colors should be enabled by inspecting the environment. Currently,
termcolor will inspect the `TERM` and `NO_COLOR` environment variables:
* If `NO_COLOR` is set to any value, then colors will be suppressed.
* If `TERM` is set to `dumb`, then colors will be suppressed.
* In non-Windows environments, if `TERM` is not set, then colors will be
suppressed.
This decision procedure may change over time.
Currently, `termcolor` does not attempt to detect whether a tty is present or
not. To achieve that, please use the [`atty`](https://crates.io/crates/atty)
crate.
### Minimum Rust version policy
This crate's minimum supported `rustc` version is `1.34.0`.
The current policy is that the minimum Rust version required to use this crate
can be increased in minor version updates. For example, if `crate 1.0` requires
Rust 1.20.0, then `crate 1.0.z` for all values of `z` will also require Rust
1.20.0 or newer. However, `crate 1.y` for `y > 0` may require a newer minimum
version of Rust.
In general, this crate will be conservative with respect to the minimum
supported version of Rust.

View File

@ -0,0 +1,2 @@
max_width = 79
use_small_heuristics = "max"

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
{"files":{"COPYING":"01c266bced4a434da0051174d6bee16a4c82cf634e2679b6155d40d75012390f","Cargo.toml":"52b63d0526a0afb7ca1c53d9b3fc712346a30772bdb2d79faa9c4903d68696fc","LICENSE-MIT":"0f96a83840e146e43c0ec96a22ec1f392e0680e6c1226e6f3ba87e0740af850f","README.md":"f2e0aea03834f9bf3bede2d5a0371f30fc7f6c8e9bdb136b810f21360e05fa39","UNLICENSE":"7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c","src/lib.rs":"c69a94806e052cd540d2eeb9e6c92ca66c6f76436903296af33107c5106401fa","src/win.rs":"c63ed910831fcaa22e27210619bc645cd4973ed9fab4aa1a164ef986f0f92772"},"package":"96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9"}

View File

@ -1,3 +0,0 @@
This project is dual-licensed under the Unlicense and MIT licenses.
You may use this code under the terms of either license.

View File

@ -1,33 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
name = "wincolor"
version = "1.0.2"
authors = ["Andrew Gallant <jamslam@gmail.com>"]
description = "A simple Windows specific API for controlling text color in a Windows console.\n"
homepage = "https://github.com/BurntSushi/termcolor/tree/master/wincolor"
documentation = "https://docs.rs/wincolor"
readme = "README.md"
keywords = ["windows", "win", "color", "ansi", "console"]
license = "Unlicense OR MIT"
repository = "https://github.com/BurntSushi/termcolor/tree/master/wincolor"
[lib]
name = "wincolor"
bench = false
[dependencies.winapi]
version = "0.3"
features = ["minwindef", "wincon"]
[dependencies.winapi-util]
version = "0.1.1"

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Andrew Gallant
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,44 +0,0 @@
wincolor
========
A simple Windows specific API for controlling text color in a Windows console.
The purpose of this crate is to expose the full inflexibility of the Windows
console without any platform independent abstraction.
[![Windows build status](https://ci.appveyor.com/api/projects/status/github/BurntSushi/ripgrep?svg=true)](https://ci.appveyor.com/project/BurntSushi/ripgrep)
[![](https://img.shields.io/crates/v/wincolor.svg)](https://crates.io/crates/wincolor)
Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
### Documentation
[https://docs.rs/wincolor](https://docs.rs/wincolor)
### Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
wincolor = "0.1"
```
and this to your crate root:
```rust
extern crate wincolor;
```
### Example
This is a simple example that shows how to write text with a foreground color
of cyan and the intense attribute set:
```rust
use wincolor::{Console, Color, Intense};
let mut con = Console::stdout().unwrap();
con.fg(Intense::Yes, Color::Cyan).unwrap();
println!("This text will be intense cyan.");
con.reset().unwrap();
println!("This text will be normal.");
```

View File

@ -1,24 +0,0 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>

View File

@ -1,35 +0,0 @@
/*!
This crate provides a safe and simple Windows specific API to control
text attributes in the Windows console. Text attributes are limited to
foreground/background colors, as well as whether to make colors intense or not.
Note that on non-Windows platforms, this crate is empty but will compile.
# Example
```no_run
# #[cfg(windows)]
# {
use wincolor::{Console, Color, Intense};
let mut con = Console::stdout().unwrap();
con.fg(Intense::Yes, Color::Cyan).unwrap();
println!("This text will be intense cyan.");
con.reset().unwrap();
println!("This text will be normal.");
# }
```
*/
#![deny(missing_docs)]
#[cfg(windows)]
extern crate winapi;
#[cfg(windows)]
extern crate winapi_util;
#[cfg(windows)]
pub use win::*;
#[cfg(windows)]
mod win;

View File

@ -1,261 +0,0 @@
use std::io;
use winapi::shared::minwindef::{WORD};
use winapi::um::wincon::{
self,
FOREGROUND_BLUE as FG_BLUE,
FOREGROUND_GREEN as FG_GREEN,
FOREGROUND_RED as FG_RED,
FOREGROUND_INTENSITY as FG_INTENSITY,
};
use winapi_util as winutil;
const FG_CYAN: WORD = FG_BLUE | FG_GREEN;
const FG_MAGENTA: WORD = FG_BLUE | FG_RED;
const FG_YELLOW: WORD = FG_GREEN | FG_RED;
const FG_WHITE: WORD = FG_BLUE | FG_GREEN | FG_RED;
/// A Windows console.
///
/// This represents a very limited set of functionality available to a Windows
/// console. In particular, it can only change text attributes such as color
/// and intensity.
///
/// There is no way to "write" to this console. Simply write to
/// stdout or stderr instead, while interleaving instructions to the console
/// to change text attributes.
///
/// A common pitfall when using a console is to forget to flush writes to
/// stdout before setting new text attributes.
#[derive(Debug)]
pub struct Console {
kind: HandleKind,
start_attr: TextAttributes,
cur_attr: TextAttributes,
}
#[derive(Clone, Copy, Debug)]
enum HandleKind {
Stdout,
Stderr,
}
impl HandleKind {
fn handle(&self) -> winutil::HandleRef {
match *self {
HandleKind::Stdout => winutil::HandleRef::stdout(),
HandleKind::Stderr => winutil::HandleRef::stderr(),
}
}
}
impl Console {
/// Get a console for a standard I/O stream.
fn create_for_stream(kind: HandleKind) -> io::Result<Console> {
let h = kind.handle();
let info = winutil::console::screen_buffer_info(&h)?;
let attr = TextAttributes::from_word(info.attributes());
Ok(Console {
kind: kind,
start_attr: attr,
cur_attr: attr,
})
}
/// Create a new Console to stdout.
///
/// If there was a problem creating the console, then an error is returned.
pub fn stdout() -> io::Result<Console> {
Self::create_for_stream(HandleKind::Stdout)
}
/// Create a new Console to stderr.
///
/// If there was a problem creating the console, then an error is returned.
pub fn stderr() -> io::Result<Console> {
Self::create_for_stream(HandleKind::Stderr)
}
/// Applies the current text attributes.
fn set(&mut self) -> io::Result<()> {
winutil::console::set_text_attributes(
self.kind.handle(),
self.cur_attr.to_word(),
)
}
/// Apply the given intensity and color attributes to the console
/// foreground.
///
/// If there was a problem setting attributes on the console, then an error
/// is returned.
pub fn fg(&mut self, intense: Intense, color: Color) -> io::Result<()> {
self.cur_attr.fg_color = color;
self.cur_attr.fg_intense = intense;
self.set()
}
/// Apply the given intensity and color attributes to the console
/// background.
///
/// If there was a problem setting attributes on the console, then an error
/// is returned.
pub fn bg(&mut self, intense: Intense, color: Color) -> io::Result<()> {
self.cur_attr.bg_color = color;
self.cur_attr.bg_intense = intense;
self.set()
}
/// Reset the console text attributes to their original settings.
///
/// The original settings correspond to the text attributes on the console
/// when this `Console` value was created.
///
/// If there was a problem setting attributes on the console, then an error
/// is returned.
pub fn reset(&mut self) -> io::Result<()> {
self.cur_attr = self.start_attr;
self.set()
}
/// Toggle virtual terminal processing.
///
/// This method attempts to toggle virtual terminal processing for this
/// console. If there was a problem toggling it, then an error returned.
/// On success, the caller may assume that toggling it was successful.
///
/// When virtual terminal processing is enabled, characters emitted to the
/// console are parsed for VT100 and similar control character sequences
/// that control color and other similar operations.
pub fn set_virtual_terminal_processing(
&mut self,
yes: bool,
) -> io::Result<()> {
let vt = wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
let handle = self.kind.handle();
let old_mode = winutil::console::mode(&handle)?;
let new_mode =
if yes {
old_mode | vt
} else {
old_mode & !vt
};
if old_mode == new_mode {
return Ok(());
}
winutil::console::set_mode(&handle, new_mode)
}
}
/// A representation of text attributes for the Windows console.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
struct TextAttributes {
fg_color: Color,
fg_intense: Intense,
bg_color: Color,
bg_intense: Intense,
}
impl TextAttributes {
fn to_word(&self) -> WORD {
let mut w = 0;
w |= self.fg_color.to_fg();
w |= self.fg_intense.to_fg();
w |= self.bg_color.to_bg();
w |= self.bg_intense.to_bg();
w
}
fn from_word(word: WORD) -> TextAttributes {
TextAttributes {
fg_color: Color::from_fg(word),
fg_intense: Intense::from_fg(word),
bg_color: Color::from_bg(word),
bg_intense: Intense::from_bg(word),
}
}
}
/// Whether to use intense colors or not.
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Intense {
Yes,
No,
}
impl Intense {
fn to_bg(&self) -> WORD {
self.to_fg() << 4
}
fn from_bg(word: WORD) -> Intense {
Intense::from_fg(word >> 4)
}
fn to_fg(&self) -> WORD {
match *self {
Intense::No => 0,
Intense::Yes => FG_INTENSITY,
}
}
fn from_fg(word: WORD) -> Intense {
if word & FG_INTENSITY > 0 {
Intense::Yes
} else {
Intense::No
}
}
}
/// The set of available colors for use with a Windows console.
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Color {
Black,
Blue,
Green,
Red,
Cyan,
Magenta,
Yellow,
White,
}
impl Color {
fn to_bg(&self) -> WORD {
self.to_fg() << 4
}
fn from_bg(word: WORD) -> Color {
Color::from_fg(word >> 4)
}
fn to_fg(&self) -> WORD {
match *self {
Color::Black => 0,
Color::Blue => FG_BLUE,
Color::Green => FG_GREEN,
Color::Red => FG_RED,
Color::Cyan => FG_CYAN,
Color::Magenta => FG_MAGENTA,
Color::Yellow => FG_YELLOW,
Color::White => FG_WHITE,
}
}
fn from_fg(word: WORD) -> Color {
match word & 0b111 {
FG_BLUE => Color::Blue,
FG_GREEN => Color::Green,
FG_RED => Color::Red,
FG_CYAN => Color::Cyan,
FG_MAGENTA => Color::Magenta,
FG_YELLOW => Color::Yellow,
FG_WHITE => Color::White,
_ => Color::Black,
}
}
}