From 8c47c3e1cf59065eaf0d8e832d33255fab77bfe6 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 19 Apr 2020 08:26:02 -0700 Subject: inline save_path --- src/main.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index c21f7c2..1edece5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -198,19 +198,14 @@ impl Bk { } } -fn save_path() -> String { - let home = std::env::var("HOME").unwrap(); - format!("{}/.local/share/bk", home) -} - -fn restore() -> (String, usize, usize) { - let save = std::fs::read_to_string(save_path()).unwrap(); +fn restore(save_path: &str) -> (String, usize, usize) { + let save = std::fs::read_to_string(save_path).unwrap(); let mut lines = save.lines(); let path = lines.next().unwrap().to_string(); if let Some(p) = std::env::args().nth(1) { if p != path { - return (p, 0, 0); + return (p, 0, 0) } } ( @@ -221,7 +216,9 @@ fn restore() -> (String, usize, usize) { } fn main() -> crossterm::Result<()> { - let (path, chapter, pos) = restore(); + let save_path = format!("{}/.local/share/bk", + std::env::var("HOME").unwrap()); + let (path, chapter, pos) = restore(&save_path); let (cols, rows) = terminal::size().unwrap(); let mut bk = Bk::new(&path, cols, rows as usize, chapter, pos, 2) @@ -260,7 +257,7 @@ fn main() -> crossterm::Result<()> { } std::fs::write( - save_path(), + save_path, format!("{}\n{}\n{}", path, bk.chapter_idx, bk.pos), ) .unwrap(); -- cgit v1.2.3