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

lpenz / ogle / 16092339124

05 Jul 2025 09:45PM UTC coverage: 62.041% (+16.6%) from 45.475%
16092339124

push

github

lpenz
Complete refactoring using layers that should be easier to test

Layers connected via streams, which we can mock and test.
This combines a bunch of commits that documented this slow conversion.

344 of 539 new or added lines in 12 files covered. (63.82%)

2 existing lines in 2 files now uncovered.

389 of 627 relevant lines covered (62.04%)

1.64 hits per line

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

0.0
/src/output.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
//! Wrapper for "low-level" system function used for the output
6
//!
7
//! This implements a command design pattern, which makes it very easy
8
//! to test that we are issuing the correct commands.
9

10
use color_eyre::Result;
11
use enum_dispatch::enum_dispatch;
12
use tokio_stream::Stream;
13
use tokio_stream::StreamExt;
14

15
use crate::term_wrapper::*;
16

17
#[enum_dispatch(OutputCommand)]
18
pub trait OutputCommandTrait {
19
    fn execute(&self);
20
}
21

22
pub struct MoveCursorUp(pub usize);
23
impl OutputCommandTrait for MoveCursorUp {
NEW
24
    fn execute(&self) {
×
NEW
25
        move_cursor_up(self.0).unwrap()
×
NEW
26
    }
×
27
}
28

29
pub struct ClearLine {}
30
impl OutputCommandTrait for ClearLine {
NEW
31
    fn execute(&self) {
×
NEW
32
        clear_line().unwrap()
×
NEW
33
    }
×
34
}
35

36
pub struct WriteAll(pub Vec<u8>);
37
impl OutputCommandTrait for WriteAll {
NEW
38
    fn execute(&self) {
×
NEW
39
        write_all(&self.0).unwrap()
×
NEW
40
    }
×
41
}
42

43
#[enum_dispatch]
44
pub enum OutputCommand {
45
    MoveCursorUp,
46
    ClearLine,
47
    WriteAll,
48
}
49

50
/// This function runs all commands in the provided stream until it is
51
/// exhausted.
52
#[allow(dead_code)]
NEW
53
pub async fn output<S>(mut stream: S) -> Result<()>
×
NEW
54
where
×
NEW
55
    S: Stream<Item = OutputCommand> + std::marker::Unpin,
×
NEW
56
{
×
NEW
57
    while let Some(cmd) = stream.next().await {
×
NEW
58
        cmd.execute();
×
NEW
59
    }
×
NEW
60
    Ok(())
×
NEW
61
}
×
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