diff --git a/changelog.md b/changelog.md index 2b294084..6c54ef70 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/mycli/main.py b/mycli/main.py index da91c5c6..2c54db82 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -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 @@ -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 == '': diff --git a/mycli/myclirc b/mycli/myclirc index 8e861ce4..0bde2007 100644 --- a/mycli/myclirc +++ b/mycli/myclirc @@ -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 = '->'