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.
This commit is contained in:
Andrew Hamilton 2016-10-27 21:32:45 +02:00
parent a93704f19b
commit a75601b13a
3 changed files with 81 additions and 42 deletions

View file

@ -354,13 +354,13 @@ class Border:
THICK = ["", "", "", "", "", "", "", ""] THICK = ["", "", "", "", "", "", "", ""]
ROUNDED = ["", "", "", "", "", "", "", ""] ROUNDED = ["", "", "", "", "", "", "", ""]
DOUBLE = ["", "", "", "", "", "", "", ""] DOUBLE = ["", "", "", "", "", "", "", ""]
HEAVY_INNER = ["", "", "", "", "", "", "", ""]
HEAVY_OUTER = ["", "", "", "", "", "", "", ""]
INNER = ["", "", "", "", " ", " ", " ", " "]
def __init__(self, widget, title=None, characters=THIN): def __init__(self, widget, title=None, characters=THIN):
self.widget = widget self.widget = widget
self.title = title self.title = title
self.set_style(characters)
def set_style(self, characters):
(self.top, self.bottom, self.left, self.right, self.top_left, (self.top, self.bottom, self.left, self.right, self.top_left,
self.bottom_left, self.bottom_right, self.top_right) = characters self.bottom_left, self.bottom_right, self.top_right) = characters
@ -370,7 +370,11 @@ class Border:
title_bar = self.top * content_width title_bar = self.top * content_width
else: else:
padded_title = (" " + self.title + " ")[:content_width] 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 = [self.top_left + title_bar + self.top_right]
result.extend(self.left + line + self.right for line in body_content) result.extend(self.left + line + self.right for line in body_content)
result.append(self.bottom_left + self.bottom * content_width + result.append(self.bottom_left + self.bottom * content_width +

View file

@ -14,11 +14,10 @@
│directory. │ │directory. │
│ │ │ │
│Keys: │ │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) │ (Bh(B - Show the help screen. (toggle) │
(Bq(B - Quit. │ (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) │ (Bt(B - Turn the result pane to portrait or landscape orientation. (toggle) │
(Bl(B - Show the activity log. (toggle) │ (Bl(B - Show the activity log. (toggle) │
(Be(B - Edit the current file with an editor defined by -e, $EDITOR or $VISUAL. │ (Be(B - Edit the current file with an editor defined by -e, $EDITOR or $VISUAL. │
@ -57,4 +56,5 @@
│ │ │ │
│ │ │ │
│ │ │ │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘(B └──────────────────────────────────────────────────────────────────────────────────────────────────┘(B

105
vigil
View file

@ -67,11 +67,10 @@ Options:
KEYS_DOC = """Keys: 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) *h - Show the help screen. (toggle)
*q - Quit. *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) *t - Turn the result pane to portrait or landscape orientation. (toggle)
*l - Show the activity log. (toggle) *l - Show the activity log. (toggle)
*e - Edit the current file with an editor defined by -e, $EDITOR or $VISUAL. *e - Edit the current file with an editor defined by -e, $EDITOR or $VISUAL.
@ -538,6 +537,7 @@ class Screen:
self._log = log self._log = log
self._appearance_changed_event = appearance_changed_event self._appearance_changed_event = appearance_changed_event
self._main_loop = main_loop self._main_loop = main_loop
self._is_summary_focused = True
self.workers = None self.workers = None
self._is_listing_portrait = False self._is_listing_portrait = False
self._is_log_visible = True self._is_log_visible = True
@ -577,10 +577,12 @@ class Screen:
self._help_widget = Help(self._summary, self) self._help_widget = Help(self._summary, self)
root_path = os.path.basename(self._summary._root_path) root_path = os.path.basename(self._summary._root_path)
summary = fill3.Border(self._summary, title="Summary of " + root_path) summary = fill3.Border(self._summary, title="Summary of " + root_path)
self._summary_border = summary
selected_widget = self._summary.get_selection() selected_widget = self._summary.get_selection()
self._view = fill3.View.from_widget(selected_widget.result) self._view = fill3.View.from_widget(selected_widget.result)
self._listing = fill3.Border(Listing(self._view)) 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), port_log = fill3.Row([fill3.Column([summary, log], self._partition),
self._listing]) self._listing])
land_log = fill3.Column([fill3.Row([summary, log]), 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]) port_no_log = fill3.Row([summary, self._listing])
land_no_log = fill3.Column([summary, self._listing], self._partition_2) land_no_log = fill3.Column([summary, self._listing], self._partition_2)
self._layouts = [[land_no_log, port_no_log], [land_log, port_log]] self._layouts = [[land_no_log, port_no_log], [land_log, port_log]]
self._set_focus()
def toggle_help(self): def toggle_help(self):
self._is_help_visible = not self._is_help_visible self._is_help_visible = not self._is_help_visible
@ -599,22 +602,52 @@ class Screen:
self._is_listing_portrait = not self._is_listing_portrait self._is_listing_portrait = not self._is_listing_portrait
def cursor_up(self): 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): 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): 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): 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): 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): 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): def _move_listing(self, vector):
dx, dy = vector dx, dy = vector
@ -639,18 +672,6 @@ class Screen:
self._move_listing((dx * (listing_width // 2), self._move_listing((dx * (listing_width // 2),
dy * (listing_height // 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): def listing_page_up(self):
self._page_listing(_UP) self._page_listing(_UP)
@ -703,6 +724,20 @@ class Screen:
def refresh(self): def refresh(self):
self._summary.refresh(self._log) 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): def _on_mouse_event(self, event):
if event[0] not in ["mouse press", "mouse drag"]: if event[0] not in ["mouse press", "mouse drag"]:
return return
@ -753,8 +788,8 @@ class Screen:
self._appearance_changed_event.set() self._appearance_changed_event.set()
_STATUS_BAR = highlight_chars( _STATUS_BAR = highlight_chars(
" *help *quit *d,*c,*j,*k,*f,*v:navigate *turn *log *edit *next *pause" " *help *quit *t*a*b:focus *turn *log *edit *next *pause *order"
" *order *refresh", Log._GREEN_STYLE) " *refresh", Log._GREEN_STYLE)
@functools.lru_cache(maxsize=2) @functools.lru_cache(maxsize=2)
def _get_status_bar_appearance(self, width, is_directory_sort, is_paused, def _get_status_bar_appearance(self, width, is_directory_sort, is_paused,
@ -778,8 +813,9 @@ class Screen:
view.position = widget.scroll_position view.position = widget.scroll_position
view.widget = widget.result view.widget = widget.result
tool_name = tools.tool_name_colored(widget.tool, widget.path) tool_name = tools.tool_name_colored(widget.tool, widget.path)
divider = " " + self._listing.top * 4 + " "
self._listing.title = ( self._listing.title = (
tools.path_colored(widget.path) + " ─── " + tool_name + " " + tools.path_colored(widget.path) + divider + tool_name + " " +
tools.status_to_str(widget.status)) tools.status_to_str(widget.status))
incomplete = self._summary.result_total - self._summary.completed_total incomplete = self._summary.result_total - self._summary.completed_total
progress_bar_size = max(0, width * incomplete // progress_bar_size = max(0, width * incomplete //
@ -796,16 +832,15 @@ class Screen:
_KEY_DATA = [ _KEY_DATA = [
({"t"}, toggle_window_orientation), ({"l"}, toggle_log), ({"t"}, toggle_window_orientation), ({"l"}, toggle_log),
({"h"}, toggle_help), ({"d", "up"}, cursor_up), ({"h"}, toggle_help), ({"up"}, cursor_up),
({"c", "down"}, cursor_down), ({"j", "left"}, cursor_left), ({"down"}, cursor_down), ({"left"}, cursor_left),
({"k", "right"}, cursor_right), ({"v"}, cursor_page_down), ({"right"}, cursor_right), ({"page down", "ctrl v"}, cursor_page_down),
({"f"}, cursor_page_up), ({"F", "page up"}, listing_page_up), ({"page up", "meta v"}, cursor_page_up), ({"o"}, toggle_order),
({"V", "page down"}, listing_page_down), ({"D"}, listing_up), ({"home", "ctrl a"}, cursor_page_left),
({"C"}, listing_down), ({"J", "home"}, listing_left), ({"end", "ctrl e"}, cursor_page_right), ({"n"}, move_to_next_issue),
({"K", "end"}, listing_right), ({"o"}, toggle_order), ({"N"}, move_to_next_issue_of_tool), ({"e"}, edit_file),
({"n"}, move_to_next_issue), ({"N"}, move_to_next_issue_of_tool), ({"q"}, quit_), ({"p"}, toggle_pause), ({"r"}, refresh),
({"e"}, edit_file), ({"q"}, quit_), ({"tab"}, toggle_focus)]
({"p"}, toggle_pause), ({"r"}, refresh)]
def add_watch_manager_to_mainloop(root_path, mainloop, on_filesystem_change, def add_watch_manager_to_mainloop(root_path, mainloop, on_filesystem_change,