• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lpenz / ogle / 13020384909

28 Jan 2025 10:03PM UTC coverage: 60.104%. Remained the same
13020384909

push

github

lpenz
[wip] output_sequence

0 of 25 new or added lines in 1 file covered. (0.0%)

2 existing lines in 1 file now uncovered.

348 of 579 relevant lines covered (60.1%)

2.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/output_sequence.rs
1
// Copyright (C) 2025 Leandro Lisboa Penz <lpenz@lpenz.org>
2
// This file is subject to the terms and conditions defined in
3
// file 'LICENSE', which is part of this source code package.
4

5
use color_eyre::Result;
6
use console::Term;
7
use std::process::ExitStatus;
8
use tracing::instrument;
9

10
use crate::cli::Cli;
11
use crate::misc::term_clear_line;
12
use crate::misc::term_width;
13
use crate::output_trait::Output;
14
use crate::progbar;
15
use crate::timewrap::Duration;
16
use crate::timewrap::Instant;
17

18
#[derive(Debug, Default)]
19
pub enum State {
20
    #[default]
21
    Starting,
22
    Sleeping {
23
        start: Instant,
24
    },
25
    Running {
26
        start: Instant,
27
        width: usize,
28
    },
29
}
30

31
#[derive(Debug)]
32
pub struct OutputSequence {
33
    state: State,
34
    term: Term,
35
    sleep_duration: Duration,
36
    refresh: Duration,
37
    last_run: Option<Duration>,
38
}
39

40
impl OutputSequence {
41
    #[instrument(level = "debug")]
42
    pub fn new(cli: &Cli) -> Self {
43
        Self {
44
            state: State::default(),
45
            term: Term::stdout(),
46
            sleep_duration: Duration::seconds(cli.period as i64),
47
            refresh: Duration::milliseconds(250),
48
            last_run: None,
49
        }
50
    }
51
}
52

53
impl Output for OutputSequence {
54
    #[instrument(level = "debug", fields(self=?self.state))]
55
    fn run_start(&mut self) -> Result<()> {
56
        let now = Instant::now();
57
        self.state = State::Running {
58
            start: now,
59
            width: term_width(&self.term),
60
        };
61
        self.tick()?;
62
        Ok(())
63
    }
64

65
    #[instrument(level = "debug", skip(self))]
66
    fn run_end(&mut self, exitstatus: &ExitStatus) -> Result<()> {
67
        let now = Instant::now();
68
        self.state = State::Sleeping { start: now };
69
        self.tick()?;
70
        Ok(())
71
    }
72

73
    #[instrument(level = "debug", skip(self))]
74
    fn out_line(&mut self, line: String) -> Result<()> {
75
        self.term.write_line(&line)?;
76
        self.tick()?;
77
        Ok(())
78
    }
79

80
    #[instrument(level = "debug", skip(self))]
81
    fn err_line(&mut self, line: String) -> Result<()> {
82
        self.term.write_line(&line)?;
83
        self.tick()?;
84
        Ok(())
85
    }
86

87
    // #[instrument(level = "debug", skip(self))]
NEW
88
    fn tick(&mut self) -> Result<()> {
×
NEW
89
        let now = Instant::now();
×
NEW
90
        match self.state {
×
NEW
91
            State::Starting => {}
×
NEW
92
            State::Sleeping { start } => {
×
NEW
93
                term_clear_line(&self.term)?;
×
NEW
94
                self.term.write_line(&progbar::progbar_sleeping(
×
NEW
95
                    &start,
×
NEW
96
                    &now,
×
NEW
97
                    &start,
×
NEW
98
                    &self.sleep_duration,
×
NEW
99
                )?)?;
×
100
            }
NEW
101
            State::Running { start, width } => {
×
NEW
102
                term_clear_line(&self.term)?;
×
103
                // let elapsed = &now - &start;
NEW
104
                self.term.write_line(&progbar::progbar_running(
×
NEW
105
                    width,
×
NEW
106
                    &now,
×
NEW
107
                    &now,
×
NEW
108
                    &start,
×
NEW
109
                    &self.last_run,
×
NEW
110
                    &self.refresh,
×
NEW
111
                    ' ',
×
NEW
112
                )?)?;
×
113
            }
114
        }
NEW
115
        Ok(())
×
NEW
116
    }
×
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc