|
@@ -6,6 +6,7 @@ use std::fs::{File};
|
|
use std::io::prelude::*;
|
|
use std::io::prelude::*;
|
|
use std::process::exit;
|
|
use std::process::exit;
|
|
use std::{thread, time};
|
|
use std::{thread, time};
|
|
|
|
+use std::env;
|
|
|
|
|
|
use argparse::{ArgumentParser, Store};
|
|
use argparse::{ArgumentParser, Store};
|
|
use pancurses::{
|
|
use pancurses::{
|
|
@@ -13,12 +14,18 @@ use pancurses::{
|
|
Window,
|
|
Window,
|
|
COLOR_GREEN, COLOR_BLACK
|
|
COLOR_GREEN, COLOR_BLACK
|
|
};
|
|
};
|
|
-use yaml_rust::{YamlLoader, YamlEmitter};
|
|
|
|
|
|
+use yaml_rust::{YamlLoader, YamlEmitter, Yaml};
|
|
|
|
|
|
fn main() {
|
|
fn main() {
|
|
|
|
|
|
// Argument handling
|
|
// Argument handling
|
|
let mut difficulty = String::from("");
|
|
let mut difficulty = String::from("");
|
|
|
|
+ // TODO can't use ? ?
|
|
|
|
+ let foo = env::var("HOME")?.add(".config/");
|
|
|
|
+ let config_dir = match env::var("XDG_CONFIG_HOME") {
|
|
|
|
+ Ok(dir) => dir,
|
|
|
|
+ Err(_) => String::from("foo"),
|
|
|
|
+ };
|
|
let mut config_location = String::from("~/.config/fallout-terminal.yaml");
|
|
let mut config_location = String::from("~/.config/fallout-terminal.yaml");
|
|
let config_help = format!("Config file location, default {}", config_location);
|
|
let config_help = format!("Config file location, default {}", config_location);
|
|
{
|
|
{
|
|
@@ -48,37 +55,37 @@ fn main() {
|
|
// Config file handling
|
|
// Config file handling
|
|
let mut config_file = match File::open(config_location.as_str()) {
|
|
let mut config_file = match File::open(config_location.as_str()) {
|
|
Ok(config_file) => config_file,
|
|
Ok(config_file) => config_file,
|
|
- Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
|
|
|
|
- // Write the file if it doesn't exist
|
|
|
|
- let mut new_config_file = match File::create(config_location.as_str()) {
|
|
|
|
- Ok(f) => f,
|
|
|
|
- Err(e) => {
|
|
|
|
- println!("Could not create {}: {}", config_location, e);
|
|
|
|
- exit(1);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- // TODO write yaml
|
|
|
|
- new_config_file.write_all(b"");
|
|
|
|
- new_config_file
|
|
|
|
- }
|
|
|
|
Err(e) => {
|
|
Err(e) => {
|
|
println!("Could not open {}: {}", config_location, e);
|
|
println!("Could not open {}: {}", config_location, e);
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- let mut config_content = String::new();
|
|
|
|
- match config_file.read_to_string(&mut config_content) {
|
|
|
|
- Ok(_) => (),
|
|
|
|
|
|
+ let mut config_str = String::new();
|
|
|
|
+ let config: Vec<Yaml>;
|
|
|
|
+ match config_file.read_to_string(&mut config_str) {
|
|
|
|
+ Ok(_) => match YamlLoader::load_from_str(&config_str) {
|
|
|
|
+ Ok(conf) => (config = conf),
|
|
|
|
+ Err(e) => {
|
|
|
|
+ println!("Could not parse YAML in {}: {}", config_location, e);
|
|
|
|
+ exit(1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
Err(e) => {
|
|
Err(e) => {
|
|
println!("Could not read {}: {}", config_location, e);
|
|
println!("Could not read {}: {}", config_location, e);
|
|
exit(1);
|
|
exit(1);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ let mut out_str = String::new();
|
|
|
|
+ let mut emitter = YamlEmitter::new(&mut out_str);
|
|
|
|
+ for x in &config {
|
|
|
|
+ println!("{:?}", emitter.dump(x).unwrap());
|
|
|
|
+ }
|
|
|
|
+
|
|
let window = initscr();
|
|
let window = initscr();
|
|
noecho();
|
|
noecho();
|
|
- // window.printw("Hello from Rust");
|
|
|
|
|
|
+ window.printw("Hello from Rust");
|
|
window_prep();
|
|
window_prep();
|
|
intro(&window);
|
|
intro(&window);
|
|
window.refresh();
|
|
window.refresh();
|