diff --git a/euclid/helpers/cli.py b/euclid/helpers/cli.py index 40ad602..5907486 100644 --- a/euclid/helpers/cli.py +++ b/euclid/helpers/cli.py @@ -13,8 +13,12 @@ from const.function_calls import DEBUG_STEPS_BREAKDOWN from utils.questionary import styled_text from const.code_execution import MAX_COMMAND_DEBUG_TRIES, MIN_COMMAND_RUN_TIME, MAX_COMMAND_RUN_TIME +interrupted = False + def enqueue_output(out, q): for line in iter(out.readline, ''): + if interrupted: # Check if the flag is set + break q.put(line) out.close() @@ -68,6 +72,7 @@ def execute_command(project, command, timeout=None, force=False): process = run_command(command, project.root_path, q, q_stderr, pid_container) output = '' start_time = time.time() + interrupted = False try: while True and return_value is None: @@ -99,6 +104,7 @@ def execute_command(project, command, timeout=None, force=False): output += line print(colored('CLI OUTPUT:', 'green') + line, end='') except (KeyboardInterrupt, TimeoutError) as e: + interrupted = True if isinstance(e, KeyboardInterrupt): print("\nCTRL+C detected. Stopping command execution...") else: diff --git a/euclid/utils/questionary.py b/euclid/utils/questionary.py index c60eeaf..d81f279 100644 --- a/euclid/utils/questionary.py +++ b/euclid/utils/questionary.py @@ -15,7 +15,7 @@ custom_style = Style.from_dict({ def styled_select(*args, **kwargs): kwargs["style"] = custom_style # Set style here - return questionary.select(*args, **kwargs).ask() # .ask() is included here + return questionary.select(*args, **kwargs).unsafe_ask() # .ask() is included here def styled_text(project, question): @@ -31,6 +31,6 @@ def styled_text(project, question): config = { 'style': custom_style, } - response = questionary.text(question, **config).ask() # .ask() is included here + response = questionary.text(question, **config).unsafe_ask() # .ask() is included here user_input = save_user_input(project, question, response) return response