Skip to content

Replace term with termcolor #2790

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

Closed
wants to merge 4 commits into from
Closed
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
48 changes: 28 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[package]
authors = ["Daniel Silverstone <dsilvers@digital-scurf.org>", "Diggory Blake <diggsey@googlemail.com>"]
authors = [
"Daniel Silverstone <dsilvers@digital-scurf.org>",
"Diggory Blake <diggsey@googlemail.com>",
]
build = "build.rs"
description = "Manage multiple rust installations with ease"
edition = "2021"
Expand All @@ -13,7 +16,12 @@ version = "1.24.3"

[features]
curl-backend = ["download/curl-backend"]
default = ["curl-backend", "reqwest-backend", "reqwest-default-tls", "reqwest-rustls-tls"]
default = [
"curl-backend",
"reqwest-backend",
"reqwest-default-tls",
"reqwest-rustls-tls",
]

reqwest-backend = ["download/reqwest-backend"]
vendored-openssl = ['openssl/vendored']
Expand All @@ -27,38 +35,43 @@ no-self-update = []
# Sorted by alphabetic order
[dependencies]
anyhow = "1.0.31"
atty = "0.2"
cfg-if = "1.0"
chrono = "0.4"
clap = "2"
download = {path = "download", default-features = false}
download = { path = "download", default-features = false }
effective-limits = "0.5.3"
enum-map = "2.0.3"
flate2 = "1"
git-testament = "0.2"
home = {git = "https://github.com/rbtcollins/home", rev = "a243ee2fbee6022c57d56f5aa79aefe194eabe53"}
home = { git = "https://github.com/rbtcollins/home", rev = "a243ee2fbee6022c57d56f5aa79aefe194eabe53" }
lazy_static = "1"
libc = "0.2"
num_cpus = "1.13"
once_cell = "1.8"
opener = "0.5.0"
# Used by `curl` or `reqwest` backend although it isn't imported
# by our rustup.
openssl = {version = "0.10", optional = true}
pulldown-cmark = {version = "0.8", default-features = false}
openssl = { version = "0.10", optional = true }
pulldown-cmark = { version = "0.8", default-features = false }
rand = "0.8"
regex = "1"
remove_dir_all = "0.7.0"
same-file = "1"
scopeguard = "1"
semver = "1.0"
serde = {version = "1.0", features = ["derive"]}
sequoia-openpgp = { version = "1.5", default-features = false, features = ["crypto-rust", "allow-experimental-crypto", "allow-variable-time-crypto"] }
sequoia-openpgp = { version = "1.5", default-features = false, features = [
"crypto-rust",
"allow-experimental-crypto",
"allow-variable-time-crypto",
] }
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
sharded-slab = "0.1.1"
strsim = "0.10"
tar = "0.4.26"
tempfile = "3.1"
# FIXME(issue #1818, #1826, and friends)
term = "=0.5.1"
termcolor = "1.1"
thiserror = "1.0"
threadpool = "1"
toml = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub mod proxy_mode;
pub mod rustup_mode;
pub mod self_update;
pub mod setup_mode;
mod term2;
pub(crate) mod term2;
mod topical_doc;
7 changes: 3 additions & 4 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{cmp, env};
use anyhow::{anyhow, Context, Result};
use git_testament::{git_testament, render_testament};
use lazy_static::lazy_static;
use term2::Terminal;

