diff mercurial/color.py @ 52442:b3214b7d2390 stable

ui: fix escape sequences in in readline prompts (issue6930) Text that is meant to represent zero-width output in a readline prompt, such as terminal escape sequences, is supposed to be delimited by \001 ... \002: > Applications may indicate that the prompt contains characters that > take up no physical screen space when displayed by bracketing a > sequence of such characters with the special markers > RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE (declared in > readline.h `\001' and `\002', respectively). This may be used to > embed terminal-specific escape sequences in prompts. https://tiswww.cwru.edu/php/chet/readline/readline.html#index-rl_005fexpand_005fprompt When formatting a readline prompt in ui._readline, arrange to do this in the color.py labelling routines. Keeping mutable dynamically scoped state like this isn't great but threading it as a parameter through all the subroutines seems like much more trouble. (This doesn't address the missing line break -- that's a separate bug in libedit.) https://bz.mercurial-scm.org/show_bug.cgi?id=6930
author Taylor R Campbell <campbell+mercurial@mumble.net>
date Thu, 05 Dec 2024 20:46:21 +0000
parents f4733654f144
children
line wrap: on
line diff
--- a/mercurial/color.py	Thu Dec 05 13:48:22 2024 +0000
+++ b/mercurial/color.py	Thu Dec 05 20:46:21 2024 +0000
@@ -386,6 +386,9 @@
         ]
         start = b'\033[' + b';'.join(start) + b'm'
         stop = b'\033[' + pycompat.bytestr(activeeffects[b'none']) + b'm'
+        if ui._readlineprompt:
+            start = b'\001' + start + b'\001'
+            stop = b'\002' + stop + b'\002'
     return _mergeeffects(text, start, stop)
 
 
@@ -518,7 +521,8 @@
         else:
             origattr = csbi.wAttributes
             ansire = re.compile(
-                br'\033\[([^m]*)m([^\033]*)(.*)', re.MULTILINE | re.DOTALL
+                br'\001?\033\[([^m]*)m\002?([^\033]*)(.*)',
+                re.MULTILINE | re.DOTALL,
             )
 
     def win32print(ui, writefunc, text, **opts):