Skip to content

Commit 461344b

Browse files
authored
Merge pull request #1709 from dbcli/RW/literal-backslash-prompt-escape
Prompt format string for literal backslash
2 parents 76222c7 + 79faa8f commit 461344b

4 files changed

Lines changed: 13 additions & 0 deletions

File tree

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Upcoming (TBD)
2+
==============
3+
4+
Features
5+
---------
6+
* Add prompt format string for literal backslash.
7+
8+
19
1.64.0 (2026/03/13)
210
==============
311

mycli/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,8 @@ def get_prompt(self, string: str, _render_counter: int) -> str:
17021702
if re.match(r'^[\d\.]+$', short_prompt_host):
17031703
short_prompt_host = prompt_host
17041704
now = datetime.now()
1705+
backslash_placeholder = '\ufffc_backslash'
1706+
string = string.replace('\\\\', backslash_placeholder)
17051707
string = string.replace("\\u", sqlexecute.user or "(none)")
17061708
string = string.replace("\\h", prompt_host or "(none)")
17071709
string = string.replace("\\H", short_prompt_host or "(none)")
@@ -1721,6 +1723,7 @@ def get_prompt(self, string: str, _render_counter: int) -> str:
17211723
string = string.replace("\\K", sqlexecute.socket or str(sqlexecute.port))
17221724
string = string.replace("\\A", self.dsn_alias or "(none)")
17231725
string = string.replace("\\_", " ")
1726+
string = string.replace(backslash_placeholder, '\\')
17241727

17251728
# jump through hoops for the test environment, and for efficiency
17261729
if hasattr(sqlexecute, 'conn') and sqlexecute.conn is not None:

mycli/myclirc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ wider_completion_menu = False
124124
# * \A - DSN alias
125125
# * \n - a newline
126126
# * \_ - a space
127+
# * \\ - a literal backslash
127128
# * \x1b[...m - an ANSI escape sequence (can style with color)
128129
prompt = '\t \u@\h:\d> '
129130
prompt_continuation = '->'

test/myclirc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ wider_completion_menu = False
122122
# * \A - DSN alias
123123
# * \n - a newline
124124
# * \_ - a space
125+
# * \\ - a literal backslash
125126
# * \x1b[...m - an ANSI escape sequence (can style with color)
126127
prompt = "\t \u@\h:\d> "
127128
prompt_continuation = ->

0 commit comments

Comments
 (0)