Skip to content

Commit 4517f49

Browse files
authored
Merge pull request #923 from rolandwalker/prompt-ansi-escape-sequences
Support ANSI escape sequences in the prompt
2 parents e593aa8 + 4cde6a8 commit 4517f49

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Features:
66

77
* Add an option `--init-command` to execute SQL after connecting (Thanks: [KITAGAWA Yasutaka]).
88
* Use InputMode.REPLACE_SINGLE
9+
* Add support for ANSI escape sequences for coloring the prompt.
910
* Allow customization of Pygments SQL syntax-highlighting styles.
1011
* Add a `\clip` special command to copy queries to the system clipboard.
1112
* Add a special command `\pipe_once` to pipe output to a subprocess.

mycli/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from prompt_toolkit.shortcuts import PromptSession, CompleteStyle
2929
from prompt_toolkit.document import Document
3030
from prompt_toolkit.filters import HasFocus, IsDone
31+
from prompt_toolkit.formatted_text import ANSI
3132
from prompt_toolkit.layout.processors import (HighlightMatchingBracketProcessor,
3233
ConditionalProcessor)
3334
from prompt_toolkit.lexers import PygmentsLexer
@@ -566,7 +567,8 @@ def get_message():
566567
prompt = self.get_prompt(self.prompt_format)
567568
if self.prompt_format == self.default_prompt and len(prompt) > self.max_len_prompt:
568569
prompt = self.get_prompt('\\d> ')
569-
return [('class:prompt', prompt)]
570+
prompt = prompt.replace("\\x1b", "\x1b")
571+
return ANSI(prompt)
570572

571573
def get_continuation(width, *_):
572574
if self.multiline_continuation_char == '':

mycli/myclirc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ wider_completion_menu = False
6666
# \t - Product type (Percona, MySQL, MariaDB)
6767
# \A - DSN alias name (from the [alias_dsn] section)
6868
# \u - Username
69+
# \x1b[...m - insert ANSI escape sequence
6970
prompt = '\t \u@\h:\d> '
7071
prompt_continuation = '->'
7172

0 commit comments

Comments
 (0)