crossterm 0.4.0

An crossplatform terminal library for manipulating terminals.

Crossterm | cross-platform terminal manipulating library written in rust.

Latest Version MIT licensed Examples Changelog Release Nodes

Ever got disappointed when a terminal library for rust was only written for unix systems? Crossterm provides the same core functionalities for both windows and unix systems.

Crossterm aims to be simple and easy to call in code. Though the simplicity of Crossterm, you do not have to worry about the platform you are working with. You can just call whatever action you want and behind the scenes it will check what to do based on the current platform.

This crate supports all unix and windows terminals down to windows 7 (not all terminals are tested see Tested Terminals for more info)

Table of contents:

Getting Started

This documentation is only for Crossterm version 0.4.0 if you have an older version of Crossterm I suggest you check the Upgrade Manual for more information about how to upgrade to a newer version. Also check out the examples folders which detailed examples for all functionality of this crate.

Add the Crossterm package to your Cargo.toml file.

crossterm = "0.4.0"

And import the Crossterm modules you want to use.

extern crate crossterm;

// this module is used for styling the terminal
use self::crossterm::style::*;
// this module is used for cursor related actions
use self::crossterm::cursor::*;
// this mudule is used for terminal related actions
use self::crossterm::terminal::*;
// this mudule is used for input related actions
use self::crossterm::input::*;

Useful Links


These are the features from this crate:

  • Cursor.
    • Moving n times Up, Down, Left, Right.
    • Goto a certain position.
    • Get cursor position
    • Storing the current cursor position and resetting to that stored cursor position later.
    • Hiding an showing the cursor.
    • Control over blinking of the terminal cursor (only some terminals are supporting this).
  • Styled output
    • Foreground color (16 base colors)
    • Background color (16 base colors)
    • 256 color support (unix only).
    • Text Attributes like: bold, italic, underscore and crossed word ect (unix only).
    • Custom ANSI color code input to set fore- and background color (unix only).
  • Terminal
    • Clearing (all lines, current line, from cursor down and up, until new line)
    • Scrolling (Up, down)
    • Get the size of the terminal
    • Set the size of the terminal.
    • Alternate screen
    • Raw screen
  • Input
    • Read character
    • Read line
    • Read async
    • Read async until
  • Exit the current process.
  • Everything is multithreaded (Send, Sync)
  • Detailed documentation on every item.
  • Crossplatform

Crossterm Type | see more

This is a wrapper for all the modules crossterm provides like terminal, cursor, styling and input.

// screen wheron the `Crossterm` methods will be executed.
let screen = Screen::default();
let crossterm = Crossterm::new(&screen);

// get instance of the modules, whereafter you can use the methods the particulary module provides. 
let color = crossterm.color();
let cursor = crossterm.cursor();
let terminal = crossterm.terminal();

// styling
let style ="Black font on Green background color").with(Color::Black).on(Color::Green);

Styled Font | see more

This module provides the functionalities to style the terminal cursor.

use crossterm::style::{Color, style};
use crossterm::Screen; 

// store objcets so it could be painted later to the screen.   
let style1 = style("Some Blue font on Black background").with(Color::Blue).on(Color::Black);
let style2 = style("Some Red font on Yellow background").with(Color::Red).on(Color::Yellow);

let screen = Screen::default();

/// !! The following code only works for unix based systems !!
// some attributes
let normal = style("Normal text");
let bold = style("Bold text").bold();
let italic = style("Italic text").italic();
let slow_blink = style("Slow blinking text").slow_blink();
let rapid_blink = style("Rapid blinking text").rapid_blink();
let hidden = style("Hidden text").hidden();
let underlined = style("Underlined text").underlined();
let reversed = style("Reversed text").reverse();
let dimmed = style("Dim text").dim();
let crossed_out = style("Crossed out font").crossed_out();

// paint styled text to screen (this could also be called inline)

// cursom rgb value
style("RGB color (10,10,10) ").with(Color::Rgb {
    r: 10,
    g: 10,
    b: 10

// custom ansi color value
style("ANSI color value (50) ").with(Color::AnsiValue(50)).paint(&screen);

Cursor | see more

This module provides the functionalities to work with the terminal cursor.

use crossterm::Screen;
use crossterm::cursor;

// create Screen to wheron the `cursor()` should function.
let screen = Screen::default();
let mut cursor = cursor(&screen);

/// Moving the cursor
// Set the cursor to position X: 10, Y: 5 in the terminal

// Move the cursor up,right,down,left 3 cells.

/// Safe the current cursor position to recall later
// Goto X: 5 Y: 5
// Safe cursor position: X: 5 Y: 5
// Goto X: 5 Y: 20
// Print at X: 5 Y: 20.
// Reset back to X: 5 Y: 5.
// Print 'Back' at X: 5 Y: 5.

// hide cursor
// show cursor;
// blink or not blinking of the cursor (not widely supported)

Input | see more

This module provides the functionalities to work with terminal input.

Check this for handling async input.

use crossterm::Screen;
use crossterm::input;

// create Screen to wheron the `cursor()` should function.
let screen = Screen::default();
let mut input = input(&screen);

 match input.read_char() {
    Ok(s) => println!("char typed: {}", s),
    Err(e) => println!("char error : {}", e),
 match input.read_line() {
     Ok(s) => println!("string typed: {}", s),
     Err(e) => println!("error: {}", e),

Terminal | see more

This module provides the functionalities to work with the terminal in general.

use crossterm::terminal::{terminal,ClearType};
use crossterm::Screen;

// create Screen to wheron the `terminal()` should function.
let screen = Screen::default();
let mut terminal = terminal(&screen);

// Clear all lines in terminal;
// Clear all cells from current cursor position down.
// Clear all cells from current cursor position down.
// Clear current line cells.
// Clear all the cells until next line.

// Get terminal size
let (width, height) = terminal.terminal_size();
print!("X: {}, y: {}", width, height);

// Scroll down, up 10 lines.

// Set terminal size (width, height)

// exit the current process.

// write to the terminal whether you are on the main screen or alternate screen.
terminal.write("Some text\n Some text on new line");

Check these links: AlternateScreen and RawScreen for information about how to work with these features.

Tested terminals

  • Windows Powershell
    • Windows 10 (pro)
  • Windows CMD
    • Windows 10 (pro)
    • Windows 8.1 (N)
  • Ubuntu Desktop Terminal
    • Ubuntu 17.10
  • Arch linux Konsole

This crate supports all Unix terminals and windows terminals down to Windows 7 but not all of them have been tested. If you have used this library for a terminal other than the above list without issues feel free to add it to the above list, I really would appreciate it.


This library is not stable yet but I expect it to not to change that much anymore. And if there are any changes that affect previous versions I will describe what to change when upgrading Crossterm to a newer version.


I still have some things in mind to implement.

  • Handling mouse events I want to be able to do something based on the clicks the user has done with its mouse.
  • Handling key events I want to be able to read key combination inputs.
  • Tests Also, I want to have tests for this crate, and yes maybe a little late :). But I find it difficult to test some functionalities because how would you ever test if the screen is indeed int alternate, raw modes or how would you ever test if the terminal cursor is moved certainly.


I highly appreciate it when you are contributing to this crate. Also Since my native language is not English my grammar and sentence order will not be perfect. So improving this by correcting these mistakes will help both me and the reader of the docs.

Check Contributing for more info about branches and code architecture.


  • Timon Post - Project Owner & creator


This project is licensed under the MIT License - see the file for details