aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
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 /src/main.rs
parent130e14d616bfeaedabd9b35a38e969da6bb16ab7 (diff)
downloadbk-2e3f4993c77b5cd986ca535d22770810701c1ad4.tar.gz
unzip
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs12
1 files changed, 3 insertions, 9 deletions
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)),