fully supporting optional themes with -t

This commit is contained in:
shockrah 2021-01-17 20:10:40 -08:00
parent ca9c10cdf2
commit a7495367f8

View File

@ -6,10 +6,11 @@ extern crate tokio;
extern crate reqwest; extern crate reqwest;
use std::{fs, env}; use std::{fs, env};
use std::path::PathBuf;
use clap::{Arg, App}; use clap::{Arg, App};
use cursive::views::{CircularFocus, Dialog, TextView};
use cursive::Cursive; use cursive::Cursive;
use cursive::views::Dialog;
use cursive::event::Key; use cursive::event::Key;
use serde_json; use serde_json;
@ -28,6 +29,12 @@ async fn main() {
.long("config") .long("config")
.value_name("CONFIG") .value_name("CONFIG")
.help("Specify path of config to use") .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(); .takes_value(true)).get_matches();
let config: types::Config = if args.args.len() == 0 { 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(); 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('q', Cursive::quit);
app.add_global_callback(Key::Esc, |s| s.select_menubar()); 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 // menu bar at the top lets us pick between different servers in the config
for server in config.servers.iter() { for server in config.servers.iter() {
@ -68,7 +80,10 @@ async fn main() {
Some(channels) => { Some(channels) => {
// add the channels to the current sub tree // add the channels to the current sub tree
for channel in channels { 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));
});
} }
}, },
_ => {} _ => {}