diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-27 21:11:19 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-05-27 21:14:27 -0400 |
commit | 4e00e82c62ded6e531f173914a68984307974323 (patch) | |
tree | 51c73862e8076736adf90f901240d11f7a2e62d5 /src/window | |
parent | 35579905606926893d4e7c0f3f58096c5b581444 (diff) |
move updating page state to cursor_move only
- refactor page state to take an end to prevent
blank views on init
- move functions out of JoshutoPanel into ui.rs
- create a struct for configuring how to display content
- new type JoshutoHistory
- rename display_options to display_menu
Diffstat (limited to 'src/window')
-rw-r--r-- | src/window/page_state.rs | 4 | ||||
-rw-r--r-- | src/window/panel.rs | 69 |
2 files changed, 2 insertions, 71 deletions
diff --git a/src/window/page_state.rs b/src/window/page_state.rs index 19967b2..cf4756e 100644 --- a/src/window/page_state.rs +++ b/src/window/page_state.rs @@ -5,8 +5,8 @@ pub struct JoshutoPageState { } impl JoshutoPageState { - pub fn new() -> Self { - JoshutoPageState { start: 0, end: 0 } + pub fn new(end: usize) -> Self { + JoshutoPageState { start: 0, end } } pub fn update_page_state( diff --git a/src/window/panel.rs b/src/window/panel.rs index 44eba9e..e9bd67a 100644 --- a/src/window/panel.rs +++ b/src/window/panel.rs @@ -3,8 +3,6 @@ use ncurses; use crate::structs; use crate::ui; -const MIN_WIN_WIDTH: usize = 4; - #[derive(Debug, Clone)] pub struct JoshutoPanel { pub win: ncurses::WINDOW, @@ -45,71 +43,4 @@ impl JoshutoPanel { pub fn queue_for_refresh(&self) { ncurses::wnoutrefresh(self.win); } - - pub fn display_contents(&self, dirlist: &mut structs::JoshutoDirList, scroll_offset: usize) { - if self.non_empty_dir_checks(dirlist, scroll_offset) { - Self::draw_dir_list(self, dirlist, ui::wprint_entry); - } - } - - pub fn display_contents_detailed( - &self, - dirlist: &mut structs::JoshutoDirList, - scroll_offset: usize, - ) { - if self.non_empty_dir_checks(dirlist, scroll_offset) { - Self::draw_dir_list(self, dirlist, ui::wprint_entry_detailed); - } - } - - pub fn draw_dir_list( - win: &JoshutoPanel, - dirlist: &structs::JoshutoDirList, - draw_func: fn(&JoshutoPanel, &structs::JoshutoDirEntry, (usize, &str), (i32, i32)), - ) { - let dir_contents = &dirlist.contents; - let (start, end) = (dirlist.pagestate.start, dirlist.pagestate.end); - - let curr_index = dirlist.index.unwrap(); - - for (i, entry) in dir_contents.iter().enumerate().take(end).skip(start) { - let coord: (i32, i32) = (i as i32 - start as i32, 0); - - ncurses::wmove(win.win, coord.0, coord.1); - - let mut attr: ncurses::attr_t = 0; - if i == curr_index { - attr |= ncurses::A_STANDOUT(); - } - let attrs = ui::get_theme_attr(attr, entry); - - draw_func(win, entry, attrs.0, coord); - - ncurses::mvwchgat(win.win, coord.0, coord.1, -1, attrs.1, attrs.2); - } - } - - fn non_empty_dir_checks( - &self, - dirlist: &mut structs::JoshutoDirList, - scroll_offset: usize, - ) -> bool { - if self.cols < MIN_WIN_WIDTH as i32 { - return false; - } - let vec_len = dirlist.contents.len(); - if vec_len == 0 { - ui::wprint_empty(self, "empty"); - return false; - } - ncurses::werase(self.win); - - if let Some(index) = dirlist.index { - dirlist - .pagestate - .update_page_state(index, self.rows, vec_len, scroll_offset); - } - ncurses::wmove(self.win, 0, 0); - true - } } |