aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock91
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs33
3 files changed, 105 insertions, 21 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fab18a3..6a286af 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -13,6 +13,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
[[package]]
+name = "argh"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca1877e24cecacd700d469066e0160c4f8497cc5635367163f50c8beec820154"
+dependencies = [
+ "argh_derive",
+ "argh_shared",
+]
+
+[[package]]
+name = "argh_derive"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e742194e0f43fc932bcb801708c2b279d3ec8f527e3acda05a6a9f342c5ef764"
+dependencies = [
+ "argh_shared",
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "argh_shared"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1ba68f4276a778591e36a0c348a269888f3a177c8d2054969389e3b59611ff5"
+
+[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -22,8 +51,8 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
name = "bk"
version = "0.1.1"
dependencies = [
+ "argh",
"crossterm",
- "pico-args",
"roxmltree",
"zip",
]
@@ -106,6 +135,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
+name = "heck"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
+dependencies = [
+ "unicode-segmentation",
+]
+
+[[package]]
name = "iovec"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -230,18 +268,30 @@ dependencies = [
]
[[package]]
-name = "pico-args"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3ad1f1b834a05d42dae330066e9699a173b28185b3bdc3dbf14ca239585de8cc"
-
-[[package]]
name = "podio"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19"
[[package]]
+name = "proc-macro2"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
name = "redox_syscall"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -296,6 +346,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4"
[[package]]
+name = "syn"
+version = "1.0.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5304cfdf27365b7585c25d4af91b35016ed21ef88f17ced89c7093b43dba8b6"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
+[[package]]
+name = "unicode-segmentation"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
+
+[[package]]
+name = "unicode-xid"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
+
+[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -347,9 +420,9 @@ checksum = "ccb4240203dadf40be2de9369e5c6dec1bf427528115b030baca3334c18362d7"
[[package]]
name = "zip"
-version = "0.5.5"
+version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6df134e83b8f0f8153a094c7b0fd79dfebe437f1d76e7715afa18ed95ebe2fd7"
+checksum = "58287c28d78507f5f91f2a4cf1e8310e2c76fd4c6932f93ac60fd1ceb402db7d"
dependencies = [
"crc32fast",
"flate2",
diff --git a/Cargo.toml b/Cargo.toml
index d217d4e..de90ce7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,8 +11,8 @@ readme = "README.md"
repository = "https://github.com/aeosynth/bk"
[dependencies]
+argh = "*"
crossterm = "*"
-pico-args = "*"
roxmltree = "*"
[dependencies.zip]
diff --git a/src/main.rs b/src/main.rs
index 4911551..1d16440 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,8 @@
use std::io::{stdout, Write};
use std::{cmp::min, collections::HashMap, env, fs, iter, process::exit};
+use argh::FromArgs;
+
use crossterm::{
cursor,
event::{self, Event, KeyCode},
@@ -349,7 +351,7 @@ struct Bk<'a> {
}
impl Bk<'_> {
- fn new(epub: epub::Epub, args: Args) -> Self {
+ fn new(epub: epub::Epub, args: Props) -> Self {
let (cols, rows) = terminal::size().unwrap();
let width = min(cols, args.width) as usize;
let mut chapters = Vec::with_capacity(epub.chapters.len());
@@ -507,18 +509,27 @@ impl Bk<'_> {
}
}
+#[derive(FromArgs)]
+/// read a book
struct Args {
+ #[argh(positional)]
+ path: Option<String>,
+
+ /// characters per line
+ #[argh(option, short = 'w', default = "75")]
+ width: u16,
+}
+
+struct Props {
chapter: usize,
line: usize,
width: u16,
}
-fn restore(save_path: &str) -> Option<(String, Args)> {
- let mut args = pico_args::Arguments::from_env();
- let width = args.opt_value_from_str("-w").unwrap().unwrap_or(75);
- let free = args.free().unwrap();
- let path = free
- .first()
+fn restore(save_path: &str) -> Option<(String, Props)> {
+ let args: Args = argh::from_env();
+ let width = args.width;
+ let path = args.path
.and_then(|s| Some(fs::canonicalize(s).unwrap().to_str().unwrap().to_string()));
let save = fs::read_to_string(save_path).and_then(|s| {
let mut lines = s.lines();
@@ -544,7 +555,7 @@ fn restore(save_path: &str) -> Option<(String, Args)> {
Some((
path,
- Args {
+ Props {
chapter,
line,
width,
@@ -560,7 +571,7 @@ fn main() {
};
let (path, args) = restore(&save_path).unwrap_or_else(|| {
- println!("usage: bk [flags] [path]");
+ println!("error: need a path");
exit(1);
});
@@ -570,11 +581,11 @@ fn main() {
});
let mut bk = Bk::new(epub, args);
- // crossterm really shouldn't error
+ // i have never seen crossterm error
bk.run().unwrap();
fs::write(save_path, format!("{}\n{}\n{}", path, bk.chapter, bk.line)).unwrap_or_else(|e| {
- println!("error saving position: {}", e);
+ println!("error saving state: {}", e);
exit(1);
});
}