From 4c0a2646d297b8890208573114f82aad1fc21241 Mon Sep 17 00:00:00 2001 From: dvkt Date: Fri, 10 Jan 2020 18:46:52 -0800 Subject: [PATCH] always start from the default cfg --- src/config.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 74cdc3a..8e742db 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,11 @@ use std::{ /// phetch will look for this file on load. const CONFIG_FILE: &str = "phetch.conf"; +/// Default start page. +const DEFAULT_START: &str = "gopher://phetch/1/home"; + /// Default config. Currently only used internally. +#[allow(dead_code)] const DEFAULT_CONFIG: &str = " ## config file for the phetch gopher client ## gopher://phkt.io/1/phetch @@ -35,7 +39,12 @@ pub struct Config { impl Default for Config { fn default() -> Self { - parse(DEFAULT_CONFIG).expect("Syntax error in config file") + Config { + start: String::from(DEFAULT_START), + tls: false, + tor: false, + wide: false, + } } } @@ -61,14 +70,9 @@ pub fn exists() -> bool { /// Parses a phetch config file into a Config struct. pub fn parse(text: &str) -> Result { let mut linenum = 0; - let mut cfg = Config { - start: String::new(), - tls: false, - tor: false, - wide: false, - }; - + let mut cfg = default(); let mut keys: HashMap<&str, bool> = HashMap::new(); + for line in text.split_terminator('\n') { linenum += 1;