Skip to content

Commit d597b79

Browse files
authored
Merge pull request #138 from joguSD/editing-mode-fix
Editing mode fix and documentation scrolling
2 parents 060c61e + 32f31d2 commit d597b79

File tree

7 files changed

+65
-15
lines changed

7 files changed

+65
-15
lines changed

README.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ Inline Documentation
180180
The aws-shell will automatically pull up documentation as you type commands.
181181
It will show inline documentation for CLI options. There is also a separate
182182
documentation panel that will show documentation for the current command or
183-
option you are typing.
183+
option you are typing. Pressing F9 or clicking this panel will focus it
184+
allowing the use of your keybindings or scroll wheel to navigate the docs.
184185

185186
.. image:: https://cloud.githubusercontent.com/assets/368057/11823320/36ae9b04-a328-11e5-9661-81abfc0afe5a.png
186187

@@ -211,6 +212,7 @@ The aws-shell has a bottom toolbar that provides several options:
211212
* ``F3`` toggles between VI and Emacs key bindings
212213
* ``F4`` toggles between single and multi column auto completions
213214
* ``F5`` shows and hides the help documentation pane
215+
* ``F9`` toggles focus between the cli and documentation pane
214216
* ``F10`` or ``Ctrl-D`` exits the aws-shell
215217

216218
As you toggle options in the toolbar, your preferences are persisted

awsshell/app.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from prompt_toolkit.interface import AbortAction, AcceptAction
1818
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
1919
from prompt_toolkit.history import InMemoryHistory, FileHistory
20+
from prompt_toolkit.enums import EditingMode
2021

2122
from awsshell.ui import create_default_layout
2223
from awsshell.config import Config
@@ -417,9 +418,15 @@ def create_application(self, completer, history,
417418
'clidocs': Buffer(read_only=True)
418419
}
419420

421+
if self.enable_vi_bindings:
422+
editing_mode = EditingMode.VI
423+
else:
424+
editing_mode = EditingMode.EMACS
425+
420426
return Application(
427+
editing_mode=editing_mode,
421428
layout=self.create_layout(display_completions_in_columns, toolbar),
422-
mouse_support=False,
429+
mouse_support=True,
423430
style=style_factory.style,
424431
buffers=buffers,
425432
buffer=self.create_buffer(completer, history),
@@ -447,8 +454,18 @@ def on_input_timeout(self, cli):
447454
self.current_docs = self._docs.extract_description(key_name)
448455
else:
449456
self.current_docs = u''
457+
458+
position = cli.buffers['clidocs'].document.cursor_position
459+
# if the docs to be displayed have changed, reset position to 0
460+
if cli.buffers['clidocs'].text != self.current_docs:
461+
position = 0
462+
450463
cli.buffers['clidocs'].reset(
451-
initial_document=Document(self.current_docs, cursor_position=0))
464+
initial_document=Document(
465+
self.current_docs,
466+
cursor_position=position
467+
)
468+
)
452469
cli.request_redraw()
453470

454471
def create_cli_interface(self, display_completions_in_columns):

awsshell/keys.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def _create_key_manager(self, get_match_fuzzy, set_match_fuzzy,
9797
enable_abort_and_exit_bindings=True,
9898
enable_system_bindings=True,
9999
enable_auto_suggest_bindings=True,
100-
enable_vi_mode=get_enable_vi_bindings(),
101100
enable_open_in_editor=False)
102101

103102
@self.manager.registry.add_binding(Keys.F2)
@@ -145,6 +144,20 @@ def handle_f5(_):
145144
set_show_help(not get_show_help())
146145
stop_input_and_refresh_cli()
147146

147+
@self.manager.registry.add_binding(Keys.F9)
148+
def handle_f9(event):
149+
"""Switch between the default and docs buffers.
150+
151+
:type event: :class:`prompt_toolkit.Event`
152+
:param event: Contains info about the event, namely the cli
153+
which is used to changing which buffer is focused.
154+
155+
"""
156+
if event.cli.current_buffer_name == u'clidocs':
157+
event.cli.focus(u'DEFAULT_BUFFER')
158+
else:
159+
event.cli.focus(u'clidocs')
160+
148161
@self.manager.registry.add_binding(Keys.F10)
149162
def handle_f10(event):
150163
"""Quit when the `F10` key is pressed.

awsshell/toolbar.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ def _create_toolbar_handler(self, get_match_fuzzy, get_enable_vi_bindings,
5454
assert callable(get_show_completion_columns)
5555
assert callable(get_show_help)
5656

57-
def get_toolbar_items(_):
57+
def get_toolbar_items(cli):
5858
"""Return the toolbar items.
5959
60-
:type _: :class:`prompt_toolkit.Cli`
61-
:param _: (Unused)
60+
:type cli: :class:`prompt_toolkit.Cli`
61+
:param cli: The command line interface from prompt_toolkit
6262
6363
:rtype: list
6464
:return: A list of (pygments.Token.Toolbar, str).
@@ -87,6 +87,10 @@ def get_toolbar_items(_):
8787
else:
8888
show_help_token = Token.Toolbar.Off
8989
show_help_cfg = 'OFF'
90+
if cli.current_buffer_name == 'DEFAULT_BUFFER':
91+
show_buffer_name = 'cli'
92+
else:
93+
show_buffer_name = 'doc'
9094
return [
9195
(match_fuzzy_token,
9296
' [F2] Fuzzy: {0} '.format(match_fuzzy_cfg)),
@@ -96,6 +100,8 @@ def get_toolbar_items(_):
96100
' [F4] {0} Column '.format(show_columns_cfg)),
97101
(show_help_token,
98102
' [F5] Help: {0} '.format(show_help_cfg)),
103+
(Token.Toolbar,
104+
' [F9] Focus: {0} '.format(show_buffer_name)),
99105
(Token.Toolbar,
100106
' [F10] Exit ')
101107
]

