From 280259deb57d8c18f7655e4ecd79ba137ca0a37c Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Thu, 11 May 2023 01:27:58 -0500 Subject: Add slash command and editing with an arbitrary editor --- src/gpt_chat_cli/color.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/gpt_chat_cli/color.py') 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 -- cgit v1.2.3