Update theme example to use Cursive::load_toml

This commit is contained in:
Alexandre Bury 2018-07-22 20:20:31 -07:00
parent 4ccc07c6d3
commit f5535f2db7
2 changed files with 4 additions and 6 deletions

View File

@ -1,7 +1,7 @@
extern crate cursive; extern crate cursive;
use cursive::views::{Dialog, TextView}; use cursive::views::{Dialog, TextView};
use cursive::Cursive; use cursive::{thene, Cursive};
fn main() { fn main() {
let mut siv = Cursive::default(); let mut siv = Cursive::default();
@ -9,7 +9,7 @@ fn main() {
siv.load_theme_file("assets/style.toml").unwrap(); siv.load_theme_file("assets/style.toml").unwrap();
// Or you can directly load it from a string for easy deployment. // Or you can directly load it from a string for easy deployment.
// siv.load_theme(include_str!("../assets/style.toml")).unwrap(); siv.load_toml(include_str!("../assets/style.toml").unwrap());
siv.add_layer( siv.add_layer(
Dialog::around(TextView::new( Dialog::around(TextView::new(

View File

@ -313,16 +313,14 @@ impl Cursive {
pub fn load_theme_file<P: AsRef<Path>>( pub fn load_theme_file<P: AsRef<Path>>(
&mut self, filename: P, &mut self, filename: P,
) -> Result<(), theme::Error> { ) -> Result<(), theme::Error> {
self.set_theme(try!(theme::load_theme_file(filename))); theme::load_theme_file(filename).map(|theme| self.set_theme(theme))
Ok(())
} }
/// Loads a theme from the given string content. /// Loads a theme from the given string content.
/// ///
/// Content must be valid toml. /// Content must be valid toml.
pub fn load_toml(&mut self, content: &str) -> Result<(), theme::Error> { pub fn load_toml(&mut self, content: &str) -> Result<(), theme::Error> {
self.set_theme(try!(theme::load_toml(content))); theme::load_toml(content).map(|theme| self.set_theme(theme))
Ok(())
} }
/// Sets the refresh rate, in frames per second. /// Sets the refresh rate, in frames per second.