diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-05-11 01:27:58 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-05-11 01:27:58 -0500 |
commit | 280259deb57d8c18f7655e4ecd79ba137ca0a37c (patch) | |
tree | 1945bd6613b7a7bb97e8a2f07326b5b61819aeff /src/gpt_chat_cli/color.py | |
parent | 8bc4d723f9e223b61a8d601e3bd1083f31b89322 (diff) | |
download | gpt-chat-cli-280259deb57d8c18f7655e4ecd79ba137ca0a37c.tar.xz gpt-chat-cli-280259deb57d8c18f7655e4ecd79ba137ca0a37c.zip |
Add slash command and editing with an arbitrary editor
Diffstat (limited to 'src/gpt_chat_cli/color.py')
-rw-r--r-- | src/gpt_chat_cli/color.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gpt_chat_cli/color.py b/src/gpt_chat_cli/color.py index ce1b182..9de82f1 100644 --- a/src/gpt_chat_cli/color.py +++ b/src/gpt_chat_cli/color.py @@ -90,3 +90,23 @@ def get_color_codes(no_color=False) -> ColorCode: return NoColorColorCode else: return VT100ColorCode + +def surround_ansi_escapes(prompt, start = "\x01", end = "\x02"): + ''' + Fixes issue on Linux with the readline module + See: https://github.com/python/cpython/issues/61539 + ''' + escaped = False + result = "" + + for c in prompt: + if c == "\x1b" and not escaped: + result += start + c + escaped = True + elif c.isalpha() and escaped: + result += c + end + escaped = False + else: + result += c + + return result |