-
Notifications
You must be signed in to change notification settings - Fork 287
Upgrade from 0.3 to 0.4
Zrzka edited this page Nov 15, 2019
·
1 revision
WARNING
This new version contains some cool features but to get those features working I needed to add some user API breaking changes. I really did not want to do this but it had to be done for some reasons.
old
use crossterm::terminal::terminal;
use crossterm::cursor::cursor;
use crossterm::style::color;
use crossterm::Context;
let context: Rc<Context> = Context::new();
let cursor = cursor(&context);
let terminal = terminal(&context);
let color = color(&context);
new
use crossterm::Screen;
let screen: Screen = Screen::default();
let cursor = cursor(&screen);
let terminal = terminal(&screen);
let color = color(&screen);
Instead you could do it like the following:
use crossterm::Crossterm;
use crossterm::style::{Color, input, style};
// 1: use the `Crossterm` type
let crossterm = Crossterm::new();
let styled_object = crossterm.style("Red text on Black background").with(Color::Red).on(Color::Black);
styled_object.paint(&screen);
// 2: use the `Terminal` type
let styled_object = style("Red text on Black background").with(Color::Red).on(Color::Black);
styled_object.paint(&screen);
Also I have changed how the alternate and raw screen are working.
// could not be used any more
::crossterm::AlternateScreen::from();
// cannot put any Write into raw mode.
::std::io::Write::into_raw_mode()
This now should be done with the Screen
type like:
use crossterm::Screen;
use crossterm::cursor::cursor;
// this will create a default screen.
let screen = Screen::default();
// this will create a new screen with raw modes enabled.
let screen = Screen::new(true);
// `false` specifies whether the alternate screen should be in raw modes.
if let Ok(alternate) = screen.enable_alternate_modes(false)
{
let cursor = cursor(&alternate.screen);
}
- ::crossterm::Crossterm::write() is gone.
- ::crossterm::Crossterm::flush() is gone.
- Context type is removed
- StateManager is removed
- ScreenManager type is renamed to Stdout.