summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2019-12-08 19:19:43 -0800
committerGitHub <noreply@github.com>2019-12-08 19:19:43 -0800
commit901812a7bf1667117668e24211a99ab7b867b98d (patch)
tree7bd29d18cefe6b8e3dcd0460544e089bf0fdb266
parent257d0f2786106c8061f5b1ca4cd130abebc6ab01 (diff)
parent36605174a4b1aa45fd46788e6cb61c970185b9ea (diff)
Merge pull request #1122 from TheJJ/prompt-colors
support ansi escape sequences for prompt colors
-rw-r--r--AUTHORS1
-rw-r--r--changelog.rst1
-rw-r--r--pgcli/main.py4
-rw-r--r--pgcli/pgclirc1
4 files changed, 6 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 14b745bc..b37ad891 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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 a8a23cb5..b97a72fb 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -4,6 +4,7 @@
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