Skip to content

Commit f485dc3

Browse files
committed
support ANSI escape sequences in the prompt
1 parent d928c03 commit f485dc3

File tree

4 files changed

+6
-1
lines changed

4 files changed

+6
-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

1011
Bug Fixes:
1112
----------

mycli/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Contributors:
7878
* bitkeen
7979
* Morgan Mitchell
8080
* Massimiliano Torromeo
81+
* Roland Walker
8182

8283
Creator:
8384
--------

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
@@ -548,7 +549,8 @@ def get_message():
548549
prompt = self.get_prompt(self.prompt_format)
549550
if self.prompt_format == self.default_prompt and len(prompt) > self.max_len_prompt:
550551
prompt = self.get_prompt('\\d> ')
551-
return [('class:prompt', prompt)]
552+
prompt = prompt.replace("\\x1b", "\x1b")
553+
return ANSI(prompt)
552554

553555
def get_continuation(width, *_):
554556
if self.multiline_continuation_char:

mycli/myclirc

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

0 commit comments

Comments
 (0)