From 8ad1d470a11dfe99d28a4f5228a3fef335f692d1 Mon Sep 17 00:00:00 2001 From: Andy Wortman Date: Fri, 1 Dec 2017 01:48:07 -0800 Subject: basic info log scroll support. uses home/end right now --- src/display/mod.rs | 10 ++++++++-- src/main.rs | 9 ++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/display/mod.rs b/src/display/mod.rs index 1fb101e..4a0f198 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -345,7 +345,7 @@ pub fn paint(tweeter: &::tw::TwitterCache, display_info: &mut DisplayInfo) -> Re // draw input prompt let mut i = 0; let log_size = 4; - let last_tail_log = display_info.log.len().saturating_sub(display_info.infos_seek as usize); + let last_tail_log = display_info.log.len().saturating_sub(display_info.log_seek as usize); let first_tail_log = last_tail_log.saturating_sub(log_size); { let to_show = display_info.log[first_tail_log..last_tail_log].iter().rev(); @@ -361,6 +361,7 @@ pub fn paint(tweeter: &::tw::TwitterCache, display_info: &mut DisplayInfo) -> Re // draw status lines // draw tweets let last_tail_twevent = display_info.infos.len().saturating_sub(display_info.infos_seek as usize); + let twevent_offset = display_info.infos.len() - last_tail_twevent; let first_tail_twevent = last_tail_twevent.saturating_sub(height as usize - 4); let last_few_twevent: Vec = display_info.infos[first_tail_twevent..last_tail_twevent].iter().map(|x| x.clone()).rev().collect::>(); @@ -372,7 +373,12 @@ pub fn paint(tweeter: &::tw::TwitterCache, display_info: &mut DisplayInfo) -> Re let (cursor_x, cursor_y) = match display_info.mode.clone() { None => { let handle = tweeter.current_profile().map(|profile| profile.user.handle.to_owned()).unwrap_or("_default_".to_owned()); - print!("{}{}", cursor::Goto(1, height - 6), clear::CurrentLine); + print!("{}{}{}", + cursor::Goto(1, height - 6), clear::CurrentLine, + if twevent_offset != 0 { + format!("{} more below", twevent_offset) + } else { "".to_owned() } + ); print!("{}{}@{}>{}", cursor::Goto(1, height - 5), clear::CurrentLine, handle, display_info.input_buf.clone().into_iter().collect::()); print!("{}{}", cursor::Goto(1, height - 4), clear::CurrentLine); ((1 + handle.len() + 2 + display_info.input_buf.len()) as u16, height as u16 - 5) diff --git a/src/main.rs b/src/main.rs index d8ef738..7595ea0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -334,15 +334,18 @@ fn handle_input(event: termion::event::Event, tweeter: &mut tw::TwitterCache, qu } } }, - Event::Key(Key::End) => { - display_info.infos_seek = 0; - } Event::Key(Key::PageUp) => { display_info.infos_seek = display_info.infos_seek.saturating_add(1); } Event::Key(Key::PageDown) => { display_info.infos_seek = display_info.infos_seek.saturating_sub(1); } + Event::Key(Key::Home) => { + display_info.log_seek = display_info.log_seek.saturating_add(1); + } + Event::Key(Key::End) => { + display_info.log_seek = display_info.log_seek.saturating_sub(1); + } Event::Key(Key::Esc) => { display_info.mode = None; } -- cgit v1.1