Crate term_cursor[−][src]
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 |
Down |
A type that when |
Goto |
A type that when |
Left |
A type that when |
Relative |
A type that when |
Right |
A type that when |
Up |
A type that when |
Enums
Error |
The error generated by operations on the terminal. |
Functions
clear |
Clear the screen, i.e. setting every character in the terminal to a space |
get_pos |
Get the current cursor position. |
set_pos |
Set the cursor position to the specified coordinates. |