diff --git a/changelogs/fragments/console_color.yml b/changelogs/fragments/console_color.yml new file mode 100644 index 00000000000..ec78dcc53bf --- /dev/null +++ b/changelogs/fragments/console_color.yml @@ -0,0 +1,2 @@ +minor_changes: + - allow user to customize default ansible-console prompt/msg default color diff --git a/lib/ansible/cli/console.py b/lib/ansible/cli/console.py index c7eb4e8af6f..f2349fc6b59 100644 --- a/lib/ansible/cli/console.py +++ b/lib/ansible/cli/console.py @@ -38,7 +38,6 @@ import sys from ansible import constants as C from ansible.cli import CLI -from ansible.errors import AnsibleError from ansible.executor.task_queue_manager import TaskQueueManager from ansible.module_utils._text import to_native, to_text from ansible.module_utils.parsing.convert_bool import boolean @@ -62,6 +61,9 @@ class ConsoleCLI(CLI, cmd.Cmd): ARGUMENTS = {'host-pattern': 'A name of a group in the inventory, a shell-like glob ' 'selecting hosts in inventory or any combination of the two separated by commas.'} + # use specific to console, but fallback to highlight for backwards compatibility + NORMAL_PROMPT = C.COLOR_CONSOLE_PROMPT or C.COLOR_HIGHLIGHT + def __init__(self, args): super(ConsoleCLI, self).__init__(args) @@ -122,7 +124,7 @@ class ConsoleCLI(CLI, cmd.Cmd): color = C.COLOR_ERROR else: prompt += "$ " - color = C.COLOR_HIGHLIGHT + color = self.NORMAL_PROMPT self.prompt = stringc(prompt, color) def list_modules(self): @@ -361,7 +363,7 @@ class ConsoleCLI(CLI, cmd.Cmd): display.display(oc['short_description']) display.display('Parameters:') for opt in oc['options'].keys(): - display.display(' ' + stringc(opt, C.COLOR_HIGHLIGHT) + ' ' + oc['options'][opt]['description'][0]) + display.display(' ' + stringc(opt, self.NORMAL_PROMPT) + ' ' + oc['options'][opt]['description'][0]) else: display.error('No documentation found for %s.' % module_name) else: diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 1e9ed2e322d..d353993b447 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -211,6 +211,14 @@ COLOR_CHANGED: ini: - {key: changed, section: colors} yaml: {key: display.colors.changed} +COLOR_CONSOLE_PROMPT: + name: "Color for ansible-console's prompt task status" + default: white + description: Defines the default color to use for ansible-console + env: [{name: ANSIBLE_COLOR_CONSOLE_PROMPT}] + ini: + - {key: console_prompt, section: colors} + version_added: "2.7" COLOR_DEBUG: name: Color for debug statements default: dark gray