Skip to content

Commit

Permalink
make the color-palette in autoprompt configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
Damans227 committed Mar 13, 2022
1 parent 2a9e152 commit 0d70831
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion awscli/autoprompt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ class AutoPrompter:
def __init__(self, completion_source, driver, prompter=None):
self._completion_source = completion_source
self._driver = driver
self._session = driver.session
if prompter is None:
prompter = PromptToolkitPrompter(self._completion_source,
self._driver)
self._driver,self._session)
self._prompter = prompter

def prompt_for_values(self, original_args):
Expand Down
21 changes: 13 additions & 8 deletions awscli/autoprompt/prompttoolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PromptToolkitPrompter:
"""

def __init__(self, completion_source, driver, completer=None,
def __init__(self, completion_source, driver, session, completer=None,
factory=None, app=None, cli_parser=None, output=None,
app_input=None):
self._completion_source = completion_source
Expand All @@ -80,14 +80,15 @@ def __init__(self, completion_source, driver, completer=None,
self.input_buffer = None
self.doc_buffer = None
self.output_buffer = None
if app is None:
app = self.create_application()
self.app = app
self._args = []
self._driver = driver
self._docs_getter = DocsGetter(self._driver)
self._output_getter = OutputGetter(self._driver)

self._session=session
if app is None:
app = self.create_application()
self.app = app

def args(self, value):
self._args = value

Expand All @@ -109,8 +110,12 @@ def _create_containers(self):
return input_buffer_container, doc_window, output_window

def create_application(self):
_colorDepth = {"black_and_white": ColorDepth.MONOCHROME, "ansi_colors": ColorDepth.ANSI_COLORS_ONLY,"256_colors": ColorDepth.DEFAULT, "true_colors": ColorDepth.TRUE_COLOR}

# There are four different levels of color depths available in python-prompt-toolkit,
# which can be used to configure different color schemes in aws cli. You can read more
# about it in the documentation linked below:
# https://python-prompt-toolkit.readthedocs.io/en/master/pages/advanced_topics/styling.html?highlight=classes#color-depths
cliColorPalette = {"black_and_white": ColorDepth.MONOCHROME, "ansi_colors": ColorDepth.ANSI_COLORS_ONLY,"256_colors": ColorDepth.DEFAULT, "true_colors": ColorDepth.TRUE_COLOR}
cliColorDepth = self._session.get_config_variable('color_palette')
self._create_buffers()
input_buffer_container, \
doc_window, output_window = self._create_containers()
Expand All @@ -123,7 +128,7 @@ def create_application(self):
kb = kb_manager.keybindings
app = Application(layout=layout, key_bindings=kb, full_screen=False,
output=self._output, erase_when_done=True,
input=self._input, color_depth=_colorDepth["true_colors"])
input=self._input, color_depth=cliColorPalette[cliColorDepth])
self._set_app_defaults(app)
return app

Expand Down

0 comments on commit 0d70831

Please sign in to comment.