From e503b0015ac5d17ccaadb569bfbb11ac24573e37 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 30 Sep 2017 20:22:43 +0300 Subject: [PATCH] Highlight unread emails differently in Index --- src/ui/index.rs | 29 +++++++++++++++++++++++------ src/ui/mod.rs | 4 ++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/ui/index.rs b/src/ui/index.rs index e3ab0e6c..8b8ed12d 100644 --- a/src/ui/index.rs +++ b/src/ui/index.rs @@ -285,13 +285,26 @@ impl Window for Index { /* Draw previous highlighted entry normally */ ncurses::wmove(self.pad, prev_idx as i32, 0); { - let pair = if self.threaded && prev_idx % 2 == 0 { - super::COLOR_PAIR_THREAD_EVEN - } else if self.threaded { - super::COLOR_PAIR_THREAD_ODD + let envelope: &Envelope = if self.threaded { + let i = self.mailbox.get_threaded_mail(prev_idx); + &self.mailbox.collection[i] + } else { + &self.mailbox.collection[prev_idx] + }; + let pair = if self.threaded { + if prev_idx % 2 == 0 && envelope.is_seen() { + super::COLOR_PAIR_THREAD_EVEN + } else if prev_idx % 2 == 0 { + super::COLOR_PAIR_UNREAD_EVEN + } else if envelope.is_seen() { + super::COLOR_PAIR_THREAD_ODD + } else { + super::COLOR_PAIR_UNREAD_ODD + } } else { super::COLOR_PAIR_DEFAULT }; + ncurses::wchgat(self.pad, 32, 0, pair); ncurses::wmove(self.pad, prev_idx as i32, 32); /* If first character in subject column is space, we need to check for indentation @@ -422,10 +435,14 @@ impl Index { /* TODO: use addchstr */ let pair = if highlight { super::COLOR_PAIR_CURSOR - } else if i % 2 == 0 { + } else if i % 2 == 0 && mail.is_seen() { super::COLOR_PAIR_THREAD_EVEN - } else { + } else if i % 2 == 0 { + super::COLOR_PAIR_UNREAD_EVEN + } else if mail.is_seen() { super::COLOR_PAIR_THREAD_ODD + } else { + super::COLOR_PAIR_UNREAD_ODD }; let attr = ncurses::COLOR_PAIR(pair); ncurses::wattron(win, attr); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 9ec2e79e..9da9dc47 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -33,6 +33,8 @@ pub static COLOR_PAIR_HEADERS: i16 = 3; pub static COLOR_PAIR_THREAD_INDENT: i16 = 4; pub static COLOR_PAIR_THREAD_ODD: i16 = 5; pub static COLOR_PAIR_THREAD_EVEN: i16 = 6; +pub static COLOR_PAIR_UNREAD_ODD: i16 = 7; +pub static COLOR_PAIR_UNREAD_EVEN: i16 = 8; pub struct TUI; @@ -53,6 +55,8 @@ impl TUI { ncurses::init_pair(COLOR_PAIR_THREAD_INDENT, 5, 0); ncurses::init_pair(COLOR_PAIR_THREAD_ODD, 15, 0); ncurses::init_pair(COLOR_PAIR_THREAD_EVEN, 15, 233); + ncurses::init_pair(COLOR_PAIR_UNREAD_ODD, 15, 7); + ncurses::init_pair(COLOR_PAIR_UNREAD_EVEN, 15, 8); /* Set the window's background color. */ ncurses::bkgd(