#cursor #cli #crossterm #terminal #crossplatform

crossterm_cursor

A cross-platform library for moving the terminal cursor

5 releases

✓ Uses Rust 2018 edition

new 0.2.3 May 20, 2019
0.2.2 May 15, 2019
0.2.1 Apr 11, 2019
0.2.0 Apr 10, 2019
0.1.0 Jan 27, 2019

#15 in HTTP client

Download history 111/week @ 2019-02-04 147/week @ 2019-02-11 115/week @ 2019-02-18 119/week @ 2019-02-25 135/week @ 2019-03-04 78/week @ 2019-03-11 100/week @ 2019-03-18 103/week @ 2019-03-25 127/week @ 2019-04-01 330/week @ 2019-04-08 200/week @ 2019-04-15 326/week @ 2019-04-22 313/week @ 2019-04-29 265/week @ 2019-05-06 495/week @ 2019-05-13

920 downloads per month
Used in 3 crates (2 directly)

MIT license

34KB
647 lines

Crossterm Cursor | cross-platform cursor movement.

Lines of Code Latest Version MIT docs Join us on Discord

This crate allows you to move the terminal cursor cross-platform. It supports all UNIX and windows terminals down to windows 7 (not all terminals are tested see Tested Terminals for more info)

This crate is a sub-crate of crossterm to move the cursor, and can be use individually.

Other sub-crates are:

When you want to use other modules as well you might want to use crossterm with feature flags.

Table of contents:

Getting Started

This documentation is only for crossterm_cursor version 0.2. Also, check out the examples folders with detailed examples for all functionality of this crate.

Add the crossterm_cursor package to your Cargo.toml file.

[dependencies]
crossterm_cursor = "0.2"

Import the crossterm_cursor modules you want to use.

extern crate crossterm_cursor;

pub use crossterm_cursor::{cursor, TerminalCursor};

Useful Links

Features

These are the features of this crate:

  • Cross-platform
  • Multithreaded (send, sync)
  • Detailed Documentation
  • Few Dependencies
  • Cursor
    • Moving n times (up, down, left, right)
    • Position (set/get)
    • Store cursor position and resetting to that later
    • Hiding/Showing
    • Blinking Cursor (only some terminals are supporting this)

Examples

The examples folder has more complete and verbose examples.

use crossterm_cursor::cursor;

let mut cursor = cursor();

/// Moving the cursor
// Set the cursor to position X: 10, Y: 5 in the terminal
cursor.goto(10,5);

// Move the cursor up,right,down,left 3 cells.
cursor.move_up(3);
cursor.move_right(3);
cursor.move_down(3);
cursor.move_left(3);

/// Safe the current cursor position to recall later
// Goto X: 5 Y: 5
cursor.goto(5,5);
// Safe cursor position: X: 5 Y: 5
cursor.save_position();
// Goto X: 5 Y: 20
cursor.goto(5,20);
// Print at X: 5 Y: 20.
print!("Yea!");
// Reset back to X: 5 Y: 5.
cursor.reset_position();
// Print 'Back' at X: 5 Y: 5.
print!("Back");

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

Tested terminals

  • Windows Powershell
    • Windows 10 (pro)
  • Windows CMD
    • Windows 10 (pro)
    • Windows 8.1 (N)
  • Ubuntu Desktop Terminal
    • Ubuntu 17.10
  • (Arch, Manjaro) KDE Konsole
  • Linux Mint

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.

Authors

  • Timon Post - Project Owner & creator

License

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

Dependencies

~575KB