Cross-platform terminal screen clearing library

Overview

Crate release version Crate license: Apache 2.0 or MIT MSRV: 1.51.0 (breaking) CI status Uses Caretaker Maintainership

ClearScreen

Cross-platform terminal screen clearing library.

Tested with and tweaked for over 80 different terminals, multiplexers, SSH clients. See my research notes in the TERMINALS.md file.

Quick start

[dependencies]
clearscreen = "1.0.4"
clearscreen::clear().unwrap();
Comments
  • XFCE4 terminal doesn't reset back to the top and I can scroll up to the output

    XFCE4 terminal doesn't reset back to the top and I can scroll up to the output

    It seems like after a recent update the clear screen option doesn't properly clear the screen anymore. My terminal doesn't reset back to the top and I can scroll up to the output of previous runs. It's possible I'm mistaken but I thought the usual behavior was that you couldn't scroll back to output of previous runs, so if I scroll up all the way I just get to the top of the current run.

    I also now see this message every time I Ctrl+C cargo watch:

    watchexec::run: 2021-08-24T19:49:13.045-04:00 - WARN - Could not pass on signal to command: I/O error: No such process (os error 3)
    

    I tried running with --debug but didn't see anything suspicious or seemingly related to clearing the screen/TTY stuff.

    I'm using:

    • cargo-watch 7.8.1
    • cargo 1.55.0-nightly (27277d966 2021-07-16)
    • xfce4-terminal 0.8.7.4
    • Xubuntu 18.04.5/Linux 4.15.0-154-generic
    opened by dbeckwith 15
  • --clear not working on iterm2

    --clear not working on iterm2

    As it says --clear doesn't seem to be working at all.

    watchexec 1.16.0 iterm2 3.4.6

    I can also replicate on the main branch but I discovered that making the following change makes --clear work.

    diff --git a/lib/src/run.rs b/lib/src/run.rs
    index f1531c6..8c82b11 100644
    --- a/lib/src/run.rs
    +++ b/lib/src/run.rs
    @@ -174,6 +174,7 @@ impl ExecHandler {
         fn spawn(&self, ops: &[PathOp]) -> Result<()> {
             if self.args.clear_screen {
                 clearscreen::clear()?;
    +            println!();
             }
    
             debug!("Launching command");
    

    That seems super odd to me, but maybe it'll help figure out the issue.

    opened by noc7c9 5
  • clearscreen::clear() returns an error on windows 7

    clearscreen::clear() returns an error on windows 7

    Code to reproduce

    main.rs

    fn main() {
        clearscreen::clear().unwrap();
    }
    

    Cargo.toml

    [dependencies]
    clearscreen = { git = "https://github.com/watchexec/clearscreen", rev = "3e1b4254f881c03b0d290a4066fc38265f2ac064" }
    

    The error

    ←[H←[2J←[3Jthread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." })', src\main.rs:2:26
    

    Doesn't matter if launch from VSCode console, cmd or powershell.

    Faulty code, according to debugger: win::is_windows_10 returns true while the platform is windows 7. This is because the logic inside the function expects pwsh_package_management to be indicator of windows 10, but it wasn't in my situation. I have no idea when and what software installed this package during windows lifetime. This caused further code to execute SetConsoleMode on stdout with flag ENABLE_VIRTUAL_TERMINAL_PROCESSING, which is absent on platforms below windows 10 build number 10586 according to this comment on stackoverflow. As a debugging measure, removing pwsh_package_management check gets rid of the error on all tested terminals.

    Additional information

    c:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
    OS Name:                   Microsoft Windows 7 Ultimate
    OS Version:                6.1.7601 Service Pack 1 Build 7601
    
    c:\>powershell.exe -Command Get-Command -Module PackageManagement
    
    c:\>echo %ERRORLEVEL%
    0
    
    opened by DaTa- 1
  • Compile failure: targets without InputFlags::IUTF8

    Compile failure: targets without InputFlags::IUTF8

    vt_well_done() uses InputFlags::IUTF8 unconditionally

    https://github.com/watchexec/clearscreen/blob/6bd57aef6926ee98cc40b272a3421b3076bf3b1c/src/lib.rs#L723

    but nix::sys::termios only defines it on certain targets

    https://docs.rs/nix/0.22.0/src/nix/sys/termios.rs.html#604

    so build fails on others (e.g., FreeBSD)

    opened by fullermd 1
  • Explicitely support tmux, fallback if terminfo isn't available

    Explicitely support tmux, fallback if terminfo isn't available

    Within tmux (and screen but that's pre-existing) we can assume the escape and avoid looking up terminfo. This can help on systems which are a bit bare or broken and don't have a functional terminfo. Even outside of these, we can detect for terminfo and not select the variant if we don't find one, which will fall back to the hardcoded sequence more often.

    From https://github.com/watchexec/cargo-watch/issues/218

    opened by passcod 0
  • Compile error on v1.0.4

    Compile error on v1.0.4

    I'm trying to install cargo-watch (latest, v7.8.1) and running into compile errors. This doesn't seem to happen for cargo-watch v7.8.0. It looks like this might be related to the nix package.

    Reason I'm filing the issue here is:

    • cargo-watch depends on
    • clearscreen, which depends on
    • nix v0.20.0
    The error
    INFO - Installing/Updating cargo-watch
        Updating crates.io index
      Installing cargo-watch v7.8.1
       Compiling libc v0.2.98
       Compiling autocfg v1.0.1
       Compiling proc-macro2 v1.0.27
       Compiling getrandom v0.1.16
       Compiling unicode-xid v0.2.2
       Compiling cfg-if v1.0.0
       Compiling syn v1.0.73
       Compiling bitflags v1.2.1
       Compiling memchr v2.4.0
       Compiling ppv-lite86 v0.2.10
       Compiling siphasher v0.3.5
       Compiling ident_case v1.0.1
       Compiling strsim v0.10.0
       Compiling fnv v1.0.7
       Compiling version_check v0.9.3
       Compiling log v0.4.14
       Compiling cfg-if v0.1.10
       Compiling regex-syntax v0.6.25
       Compiling same-file v1.0.6
       Compiling lazy_static v1.4.0
       Compiling either v1.6.1
       Compiling unicode-width v0.1.8
       Compiling camino v1.0.4
       Compiling vec_map v0.8.2
       Compiling strsim v0.8.0
       Compiling termcolor v1.1.2
       Compiling ansi_term v0.11.0
       Compiling glob v0.3.0
       Compiling shell-escape v0.1.5
       Compiling phf_shared v0.8.0
       Compiling walkdir v2.3.2
       Compiling thread_local v1.0.1
       Compiling textwrap v0.11.0
       Compiling memoffset v0.6.4
       Compiling num-traits v0.2.14
       Compiling num-integer v0.1.44
       Compiling nom v5.1.2
       Compiling phf v0.8.0
       Compiling aho-corasick v0.7.18
       Compiling bstr v0.2.16
       Compiling quote v1.0.9
       Compiling regex v1.5.4
       Compiling dirs-sys v0.3.6
       Compiling fsevent-sys v2.0.1
       Compiling atty v0.2.14
       Compiling nix v0.20.0
       Compiling which v4.1.0
       Compiling nix v0.22.0
       Compiling filetime v0.2.14
       Compiling time v0.1.43
       Compiling clap v2.33.3
       Compiling dirs v2.0.2
       Compiling fsevent v0.4.0
       Compiling rand_core v0.5.1
    error[E0433]: failed to resolve: could not find `addr_of` in `ptr`
       --> /Users/spark/.cargo/registry/src/github.com-1ecc6299db9ec823/nix-0.22.0/src/sys/socket/addr.rs:809:24
        |
    809 |                 (len + offset_of!(libc::sockaddr_un, sun_path)) as libc::socklen_t
        |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `addr_of` in `ptr`
        |
        = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error[E0433]: failed to resolve: could not find `addr_of` in `ptr`
        --> /Users/spark/.cargo/registry/src/github.com-1ecc6299db9ec823/nix-0.22.0/src/sys/socket/mod.rs:1768:33
         |
    1768 |             let pathlen = len - offset_of!(sockaddr_un, sun_path);
         |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `addr_of` in `ptr`
         |
         = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
    
       Compiling notify v4.0.17
       Compiling chrono v0.4.19
       Compiling rand_pcg v0.2.1
       Compiling rand_chacha v0.2.2
       Compiling globset v0.4.6
       Compiling rand v0.7.3
    error: aborting due to 2 previous errors
    
    For more information about this error, try `rustc --explain E0433`.
    error: could not compile `nix`
    
    To learn more, run the command again with --verbose.
    warning: build failed, waiting for other jobs to finish...
    error: failed to compile `cargo-watch v7.8.1`, intermediate artifacts can be found at `/var/folders/kf/22xj2m2s2qz93d4cdxdqj5yr0000gn/T/cargo-installwa4soM`
    
    Caused by:
      build failed
    

    I noticed that a change to the offset_of macro was made in the diffs from nix v0.20 to v0.21:

    • https://github.com/nix-rust/nix/compare/v0.20.0...v0.21.0
    • https://github.com/nix-rust/nix/commit/987c8a607b7b5b12660efeb50376ccce6b17e9a6

    So maybe update the version pin in this repo and then cargo-watch can update their dep and hopefully the error is fixed?

    opened by goodspark 0
Releases(v2.0.0)
Cross platform terminal library rust

Cross-platform Terminal Manipulation Library Crossterm is a pure-rust, terminal manipulation library that makes it possible to write cross-platform te

crossterm-rs 2.1k Jan 2, 2023
A screen saver for the terminal 🌃

tnap - Let's take a nap ?? tnap is a screen saver for the terminal. You can rest the terminal in a secure. Features Display images in the terminal and

pigeon-sable 4 Feb 27, 2024
Alacritty - A fast, cross-platform, OpenGL terminal emulator

Alacritty is a modern terminal emulator that comes with sensible defaults, but allows for extensive configuration. By integrating with other applications, rather than reimplementing their functionality, it manages to provide a flexible set of features with high performance. The supported platforms currently consist of BSD, Linux, macOS and Windows.

Alacritty 43.8k Dec 31, 2022
Cross-platform terminal program to download IEEE journals

IEEE Journal Downloader A cross-platform terminal program which tries to download every article in a specified journal and merge the documents into on

Fong Chien Yoong 18 Jul 23, 2022
Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Native cross-platform full feature terminal-based sequence editor for git interactive rebase.

Tim Oram 1.2k Jan 2, 2023
Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.

Bunt: simple macro-based terminal colors and styles bunt offers macros to easily print colored and formatted text to a terminal. It is just a convenie

Lukas Kalbertodt 202 Dec 22, 2022
glicol cli: cross-platform music live coding in terminal

glicol-cli What's this? It's a command line interface that you can use for music live coding with Glicol. It watches a file changes and then update th

Glicol 70 Apr 14, 2023
A library to capture the Screen on Linux, MacOS and Windows.

Captis - A library for capturing the screen on Linux, MacOS and Windows It's a fairly simple library that performs good enough, the OS level APIs that

CrewNew.com 17 Dec 23, 2022
Cross-platform WebView library in Rust for Tauri.

Cross-platform WebView rendering library in Rust that supports all major desktop platforms like Windows, macOS, and Linux. Overview Wry connects the w

Tauri 2.2k Jan 9, 2023
A cross-platform library for retrieving information about connected devices.

Devices devices is a cross-platform library for retrieving information about connected devices. Combined with a library like sysinfo, a more or less c

Hank Jordan 4 Jan 8, 2023
Rusty fast cross-platform 2D drawing library

Bly Rusty fast cross-platform 2D graphics library Concept Easy to use Bly is easy to use and yet can be called from various windowing libraries using

null 4 Feb 27, 2023
A new pure-Rust library for cross-platform low-level access to USB devices.

nusb A new pure-Rust library for cross-platform low-level access to USB devices. Documentation Compared to rusb and libusb Pure Rust, no dependency on

Kevin Mehall 23 Oct 30, 2023
General purpose cross-platform GIS-rendering library written in Rust

Galileo is a general purpose cross-platform geo-rendering library. Web examples Raster tile layer (OSM) Vector tile layer (Maplibre) Use buttons at th

Maxim 16 Dec 15, 2023
Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.

2D graphics in any programming language with just print statements!

Caleb Winston 123 Nov 20, 2022
A small utility that moves the start menu to the top-center of the screen in Windows 11.

TopCenterStart11 A small utility that moves the start menu to the top-center of the screen in Windows 11. As of right now, this application can only p

Ryan de Jonge 12 Nov 12, 2022
a FREE and MODERN split-screen tetris game WITHOUT ADS

tetr:: A ✨ modern ✨ Tetris game made in OpenGL and Rust Gameplay tetr:: is an implementaion of modern Tetris, and essentially a clone of tetr.io. This

Adam Harmansky 3 Sep 10, 2022
Adapt the screen's color spectrum according to the hour of the day in order to improve your sleep

circadianlight What It Is Circadian Light is a program, currently only working on Linux with X, that controls the color spectrum of your screen accord

null 7 Dec 28, 2022
High performance wlroots screen recording, featuring hardware encoding

wl-screenrec High performance wlroots based screen recorder. Uses dma-buf transfers to get surface, and uses the GPU to do both the pixel format conve

Russell Greene 32 Jan 21, 2023
on-screen keyboard display for your coding streams.

⌨ OSKD (On-screen key display) OSKD is an on-screen keyboard display that can be used during streams. It provides an intuitive and easy-to-use interfa

Sammwy 46 May 6, 2023