aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Campos <james.r.campos@gmail.com>2020-05-30 03:14:02 -0700
committerJames Campos <james.r.campos@gmail.com>2020-05-30 03:14:02 -0700
commit2e3f4993c77b5cd986ca535d22770810701c1ad4 (patch)
tree4b8331d7527b5c4a144328126bbaadb450856eca
parent130e14d616bfeaedabd9b35a38e969da6bb16ab7 (diff)
downloadbk-2e3f4993c77b5cd986ca535d22770810701c1ad4.tar.gz
unzip
-rw-r--r--Cargo.lock12
-rw-r--r--src/main.rs12
2 files changed, 9 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a0a122e..da6cad4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -53,9 +53,9 @@ dependencies = [
[[package]]
name = "crossterm"
-version = "0.17.4"
+version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2a880035bfe4707e344da9acf50cc94d003fe337f50afd94c8722c1bb4e0a933"
+checksum = "9851d20b9809e561297ec3ca85d7cba3a57507fe8d01d07ba7b52469e1c89a11"
dependencies = [
"bitflags",
"crossterm_winapi",
@@ -131,9 +131,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
-version = "0.2.70"
+version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3baa92041a6fec78c687fa0cc2b3fae8884f743d672cf551bed1d6dac6988d0f"
+checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
[[package]]
name = "lock_api"
@@ -230,9 +230,9 @@ dependencies = [
[[package]]
name = "podio"
-version = "0.1.6"
+version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd"
+checksum = "b18befed8bc2b61abc79a457295e7e838417326da1586050b919414073977f19"
[[package]]
name = "redox_syscall"
diff --git a/src/main.rs b/src/main.rs
index 0d68a05..c66bf64 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -352,8 +352,8 @@ impl Bk<'_> {
fn new(epub: epub::Epub, chapter: usize, line: usize, max_width: u16) -> Self {
let (cols, rows) = terminal::size().unwrap();
let width = min(cols, max_width) as usize;
-
let mut chapters = Vec::with_capacity(epub.chapters.len());
+
for (title, text) in epub.chapters {
let title = if title.chars().count() > width {
title
@@ -364,14 +364,7 @@ impl Bk<'_> {
} else {
title
};
- let wrap = wrap(&text, width);
- let mut lines = Vec::with_capacity(wrap.len());
- let mut bytes = Vec::with_capacity(wrap.len());
-
- for (byte, line) in wrap {
- lines.push(line);
- bytes.push(byte);
- }
+ let (bytes, lines) = wrap(&text, width).into_iter().unzip();
chapters.push(Chapter {
title,
text,
@@ -535,6 +528,7 @@ fn restore(save_path: &str) -> Option<(String, usize, usize)> {
.to_string()
};
+ // XXX move errors when i try to refactor
match (save, path) {
(Err(_), None) => None,
(Err(_), Some(path)) => Some((canon(path), 0, 0)),