Skip to content

Upgrade from 0.2.1 to 0.3.0

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 braking changes. I really did not want to do this but it had to be done for some reasons. Check LINK (updates crossterm version) for more info about why.

First thing that has changed is that you need to pass a reference to an Rc<Context> to the modules: cursor(), color(), terminal()

old

use crossterm::terminal::terminal;
use crossterm::cursor::cursor;
use crossterm::style::color;

/// Old situation
let cursor = cursor();
let terminal = terminal();
let color = color();

new

use crossterm::Context;

let context: Rc<Context> = Context::new();

let cursor = cursor(&context);
let terminal = terminal(&context);
let color = color(&context);

Also the ::crossterm::style::paint() function does not exits anymore like before:

Instead you could do it like the following:

use crossterm::Crossterm;
use crossterm::style::Color;
use crossterm::terminal::terminal;

// 1: use the `Crossterm` type
let crossterm = Crossterm::new();
let mut color = crossterm.paint("Red on Blue").with(Color::Red).on(Color::Blue);

// 2: use the `Terminal` type
let context: Rc<Context> = Context::new();
let terminal = terminal(&context).paint("Red on Blue").with(Color::Red).on(Color::Blue);

And you do not need mut for a lot of function calls anymore.