Expand description
§Intro
term_cursor
is a crate for handling terminal cursor movement in a platform independent way.
The supported platforms are:
Windows
Linux
macOS
FreeBSD
OpenBSD
Throughout this crate X and Y are used to denote the coordinates of the cursor.
X corresponds to columns and Y corresponds to rows.
All tuples like (i32, i32)
are interpreted as (X, Y)
.
§API
This crate provides 2 APIs that can be used to achieve the same effects:
- A functions based approach that provides very simple functions to directly interact with the terminal (see the functions
set_pos
,get_pos
andclear
). - A newtype pattern based approach that provies a bunch of types which all implement
std::fmt::Display
(see the structs section below). These types call theset_pos
,get_pos
andclear
functions internally, when they get formatted.
§Watch out!
- Both APIs always operate on the “default” terminal that is bound to the process.
In other words, on Windows
GetStdHandle(STD_OUTPUT_HANDLE)
is used, and on *NIX, the ANSI terminal communcation is done throughstdout
/stdin
. - Drawing outside the boundaries of the buffer / terminal is undefined behaviour.
Structs§
- Clear
- A type that when
Display
ed, clears the entire terminal screen. - Down
- A type that when
Display
ed, moves the cursor down by the specified amount. - Goto
- A type that when
Display
ed, moves the cursor to the specified coordinates. - Left
- A type that when
Display
ed, moves the cursor left by the specified amount. - Relative
- A type that when
Display
ed, moves the cursor by the specified amounts. - Right
- A type that when
Display
ed, moves the cursor right by the specified amount. - Up
- A type that when
Display
ed, moves the cursor up by the specified amount.
Enums§
- Error
- The error generated by operations on the terminal.