use super::self_update;
use super::term2;
Expand Down Expand Up @@ -194,7 +193,7 @@ fn show_channel_updates(cfg: &Cfg, toolchains: Vec<(String, Result<UpdateStatus>
match result {
Ok(UpdateStatus::Installed) => {
banner = "installed";
color = Some(term2::color::GREEN);
color = Some(term2::Color::Green);
}
Ok(UpdateStatus::Updated(v)) => {
if name == "rustup" {
Expand All @@ -204,7 +203,7 @@ fn show_channel_updates(cfg: &Cfg, toolchains: Vec<(String, Result<UpdateStatus>
previous_version = Some(v);
}
banner = "updated";
color = Some(term2::color::GREEN);
color = Some(term2::Color::Green);
}
Ok(UpdateStatus::Unchanged) => {
if name == "rustup" {
Expand All @@ -215,7 +214,7 @@ fn show_channel_updates(cfg: &Cfg, toolchains: Vec<(String, Result<UpdateStatus>
}
Err(_) => {
banner = "update failed";
color = Some(term2::color::RED);
color = Some(term2::Color::Red);
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use std::fmt;
use std::io::Write;
use std::time::{Duration, Instant};

use term::Terminal;

use super::term2;
use crate::dist::Notification as In;
use crate::utils::tty;
Expand Down Expand Up @@ -32,10 +30,7 @@ pub(crate) struct DownloadTracker {
/// Time stamp of the start of the download
start_sec: Option<Instant>,
/// The terminal we write the information to.
/// XXX: Could be a term trait, but with #1818 on the horizon that
/// is a pointless change to make - better to let that transition
/// happen and take stock after that.
term: term2::StdoutTerminal,
term: Box<dyn term2::Terminal>,
/// Whether we displayed progress for the download or not.
///
/// If the download is quick enough, we don't have time to
Expand Down
9 changes: 4 additions & 5 deletions src/cli/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt;
use std::io::Write;
use term2::Terminal;

use super::term2;
use crate::process;
Expand All @@ -25,7 +24,7 @@ macro_rules! debug {

pub(crate) fn warn_fmt(args: fmt::Arguments<'_>) {
let mut t = term2::stderr();
let _ = t.fg(term2::color::YELLOW);
let _ = t.fg(term2::Color::Yellow);
let _ = t.attr(term2::Attr::Bold);
let _ = write!(t, "warning: ");
let _ = t.reset();
Expand All @@ -35,7 +34,7 @@ pub(crate) fn warn_fmt(args: fmt::Arguments<'_>) {

pub(crate) fn err_fmt(args: fmt::Arguments<'_>) {
let mut t = term2::stderr();
let _ = t.fg(term2::color::RED);
let _ = t.fg(term2::Color::Red);
let _ = t.attr(term2::Attr::Bold);
let _ = write!(t, "error: ");
let _ = t.reset();
Expand All @@ -54,7 +53,7 @@ pub(crate) fn info_fmt(args: fmt::Arguments<'_>) {

pub(crate) fn verbose_fmt(args: fmt::Arguments<'_>) {
let mut t = term2::stderr();
let _ = t.fg(term2::color::MAGENTA);
let _ = t.fg(term2::Color::Magenta);
let _ = t.attr(term2::Attr::Bold);
let _ = write!(t, "verbose: ");
let _ = t.reset();
Expand All @@ -65,7 +64,7 @@ pub(crate) fn verbose_fmt(args: fmt::Arguments<'_>) {
pub(crate) fn debug_fmt(args: fmt::Arguments<'_>) {
if process().var("RUSTUP_DEBUG").is_ok() {
let mut t = term2::stderr();
let _ = t.fg(term2::color::BLUE);
let _ = t.fg(term2::Color::Blue);
let _ = t.attr(term2::Attr::Bold);
let _ = write!(t, "debug: ");
let _ = t.reset();
Expand Down
24 changes: 11 additions & 13 deletions src/cli/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
// Write Markdown to the terminal

use std::io;

use pulldown_cmark::{Event, Tag};

use super::term2::{color, Attr, Terminal};
use super::term2::{Attr, Color, Terminal};

// Handles the wrapping of text written to the console
struct LineWrapper<'a, T: Terminal> {
struct LineWrapper<'a> {
indent: u32,
margin: u32,
pos: u32,
w: &'a mut T,
w: &'a mut dyn Terminal,
}

impl<'a, T: Terminal + 'a> LineWrapper<'a, T> {
impl<'a> LineWrapper<'a> {
// Just write a newline
fn write_line(&mut self) {
let _ = writeln!(self.w);
Expand Down Expand Up @@ -81,7 +79,7 @@ impl<'a, T: Terminal + 'a> LineWrapper<'a, T> {
}
}
// Constructor
fn new(w: &'a mut T, indent: u32, margin: u32) -> Self {
fn new(w: &'a mut dyn Terminal, indent: u32, margin: u32) -> Self {
LineWrapper {
indent,
margin,
Expand All @@ -92,14 +90,14 @@ impl<'a, T: Terminal + 'a> LineWrapper<'a, T> {
}

// Handles the formatting of text
struct LineFormatter<'a, T: Terminal + io::Write> {
struct LineFormatter<'a> {
is_code_block: bool,
wrapper: LineWrapper<'a, T>,
wrapper: LineWrapper<'a>,
attrs: Vec<Attr>,
}

impl<'a, T: Terminal + io::Write + 'a> LineFormatter<'a, T> {
fn new(w: &'a mut T, indent: u32, margin: u32) -> Self {
impl<'a> LineFormatter<'a> {
fn new(w: &'a mut dyn Terminal, indent: u32, margin: u32) -> Self {
LineFormatter {
is_code_block: false,
wrapper: LineWrapper::new(w, indent, margin),
Expand Down Expand Up @@ -145,7 +143,7 @@ impl<'a, T: Terminal + io::Write + 'a> LineFormatter<'a, T> {
self.wrapper.write_line();
}
Tag::Emphasis => {
self.push_attr(Attr::ForegroundColor(color::RED));
self.push_attr(Attr::ForegroundColor(Color::Red));
}
Tag::Strong => {}
Tag::Strikethrough => {}
Expand Down Expand Up @@ -221,7 +219,7 @@ impl<'a, T: Terminal + io::Write + 'a> LineFormatter<'a, T> {
}
}

pub(crate) fn md<'a, S: AsRef<str>, T: Terminal + io::Write + 'a>(t: &'a mut T, content: S) {
pub(crate) fn md<S: AsRef<str>>(t: &mut dyn Terminal, content: S) {
let mut f = LineFormatter::new(t, 0, 79);
let parser = pulldown_cmark::Parser::new(content.as_ref());
for event in parser {
Expand Down
Loading