awsshell/ui.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def separator():
155155
lexer=lexer,
156156
# Enable preview_search, we want to have immediate
157157
# feedback in reverse-i-search mode.
158-
preview_search=Always()),
158+
preview_search=Always(),
159+
focus_on_click=True,
160+
),
159161
get_height=get_height,
160162
),
161163
[
@@ -179,7 +181,8 @@ def separator():
179181
ConditionalContainer(
180182
content=Window(
181183
BufferControl(
182-
buffer_name='clidocs',
184+
focus_on_click=True,
185+
buffer_name=u'clidocs',
183186
),
184187
height=LayoutDimension(max=15)),
185188
filter=HasDocumentation(app) & ~IsDone(),

tests/integration/test_keys.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,25 @@ def test_F3(self):
4646
enable_vi_bindings = self.aws_shell.enable_vi_bindings
4747
with self.assertRaises(InputInterrupt):
4848
self.feed_key(Keys.F3)
49-
assert enable_vi_bindings != self.aws_shell.enable_vi_bindings
49+
assert enable_vi_bindings != self.aws_shell.enable_vi_bindings
5050

5151
def test_F4(self):
5252
show_completion_columns = self.aws_shell.show_completion_columns
5353
with self.assertRaises(InputInterrupt):
5454
self.feed_key(Keys.F4)
55-
assert show_completion_columns != \
56-
self.aws_shell.show_completion_columns
55+
assert show_completion_columns != \
56+
self.aws_shell.show_completion_columns
5757

5858
def test_F5(self):
5959
show_help = self.aws_shell.show_help
6060
with self.assertRaises(InputInterrupt):
6161
self.feed_key(Keys.F5)
62-
assert show_help != self.aws_shell.show_help
62+
assert show_help != self.aws_shell.show_help
63+
64+
def test_F9(self):
65+
assert self.aws_shell.cli.current_buffer_name == u'DEFAULT_BUFFER'
66+
self.feed_key(Keys.F9)
67+
assert self.aws_shell.cli.current_buffer_name == u'clidocs'
6368

6469
def test_F10(self):
6570
self.feed_key(Keys.F10)

tests/unit/test_toolbar.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ToolbarTest(unittest.TestCase):
2222

2323
def setUp(self):
2424
self.aws_shell = AWSShell(mock.Mock(), mock.Mock(), mock.Mock())
25+
self.cli = mock.Mock()
2526
self.toolbar = Toolbar(
2627
lambda: self.aws_shell.model_completer.match_fuzzy,
2728
lambda: self.aws_shell.enable_vi_bindings,
@@ -38,18 +39,21 @@ def test_toolbar_on(self):
3839
(Token.Toolbar.On, ' [F3] Keys: Vi '),
3940
(Token.Toolbar.On, ' [F4] Multi Column '),
4041
(Token.Toolbar.On, ' [F5] Help: ON '),
42+
(Token.Toolbar, ' [F9] Focus: doc '),
4143
(Token.Toolbar, ' [F10] Exit ')]
42-
assert expected == self.toolbar.handler(None)
44+
assert expected == self.toolbar.handler(self.cli)
4345

4446
def test_toolbar_off(self):
4547
self.aws_shell.model_completer.match_fuzzy = False
4648
self.aws_shell.enable_vi_bindings = False
4749
self.aws_shell.show_completion_columns = False
4850
self.aws_shell.show_help = False
51+
self.cli.current_buffer_name = 'DEFAULT_BUFFER'
4952
expected = [
5053
(Token.Toolbar.Off, ' [F2] Fuzzy: OFF '),
5154
(Token.Toolbar.On, ' [F3] Keys: Emacs '),
5255
(Token.Toolbar.On, ' [F4] Single Column '),
5356
(Token.Toolbar.Off, ' [F5] Help: OFF '),
57+
(Token.Toolbar, ' [F9] Focus: cli '),
5458
(Token.Toolbar, ' [F10] Exit ')]
55-
assert expected == self.toolbar.handler(None)
59+
assert expected == self.toolbar.handler(self.cli)

0 commit comments

Comments
 (0)