Skip to content

Commit 11510b2

Browse files
committed
Auto merge of #59766 - xales:revertlibtest, r=Manishearth
Revert "Auto merge of #57842 - gnzlbg:extract_libtest, r=gnzlbg" This reverts commit 3eb4890, reversing changes made to 7a4df3b. This is, as best I can tell, a clean revert of #57842. It retains some interim changes, like moving `black_box`, and otherwise brings libtest back in as it was before removal.
2 parents df7a91f + 28ea249 commit 11510b2

File tree

17 files changed

+5608
-57
lines changed

17 files changed

+5608
-57
lines changed

Cargo.lock

+6-17
Original file line numberDiff line numberDiff line change
@@ -1319,15 +1319,6 @@ dependencies = [
13191319
"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
13201320
]
13211321

1322-
[[package]]
1323-
name = "libtest"
1324-
version = "0.0.1"
1325-
source = "registry+https://github.com/rust-lang/crates.io-index"
1326-
dependencies = [
1327-
"getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
1328-
"rustc_term 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1329-
]
1330-
13311322
[[package]]
13321323
name = "libz-sys"
13331324
version = "1.0.25"
@@ -2952,11 +2943,6 @@ dependencies = [
29522943
"serialize 0.0.0",
29532944
]
29542945

2955-
[[package]]
2956-
name = "rustc_term"
2957-
version = "0.0.1"
2958-
source = "registry+https://github.com/rust-lang/crates.io-index"
2959-
29602946
[[package]]
29612947
name = "rustc_tools_util"
29622948
version = "0.1.1"
@@ -3439,6 +3425,10 @@ dependencies = [
34393425
"utf-8 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
34403426
]
34413427

