fully supporting optional themes with -t
This commit is contained in:
parent
ca9c10cdf2
commit
a7495367f8
@ -6,10 +6,11 @@ extern crate tokio;
|
||||
extern crate reqwest;
|
||||
|
||||
use std::{fs, env};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Arg, App};
|
||||
use cursive::views::{CircularFocus, Dialog, TextView};
|
||||
use cursive::Cursive;
|
||||
use cursive::views::Dialog;
|
||||
use cursive::event::Key;
|
||||
|
||||
use serde_json;
|
||||
@ -28,6 +29,12 @@ async fn main() {
|
||||
.long("config")
|
||||
.value_name("CONFIG")
|
||||
.help("Specify path of config to use")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("theme")
|
||||
.short("t")
|
||||
.long("theme")
|
||||
.value_name("THEME_FILE")
|
||||
.help("Specify theme file on startup")
|
||||
.takes_value(true)).get_matches();
|
||||
|
||||
let config: types::Config = if args.args.len() == 0 {
|
||||
@ -44,18 +51,23 @@ async fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// only load a theme if requested
|
||||
let theme = if let Some(theme) = args.value_of("theme") {
|
||||
Some(PathBuf::from(theme))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut app = cursive::default();
|
||||
|
||||
// optionally load optional theme
|
||||
if let Some(theme) = theme { let _ = app.load_theme_file(theme); }
|
||||
|
||||
app.add_global_callback('q', Cursive::quit);
|
||||
app.add_global_callback(Key::Esc, |s| s.select_menubar());
|
||||
|
||||
|
||||
app.add_layer(CircularFocus::wrap_tab(
|
||||
Dialog::around(TextView::new("something"))
|
||||
.title("Freechat")
|
||||
.button("Random", |_s| {})
|
||||
.button("Quit", |s| { s.quit() })
|
||||
));
|
||||
|
||||
// menu bar at the top lets us pick between different servers in the config
|
||||
for server in config.servers.iter() {
|
||||
@ -68,7 +80,10 @@ async fn main() {
|
||||
Some(channels) => {
|
||||
// add the channels to the current sub tree
|
||||
for channel in channels {
|
||||
app.menubar().add_leaf(name, |_| {});
|
||||
app.menubar().add_leaf(&name, move |appref| {
|
||||
let address = format!("{}", channel.ip);
|
||||
appref.add_layer(Dialog::info(address));
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
|
Loading…
Reference in New Issue
Block a user