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

lpenz / ogle / 15954208971

29 Jun 2025 10:23AM UTC coverage: 59.677% (+12.9%) from 46.809%
15954208971

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.

327 of 534 new or added lines in 13 files covered. (61.24%)

2 existing lines in 2 files now uncovered.

370 of 620 relevant lines covered (59.68%)

1.56 hits per line

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

0.0
/src/term_wrapper.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 terminal manipulation.
6
//!
7
//! This wraps [`console::Term`] at the moment, and provides singleton
8
//! functions that do not require an object. We do that by wrapping
9
//! the Term object in a [`std::sync::Mutex`].
10
//!
11
//! A side-effect of this style of interface is that we can change the
12
//! underlying library with (hopefully) no impact on users.
13

14
use console::Term;
15
use std::io::Result;
16
use std::io::Write;
17
use std::sync::LazyLock;
18
use std::sync::Mutex;
19

NEW
20
static TERM: LazyLock<Mutex<Term>> = LazyLock::new(|| Mutex::new(Term::stdout()));
×
21

22
/// Returns the width of the terminal
23
///
24
/// Uses [`console::Term::size_checked`]
NEW
25
pub fn get_width() -> Option<u16> {
×
NEW
26
    TERM.lock()
×
NEW
27
        .expect("unable to lock TERM")
×
NEW
28
        .size_checked()
×
NEW
29
        .map(|(_, width)| width)
×
NEW
30
}
×
31

32
/// Move the cursor up by `n` lines, if possible.
33
///
34
/// Wraps [`console::Term::move_cursor_up`]
NEW
35
pub fn move_cursor_up(n: usize) -> Result<()> {
×
NEW
36
    TERM.lock().expect("unable to lock TERM").move_cursor_up(n)
×
NEW
37
}
×
38

39
/// Clear the current line.
40
///
41
/// Position the cursor at the beginning of the current line.
42
///
43
/// Wraps [`console::Term::clear_line`]
NEW
44
pub fn clear_line() -> Result<()> {
×
NEW
45
    TERM.lock().expect("unable to lock TERM").clear_line()
×
NEW
46
}
×
47

48
/// Attempts to write an entire buffer to the terminal.
49
///
50
/// Wraps [`console::Term::write_all`]
NEW
51
pub fn write_all(buf: &[u8]) -> Result<()> {
×
NEW
52
    TERM.lock().expect("unable to lock TERM").write_all(buf)
×
NEW
53
}
×
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