mirror of
https://github.com/lotabout/skim.git
synced 2026-09-10 07:16:23 -04:00
[color] color for print item done.
This commit is contained in:
parent
6e42a846a4
commit
4e6fc1a8c3
|
|
@ -99,6 +99,13 @@ impl Curses {
|
|||
addstr(text);
|
||||
attroff(attr);
|
||||
}
|
||||
|
||||
pub fn caddch(&self, pair: i16, is_bold: bool, ch: char) {
|
||||
let attr = self.get_color(pair, is_bold);
|
||||
attron(attr);
|
||||
addch(ch as u64);
|
||||
attroff(attr);
|
||||
}
|
||||
}
|
||||
|
||||
// use default if x is COLOR_UNDEFINED, else use x
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ fn main() {
|
|||
}
|
||||
|
||||
Event::EvMatcherUpdateProcess => {
|
||||
let (matched, total) : (u64, u64) = *val.downcast().unwrap();
|
||||
model.update_process_info(matched, total);
|
||||
let (matched, total, processed) : (u64, u64, u64) = *val.downcast().unwrap();
|
||||
model.update_process_info(matched, total, processed);
|
||||
|
||||
while let Ok(matched_item) = rx_matched.try_recv() {
|
||||
model.push_item(matched_item);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ impl Matcher {
|
|||
break;
|
||||
}
|
||||
}
|
||||
(*self.eb_notify).set(Event::EvMatcherUpdateProcess, Box::new((self.num_matched, items.len() as u64)));
|
||||
(*self.eb_notify).set(Event::EvMatcherUpdateProcess, Box::new((self.num_matched, items.len() as u64, self.item_pos as u64)));
|
||||
}
|
||||
|
||||
fn reset_query(&mut self, query: &str) {
|
||||
|
|
|
|||
18
src/model.rs
18
src/model.rs
|
|
@ -19,6 +19,7 @@ pub struct Model {
|
|||
pub items: Arc<RwLock<Vec<Item>>>, // all items
|
||||
selected_indics: HashSet<usize>,
|
||||
pub matched_items: RefCell<OrderedVec<MatchedItem>>,
|
||||
processed_percentage: u64,
|
||||
item_cursor: usize, // the index of matched item currently highlighted.
|
||||
line_cursor: usize, // line No.
|
||||
item_start_pos: usize, // for screen scroll.
|
||||
|
|
@ -39,6 +40,7 @@ impl Model {
|
|||
items: Arc::new(RwLock::new(Vec::new())),
|
||||
selected_indics: HashSet::new(),
|
||||
matched_items: RefCell::new(OrderedVec::new()),
|
||||
processed_percentage: 100,
|
||||
item_cursor: 0,
|
||||
line_cursor: (max_y - 3) as usize,
|
||||
item_start_pos: 0,
|
||||
|
|
@ -82,9 +84,10 @@ impl Model {
|
|||
self.query_cursor = cursor;
|
||||
}
|
||||
|
||||
pub fn update_process_info(&mut self, matched: u64, total: u64) {
|
||||
pub fn update_process_info(&mut self, matched: u64, total: u64, processed: u64) {
|
||||
self.num_matched = matched;
|
||||
self.num_total = total;
|
||||
self.processed_percentage = (processed+1)*100/(total+1);
|
||||
}
|
||||
|
||||
pub fn push_item(&mut self, item: MatchedItem) {
|
||||
|
|
@ -131,7 +134,9 @@ impl Model {
|
|||
|
||||
pub fn print_info(&self) {
|
||||
mv(self.max_y-2, 0);
|
||||
addstr(format!(" {}/{}", self.num_matched, self.num_total).as_str());
|
||||
addstr(format!(" {}/{}{}", self.num_matched, self.num_total,
|
||||
if self.processed_percentage == 100 {"".to_string()} else {format!("({}%)", self.processed_percentage)}
|
||||
).as_str());
|
||||
}
|
||||
|
||||
fn print_item(&self, matched: &MatchedItem, is_current: bool) {
|
||||
|
|
@ -152,16 +157,13 @@ impl Model {
|
|||
for (idx, ch) in item.text.chars().enumerate() {
|
||||
if let Some(&&index) = matched_indics_iter.peek() {
|
||||
if idx == index {
|
||||
let attr = self.curses.get_color(COLOR_MATCHED, false);
|
||||
attron(attr);
|
||||
addch(ch as u64);
|
||||
attroff(attr);
|
||||
self.curses.caddch(COLOR_MATCHED, is_current, ch);
|
||||
let _ = matched_indics_iter.next();
|
||||
} else {
|
||||
addch(ch as u64);
|
||||
self.curses.caddch(if is_current {COLOR_CURRENT} else {COLOR_NORMAL}, is_current, ch)
|
||||
}
|
||||
} else {
|
||||
addch(ch as u64);
|
||||
self.curses.caddch(if is_current {COLOR_CURRENT} else {COLOR_NORMAL}, is_current, ch)
|
||||
}
|
||||
if idx >= (self.max_x - 3) as usize {
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in a new issue