diff --git a/changelog.md b/changelog.md index 49624208..abad33bb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,11 @@ +Upcoming (TBD) +============== + +Features +--------- +* Add prompt format string for literal backslash. + + 1.64.0 (2026/03/13) ============== diff --git a/mycli/main.py b/mycli/main.py index 5a8390ca..b8a4330e 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -1702,6 +1702,8 @@ def get_prompt(self, string: str, _render_counter: int) -> str: if re.match(r'^[\d\.]+$', short_prompt_host): short_prompt_host = prompt_host now = datetime.now() + backslash_placeholder = '\ufffc_backslash' + string = string.replace('\\\\', backslash_placeholder) string = string.replace("\\u", sqlexecute.user or "(none)") string = string.replace("\\h", prompt_host or "(none)") string = string.replace("\\H", short_prompt_host or "(none)") @@ -1721,6 +1723,7 @@ def get_prompt(self, string: str, _render_counter: int) -> str: string = string.replace("\\K", sqlexecute.socket or str(sqlexecute.port)) string = string.replace("\\A", self.dsn_alias or "(none)") string = string.replace("\\_", " ") + string = string.replace(backslash_placeholder, '\\') # jump through hoops for the test environment, and for efficiency if hasattr(sqlexecute, 'conn') and sqlexecute.conn is not None: diff --git a/mycli/myclirc b/mycli/myclirc index b06c77a6..ff44a15e 100644 --- a/mycli/myclirc +++ b/mycli/myclirc @@ -124,6 +124,7 @@ wider_completion_menu = False # * \A - DSN alias # * \n - a newline # * \_ - a space +# * \\ - a literal backslash # * \x1b[...m - an ANSI escape sequence (can style with color) prompt = '\t \u@\h:\d> ' prompt_continuation = '->' diff --git a/test/myclirc b/test/myclirc index d10b90ee..fa10eabf 100644 --- a/test/myclirc +++ b/test/myclirc @@ -122,6 +122,7 @@ wider_completion_menu = False # * \A - DSN alias # * \n - a newline # * \_ - a space +# * \\ - a literal backslash # * \x1b[...m - an ANSI escape sequence (can style with color) prompt = "\t \u@\h:\d> " prompt_continuation = ->