Skip to content

Merge libterm into libtest #87247

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

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5090,14 +5090,6 @@ dependencies = [
"serde_json",
]

[[package]]
name = "term"
version = "0.0.0"
dependencies = [
"core",
"std",
]

[[package]]
name = "term"
version = "0.6.1"
Expand Down Expand Up @@ -5150,7 +5142,6 @@ dependencies = [
"panic_unwind",
"proc_macro",
"std",
"term 0.0.0",
]

[[package]]
Expand Down
9 changes: 0 additions & 9 deletions library/term/Cargo.toml

This file was deleted.

194 changes: 0 additions & 194 deletions library/term/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion library/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ crate-type = ["dylib", "rlib"]
[dependencies]
cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] }
getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
term = { path = "../term" }
std = { path = "../std" }
core = { path = "../core" }
libc = { version = "0.2", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{
formatters::{JsonFormatter, JunitFormatter, OutputFormatter, PrettyFormatter, TerseFormatter},
helpers::{concurrency::get_concurrency, metrics::MetricMap},
options::{Options, OutputFormat},
run_tests,
run_tests, term,
test_result::TestResult,
time::{TestExecTime, TestSuiteExecTime},
types::{NamePadding, TestDesc, TestDescAndFn},
Expand Down
1 change: 1 addition & 0 deletions library/test/src/formatters/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::OutputFormatter;
use crate::{
bench::fmt_bench_samples,
console::{ConsoleTestState, OutputLocation},
term,
test_result::TestResult,
time,
types::TestDesc,
Expand Down
1 change: 1 addition & 0 deletions library/test/src/formatters/terse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::OutputFormatter;
use crate::{
bench::fmt_bench_samples,
console::{ConsoleTestState, OutputLocation},
term,
test_result::TestResult,
time,
types::NamePadding,
Expand Down
3 changes: 2 additions & 1 deletion library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![crate_name = "test"]
#![unstable(feature = "test", issue = "50297")]
#![doc(test(attr(deny(warnings))))]
#![cfg_attr(unix, feature(libc))]
#![feature(libc)]
#![feature(rustc_private)]
#![feature(nll)]
#![feature(available_concurrency)]
Expand Down Expand Up @@ -80,6 +80,7 @@ mod formatters;
mod helpers;
mod options;
pub mod stats;
mod term;
mod test_result;
mod time;
mod types;
Expand Down
85 changes: 85 additions & 0 deletions library/test/src/term.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//! Terminal formatting module.
//!
//! This module provides the `Terminal` trait, which abstracts over an [ANSI
//! Terminal][ansi] to provide color printing, among other things. There are two
//! implementations, the `TerminfoTerminal`, which uses control characters from
//! a [terminfo][ti] database, and `WinConsole`, which uses the [Win32 Console
//! API][win].
//!
//! [ansi]: https://en.wikipedia.org/wiki/ANSI_escape_code
//! [win]: https://docs.microsoft.com/en-us/windows/console/character-mode-applications
//! [ti]: https://en.wikipedia.org/wiki/Terminfo

#![deny(missing_docs)]

use std::io::{self, prelude::*};

pub(crate) use terminfo::TerminfoTerminal;
#[cfg(windows)]
pub(crate) use win::WinConsole;

pub(crate) mod terminfo;

#[cfg(windows)]
mod win;

/// Alias for stdout terminals.
pub(crate) type StdoutTerminal = dyn Terminal + Send;

#[cfg(not(windows))]
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
/// opened.
pub(crate) fn stdout() -> Option<Box<StdoutTerminal>> {
TerminfoTerminal::new(io::stdout()).map(|t| Box::new(t) as Box<StdoutTerminal>)
}

#[cfg(windows)]
/// Returns a Terminal wrapping stdout, or None if a terminal couldn't be
/// opened.
pub(crate) fn stdout() -> Option<Box<StdoutTerminal>> {
TerminfoTerminal::new(io::stdout())
.map(|t| Box::new(t) as Box<StdoutTerminal>)
.or_else(|| WinConsole::new(io::stdout()).ok().map(|t| Box::new(t) as Box<StdoutTerminal>))
}

/// Terminal color definitions
#[allow(missing_docs)]
#[cfg_attr(not(windows), allow(dead_code))]
pub(crate) mod color {
/// Number for a terminal color
pub(crate) type Color = u32;

pub(crate) const BLACK: Color = 0;
pub(crate) const RED: Color = 1;
pub(crate) const GREEN: Color = 2;
pub(crate) const YELLOW: Color = 3;
pub(crate) const BLUE: Color = 4;
pub(crate) const MAGENTA: Color = 5;
pub(crate) const CYAN: Color = 6;
pub(crate) const WHITE: Color = 7;
}

/// A terminal with similar capabilities to an ANSI Terminal
/// (foreground/background colors etc).
pub trait Terminal: Write {
/// Sets the foreground color to the given color.
///
/// If the color is a bright color, but the terminal only supports 8 colors,
/// the corresponding normal color will be used instead.
///
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
/// if there was an I/O error.
fn fg(&mut self, color: color::Color) -> io::Result<bool>;

/// Resets all terminal attributes and colors to their defaults.
///
/// Returns `Ok(true)` if the terminal was reset, `Ok(false)` otherwise, and `Err(e)` if there
/// was an I/O error.
///
/// *Note: This does not flush.*
///
/// That means the reset command may get buffered so, if you aren't planning on doing anything
/// else that might flush stdout's buffer (e.g., writing a line of text), you should flush after
/// calling reset.
fn reset(&mut self) -> io::Result<bool>;
}
Loading