From a75601b13a35b9fc4dcd35e2ca964686520f1a8f Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Thu, 27 Oct 2016 21:32:45 +0200 Subject: [PATCH] Trying different keys for navigation. I was having problems with the old scheme. Now you use tab to switch focus between the summary and result panes. The keys to navigate are the same in both places. --- fill3.py | 12 ++++-- golden-files/help | 6 +-- vigil | 105 ++++++++++++++++++++++++++++++---------------- 3 files changed, 81 insertions(+), 42 deletions(-) diff --git a/fill3.py b/fill3.py index 01a3971..442d4a7 100644 --- a/fill3.py +++ b/fill3.py @@ -354,13 +354,13 @@ class Border: THICK = ["━", "━", "┃", "┃", "┏", "┗", "┛", "┓"] ROUNDED = ["─", "─", "│", "│", "╭", "╰", "╯", "╮"] DOUBLE = ["═", "═", "║", "║", "╔", "╚", "╝", "╗"] - HEAVY_INNER = ["▄", "▀", "▐", "▌", "▗", "▝", "▘", "▖"] - HEAVY_OUTER = ["▀", "▄", "▌", "▐", "▛", "▙", "▟", "▜"] - INNER = ["▁", "▔", "▕", "▏", " ", " ", " ", " "] def __init__(self, widget, title=None, characters=THIN): self.widget = widget self.title = title + self.set_style(characters) + + def set_style(self, characters): (self.top, self.bottom, self.left, self.right, self.top_left, self.bottom_left, self.bottom_right, self.top_right) = characters @@ -370,7 +370,11 @@ class Border: title_bar = self.top * content_width else: padded_title = (" " + self.title + " ")[:content_width] - title_bar = padded_title.center(content_width, self.top) + try: + title_bar = padded_title.center(content_width, self.top) + except TypeError: + padded_title = termstr.TermStr(padded_title) + title_bar = padded_title.center(content_width, self.top) result = [self.top_left + title_bar + self.top_right] result.extend(self.left + line + self.right for line in body_content) result.append(self.bottom_left + self.bottom * content_width + diff --git a/golden-files/help b/golden-files/help index f30f505..42f986b 100644 --- a/golden-files/help +++ b/golden-files/help @@ -14,11 +14,10 @@ │directory. │ │ │ │Keys: │ +│ arrow keys, page up/down, mouse - Move the cursor or scroll the result pane. │ +│ tab - Change the focus between summary and result pane. │ │ (Bh(B - Show the help screen. (toggle) │ │ (Bq(B - Quit. │ -│ (Bd(B, (Bc(B, (Bj(B, (Bk(B, (Bf(B, (Bv(B or arrow keys or mouse click - Move the cursor. │ -│ (BD(B, (BC(B, (BJ(B, (BK(B, (BF(B, (BV(B or page up, page down, home, end or the mouse wheel - │ -│ Scroll the result pane. │ │ (Bt(B - Turn the result pane to portrait or landscape orientation. (toggle) │ │ (Bl(B - Show the activity log. (toggle) │ │ (Be(B - Edit the current file with an editor defined by -e, $EDITOR or $VISUAL. │ @@ -57,4 +56,5 @@ │ │ │ │ │ │ +│ │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘(B \ No newline at end of file diff --git a/vigil b/vigil index 6f65b2c..29dee66 100755 --- a/vigil +++ b/vigil @@ -67,11 +67,10 @@ Options: KEYS_DOC = """Keys: + arrow keys, page up/down, mouse - Move the cursor or scroll the result pane. + tab - Change the focus between summary and result pane. *h - Show the help screen. (toggle) *q - Quit. - *d, *c, *j, *k, *f, *v or arrow keys or mouse click - Move the cursor. - *D, *C, *J, *K, *F, *V or page up, page down, home, end or the mouse wheel - - Scroll the result pane. *t - Turn the result pane to portrait or landscape orientation. (toggle) *l - Show the activity log. (toggle) *e - Edit the current file with an editor defined by -e, $EDITOR or $VISUAL. @@ -538,6 +537,7 @@ class Screen: self._log = log self._appearance_changed_event = appearance_changed_event self._main_loop = main_loop + self._is_summary_focused = True self.workers = None self._is_listing_portrait = False self._is_log_visible = True @@ -577,10 +577,12 @@ class Screen: self._help_widget = Help(self._summary, self) root_path = os.path.basename(self._summary._root_path) summary = fill3.Border(self._summary, title="Summary of " + root_path) + self._summary_border = summary selected_widget = self._summary.get_selection() self._view = fill3.View.from_widget(selected_widget.result) self._listing = fill3.Border(Listing(self._view)) - log = fill3.Border(self._log, title="Log") + log = fill3.Border(self._log, title="Log", + characters=Screen._DIMMED_BORDER) port_log = fill3.Row([fill3.Column([summary, log], self._partition), self._listing]) land_log = fill3.Column([fill3.Row([summary, log]), self._listing], @@ -588,6 +590,7 @@ class Screen: port_no_log = fill3.Row([summary, self._listing]) land_no_log = fill3.Column([summary, self._listing], self._partition_2) self._layouts = [[land_no_log, port_no_log], [land_log, port_log]] + self._set_focus() def toggle_help(self): self._is_help_visible = not self._is_help_visible @@ -599,22 +602,52 @@ class Screen: self._is_listing_portrait = not self._is_listing_portrait def cursor_up(self): - self._summary.cursor_up() + if self._is_summary_focused: + self._summary.cursor_up() + else: + self._move_listing(_UP) def cursor_down(self): - self._summary.cursor_down() + if self._is_summary_focused: + self._summary.cursor_down() + else: + self._move_listing(_DOWN) def cursor_right(self): - self._summary.cursor_right() + if self._is_summary_focused: + self._summary.cursor_right() + else: + self._move_listing(_RIGHT) def cursor_left(self): - self._summary.cursor_left() + if self._is_summary_focused: + self._summary.cursor_left() + else: + self._move_listing(_LEFT) def cursor_page_up(self): - self._summary.cursor_page_up() + if self._is_summary_focused: + self._summary.cursor_page_up() + else: + self.listing_page_up() def cursor_page_down(self): - self._summary.cursor_page_down() + if self._is_summary_focused: + self._summary.cursor_page_down() + else: + self.listing_page_down() + + def cursor_page_right(self): + if self._is_summary_focused: + pass # Fix + else: + self._page_listing(_RIGHT) + + def cursor_page_left(self): + if self._is_summary_focused: + pass # Fix + else: + self._page_listing(_LEFT) def _move_listing(self, vector): dx, dy = vector @@ -639,18 +672,6 @@ class Screen: self._move_listing((dx * (listing_width // 2), dy * (listing_height // 2))) - def listing_up(self): - self._move_listing(_UP) - - def listing_down(self): - self._move_listing(_DOWN) - - def listing_right(self): - self._page_listing(_RIGHT) - - def listing_left(self): - self._page_listing(_LEFT) - def listing_page_up(self): self._page_listing(_UP) @@ -703,6 +724,20 @@ class Screen: def refresh(self): self._summary.refresh(self._log) + _DIMMED_BORDER = [termstr.TermStr(part).fg_color(termstr.Color.grey_100) + for part in fill3.Border.THIN] + + def _set_focus(self): + focused, unfocused = fill3.Border.THICK, Screen._DIMMED_BORDER + self._summary_border.set_style(focused if self._is_summary_focused + else unfocused) + self._listing.set_style(unfocused if self._is_summary_focused + else focused) + + def toggle_focus(self): + self._is_summary_focused = not self._is_summary_focused + self._set_focus() + def _on_mouse_event(self, event): if event[0] not in ["mouse press", "mouse drag"]: return @@ -753,8 +788,8 @@ class Screen: self._appearance_changed_event.set() _STATUS_BAR = highlight_chars( - " *help *quit *d,*c,*j,*k,*f,*v:navigate *turn *log *edit *next *pause" - " *order *refresh", Log._GREEN_STYLE) + " *help *quit *t*a*b:focus *turn *log *edit *next *pause *order" + " *refresh", Log._GREEN_STYLE) @functools.lru_cache(maxsize=2) def _get_status_bar_appearance(self, width, is_directory_sort, is_paused, @@ -778,8 +813,9 @@ class Screen: view.position = widget.scroll_position view.widget = widget.result tool_name = tools.tool_name_colored(widget.tool, widget.path) + divider = " " + self._listing.top * 4 + " " self._listing.title = ( - tools.path_colored(widget.path) + " ─── " + tool_name + " " + + tools.path_colored(widget.path) + divider + tool_name + " " + tools.status_to_str(widget.status)) incomplete = self._summary.result_total - self._summary.completed_total progress_bar_size = max(0, width * incomplete // @@ -796,16 +832,15 @@ class Screen: _KEY_DATA = [ ({"t"}, toggle_window_orientation), ({"l"}, toggle_log), - ({"h"}, toggle_help), ({"d", "up"}, cursor_up), - ({"c", "down"}, cursor_down), ({"j", "left"}, cursor_left), - ({"k", "right"}, cursor_right), ({"v"}, cursor_page_down), - ({"f"}, cursor_page_up), ({"F", "page up"}, listing_page_up), - ({"V", "page down"}, listing_page_down), ({"D"}, listing_up), - ({"C"}, listing_down), ({"J", "home"}, listing_left), - ({"K", "end"}, listing_right), ({"o"}, toggle_order), - ({"n"}, move_to_next_issue), ({"N"}, move_to_next_issue_of_tool), - ({"e"}, edit_file), ({"q"}, quit_), - ({"p"}, toggle_pause), ({"r"}, refresh)] + ({"h"}, toggle_help), ({"up"}, cursor_up), + ({"down"}, cursor_down), ({"left"}, cursor_left), + ({"right"}, cursor_right), ({"page down", "ctrl v"}, cursor_page_down), + ({"page up", "meta v"}, cursor_page_up), ({"o"}, toggle_order), + ({"home", "ctrl a"}, cursor_page_left), + ({"end", "ctrl e"}, cursor_page_right), ({"n"}, move_to_next_issue), + ({"N"}, move_to_next_issue_of_tool), ({"e"}, edit_file), + ({"q"}, quit_), ({"p"}, toggle_pause), ({"r"}, refresh), + ({"tab"}, toggle_focus)] def add_watch_manager_to_mainloop(root_path, mainloop, on_filesystem_change,