diff options
author | Jonas Jelten <jj@sft.mx> | 2019-11-25 22:38:11 +0100 |
---|---|---|
committer | Jonas Jelten <jj@sft.mx> | 2019-11-25 22:51:15 +0100 |
commit | 36605174a4b1aa45fd46788e6cb61c970185b9ea (patch) | |
tree | 1c329e307150a664a1ff3f5fc6ddb5c02bfd0ea8 | |
parent | 0f969aba0cbf9b1a93c679a442e74e13f00a1702 (diff) |
support ansi escape sequences for prompt colors
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | changelog.rst | 1 | ||||
-rw-r--r-- | pgcli/main.py | 4 | ||||
-rw-r--r-- | pgcli/pgclirc | 1 |
4 files changed, 6 insertions, 1 deletions
@@ -101,6 +101,7 @@ Contributors: * Sebastian Janko (sebojanko) * Pedro Ferrari (petobens) * Martin Matejek (mmtj) + * Jonas Jelten Creator: -------- diff --git a/changelog.rst b/changelog.rst index 69d98b1c..0c48ece9 100644 --- a/changelog.rst +++ b/changelog.rst @@ -4,6 +4,7 @@ Upcoming: Features: --------- +* Add support for ANSI escape sequences for coloring the prompt (#1123). * Add `\\G` as a terminator to sql statements that will show the results in expanded mode. This feature is copied from mycli. (Thanks: `Amjith Ramanujam`_) * Removed limit prompt and added automatic row limit on queries with no LIMIT clause (#1079) (Thanks: `Sebastian Janko`_) * Function argument completions now take account of table aliases (#1048). (Thanks: `Owen Stephens`_) diff --git a/pgcli/main.py b/pgcli/main.py index 0d9fcce5..2301d16f 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -36,6 +36,7 @@ from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode from prompt_toolkit.shortcuts import PromptSession, CompleteStyle from prompt_toolkit.document import Document from prompt_toolkit.filters import HasFocus, IsDone +from prompt_toolkit.formatted_text import ANSI from prompt_toolkit.lexers import PygmentsLexer from prompt_toolkit.layout.processors import ( ConditionalProcessor, @@ -776,7 +777,8 @@ class PGCli(object): ): prompt = self.get_prompt("\\d> ") - return [("class:prompt", prompt)] + prompt = prompt.replace("\\x1b", "\x1b") + return ANSI(prompt) def get_continuation(width, line_number, is_soft_wrap): continuation = self.multiline_continuation_char * (width - 1) + " " diff --git a/pgcli/pgclirc b/pgcli/pgclirc index 29b1b4c5..13380280 100644 --- a/pgcli/pgclirc +++ b/pgcli/pgclirc @@ -126,6 +126,7 @@ less_chatty = False # \# - "@" sign if logged in as superuser, '>' in other case # \n - Newline # \dsn_alias - name of dsn alias if -D option is used (empty otherwise) +# \x1b[...m - insert ANSI escape sequence prompt = '\u@\h:\d> ' # Number of lines to reserve for the suggestion menu |