Simplify key maps.

- Atm there is only one key for every action.
This commit is contained in:
Andrew Hamilton 2021-04-11 18:42:58 +10:00
parent 3c3f06326b
commit 14eef08897

View file

@ -630,14 +630,6 @@ def get_status_help():
for status, meaning in tools.STATUS_MEANINGS])
def make_key_map(key_data):
key_map = {}
for keys, action in key_data:
for key in keys:
key_map[key] = action
return key_map
class Help:
def __init__(self, summary, screen):
@ -648,13 +640,11 @@ class Help:
self.view = fill3.View.from_widget(fill3.Text(help_text))
self.widget = fill3.Border(self.view, title="Help")
portal = self.view.portal
self.key_map = make_key_map([
({"h"}, self._exit_help),
({terminal.UP_KEY}, portal.scroll_up),
({terminal.DOWN_KEY}, portal.scroll_down),
({terminal.LEFT_KEY}, portal.scroll_left),
({terminal.RIGHT_KEY}, portal.scroll_right),
({"q"}, self._exit_help)])
self.key_map = {"h": self._exit_help, terminal.UP_KEY: portal.scroll_up,
terminal.DOWN_KEY: portal.scroll_down,
terminal.LEFT_KEY: portal.scroll_left,
terminal.RIGHT_KEY: portal.scroll_right,
"q": self._exit_help}
def _exit_help(self):
self.screen._is_help_visible = False
@ -704,7 +694,6 @@ class Screen:
self._is_help_visible = False
self._is_fullscreen = False
self._make_widgets()
self._key_map = make_key_map(Screen._KEY_DATA)
self._last_mouse_position = 0, 0
def __getstate__(self):
@ -977,8 +966,8 @@ class Screen:
self._help_widget.on_keyboard_input(
term_code, self._appearance_changed_event)
return
action = (self._key_map.get(term_code) or
self._key_map.get(term_code.lower()))
action = (Screen._KEY_MAP.get(term_code) or
Screen._KEY_MAP.get(term_code.lower()))
if action is not None:
action(self)
self._appearance_changed_event.set()
@ -1048,18 +1037,16 @@ class Screen:
return (result if (width, height) == dimensions
else fill3.appearance_resize(result, dimensions))
_KEY_DATA = [
({"o"}, toggle_window_orientation), ({"l"}, toggle_log),
({"h"}, toggle_help), ({terminal.UP_KEY}, cursor_up),
({terminal.DOWN_KEY}, cursor_down), ({terminal.LEFT_KEY}, cursor_left),
({terminal.RIGHT_KEY}, cursor_right),
({terminal.PAGE_DOWN_KEY}, cursor_page_down),
({terminal.PAGE_UP_KEY}, cursor_page_up), ({"s"}, toggle_order),
({terminal.HOME_KEY}, cursor_home),
({terminal.END_KEY}, cursor_end), ({"n"}, move_to_next_issue),
({"N"}, move_to_next_issue_of_tool), ({"e"}, edit_file),
({"q"}, quit_), ({"r"}, refresh), ({"R"}, refresh_tool),
({"\t"}, toggle_focus), ({"f"}, toggle_fullscreen), ("x", xdg_open)]
_KEY_MAP = {
"o": toggle_window_orientation, "l": toggle_log, "h": toggle_help,
terminal.UP_KEY: cursor_up, terminal.DOWN_KEY: cursor_down,
terminal.LEFT_KEY: cursor_left, terminal.RIGHT_KEY: cursor_right,
terminal.PAGE_DOWN_KEY: cursor_page_down,
terminal.PAGE_UP_KEY: cursor_page_up, "s": toggle_order,
terminal.HOME_KEY: cursor_home, terminal.END_KEY: cursor_end,
"n": move_to_next_issue, "N": move_to_next_issue_of_tool,
"e": edit_file, "q": quit_, "r": refresh, "R": refresh_tool,
"\t": toggle_focus, "f": toggle_fullscreen, "x": xdg_open}
def setup_inotify(root_path, loop, on_filesystem_event, exclude_filter):