Skip to content

Commit

Permalink
Merge pull request #923 from rolandwalker/prompt-ansi-escape-sequences
Browse files Browse the repository at this point in the history
Support ANSI escape sequences in the prompt
  • Loading branch information
amjith authored Jan 2, 2021
2 parents e593aa8 + 4cde6a8 commit 4517f49
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Features:

* Add an option `--init-command` to execute SQL after connecting (Thanks: [KITAGAWA Yasutaka]).
* Use InputMode.REPLACE_SINGLE
* Add support for ANSI escape sequences for coloring the prompt.
* Allow customization of Pygments SQL syntax-highlighting styles.
* Add a `\clip` special command to copy queries to the system clipboard.
* Add a special command `\pipe_once` to pipe output to a subprocess.
Expand Down
4 changes: 3 additions & 1 deletion mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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.layout.processors import (HighlightMatchingBracketProcessor,
ConditionalProcessor)
from prompt_toolkit.lexers import PygmentsLexer
Expand Down Expand Up @@ -566,7 +567,8 @@ def get_message():
prompt = self.get_prompt(self.prompt_format)
if self.prompt_format == self.default_prompt and len(prompt) > self.max_len_prompt:
prompt = self.get_prompt('\\d> ')
return [('class:prompt', prompt)]
prompt = prompt.replace("\\x1b", "\x1b")
return ANSI(prompt)

def get_continuation(width, *_):
if self.multiline_continuation_char == '':
Expand Down
1 change: 1 addition & 0 deletions mycli/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ wider_completion_menu = False
# \t - Product type (Percona, MySQL, MariaDB)
# \A - DSN alias name (from the [alias_dsn] section)
# \u - Username
# \x1b[...m - insert ANSI escape sequence
prompt = '\t \u@\h:\d> '
prompt_continuation = '->'

Expand Down

0 comments on commit 4517f49

Please sign in to comment.