From 19cfd6fbe93f8fa8dd85acce7eb1f38184469cb9 Mon Sep 17 00:00:00 2001 From: Jerry Yang Date: Thu, 30 Mar 2023 00:40:04 +0800 Subject: [PATCH 1/2] feat: improve user input handling by detecting command text This commit improves the user input handling by detecting the command text at the `user_input` function. Previously, the input process did not differentiate between command and regular text, requiring the user to press Enter twice to signal the end of input for both cases. With this update, the command text can be directly parsed and executed with the first Enter key press. --- src/utils/io.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/io.py b/src/utils/io.py index e6112da..f2c961f 100644 --- a/src/utils/io.py +++ b/src/utils/io.py @@ -114,10 +114,12 @@ def user_input(prompt="\nUser: ") -> str: # Use readline to handle user input lines = [] while True: - line = input(prompt) - if line.strip() == "": + line = input(prompt).strip() + if line == "": break lines.append(line) + if lines[0].startswith("!"): + break # Update the prompt using readline prompt = "\r" + " " * len(prompt) + "\r" + " .... " readline.get_line_buffer() From ea73eab88349e33707b32e98826ebef5d8fbf990 Mon Sep 17 00:00:00 2001 From: Jerry Yang Date: Sat, 1 Apr 2023 14:40:08 +0800 Subject: [PATCH 2/2] chore: empty input handling in editor mode --- src/utils/cmd.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/cmd.py b/src/utils/cmd.py index b656673..740d839 100644 --- a/src/utils/cmd.py +++ b/src/utils/cmd.py @@ -55,6 +55,8 @@ def post_command_process(user_message): if user_message.startswith("!e ") or user_message.startswith("!editor "): user_message = pattern.sub("", user_message) user_output(user_message) + if not user_message: + printmd("**[Empty Input Skipped]**") else: user_message = pattern.sub("", user_message) return user_message