Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add possibility to style the individual prompt placeholders #502

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions mssqlcli/mssql_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
format_numbers)
import humanize
import click
from prompt_toolkit import HTML
from prompt_toolkit.shortcuts import PromptSession, CompleteStyle
from prompt_toolkit.completion import DynamicCompleter, ThreadedCompleter
from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode
Expand Down Expand Up @@ -457,8 +458,7 @@ def _build_cli(self, history):
"""

def get_message():
prompt = self.get_prompt(self.prompt_format)
return [(u'class:prompt', prompt)]
return self.get_prompt(self.prompt_format)

def get_continuation(width, line_number, is_soft_wrap):
"""
Expand Down Expand Up @@ -709,13 +709,13 @@ def get_completions(self, text, cursor_position):
Document(text=text, cursor_position=cursor_position), None)

def get_prompt(self, string):
string = string.replace('\\t', self.now.strftime('%x %X'))
string = string.replace('\\u', self.mssqlcliclient_main.user_name or '(none)')
string = string.replace('\\h', self.mssqlcliclient_main.prompt_host or '(none)')
string = string.replace('\\d', self.mssqlcliclient_main.connected_database or '(none)')
string = string.replace('\\p', str(self.mssqlcliclient_main.prompt_port) or '(none)')
string = string.replace('\\t', "<prompt.datetime>%s</prompt.datetime>" % self.now.strftime('%x %X'))
string = string.replace('\\u', "<prompt.username>%s</prompt.username>" % self.mssqlcliclient_main.user_name or '(none)')
string = string.replace('\\h', "<prompt.hostname>%s</prompt.hostname>" % self.mssqlcliclient_main.prompt_host or '(none)')
string = string.replace('\\d', "<prompt.database>%s</prompt.database>" % self.mssqlcliclient_main.connected_database or '(none)')
string = string.replace('\\p', "<prompt.port>%s</prompt.port>" % str(self.mssqlcliclient_main.prompt_port) or '(none)')
string = string.replace('\\n', "\n")
return string
return HTML("<prompt.default>%s</prompt.default>" % string)

def get_last_query(self):
"""Get the last query executed or None."""
Expand Down
8 changes: 8 additions & 0 deletions mssqlcli/mssqlclirc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ arg-toolbar.text = 'nobold'
bottom-toolbar.transaction.valid = 'bg:#222222 #00ff5f bold'
bottom-toolbar.transaction.failed = 'bg:#222222 #ff005f bold'

# style classes for the prompt
# prompt.default = 'bg:#000000 #FFFFFF'
# prompt.datetime = 'bg:#000000 #FFFFFF'
# prompt.username = 'bg:#000000 #FFFFFF'
# prompt.hostname = 'bg:#000000 #FFFFFF'
# prompt.database = 'bg:#000000 #FFFFFF'
# prompt.port = 'bg:#000000 #FFFFFF'

# style classes for colored table output
output.header = "#00ff5f bold"
output.odd-row = ""
Expand Down