aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-07-26 18:19:26 +0000
committerFuwn <[email protected]>2022-07-26 18:19:26 +0000
commitf4d0425406369c5b7c2c41ce0e8f453b2d747b3b (patch)
tree84ce52912f386b880bfa7bc9f6706b641d4ae692
parentfeat(src): prefix urls everywhere (diff)
downloadsydney-f4d0425406369c5b7c2c41ce0e8f453b2d747b3b.tar.xz
sydney-f4d0425406369c5b7c2c41ce0e8f453b2d747b3b.zip
fix(ui.rs): reimplement text wrap
-rw-r--r--src/ui.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ui.rs b/src/ui.rs
index cfe391a..c16a572 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -60,10 +60,33 @@ pub fn ui<B: tui::backend::Backend>(
}
}
+ macro_rules! wrap_split {
+ ($text:ident, $spans:ident) => {
+ let wrappeds = $text
+ .as_bytes()
+ .chunks((app.wrap_at as usize) - 5)
+ .map(|buf| {
+ #[allow(unsafe_code)]
+ unsafe { std::str::from_utf8_unchecked(buf) }.to_string()
+ })
+ .collect::<Vec<_>>();
+
+ for (i, wrapped) in wrappeds.iter().enumerate() {
+ $spans.push(Spans::from(format!(" {}{}", wrapped, {
+ if i == wrappeds.len() - 1 && wrappeds.len() != 1 {
+ ""
+ } else {
+ "-"
+ }
+ })));
+ }
+ };
+ }
+
match line {
germ::ast::Node::Text(text) =>
if text != "sydney_abc_123" {
- spans.push(tui::text::Spans::from(format!(" {}", text)));
+ wrap_split!(text, spans);
},
germ::ast::Node::Blockquote(text) => {
spans.push(Spans::from(vec![