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;
use cursive::views::{Dialog, TextView};
use cursive::Cursive;
use cursive::{thene, Cursive};
fn main() {
let mut siv = Cursive::default();
@ -9,7 +9,7 @@ fn main() {
siv.load_theme_file("assets/style.toml").unwrap();
// 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(
Dialog::around(TextView::new(

View File

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