diff --git a/src/bookmarks.rs b/src/bookmarks.rs index 8aec1fa..4318c33 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -1,4 +1,4 @@ -use crate::config; +use crate::phetchdir; use std::io::{Read, Result}; // Bookmarks only work if you've created a ~/.config/phetch/ manually. @@ -16,12 +16,12 @@ i\r\nimkdir -p {dir}" /// Get all bookmarks in Gophermap format. pub fn as_raw_menu() -> String { - let path = config::path(); + let path = phetchdir::path(); if let Err(e) = path { - return format!(dir_missing_fmt!(), error = e, dir = config::DIR); + return format!(dir_missing_fmt!(), error = e, dir = phetchdir::DIR); } - let mut out = format!("i{}{}:\r\ni\r\n", config::DIR, BOOKMARKS_FILE); + let mut out = format!("i{}{}:\r\ni\r\n", phetchdir::DIR, BOOKMARKS_FILE); let path = path.unwrap().join(BOOKMARKS_FILE); if !path.exists() { @@ -29,7 +29,7 @@ pub fn as_raw_menu() -> String { return out; } - config::load(BOOKMARKS_FILE) + phetchdir::load(BOOKMARKS_FILE) .and_then(|mut reader| reader.read_to_string(&mut out)) .map_err(|e| { out = format!("3{}", e); @@ -40,7 +40,7 @@ pub fn as_raw_menu() -> String { /// Save a single bookmark entry. pub fn save(label: &str, url: &str) -> Result<()> { - config::append( + phetchdir::append( BOOKMARKS_FILE, label .trim_start_matches("gopher://") diff --git a/src/history.rs b/src/history.rs index a7b42a0..de7ffef 100644 --- a/src/history.rs +++ b/src/history.rs @@ -1,4 +1,4 @@ -use crate::config; +use crate::phetchdir; use std::io::{BufRead, Result}; /// History only works if you've created ~/.config/phetch/history.gph manually. @@ -16,13 +16,13 @@ i\r\nimkdir -p {dir} && touch {file}" /// Returns history as a Gophermap. pub fn as_raw_menu() -> String { - let homepath = format!("{}{}", config::DIR, HISTORY_FILE); - let path = config::path(); + let homepath = format!("{}{}", phetchdir::DIR, HISTORY_FILE); + let path = phetchdir::path(); if let Err(error) = path { return format!( file_missing_fmt!(), file = homepath, - dir = config::DIR, + dir = phetchdir::DIR, error = error ); } @@ -32,13 +32,13 @@ pub fn as_raw_menu() -> String { return format!( file_missing_fmt!(), file = homepath, - dir = config::DIR, + dir = phetchdir::DIR, error = "No history file found." ); } let mut out = vec![format!("i{}:\r\ni", homepath)]; - config::load(HISTORY_FILE) + phetchdir::load(HISTORY_FILE) .and_then(|reader| { let mut lines = reader.lines(); while let Some(Ok(line)) = lines.next() { @@ -59,9 +59,9 @@ pub fn as_raw_menu() -> String { /// Save a single history entry if the history file exists. pub fn save(label: &str, url: &str) -> Result<()> { - if let Err(e) = config::path() { + if let Err(e) = phetchdir::path() { return Err(error!("History file doesn't exist: {}", e)); } - config::append(HISTORY_FILE, label, url) + phetchdir::append(HISTORY_FILE, label, url) } diff --git a/src/lib.rs b/src/lib.rs index 6cb0170..2ca35f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,11 +3,11 @@ #[macro_use] pub mod utils; pub mod bookmarks; -pub mod config; pub mod gopher; pub mod help; pub mod history; pub mod menu; +pub mod phetchdir; pub mod text; pub mod ui; diff --git a/src/config.rs b/src/phetchdir.rs similarity index 83% rename from src/config.rs rename to src/phetchdir.rs index e8aba0b..cefea8d 100644 --- a/src/config.rs +++ b/src/phetchdir.rs @@ -4,9 +4,11 @@ use std::{ io::{prelude::*, BufReader, Result, Write}, }; +/// The directory where phetch stores its files. Ex: bookmarks file +/// If you want the full, expanded path, use `path()`. pub const DIR: &str = "~/.config/phetch/"; -/// Loads a file in the config directory for reading. +/// Loads a file from the phetchdir for reading. pub fn load(filename: &str) -> Result> { path().and_then(|dotdir| { let path = dotdir.join(filename); @@ -18,7 +20,7 @@ pub fn load(filename: &str) -> Result> { }) } -/// Append a menu item as a line to a file in the config dir. +/// Append a menu item as a line to a file in the phetchdir. pub fn append(filename: &str, label: &str, url: &str) -> Result<()> { path().and_then(|dotdir| { let path = dotdir.join(filename); @@ -42,7 +44,7 @@ pub fn append(filename: &str, label: &str, url: &str) -> Result<()> { }) } -/// Add a menu item as the first line in a file in the config dir. +/// Add a menu item as the first line in a file in the phetchdir. pub fn prepend(filename: &str, label: &str, url: &str) -> Result<()> { path().and_then(|dotdir| { let path = dotdir.join(filename); @@ -75,8 +77,10 @@ pub fn prepend(filename: &str, label: &str, url: &str) -> Result<()> { }) } -/// PathBuf to expanded config dir if it exists. -/// None if the config dir doesn't exist. +/// Returns the full, expanded PathBuf of the phetchdir only if it exists. +/// Returns None otherwise. +/// If you just want the phetchdir path whether or not it exists, use +/// the DIR constant directly. pub fn path() -> Result { let homevar = std::env::var("HOME"); if homevar.is_err() {