Skip to content

Commit

Permalink
Fixed #13: Remapped docs from F1 to F9.
Browse files Browse the repository at this point in the history
  • Loading branch information
donnemartin committed Sep 20, 2015
1 parent 7a68ef0 commit 39caf27
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions saws/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ def create_key_manager(self, set_color, get_color,
assert callable(handle_docs)
self.manager = KeyBindingManager(enable_system_bindings=True)

@self.manager.registry.add_binding(Keys.F1)
def handle_f1(_):
"""Inputs the "docs" command when the `F1` key is pressed.
Args:
* _: An instance of prompt_toolkit's Event (not used).
Returns:
None.
"""
handle_docs(from_fkey=True)

@self.manager.registry.add_binding(Keys.F2)
def handle_f2(_):
"""Enables/Disables color output.
Expand Down Expand Up @@ -136,6 +124,18 @@ def handle_f5(_):
"""
refresh_resources()

@self.manager.registry.add_binding(Keys.F9)
def handle_f9(_):
"""Inputs the "docs" command when the `F9` key is pressed.
Args:
* _: An instance of prompt_toolkit's Event (not used).
Returns:
None.
"""
handle_docs(from_fkey=True)

@self.manager.registry.add_binding(Keys.F10)
def handle_f10(_):
"""Quits when the `F10` key is pressed.
Expand Down
8 changes: 4 additions & 4 deletions saws/saws.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def refresh_resources(self):
self.completer.refresh_resources(force_refresh=True)

def handle_docs(self, text=None, from_fkey=False):
"""Displays contextual web docs for `F1` or the `docs` command.
"""Displays contextual web docs for `F9` or the `docs` command.
Displays the web docs specific to the currently entered:
Expand All @@ -232,7 +232,7 @@ def handle_docs(self, text=None, from_fkey=False):
Args:
* text: A string representing the input command text.
* from_fkey: A boolean representing whether this function is
being executed from an `F1` key press.
being executed from an `F9` key press.
Returns:
A boolean representing whether the web docs were shown.
Expand All @@ -241,7 +241,7 @@ def handle_docs(self, text=None, from_fkey=False):
index_html = 'index.html'
if text is None:
text = self.aws_cli.current_buffer.document.text
# If the user hit the F1 key, append 'docs' to the text
# If the user hit the F9 key, append 'docs' to the text
if from_fkey:
text = text.strip() + ' ' + AwsCommands.AWS_DOCS
tokens = text.split()
Expand All @@ -262,7 +262,7 @@ def handle_docs(self, text=None, from_fkey=False):
return True
webbrowser.open(base_url + index_html)
# If we still haven't opened the help doc at this point and the
# user hit the F1 key or typed docs, just open the main docs index
# user hit the F9 key or typed docs, just open the main docs index
if from_fkey or AwsCommands.AWS_DOCS in tokens:
webbrowser.open(base_url + index_html)
return True
Expand Down
2 changes: 1 addition & 1 deletion saws/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def get_toolbar_items(_):
shortcuts_token = Token.Toolbar.Off
shortcuts = 'OFF'
return [
(Token.Toolbar, ' [F1] Docs '),
(color_token, ' [F2] Color: {0} '.format(color)),
(fuzzy_token, ' [F3] Fuzzy: {0} '.format(fuzzy)),
(shortcuts_token, ' [F4] Shortcuts: {0} '.format(shortcuts)),
(Token.Toolbar, ' [F5] Refresh '),
(Token.Toolbar, ' [F9] Docs '),
(Token.Toolbar, ' [F10] Exit ')
]

Expand Down
10 changes: 5 additions & 5 deletions tests/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ def setUp(self, mock_print):
self.processor = self.saws.aws_cli.input_processor
self.DOCS_HOME_URL = 'http://docs.aws.amazon.com/cli/latest/reference/index.html'

@mock.patch('saws.saws.webbrowser')
def test_F1(self, mock_webbrowser):
self.processor.feed_key(KeyPress(Keys.F1, ''))
mock_webbrowser.open.assert_called_with(self.DOCS_HOME_URL)

def test_F2(self):
orig_color = self.saws.get_color()
self.processor.feed_key(KeyPress(Keys.F2, ''))
Expand All @@ -59,6 +54,11 @@ def test_F4(self):
self.processor.feed_key(KeyPress(Keys.F4, ''))
assert orig_shortcut != self.saws.get_shortcut_match()

@mock.patch('saws.saws.webbrowser')
def test_F9(self, mock_webbrowser):
self.processor.feed_key(KeyPress(Keys.F9, ''))
mock_webbrowser.open.assert_called_with(self.DOCS_HOME_URL)

def test_F10(self):
with self.assertRaises(EOFError):
self.processor.feed_key(KeyPress(Keys.F10, ''))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def setUp(self, mock_print):

def test_toolbar_on(self):
expected = [
(Token.Toolbar, ' [F1] Docs '),
(Token.Toolbar.On, ' [F2] Color: ON '),
(Token.Toolbar.On, ' [F3] Fuzzy: ON '),
(Token.Toolbar.On, ' [F4] Shortcuts: ON '),
(Token.Toolbar, ' [F5] Refresh '),
(Token.Toolbar, ' [F9] Docs '),
(Token.Toolbar, ' [F10] Exit ')]
assert expected == self.toolbar.handler(None)

Expand All @@ -47,10 +47,10 @@ def test_toolbar_off(self):
self.saws.set_fuzzy_match(False)
self.saws.set_shortcut_match(False)
expected = [
(Token.Toolbar, ' [F1] Docs '),
(Token.Toolbar.Off, ' [F2] Color: OFF '),
(Token.Toolbar.Off, ' [F3] Fuzzy: OFF '),
(Token.Toolbar.Off, ' [F4] Shortcuts: OFF '),
(Token.Toolbar, ' [F5] Refresh '),
(Token.Toolbar, ' [F9] Docs '),
(Token.Toolbar, ' [F10] Exit ')]
assert expected == self.toolbar.handler(None)

0 comments on commit 39caf27

Please sign in to comment.