<commit_before>use std::cmp;
use std::iter;
use std::time::{Instant, Duration};

use core::shell::Verbosity;
use util::{Config, CargoResult};

pub struct Progress<'cfg> {
    state: Option<State<'cfg>>,
}

struct State<'cfg> {
    config: &'cfg Config,
    width: usize,
    first: bool,
    last_update: Instant,
    name: String,
    done: bool,
}

impl<'cfg> Progress<'cfg> {
    pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
        // no progress if `-q` is passed as, well, we're supposed to be quiet
        if cfg.shell().verbosity() == Verbosity::Quiet {
            return Progress { state: None }
        }

        Progress {
            state: cfg.shell().err_width().map(|n| {
                State {
                    config: cfg,
                    width: cmp::min(n, 80),<commit_msg>util/progress: no progress reporting in dumb terminals<commit_after>use std::cmp;
use std::env;
use std::iter;
use std::time::{Instant, Duration};

use core::shell::Verbosity;
use util::{Config, CargoResult};

pub struct Progress<'cfg> {
    state: Option<State<'cfg>>,
}

struct State<'cfg> {
    config: &'cfg Config,
    width: usize,
    first: bool,
    last_update: Instant,
    name: String,
    done: bool,
}

impl<'cfg> Progress<'cfg> {
    pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
        // report no progress when -q (for quiet) or TERM=dumb are set
        let dumb = match env::var("TERM") {
            Ok(term) => term == "dumb",
            Err(_) => false,
        };
        if cfg.shell().verbosity() == Verbosity::Quiet || dumb {
            return Progress { state: None }
        }

        Progress {
            state: cfg.shell().err_width().map(|n| {
                State {
                    config: cfg,
                    width: cmp::min(n, 80),
{'fraction_non_alphanumeric': 0.15456545654565457, 'fraction_numerical': 0.0022002200220022, 'mean_word_length': 2.2893309222423146, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3190351', 'n_tokens_mistral': 584, 'n_tokens_neox': 582, 'n_words': 157}