3428+
[[package]]
3429+
name = "term"
3430+
version = "0.0.0"
3431+
34423432
[[package]]
34433433
name = "term"
34443434
version = "0.4.6"
@@ -3479,8 +3469,9 @@ dependencies = [
34793469
name = "test"
34803470
version = "0.0.0"
34813471
dependencies = [
3482-
"libtest 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
3472+
"getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
34833473
"proc_macro 0.0.0",
3474+
"term 0.0.0",
34843475
]
34853476

34863477
[[package]]
@@ -4113,7 +4104,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41134104
"checksum libgit2-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "48441cb35dc255da8ae72825689a95368bf510659ae1ad55dc4aa88cb1789bf1"
41144105
"checksum libnghttp2-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d75d7966bda4730b722d1eab8e668df445368a24394bae9fc1e8dc0ab3dbe4f4"
41154106
"checksum libssh2-sys 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "126a1f4078368b163bfdee65fbab072af08a1b374a5551b21e87ade27b1fbf9d"
4116-
"checksum libtest 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a51ac59582b915cdfc426dada72c6d9eba95818a6b481ca340f5c7152166837"
41174107
"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe"
41184108
"checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54"
41194109
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
@@ -4222,7 +4212,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
42224212
"checksum rustc-rayon 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d98c51d9cbbe810c8b6693236d3412d8cd60513ff27a3e1b6af483dca0af544"
42234213
"checksum rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "526e7b6d2707a5b9bec3927d424ad70fa3cfc68e0ac1b75e46cdbbc95adc5108"
42244214
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
4225-
"checksum rustc_term 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c69abe7f181d2ea8d2f7b44a4aa86f4b4a567444bcfcf51ed45ede957fbf064"
42264215
"checksum rustc_tools_util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c5a95edfa0c893236ae4778bb7c4752760e4c0d245e19b5eff33c5aa5eb9dc"
42274216
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
42284217
"checksum rustfix 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "af7c21531a91512a4a51b490be6ba1c8eff34fdda0dc5bf87dc28d86748aac56"

src/bootstrap/dist.rs

+1
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ impl Step for Src {
901901
"src/libstd",
902902
"src/libunwind",
903903
"src/libtest",
904+
"src/libterm",
904905
"src/libprofiler_builtins",
905906
"src/stdsimd",
906907
"src/libproc_macro",

src/libterm/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "term"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "term"
9+
path = "lib.rs"
10+
crate-type = ["dylib", "rlib"]

src/libterm/lib.rs

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
//! Terminal formatting library.
2+
//!
3+
//! This crate provides the `Terminal` trait, which abstracts over an [ANSI
4+
//! Terminal][ansi] to provide color printing, among other things. There are two
5+
//! implementations, the `TerminfoTerminal`, which uses control characters from
6+
//! a [terminfo][ti] database, and `WinConsole`, which uses the [Win32 Console
7+
//! API][win].
8+
//!
9+
//! # Examples
10+
//!
11+
//! ```no_run
12+
//! # #![feature(rustc_private)]
13+
//! extern crate term;
14+
//! use std::io::prelude::*;
15+
//!
16+
//! fn main() {
17+
//! let mut t = term::stdout().unwrap();
18+
//!
19+
//! t.fg(term::color::GREEN).unwrap();
20+
//! write!(t, "hello, ").unwrap();
21+
//!
22+
//! t.fg(term::color::RED).unwrap();
23+
//! writeln!(t, "world!").unwrap();
24+
//!
25+
//! assert!(t.reset().unwrap());
26+
//! }
27+
//! ```
28+
//!
29+
//! [ansi]: https://en.wikipedia.org/wiki/ANSI_escape_code
30+
//! [win]: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682010%28v=vs.85%29.aspx
31+
//! [ti]: https://en.wikipedia.org/wiki/Terminfo
32+
33+
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
34+
html_playground_url = "https://play.rust-lang.org/",
35+
test(attr(deny(warnings))))]
36+
#![deny(missing_docs)]
37+
38+
#![deny(rust_2018_idioms)]
39+
40+
#![cfg_attr(windows, feature(libc))]
41+
// Handle rustfmt skips
42+
#![feature(custom_attribute)]
43+
#![allow(unused_attributes)]
44+
45+
use std::io::prelude::*;
46+
use std::io::{self, Stdout, Stderr};
47+
48+
pub use terminfo::TerminfoTerminal;
49+
#[cfg(windows)]
50+
pub use win::WinConsole;
51+
52+
pub mod terminfo;
53+
54+
#[cfg(windows)]
55+
mod win;
56+
57+
/// Alias for stdout terminals.
58+
pub type StdoutTerminal = dyn Terminal<Output = Stdout> + Send;
59+
/// Alias for stderr terminals.
60+
pub type StderrTerminal = dyn Terminal<Output = Stderr> + Send;
61+
62+
#[cfg(not(windows))]
63+
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
64+
/// opened.
65+
pub fn stdout() -> Option<Box<StdoutTerminal>> {
66+
TerminfoTerminal::new(io::stdout()).map(|t| Box::new(t) as Box<StdoutTerminal>)
67+
}
68+
69+
#[cfg(windows)]
70+
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
71+
/// opened.
72+
pub fn stdout() -> Option<Box<StdoutTerminal>> {
73+
TerminfoTerminal::new(io::stdout())
74+
.map(|t| Box::new(t) as Box<StdoutTerminal>)
75+
.or_else(|| WinConsole::new(io::stdout()).ok().map(|t| Box::new(t) as Box<StdoutTerminal>))
76+
}
77+
78+
#[cfg(not(windows))]
79+
/// Returns a Terminal wrapping stderr, or None if a terminal couldn't be
80+
/// opened.
81+
pub fn stderr() -> Option<Box<StderrTerminal>> {
82+
TerminfoTerminal::new(io::stderr()).map(|t| Box::new(t) as Box<StderrTerminal>)
83+
}
84+
85+
#[cfg(windows)]
86+
/// Returns a Terminal wrapping stderr, or None if a terminal couldn't be
87+
/// opened.
88+
pub fn stderr() -> Option<Box<StderrTerminal>> {
89+
TerminfoTerminal::new(io::stderr())
90+
.map(|t| Box::new(t) as Box<StderrTerminal>)
91+
.or_else(|| WinConsole::new(io::stderr()).ok().map(|t| Box::new(t) as Box<StderrTerminal>))
92+
}
93+
94+
95+
/// Terminal color definitions
96+
#[allow(missing_docs)]
97+
pub mod color {
98+
/// Number for a terminal color
99+
pub type Color = u16;
100+
101+
pub const BLACK: Color = 0;
102+
pub const RED: Color = 1;
103+
pub const GREEN: Color = 2;
104+
pub const YELLOW: Color = 3;
105+
pub const BLUE: Color = 4;
106+
pub const MAGENTA: Color = 5;
107+
pub const CYAN: Color = 6;
108+
pub const WHITE: Color = 7;
109+
110+
pub const BRIGHT_BLACK: Color = 8;
111+
pub const BRIGHT_RED: Color = 9;
112+
pub const BRIGHT_GREEN: Color = 10;
113+
pub const BRIGHT_YELLOW: Color = 11;
114+
pub const BRIGHT_BLUE: Color = 12;
115+
pub const BRIGHT_MAGENTA: Color = 13;
116+
pub const BRIGHT_CYAN: Color = 14;
117+
pub const BRIGHT_WHITE: Color = 15;
118+
}
119+
120+
/// Terminal attributes for use with term.attr().
121+
///
122+
/// Most attributes can only be turned on and must be turned off with term.reset().
123+
/// The ones that can be turned off explicitly take a boolean value.
124+
/// Color is also represented as an attribute for convenience.
125+
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
126+
pub enum Attr {
127+
/// Bold (or possibly bright) mode
128+
Bold,
129+
/// Dim mode, also called faint or half-bright. Often not supported
130+
Dim,
131+
/// Italics mode. Often not supported
132+
Italic(bool),
133+
/// Underline mode
134+
Underline(bool),
135+
/// Blink mode
136+
Blink,
137+
/// Standout mode. Often implemented as Reverse, sometimes coupled with Bold
138+
Standout(bool),
139+
/// Reverse mode, inverts the foreground and background colors
140+
Reverse,
141+
/// Secure mode, also called invis mode. Hides the printed text
142+
Secure,
143+
/// Convenience attribute to set the foreground color
144+
ForegroundColor(color::Color),
145+
/// Convenience attribute to set the background color
146+
BackgroundColor(color::Color),
147+
}
148+
149+
/// A terminal with similar capabilities to an ANSI Terminal
150+
/// (foreground/background colors etc).
151+
pub trait Terminal: Write {
152+
/// The terminal's output writer type.
153+
type Output: Write;
154+
155+
/// Sets the foreground color to the given color.
156+
///
157+
/// If the color is a bright color, but the terminal only supports 8 colors,
158+
/// the corresponding normal color will be used instead.
159+
///
160+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
161+
/// if there was an I/O error.
162+
fn fg(&mut self, color: color::Color) -> io::Result<bool>;
163+
164+
/// Sets the background color to the given color.
165+
///
166+
/// If the color is a bright color, but the terminal only supports 8 colors,
167+
/// the corresponding normal color will be used instead.
168+
///
169+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
170+
/// if there was an I/O error.
171+
fn bg(&mut self, color: color::Color) -> io::Result<bool>;
172+
173+
/// Sets the given terminal attribute, if supported. Returns `Ok(true)`
174+
/// if the attribute was supported, `Ok(false)` otherwise, and `Err(e)` if
175+
/// there was an I/O error.
176+
fn attr(&mut self, attr: Attr) -> io::Result<bool>;
177+
178+
/// Returns `true` if the given terminal attribute is supported.
179+
fn supports_attr(&self, attr: Attr) -> bool;
180+
181+
/// Resets all terminal attributes and colors to their defaults.
182+
///
183+
/// Returns `Ok(true)` if the terminal was reset, `Ok(false)` otherwise, and `Err(e)` if there
184+
/// was an I/O error.
185+
///
186+
/// *Note: This does not flush.*
187+
///
188+
/// That means the reset command may get buffered so, if you aren't planning on doing anything
189+
/// else that might flush stdout's buffer (e.g., writing a line of text), you should flush after
190+
/// calling reset.
191+
fn reset(&mut self) -> io::Result<bool>;
192+
193+
/// Gets an immutable reference to the stream inside
194+
fn get_ref(&self) -> &Self::Output;
195+
196+
/// Gets a mutable reference to the stream inside
197+
fn get_mut(&mut self) -> &mut Self::Output;
198+
199+
/// Returns the contained stream, destroying the `Terminal`
200+
fn into_inner(self) -> Self::Output where Self: Sized;
201+
}

0 commit comments

Comments
 (0)