aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-04-19 08:26:02 -0700
committerJames Campos <james.r.campos@gmail.com>2020-04-19 08:26:02 -0700
commit8c47c3e1cf59065eaf0d8e832d33255fab77bfe6 (patch)
treee300580ceb2787f9402adcf0748c854fa3014d27 /src
parent73b16d35bb72b326e512eb85e6eea0830c8ec124 (diff)
downloadbk-8c47c3e1cf59065eaf0d8e832d33255fab77bfe6.tar.gz
inline save_path
Diffstat (limited to 'src')
-rw-r--r--src/main.rs17
1 files changed, 7 insertions, 10 deletions
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();