-
Notifications
You must be signed in to change notification settings - Fork 287
Upgrade from 0.4 to 0.5
WARNING
I workded on making the user API more convenient therefore I had to make some changes to the user API. The problem with 0.4
is that you need to pass a Screen
to the modules: cursor(), color(), terminal()
.
In the new situation you only have to do this when working with raw or alternate screen. When you just want to perform actions like styling on the main screen you don't have to to pass in the Screen
any more. This will look like the following:
old
let screen = Screen::default();
let color = color(&screen);
let cursor = cursor(&screen);
let input = input(&screen);
let terminal = terminal(&screen);
let crossterm = Crossterm::new(&screen);
let terminal = Terminal::new(&screen.stdout);
let cursor = TerminalCursor::new(&screen.stdout);
let color = TerminalColor::new(&screen.stdout);
let input = TerminalInput::new(&screen.stdout);
new
let color = color();
let cursor = cursor();
let input = input();
let terminal = terminal();
let crossterm = Crossterm::new();
let terminal = Terminal::new();
let cursor = TerminalCursor::new();
let color = TerminalColor::new();
let input = TerminalInput::new();
When working with alternate and or raw screen you still have to provide a Screen
instance since information of the alternate and raw screen is stored in it. When doing this, the actions of the module will be perfomed on the alternate screen. If you don't do this your actions will executed at the main screen.
use crossterm::cursor;
use crossterm::color;
use crossterm::input;
use crossterm::terminal;
let screen = Screen::default();
if let Ok(alternate) = screen.enable_alternate_modes(false) {
let screen = alternate.screen;
let color = color::from_screen(&screen);
let cursor = cursor::from_screen(&screen);
let input = input::from_screen(&screen);
let terminal = terminal::from_screen(&screen);
let crossterm = Crossterm::from_screen(&screen);
let terminal = Terminal::from_output(&screen.stdout);
let cursor = TerminalCursor::from_output(&screen.stdout);
let color = TerminalColor::from_output(&screen.stdout);
let input = TerminalInput::from_output(&screen.stdout);
}