summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2018-08-08 12:38:24 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:27 +0300
commit93b36a99412f91344dc8767c7317386fcc9eaaaf (patch)
treeb60c9bc5ab013b466b68422582f125a777866789 /ui
parent2932dd0dc086410fcee54fa15f468ea623924ce3 (diff)
Semifix for more than 1 digit url indexes in ViewMode::Url
Diffstat (limited to 'ui')
-rw-r--r--ui/src/components/mail/view.rs32
1 files changed, 27 insertions, 5 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index 516e2002..0a723afb 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -197,7 +197,16 @@ impl Component for MailView {
ViewMode::Url => {
let mut t = envelope.body().text().to_string();
for (lidx, l) in finder.links(&envelope.body().text()).enumerate() {
- t.insert_str(l.start() + (lidx * 3), &format!("[{}]", lidx));
+ let offset = if lidx < 10 {
+ lidx * 3
+ } else if lidx < 100 {
+ 26 + (lidx - 9) * 4
+ } else if lidx < 1000 {
+ 385 + (lidx - 99) * 5
+ } else {
+ panic!("BUG: Message body with more than 100 urls");
+ };
+ t.insert_str(l.start() + offset, &format!("[{}]", lidx));
}
if envelope.body().count_attachments() > 1 {
t = envelope.body().attachments().iter().enumerate().fold(
@@ -220,13 +229,26 @@ impl Component for MailView {
let mut buf = CellBuffer::from(&text);
if self.mode == ViewMode::Url {
// URL indexes must be colored (ugh..)
- let lines: Vec<&str> = text.split('\n').collect();
+ let lines: Vec<&str> = text.split('\n').map(|l| l.trim_right()).collect();
let mut shift = 0;
+ let mut lidx_total = 0;
for r in &lines {
for l in finder.links(&r) {
- buf[(l.start() + shift - 1, 0)].set_fg(Color::Byte(226));
- buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226));
- buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226));
+ let offset = if lidx_total < 10 {
+ 3
+ } else if lidx_total < 100 {
+ 4
+ } else if lidx_total < 1000 {
+ 5
+ } else {
+ panic!("BUG: Message body with more than 100 urls");
+ };
+ for i in 1..=offset {
+ buf[(l.start() + shift - i, 0)].set_fg(Color::Byte(226));
+ //buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226));
+ //buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226));
+ }
+ lidx_total += 1;
}
// Each Cell represents one char so next line will be:
shift += r.chars().count() + 1;