crossterm_screen crate is deprecated and no longer maintained. The GitHub repository will
be archived soon. All the code is being moved to the
crate. You can learn more in
the Merge sub-crates to the crossterm crate
crossterm_screen crate provides the functionality to work with the terminal screen.
This documentation does not contain a lot of examples. The reason is that it's fairly obvious how to use this crate. Although, we do provide examples repository to demonstrate the capabilities.
A screen buffer is a two-dimensional array of characters and color data to be output in a console window. A terminal can have multiple of those screen buffers, and the active screen buffer is the one that is displayed on the screen.
Crossterm allows you to switch between those buffers; the screen you are working in is called the 'main screen'. We call the other screen the 'alternate screen'. One note to take is that crossterm does not support the creation and switching between several buffers.
Normally you are working on the main screen but an alternate screen is somewhat different from a normal screen. For example, it has the exact dimensions of the terminal window, without any scroll back region. An example of this is vim when it is launched from bash.
Vim uses the entirety of the screen to edit the file, then exits to bash leaving the original buffer unchanged.
Crossterm provides the ability to switch to the alternate screen, make some changes, and then go back to the main screen. The main screen will still have its original data since we made all the edits on the alternate screen.
By default, the terminal behaves in a certain way. You can think of going to a new line if the input is at the end of the current line, or interpreting backspace to remove letters. Sometimes it can be useful to disable these modes because this is undesirable. This may be undesirable if your application wants to read the input without it being shown on the screen. Raw modes are the modes to create this possibility. Those modes will be set when enabling raw modes:
- Input will not be forwarded to screen
- Input will not be processed on enter press
- Input will not be line buffered (input sent byte-by-byte to input buffer)
- Special keys like backspace and CTL+C will not be processed by terminal driver
- New line character will not be processed therefore
println!can't be used, use
An alternate screen.
A command to switch to the alternate screen.
A command to switch back to the main screen.
A raw screen.
Allows to enable raw mode.