From 073321668ad3215261312439d12c520dd789fe42 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Thu, 21 Jun 2018 11:20:20 +0100 Subject: [PATCH 01/10] Initial changes to support keyboard shortcut customization. Due to the limitations imposed by the way key bindings are registered in prompt-toolkit 1.0.15, it's necessary to grab the attributes from the centralized Keys collection by name. Until upgrading to version 2.0.0 or higher, this is the best way to register these events. TODO: Update the test names and configurations. --- awsshell/app.py | 9 +++++++-- awsshell/awsshellrc | 9 +++++++++ awsshell/keys.py | 30 ++++++++++++++++-------------- awsshell/toolbar.py | 17 +++++++++-------- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/awsshell/app.py b/awsshell/app.py index 84b5660..4baf3d3 100644 --- a/awsshell/app.py +++ b/awsshell/app.py @@ -252,6 +252,7 @@ def __init__(self, completer, model_completer, docs, self.show_completion_columns = None self.show_help = None self.theme = None + self.key_bindings = None self.load_config() @@ -268,6 +269,7 @@ def load_config(self): 'show_completion_columns') self.show_help = self.config_section.as_bool('show_help') self.theme = self.config_section['theme'] + self.key_bindings = self.config_section['keys'] def save_config(self): """Save the config to the config file.""" @@ -277,6 +279,7 @@ def save_config(self): self.show_completion_columns self.config_section['show_help'] = self.show_help self.config_section['theme'] = self.theme + self.config_section['keys'] = self.key_bindings self.config_obj.write() @property @@ -410,7 +413,8 @@ def set_show_help(show_help): lambda: self.enable_vi_bindings, set_enable_vi_bindings, lambda: self.show_completion_columns, set_show_completion_columns, lambda: self.show_help, set_show_help, - self.stop_input_and_refresh_cli) + self.stop_input_and_refresh_cli, + self.key_bindings) def create_application(self, completer, history, display_completions_in_columns): @@ -419,7 +423,8 @@ def create_application(self, completer, history, lambda: self.model_completer.match_fuzzy, lambda: self.enable_vi_bindings, lambda: self.show_completion_columns, - lambda: self.show_help) + lambda: self.show_help, + self.key_manager.key_bindings) style_factory = StyleFactory(self.theme) buffers = { 'clidocs': Buffer(read_only=True) diff --git a/awsshell/awsshellrc b/awsshell/awsshellrc index a51950b..ab19659 100644 --- a/awsshell/awsshellrc +++ b/awsshell/awsshellrc @@ -18,3 +18,12 @@ show_help = True # pastie, paraiso-light, trac, default, fruity. # to disable themes, set theme = none theme = vim + +# keyboard shortcuts configuration +[[keys]] + toggle_fuzzy = 'f12' + toggle_editor = 'f9' + toggle_column = 'f4' + toggle_help = 'f5' + toggle_focus = 'f2' + exit = 'f10' diff --git a/awsshell/keys.py b/awsshell/keys.py index 5e2df96..6d4928b 100644 --- a/awsshell/keys.py +++ b/awsshell/keys.py @@ -11,7 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. from prompt_toolkit.key_binding.manager import KeyBindingManager -from prompt_toolkit.keys import Keys +from prompt_toolkit.keys import Keys, Key class KeyManager(object): @@ -30,8 +30,10 @@ class KeyManager(object): def __init__(self, get_match_fuzzy, set_match_fuzzy, get_enable_vi_bindings, set_enable_vi_bindings, get_show_completion_columns, set_show_completion_columns, - get_show_help, set_show_help, stop_input_and_refresh_cli): + get_show_help, set_show_help, stop_input_and_refresh_cli, + key_bindings): self.manager = None + self.key_bindings = key_bindings self._create_key_manager( get_match_fuzzy, set_match_fuzzy, get_enable_vi_bindings, set_enable_vi_bindings, @@ -99,8 +101,8 @@ def _create_key_manager(self, get_match_fuzzy, set_match_fuzzy, enable_auto_suggest_bindings=True, enable_open_in_editor=False) - @self.manager.registry.add_binding(Keys.F2) - def handle_f2(_): + @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_fuzzy'])) + def handle_toggle_fuzzy(_): """Toggle fuzzy matching. :type _: :class:`prompt_toolkit.Event` @@ -109,8 +111,8 @@ def handle_f2(_): """ set_match_fuzzy(not get_match_fuzzy()) - @self.manager.registry.add_binding(Keys.F3) - def handle_f3(_): + @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_editor'])) + def handle_toggle_editor(_): """Toggle Vi mode keybindings matching. Disabling Vi keybindings will enable Emacs keybindings. @@ -122,8 +124,8 @@ def handle_f3(_): set_enable_vi_bindings(not get_enable_vi_bindings()) stop_input_and_refresh_cli() - @self.manager.registry.add_binding(Keys.F4) - def handle_f4(_): + @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_column'])) + def handle_toggle_column(_): """Toggle multiple column completions. :type _: :class:`prompt_toolkit.Event` @@ -133,8 +135,8 @@ def handle_f4(_): set_show_completion_columns(not get_show_completion_columns()) stop_input_and_refresh_cli() - @self.manager.registry.add_binding(Keys.F5) - def handle_f5(_): + @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_help'])) + def handle_toggle_help(_): """Toggle the help container. :type _: :class:`prompt_toolkit.Event` @@ -144,8 +146,8 @@ def handle_f5(_): set_show_help(not get_show_help()) stop_input_and_refresh_cli() - @self.manager.registry.add_binding(Keys.F9) - def handle_f9(event): + @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_focus'])) + def handle_toggle_focus(event): """Switch between the default and docs buffers. :type event: :class:`prompt_toolkit.Event` @@ -158,8 +160,8 @@ def handle_f9(event): else: event.cli.focus(u'clidocs') - @self.manager.registry.add_binding(Keys.F10) - def handle_f10(event): + @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['exit'])) + def handle_exit(event): """Quit when the `F10` key is pressed. :type event: :class:`prompt_toolkit.Event` diff --git a/awsshell/toolbar.py b/awsshell/toolbar.py index 6b4d344..986da6d 100644 --- a/awsshell/toolbar.py +++ b/awsshell/toolbar.py @@ -22,10 +22,11 @@ class Toolbar(object): """ def __init__(self, get_match_fuzzy, get_enable_vi_bindings, - get_show_completion_columns, get_show_help): + get_show_completion_columns, get_show_help, key_bindings): + self.key_bindings = key_bindings self.handler = self._create_toolbar_handler( get_match_fuzzy, get_enable_vi_bindings, - get_show_completion_columns, get_show_help) + get_show_completion_columns, get_show_help,) def _create_toolbar_handler(self, get_match_fuzzy, get_enable_vi_bindings, get_show_completion_columns, get_show_help): @@ -93,17 +94,17 @@ def get_toolbar_items(cli): show_buffer_name = 'doc' return [ (match_fuzzy_token, - ' [F2] Fuzzy: {0} '.format(match_fuzzy_cfg)), + ' [{0}] Fuzzy: {1} '.format(self.key_bindings['toggle_fuzzy'], match_fuzzy_cfg)), (enable_vi_bindings_token, - ' [F3] Keys: {0} '.format(enable_vi_bindings_cfg)), + ' [{0}] Keys: {1} '.format(self.key_bindings['toggle_editor'], enable_vi_bindings_cfg)), (show_columns_token, - ' [F4] {0} Column '.format(show_columns_cfg)), + ' [{0}] {1} Column '.format(self.key_bindings['toggle_column'], show_columns_cfg)), (show_help_token, - ' [F5] Help: {0} '.format(show_help_cfg)), + ' [{0}] Help: {1} '.format(self.key_bindings['toggle_help'], show_help_cfg)), (Token.Toolbar, - ' [F9] Focus: {0} '.format(show_buffer_name)), + ' [{0}] Focus: {1} '.format(self.key_bindings['toggle_focus'], show_buffer_name)), (Token.Toolbar, - ' [F10] Exit ') + ' [{0}] Exit '.format(self.key_bindings['exit'])) ] return get_toolbar_items From 097272ed4fdc2852fff6b5cdd7d6b4ea30e798e5 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Thu, 21 Jun 2018 12:01:54 +0100 Subject: [PATCH 02/10] Added default key binding loading in the case that it's not in the file. This was added specifically for the case of upgrading, since the user might have a file without this section in their home directory. In newly-installed cases, we could include the keys in the config file by default. TODO: Update the test names and configurations. --- awsshell/app.py | 18 +++++++++++++++++- awsshell/awsshellrc | 9 --------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/awsshell/app.py b/awsshell/app.py index 4baf3d3..80e2d5e 100644 --- a/awsshell/app.py +++ b/awsshell/app.py @@ -256,6 +256,9 @@ def __init__(self, completer, model_completer, docs, self.load_config() + if self.key_bindings is None: + self.set_default_key_bindings() + def load_config(self): """Load the config from the config file or template.""" config = Config() @@ -269,7 +272,8 @@ def load_config(self): 'show_completion_columns') self.show_help = self.config_section.as_bool('show_help') self.theme = self.config_section['theme'] - self.key_bindings = self.config_section['keys'] + if 'keys' in self.config_section: + self.key_bindings = self.config_section['keys'] def save_config(self): """Save the config to the config file.""" @@ -282,6 +286,18 @@ def save_config(self): self.config_section['keys'] = self.key_bindings self.config_obj.write() + def set_default_key_bindings(self): + pass + self.key_bindings = { + 'toggle_fuzzy': 'F2', + 'toggle_editor': 'F3', + 'toggle_column': 'F4', + 'toggle_help': 'F5', + 'toggle_focus': 'F9', + 'exit': 'F10' + } + + @property def cli(self): if self._cli is None or self.refresh_cli: diff --git a/awsshell/awsshellrc b/awsshell/awsshellrc index ab19659..a51950b 100644 --- a/awsshell/awsshellrc +++ b/awsshell/awsshellrc @@ -18,12 +18,3 @@ show_help = True # pastie, paraiso-light, trac, default, fruity. # to disable themes, set theme = none theme = vim - -# keyboard shortcuts configuration -[[keys]] - toggle_fuzzy = 'f12' - toggle_editor = 'f9' - toggle_column = 'f4' - toggle_help = 'f5' - toggle_focus = 'f2' - exit = 'f10' From 4e8a347ec27118ab0bd19d6e75a0ec3e37150669 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Thu, 21 Jun 2018 12:23:54 +0100 Subject: [PATCH 03/10] Updating tests to make sure they work. --- tests/unit/test_toolbar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_toolbar.py b/tests/unit/test_toolbar.py index aec722a..e372912 100644 --- a/tests/unit/test_toolbar.py +++ b/tests/unit/test_toolbar.py @@ -27,7 +27,8 @@ def setUp(self): lambda: self.aws_shell.model_completer.match_fuzzy, lambda: self.aws_shell.enable_vi_bindings, lambda: self.aws_shell.show_completion_columns, - lambda: self.aws_shell.show_help) + lambda: self.aws_shell.show_help, + self.aws_shell.key_bindings) def test_toolbar_on(self): self.aws_shell.model_completer.match_fuzzy = True From ee015bc9e3f3e44f8ae961687a8ad093b4b6cdbd Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Thu, 21 Jun 2018 12:28:08 +0100 Subject: [PATCH 04/10] Updating test names to reflect the refactor. Fixed a file close warning in 'test_utils.py' --- tests/integration/test_keys.py | 12 ++++++------ tests/unit/test_utils.py | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/integration/test_keys.py b/tests/integration/test_keys.py index 3186113..8fe0012 100644 --- a/tests/integration/test_keys.py +++ b/tests/integration/test_keys.py @@ -37,35 +37,35 @@ def feed_key(self, key): self.processor.feed(KeyPress(key, u'')) self.processor.process_keys() - def test_F2(self): + def test_toggle_fuzzy(self): match_fuzzy = self.aws_shell.model_completer.match_fuzzy self.feed_key(Keys.F2) assert match_fuzzy != self.aws_shell.model_completer.match_fuzzy - def test_F3(self): + def test_toggle_editor(self): enable_vi_bindings = self.aws_shell.enable_vi_bindings with self.assertRaises(InputInterrupt): self.feed_key(Keys.F3) assert enable_vi_bindings != self.aws_shell.enable_vi_bindings - def test_F4(self): + def test_toggle_column(self): show_completion_columns = self.aws_shell.show_completion_columns with self.assertRaises(InputInterrupt): self.feed_key(Keys.F4) assert show_completion_columns != \ self.aws_shell.show_completion_columns - def test_F5(self): + def test_toggle_help(self): show_help = self.aws_shell.show_help with self.assertRaises(InputInterrupt): self.feed_key(Keys.F5) assert show_help != self.aws_shell.show_help - def test_F9(self): + def test_toggle_focus(self): assert self.aws_shell.cli.current_buffer_name == u'DEFAULT_BUFFER' self.feed_key(Keys.F9) assert self.aws_shell.cli.current_buffer_name == u'clidocs' - def test_F10(self): + def test_press_exit(self): self.feed_key(Keys.F10) assert self.aws_shell.cli.is_exiting diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index bd9f9b0..fb87fa4 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -73,7 +73,9 @@ def test_can_use_as_context_manager(self): filename = f.name f.write("foobar") f.flush() - self.assertEqual(open(filename).read(), "foobar") + f = open(filename) + self.assertEqual(f.read(), "foobar") + f.close() def test_is_removed_after_exiting_context(self): with temporary_file('w') as f: From 6bce7edeaa0a14e7baa4fd374f93106c8a324977 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Thu, 21 Jun 2018 13:57:04 +0100 Subject: [PATCH 05/10] Adding comments to configuration file for allowed values (based on prompt toolkit v1.0.15 Keys collection). --- awsshell/awsshellrc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/awsshell/awsshellrc b/awsshell/awsshellrc index a51950b..7b9edc8 100644 --- a/awsshell/awsshellrc +++ b/awsshell/awsshellrc @@ -18,3 +18,48 @@ show_help = True # pastie, paraiso-light, trac, default, fruity. # to disable themes, set theme = none theme = vim + +# Keyboard Shortcuts +[[keys]] +toggle_fuzzy = F2 +toggle_editor = F3 +toggle_column = F4 +toggle_help = F5 +toggle_focus = F9 +exit = F10 + +# Keyboard Shortcuts Possible Values +# ControlA, ControlB, .., ContolZ + +# ControlSpace +# ControlBackslash +# ControlSquareClose +# ControlCircumflex +# ControlUnderscore +# ControlLeft +# ControlRight +# ControlUp +# ControlDown + +# Up +# Down +# Right +# Left + +# ShiftLeft +# ShiftUp +# ShiftDown +# ShiftRight + +# Home +# End +# Delete +# ShiftDelete +# ControlDelete +# PageUp +# PageDown +# BackTab +# Insert +# Backspace + +# F1, F2, .. , F24 \ No newline at end of file From ab1c1b7fe9e753a0cd889575f56fe265bd5875f1 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Tue, 28 Aug 2018 13:00:56 +0100 Subject: [PATCH 06/10] Format of awsshellrc --- awsshell/awsshellrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/awsshell/awsshellrc b/awsshell/awsshellrc index 7b9edc8..50146d8 100644 --- a/awsshell/awsshellrc +++ b/awsshell/awsshellrc @@ -62,4 +62,5 @@ exit = F10 # Insert # Backspace -# F1, F2, .. , F24 \ No newline at end of file +# F1, F2, .. , F24 + From ca21150c56e5c2cfcefeb094083e53b9b4e4ea98 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Tue, 28 Aug 2018 13:12:14 +0100 Subject: [PATCH 07/10] Fixing style for keys and toolbar. --- awsshell/keys.py | 18 ++++++++++++------ awsshell/toolbar.py | 15 ++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/awsshell/keys.py b/awsshell/keys.py index 6d4928b..9efa17e 100644 --- a/awsshell/keys.py +++ b/awsshell/keys.py @@ -101,7 +101,8 @@ def _create_key_manager(self, get_match_fuzzy, set_match_fuzzy, enable_auto_suggest_bindings=True, enable_open_in_editor=False) - @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_fuzzy'])) + @self.manager.registry.add_binding( + getattr(Keys, self.key_bindings['toggle_fuzzy'])) def handle_toggle_fuzzy(_): """Toggle fuzzy matching. @@ -111,7 +112,8 @@ def handle_toggle_fuzzy(_): """ set_match_fuzzy(not get_match_fuzzy()) - @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_editor'])) + @self.manager.registry.add_binding( + getattr(Keys, self.key_bindings['toggle_editor'])) def handle_toggle_editor(_): """Toggle Vi mode keybindings matching. @@ -124,7 +126,8 @@ def handle_toggle_editor(_): set_enable_vi_bindings(not get_enable_vi_bindings()) stop_input_and_refresh_cli() - @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_column'])) + @self.manager.registry.add_binding( + getattr(Keys, self.key_bindings['toggle_column'])) def handle_toggle_column(_): """Toggle multiple column completions. @@ -135,7 +138,8 @@ def handle_toggle_column(_): set_show_completion_columns(not get_show_completion_columns()) stop_input_and_refresh_cli() - @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_help'])) + @self.manager.registry.add_binding( + getattr(Keys, self.key_bindings['toggle_help'])) def handle_toggle_help(_): """Toggle the help container. @@ -146,7 +150,8 @@ def handle_toggle_help(_): set_show_help(not get_show_help()) stop_input_and_refresh_cli() - @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['toggle_focus'])) + @self.manager.registry.add_binding( + getattr(Keys, self.key_bindings['toggle_focus'])) def handle_toggle_focus(event): """Switch between the default and docs buffers. @@ -160,7 +165,8 @@ def handle_toggle_focus(event): else: event.cli.focus(u'clidocs') - @self.manager.registry.add_binding(getattr(Keys, self.key_bindings['exit'])) + @self.manager.registry.add_binding( + getattr(Keys, self.key_bindings['exit'])) def handle_exit(event): """Quit when the `F10` key is pressed. diff --git a/awsshell/toolbar.py b/awsshell/toolbar.py index 986da6d..32b1088 100644 --- a/awsshell/toolbar.py +++ b/awsshell/toolbar.py @@ -94,15 +94,20 @@ def get_toolbar_items(cli): show_buffer_name = 'doc' return [ (match_fuzzy_token, - ' [{0}] Fuzzy: {1} '.format(self.key_bindings['toggle_fuzzy'], match_fuzzy_cfg)), + ' [{0}] Fuzzy: {1} '.format( + self.key_bindings['toggle_fuzzy'], match_fuzzy_cfg)), (enable_vi_bindings_token, - ' [{0}] Keys: {1} '.format(self.key_bindings['toggle_editor'], enable_vi_bindings_cfg)), + ' [{0}] Keys: {1} '.format( + self.key_bindings['toggle_editor'], enable_vi_bindings_cfg)), (show_columns_token, - ' [{0}] {1} Column '.format(self.key_bindings['toggle_column'], show_columns_cfg)), + ' [{0}] {1} Column '.format( + self.key_bindings['toggle_column'], show_columns_cfg)), (show_help_token, - ' [{0}] Help: {1} '.format(self.key_bindings['toggle_help'], show_help_cfg)), + ' [{0}] Help: {1} '.format( + self.key_bindings['toggle_help'], show_help_cfg)), (Token.Toolbar, - ' [{0}] Focus: {1} '.format(self.key_bindings['toggle_focus'], show_buffer_name)), + ' [{0}] Focus: {1} '.format( + self.key_bindings['toggle_focus'], show_buffer_name)), (Token.Toolbar, ' [{0}] Exit '.format(self.key_bindings['exit'])) ] From 5a2ef3ba27822e81ff2a14415be4700b640e2565 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Tue, 28 Aug 2018 13:20:25 +0100 Subject: [PATCH 08/10] Fixing tabs... --- awsshell/keys.py | 12 ++++++------ awsshell/toolbar.py | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/awsshell/keys.py b/awsshell/keys.py index 9efa17e..1c21817 100644 --- a/awsshell/keys.py +++ b/awsshell/keys.py @@ -102,7 +102,7 @@ def _create_key_manager(self, get_match_fuzzy, set_match_fuzzy, enable_open_in_editor=False) @self.manager.registry.add_binding( - getattr(Keys, self.key_bindings['toggle_fuzzy'])) + getattr(Keys, self.key_bindings['toggle_fuzzy'])) def handle_toggle_fuzzy(_): """Toggle fuzzy matching. @@ -113,7 +113,7 @@ def handle_toggle_fuzzy(_): set_match_fuzzy(not get_match_fuzzy()) @self.manager.registry.add_binding( - getattr(Keys, self.key_bindings['toggle_editor'])) + getattr(Keys, self.key_bindings['toggle_editor'])) def handle_toggle_editor(_): """Toggle Vi mode keybindings matching. @@ -127,7 +127,7 @@ def handle_toggle_editor(_): stop_input_and_refresh_cli() @self.manager.registry.add_binding( - getattr(Keys, self.key_bindings['toggle_column'])) + getattr(Keys, self.key_bindings['toggle_column'])) def handle_toggle_column(_): """Toggle multiple column completions. @@ -139,7 +139,7 @@ def handle_toggle_column(_): stop_input_and_refresh_cli() @self.manager.registry.add_binding( - getattr(Keys, self.key_bindings['toggle_help'])) + getattr(Keys, self.key_bindings['toggle_help'])) def handle_toggle_help(_): """Toggle the help container. @@ -151,7 +151,7 @@ def handle_toggle_help(_): stop_input_and_refresh_cli() @self.manager.registry.add_binding( - getattr(Keys, self.key_bindings['toggle_focus'])) + getattr(Keys, self.key_bindings['toggle_focus'])) def handle_toggle_focus(event): """Switch between the default and docs buffers. @@ -166,7 +166,7 @@ def handle_toggle_focus(event): event.cli.focus(u'clidocs') @self.manager.registry.add_binding( - getattr(Keys, self.key_bindings['exit'])) + getattr(Keys, self.key_bindings['exit'])) def handle_exit(event): """Quit when the `F10` key is pressed. diff --git a/awsshell/toolbar.py b/awsshell/toolbar.py index 32b1088..a14087b 100644 --- a/awsshell/toolbar.py +++ b/awsshell/toolbar.py @@ -95,19 +95,19 @@ def get_toolbar_items(cli): return [ (match_fuzzy_token, ' [{0}] Fuzzy: {1} '.format( - self.key_bindings['toggle_fuzzy'], match_fuzzy_cfg)), + self.key_bindings['toggle_fuzzy'], match_fuzzy_cfg)), (enable_vi_bindings_token, ' [{0}] Keys: {1} '.format( - self.key_bindings['toggle_editor'], enable_vi_bindings_cfg)), + self.key_bindings['toggle_editor'], enable_vi_bindings_cfg)), (show_columns_token, ' [{0}] {1} Column '.format( - self.key_bindings['toggle_column'], show_columns_cfg)), + self.key_bindings['toggle_column'], show_columns_cfg)), (show_help_token, ' [{0}] Help: {1} '.format( - self.key_bindings['toggle_help'], show_help_cfg)), + self.key_bindings['toggle_help'], show_help_cfg)), (Token.Toolbar, ' [{0}] Focus: {1} '.format( - self.key_bindings['toggle_focus'], show_buffer_name)), + self.key_bindings['toggle_focus'], show_buffer_name)), (Token.Toolbar, ' [{0}] Exit '.format(self.key_bindings['exit'])) ] From 29f72faafc251473825912dadd1290b53319a7d7 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Tue, 28 Aug 2018 13:25:33 +0100 Subject: [PATCH 09/10] Fixing styling. --- awsshell/keys.py | 2 +- awsshell/toolbar.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/awsshell/keys.py b/awsshell/keys.py index 1c21817..b9c4690 100644 --- a/awsshell/keys.py +++ b/awsshell/keys.py @@ -11,7 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. from prompt_toolkit.key_binding.manager import KeyBindingManager -from prompt_toolkit.keys import Keys, Key +from prompt_toolkit.keys import Keys class KeyManager(object): diff --git a/awsshell/toolbar.py b/awsshell/toolbar.py index a14087b..02c921a 100644 --- a/awsshell/toolbar.py +++ b/awsshell/toolbar.py @@ -95,19 +95,24 @@ def get_toolbar_items(cli): return [ (match_fuzzy_token, ' [{0}] Fuzzy: {1} '.format( - self.key_bindings['toggle_fuzzy'], match_fuzzy_cfg)), + self.key_bindings['toggle_fuzzy'], + match_fuzzy_cfg)), (enable_vi_bindings_token, ' [{0}] Keys: {1} '.format( - self.key_bindings['toggle_editor'], enable_vi_bindings_cfg)), + self.key_bindings['toggle_editor'], + enable_vi_bindings_cfg)), (show_columns_token, ' [{0}] {1} Column '.format( - self.key_bindings['toggle_column'], show_columns_cfg)), + self.key_bindings['toggle_column'],i + show_columns_cfg)), (show_help_token, ' [{0}] Help: {1} '.format( - self.key_bindings['toggle_help'], show_help_cfg)), + self.key_bindings['toggle_help'],i + show_help_cfg)), (Token.Toolbar, ' [{0}] Focus: {1} '.format( - self.key_bindings['toggle_focus'], show_buffer_name)), + self.key_bindings['toggle_focus'],i + show_buffer_name)), (Token.Toolbar, ' [{0}] Exit '.format(self.key_bindings['exit'])) ] From 8fba9f0e8b65069ee05c1d245f51453765dabeb8 Mon Sep 17 00:00:00 2001 From: MikeMorain Date: Tue, 28 Aug 2018 13:33:49 +0100 Subject: [PATCH 10/10] fixing error with setting default key bindings, and one more styling fix. --- awsshell/app.py | 2 -- awsshell/toolbar.py | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/awsshell/app.py b/awsshell/app.py index 80e2d5e..21c16a7 100644 --- a/awsshell/app.py +++ b/awsshell/app.py @@ -287,7 +287,6 @@ def save_config(self): self.config_obj.write() def set_default_key_bindings(self): - pass self.key_bindings = { 'toggle_fuzzy': 'F2', 'toggle_editor': 'F3', @@ -297,7 +296,6 @@ def set_default_key_bindings(self): 'exit': 'F10' } - @property def cli(self): if self._cli is None or self.refresh_cli: diff --git a/awsshell/toolbar.py b/awsshell/toolbar.py index 02c921a..c405c21 100644 --- a/awsshell/toolbar.py +++ b/awsshell/toolbar.py @@ -103,15 +103,15 @@ def get_toolbar_items(cli): enable_vi_bindings_cfg)), (show_columns_token, ' [{0}] {1} Column '.format( - self.key_bindings['toggle_column'],i + self.key_bindings['toggle_column'], show_columns_cfg)), (show_help_token, ' [{0}] Help: {1} '.format( - self.key_bindings['toggle_help'],i + self.key_bindings['toggle_help'], show_help_cfg)), (Token.Toolbar, ' [{0}] Focus: {1} '.format( - self.key_bindings['toggle_focus'],i + self.key_bindings['toggle_focus'], show_buffer_name)), (Token.Toolbar, ' [{0}] Exit '.format(self.key_bindings['exit']))