Fixes so that the user can exit the app when CTRL+C is pressed

This commit is contained in:
Zvonimir Sabljic
2023-08-16 13:03:10 +02:00
parent 367d6d132b
commit bbadcc5f6c
2 changed files with 8 additions and 2 deletions

View File

@@ -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:

View File

@@ -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