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

lpenz / ogle / 21597759092

02 Feb 2026 04:10PM UTC coverage: 58.629% (-0.5%) from 59.173%
21597759092

push

github

lpenz
Use raw mode in terminal to get keys immediately and avoid echo

Raw mode is enabled when the user stream is constructed, and disabled
when it's dropped.

4 of 9 new or added lines in 2 files covered. (44.44%)

10 existing lines in 2 files now uncovered.

462 of 788 relevant lines covered (58.63%)

1.52 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 crossterm::{
15
    cursor::{MoveToColumn, MoveUp},
16
    execute,
17
    terminal::{Clear, ClearType, size},
18
};
19
use std::io::Result;
20
use std::io::{Write, stdout};
21

22
/// Returns the width of the terminal
23
///
24
/// Uses [`console::Term::size_checked`]
25
#[allow(dead_code)]
26
pub fn get_width() -> Option<u16> {
×
27
    size().ok().map(|(w, _)| w)
×
28
}
×
29

30
/// Move the cursor up by `n` lines, if possible.
31
///
32
/// Wraps [`console::Term::move_cursor_up`]
33
pub fn move_cursor_up(n: u16) -> Result<()> {
×
34
    execute!(stdout(), MoveUp(n))
×
35
}
×
36

37
/// Clear the current line.
38
///
39
/// Position the cursor at the beginning of the current line.
40
///
41
/// Wraps [`console::Term::clear_line`]
42
pub fn clear_line() -> Result<()> {
×
NEW
43
    execute!(stdout(), Clear(ClearType::CurrentLine))?;
×
NEW
44
    execute!(stdout(), MoveToColumn(0))
×
UNCOV
45
}
×
46

47
/// Attempts to write an entire buffer to the terminal.
48
///
49
/// Wraps [`console::Term::write_all`]
50
pub fn write_all(buf: &[u8]) -> Result<()> {
×
51
    stdout().write_all(buf)?;
×
52
    stdout().flush()?;
×
NEW
53
    execute!(stdout(), MoveToColumn(0))?;
×
54
    Ok(())
×
55
}
×
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