&'a str
SetTitle
command to change the terminal title.Colorize
and Styler
impls, add an impl for String
STDOUT_FILENO
if /dev/tty
is missing.”./dev/tty
.STDOUT_FILENO
if /dev/tty
is missing.ContentStyle
to bitmask.SetAttributes
command.Attributes
type, which is a bitfield of enabled attributes.exit()
, was useless.Command
for &T: Command
. This allows commands to be queued by reference, as well as by value.Clone
trait bounds from StyledContent
.StyledContent::style_mut
.execute!
and queue!
.execute!
and queue!
.ContentStyle::apply
to take self by value instead of reference, to prevent an unnecessary extra clone.Debug
, Clone
, Copy
, etc) to all of the command structsResetColor
uses &'static str
instead of String
queue
macro were it consumed a type and required an type to be Copy
.input
module with brand new event
moduledocs/UPGRADE.md
with the Upgrade Paths documentationMoveToColumn
, MoveToPreviousLine
, MoveToNextLine
commandsscreen
module into terminal
screen::AlternateScreen
screen::Rawscreen
Rawscreen::into_raw_mode
and Rawscreen::disable_raw_mode
to terminal::enable_raw_mode
and terminal::disable_raw_mode
screen::EnterAlternateScreen
and screen::LeaveAlternateScreen
to terminal::EnterAlternateScreen
and terminal::LeaveAlternateScreen
utils::Output
command with style::Print
commandqueue!
& execute!
macrosinput::stop_reading_thread()
functionMajor API-change, removed old-api
Crossterm
typeTerminalCursor
, TerminalColor
, Terminal
cursor()
, color()
, terminal()
module::types
(cursor::MoveTo
)input
moduleEnableMouseCapture
and EnableMouseCapture
commandscursor
modulecrossterm::cursor::position
in place of TerminalCursor::pos
Goto
to MoveTo
Up
to MoveLeft
Right
to MoveRight
Down
to MoveDown
BlinkOn
to EnableBlinking
BlinkOff
to DisableBlinking
ResetPos
to ResetPosition
SavePos
to SavePosition
terminal
crossterm::terminal::size
in place of Terminal::size
crossterm::terminal::exit
in place of Terminal::exit
style module
ObjectStyle
to ContentStyle
. Now full names are used for methodsStyledObject
to StyledContent
and made members privatePrintStyledFont
to PrintStyledContent
attr
method to attribute
.Attribute::NoInverse
to NoReverse
Colored
private, user should use commands insteadSetFg
-> SetForegroundColor
SetBg
-> SetBackgroundColor
SetAttr
-> SetAttribute
ContentStyle::fg_color
-> ContentStyle::foreground_color
ContentStyle::bg_color
-> ContentStyle::background_color
ContentStyle::attrs
-> ContentStyle::attributes
crossterm_
crates code was moved to the crossterm
cratecrossterm_cursor
is in the cursor
module, etc.crossterm_cursor
crossterm_input
crossterm_screen
crossterm_style
crossterm_terminal
crossterm_utils
crossterm_cursor
0.4.0RAW_MODE_ENABLED
with is_raw_mode_enabled
(PR #9)SyncReader
& InputEvent::CursorPosition
for pos_raw()
(PR #10)crossterm_input
0.5.0SyncReader::next()
Windows and UNIX behavior (PR #5)(0, 0)
AsyncReader
AsyncReader
SIGTTIN
when executed under the LLDB0
crossterm_screen
0.3.2to_alternate
switch back to main screen if it fails to switch into raw mode (PR #4)EnterAlternateScreen
LeaveAlternateScreen
crossterm_style
0.5.2lib.rs
SetBg
command, WinApi logicStyledObject
, used stdout for resetting terminal colorResetColor
commandcrossterm_terminal
0.3.2crossterm_cursor::sys
dependency (PR #2)crossterm_utils
0.4.0sys::unix::RAW_MODE_ENABLED
replaced with sys::unix::is_raw_mode_enabled()
(breaking)lazy_static
dependencycrossterm_winapi
0.3.0crossterm-rs
organizationAs a preparation for crossterm 0.1.0 we have moved crossterm to an organisation called ‘crossterm-rs’.
Debug
for ObjectStyle
debug-derive, Serialize/Deserialize for key events serdecrossterm::Result
from all api's: return_crossterm_resultTerminalCursor::pos()
returns Result<(u16, u16)>
Terminal::size()
returns Result<(u16, u16)>
TerminalCursor::move_*
returns crossterm::Result
ExecutableCommand::queue
returns crossterm::Result
QueueableCommand::queue
returns crossterm::Result
get_available_color_count
returns no resultRawScreen::into_raw_mode
returns crossterm::Result
instead of io::Result
RawScreen::disable_raw_mode
returns crossterm::Result
instead of io::Result
AlternateScreen::to_alternate
returns crossterm::Result
instead of io::Result
TerminalInput::read_line
returns crossterm::Result
instead of io::Result
TerminalInput::read_char
returns crossterm::Result
instead of io::Result
AsyncReader::stop_reading()
to stop()
RawScreen::disable_raw_mode_on_drop
to keep_raw_mode_on_drop
TerminalCursor::reset_position()
to restore_position()
Command::get_anis_code()
to ansi_code()
available_color_count
to available_color_count()
Terminal::terminal_size
to Terminal::size
Console::get_handle
to Console::handle
i16
values for indexing: set size, set cursor pos, scrolling synced to u16
valuesSyncReader
This release is all about moving to a stabilized API for 1.0.
from_screen
, from_output
Arc<TerminalOutput>
from all internal Api's.TerminalOutput
Screen
NoItalic
attributeAttributes
ColorType
since it was unnecessary.Screen
unless working with when working with alternate or raw screen PRas_any()
and as_any_mut()
from TerminalOutput
Send
, Sync
)This version has some braking changes check upgrade manual for more information about what is changed. I think you should not switch to version 0.3.0
if you aren't going to use the AlternateScreen feature. Because you will have some work to get to the new version of crossterm depending on your situation.
Some Features crossterm 0.3.0
This create supports alternate screen for both windows and unix systems. You can use
*Nix style applications often utilize an alternate screen buffer, so that they can modify the entire contents of the buffer, without affecting the application that started them. The alternate buffer is exactly the dimensions of the window, without any scrollback region. For an example of this behavior, consider when vim is launched from bash. Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
I Highly recommend you to check the examples/program_examples/first_depth_search
for seeing this in action.
This crate now supports raw screen for both windows and unix systems. What exactly is raw state:
Crossterm
.Added examples for each version of the crossterm version. Also added a folder with some real life examples.
What is the Context
all about? This Context
has several reasons why it is introduced into crossterm version 0.3.0
. These points are related to the features like Alternatescreen
and managing the terminal state.
At first Terminal state
:
Because this is a terminal manipulating library there will be made changes to terminal when running an process. If you stop the process you want the terminal back in its original state. Therefore, I need to track the changes made to the terminal.
At second Handle to the console
In Rust we can use stdout()
to get an handle to the current default console handle. For example when in unix systems you want to print something to the main screen you can use the following code:
write!(std::io::stdout(), "{}", "some text").
But things change when we are in alternate screen modes. We can not simply use stdout()
to get a handle to the alternate screen, since this call returns the current default console handle (handle to mainscreen).
Because of that we need to store an handle to the current screen. This handle could be used to put into alternate screen modes and back into main screen modes. Through this stored handle Crossterm can execute its command and write on and to the current screen whether it be alternate screen or main screen.
For unix systems we store the handle gotten from stdout()
for windows systems that are not supporting ANSI escape codes we store WinApi HANDLE
struct witch will provide access to the current screen.
So to recap this Context
struct is a wrapper for a type that manges terminal state changes. When this Context
goes out of scope all changes made will be undone. Also is this Context
is a wrapper for access to the current console screen.
Because Crossterm needs access to the above to types quite often I have chosen to add those two in one struct called Context
so that this type could be shared throughout library. Check this link for more info: cleanup of rust code. More info over writing to alternate screen buffer on windows and unix see this link
Now the user has to pass an context type to the modules of Crossterm like this:
let context = Context::new(); let cursor = cursor(&context); let terminal = terminal(&context); let color = color(&context);
Because this looks a little odd I will provide a type withs will manage the Context
for you. You can call the different modules like the following:
let crossterm = Crossterm::new(); let color = crossterm.color(); let cursor = crossterm.cursor(); let terminal = crossterm.terminal();
When you want to switch to alternate screen there are a couple of things to keep in mind for it to work correctly. First off some code of how to switch to Alternate screen, for more info check the alternate screen example.
Create alternate screen from Context
// create context. let context = crossterm::Context::new(); // create instance of Alternatescreen by the given context, this wil also switch to it. let mut screen = crossterm::AlternateScreen::from(context.clone()); // write to the alternate screen. write!(screen, "test");
Create alternate screen from Crossterm
:
// create context. let crossterm = ::crossterm::Crossterm::new(); // create instance of Alternatescreen by the given refrence to crossterm, this wil also switch to it. let mut screen = crossterm::AlternateScreen::from(&crossterm); // write to the alternate screen. write!(screen, "test");
like demonstrated above, to get the functionalities of cursor(), color(), terminal()
also working on alternate screen. You need to pass it the same Context
as you have passed to the previous three called functions, If you don't use the same Context
in cursor(), color(), terminal()
than these modules will be using the main screen and you will not see anything at the alternate screen. If you use the Crossterm type you can get the Context
from it by calling the crossterm.get_context() whereafter you can create the AlternateScreen from it.