Skip to content

Commit 39d8d3a

Browse files
committed
Auto merge of rust-lang#87247 - crlf0710:merge-libterm-into-libtest, r=nagisa
Merge libterm into libtest I think it's quite clear at this point that rust won't stablize the current libterm APIs to the outside world. And its only user is libtest. The compiler doesn't use this api at all. So I'm merging the crate into libtest as a module. This also allows me to remove 15% of the libterm code, since these APIs are dead-code now.
2 parents 5c0ca08 + 4486795 commit 39d8d3a

File tree

17 files changed

+133
-410
lines changed

17 files changed

+133
-410
lines changed

Cargo.lock

-9
Original file line numberDiff line numberDiff line change
@@ -5095,14 +5095,6 @@ dependencies = [
50955095
"serde_json",
50965096
]
50975097

5098-
[[package]]
5099-
name = "term"
5100-
version = "0.0.0"
5101-
dependencies = [
5102-
"core",
5103-
"std",
5104-
]
5105-
51065098
[[package]]
51075099
name = "term"
51085100
version = "0.6.1"
@@ -5155,7 +5147,6 @@ dependencies = [
51555147
"panic_unwind",
51565148
"proc_macro",
51575149
"std",
5158-
"term 0.0.0",
51595150
]
51605151

51615152
[[package]]

library/term/Cargo.toml

-9
This file was deleted.

library/term/src/lib.rs

-194
This file was deleted.

library/test/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ crate-type = ["dylib", "rlib"]
1010
[dependencies]
1111
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
1212
getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
13-
term = { path = "../term" }
1413
std = { path = "../std" }
1514
core = { path = "../core" }
1615
libc = { version = "0.2", default-features = false }

library/test/src/console.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{
1313
formatters::{JsonFormatter, JunitFormatter, OutputFormatter, PrettyFormatter, TerseFormatter},
1414
helpers::{concurrency::get_concurrency, metrics::MetricMap},
1515
options::{Options, OutputFormat},
16-
run_tests,
16+
run_tests, term,
1717
test_result::TestResult,
1818
time::{TestExecTime, TestSuiteExecTime},
1919
types::{NamePadding, TestDesc, TestDescAndFn},

library/test/src/formatters/pretty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::OutputFormatter;
44
use crate::{
55
bench::fmt_bench_samples,
66
console::{ConsoleTestState, OutputLocation},
7+
term,
78
test_result::TestResult,
89
time,
910
types::TestDesc,

library/test/src/formatters/terse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::OutputFormatter;
44
use crate::{
55
bench::fmt_bench_samples,
66
console::{ConsoleTestState, OutputLocation},
7+
term,
78
test_result::TestResult,
89
time,
910
types::NamePadding,

library/test/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#![crate_name = "test"]
2121
#![unstable(feature = "test", issue = "50297")]
2222
#![doc(test(attr(deny(warnings))))]
23-
#![cfg_attr(unix, feature(libc))]
23+
#![feature(libc)]
2424
#![feature(rustc_private)]
2525
#![feature(nll)]
2626
#![feature(available_concurrency)]
@@ -80,6 +80,7 @@ mod formatters;
8080
mod helpers;
8181
mod options;
8282
pub mod stats;
83+
mod term;
8384
mod test_result;
8485
mod time;
8586
mod types;

library/test/src/term.rs

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//! Terminal formatting module.
2+
//!
3+
//! This module 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+
//! [ansi]: https://en.wikipedia.org/wiki/ANSI_escape_code
10+
//! [win]: https://docs.microsoft.com/en-us/windows/console/character-mode-applications
11+
//! [ti]: https://en.wikipedia.org/wiki/Terminfo
12+
13+
#![deny(missing_docs)]
14+
15+
use std::io::{self, prelude::*};
16+
17+
pub(crate) use terminfo::TerminfoTerminal;
18+
#[cfg(windows)]
19+
pub(crate) use win::WinConsole;
20+
21+
pub(crate) mod terminfo;
22+
23+
#[cfg(windows)]
24+
mod win;
25+
26+
/// Alias for stdout terminals.
27+
pub(crate) type StdoutTerminal = dyn Terminal + Send;
28+
29+
#[cfg(not(windows))]
30+
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
31+
/// opened.
32+
pub(crate) fn stdout() -> Option<Box<StdoutTerminal>> {
33+
TerminfoTerminal::new(io::stdout()).map(|t| Box::new(t) as Box<StdoutTerminal>)
34+
}
35+
36+
#[cfg(windows)]
37+
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
38+
/// opened.
39+
pub(crate) fn stdout() -> Option<Box<StdoutTerminal>> {
40+
TerminfoTerminal::new(io::stdout())
41+
.map(|t| Box::new(t) as Box<StdoutTerminal>)
42+
.or_else(|| WinConsole::new(io::stdout()).ok().map(|t| Box::new(t) as Box<StdoutTerminal>))
43+
}
44+
45+
/// Terminal color definitions
46+
#[allow(missing_docs)]
47+
#[cfg_attr(not(windows), allow(dead_code))]
48+
pub(crate) mod color {
49+
/// Number for a terminal color
50+
pub(crate) type Color = u32;
51+
52+
pub(crate) const BLACK: Color = 0;
53+
pub(crate) const RED: Color = 1;
54+
pub(crate) const GREEN: Color = 2;
55+
pub(crate) const YELLOW: Color = 3;
56+
pub(crate) const BLUE: Color = 4;
57+
pub(crate) const MAGENTA: Color = 5;
58+
pub(crate) const CYAN: Color = 6;
59+
pub(crate) const WHITE: Color = 7;
60+
}
61+
62+
/// A terminal with similar capabilities to an ANSI Terminal
63+
/// (foreground/background colors etc).
64+
pub trait Terminal: Write {
65+
/// Sets the foreground color to the given color.
66+
///
67+
/// If the color is a bright color, but the terminal only supports 8 colors,
68+
/// the corresponding normal color will be used instead.
69+
///
70+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
71+
/// if there was an I/O error.
72+
fn fg(&mut self, color: color::Color) -> io::Result<bool>;
73+
74+
/// Resets all terminal attributes and colors to their defaults.
75+
///
76+
/// Returns `Ok(true)` if the terminal was reset, `Ok(false)` otherwise, and `Err(e)` if there
77+
/// was an I/O error.
78+
///
79+
/// *Note: This does not flush.*
80+
///
81+
/// That means the reset command may get buffered so, if you aren't planning on doing anything
82+
/// else that might flush stdout's buffer (e.g., writing a line of text), you should flush after
83+
/// calling reset.
84+
fn reset(&mut self) -> io::Result<bool>;
85+
}

0 commit comments

Comments
 (0)