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

lpenz / ogle / 16923016227

12 Aug 2025 11:06PM UTC coverage: 61.892%. Remained the same
16923016227

push

github

lpenz
Upgrade deps in lock file (slab); increment version to 2.1.11

458 of 740 relevant lines covered (61.89%)

1.61 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

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`]
25
pub fn get_width() -> Option<u16> {
×
26
    TERM.lock()
×
27
        .expect("unable to lock TERM")
×
28
        .size_checked()
×
29
        .map(|(_, width)| width)
×
30
}
×
31

32
/// Move the cursor up by `n` lines, if possible.
33
///
34
/// Wraps [`console::Term::move_cursor_up`]
35
pub fn move_cursor_up(n: usize) -> Result<()> {
×
36
    TERM.lock().expect("unable to lock TERM").move_cursor_up(n)
×
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`]
44
pub fn clear_line() -> Result<()> {
×
45
    TERM.lock().expect("unable to lock TERM").clear_line()
×
46
}
×
47

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