diff options
| author | Fuwn <[email protected]> | 2022-07-26 18:19:26 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-07-26 18:19:26 +0000 |
| commit | f4d0425406369c5b7c2c41ce0e8f453b2d747b3b (patch) | |
| tree | 84ce52912f386b880bfa7bc9f6706b641d4ae692 | |
| parent | feat(src): prefix urls everywhere (diff) | |
| download | sydney-f4d0425406369c5b7c2c41ce0e8f453b2d747b3b.tar.xz sydney-f4d0425406369c5b7c2c41ce0e8f453b2d747b3b.zip | |
fix(ui.rs): reimplement text wrap
| -rw-r--r-- | src/ui.rs | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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![ |