From f5feb6274d355d53fc13a69cda7f87ed468ae60c Mon Sep 17 00:00:00 2001 From: LeonOstrez Date: Fri, 29 Sep 2023 22:37:35 +0100 Subject: [PATCH] fixes --- pilot/helpers/cli.py | 8 +++----- pilot/main.py | 3 --- pilot/utils/arguments.py | 14 +++++++------- pilot/utils/questionary.py | 9 +++++++-- pilot/utils/style.py | 1 - 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pilot/helpers/cli.py b/pilot/helpers/cli.py index caf235c..ab0f722 100644 --- a/pilot/helpers/cli.py +++ b/pilot/helpers/cli.py @@ -4,17 +4,14 @@ import signal import threading import queue import time -import uuid import platform -from utils.style import yellow, green, white, red, yellow_bold, white_bold +from utils.style import yellow, green, red, yellow_bold, white_bold from database.database import get_saved_command_run, save_command_run -from const.function_calls import DEBUG_STEPS_BREAKDOWN from helpers.exceptions.TooDeepRecursionError import TooDeepRecursionError from helpers.exceptions.TokenLimitError import TokenLimitError from prompts.prompts import ask_user -from utils.questionary import styled_text -from const.code_execution import MAX_COMMAND_DEBUG_TRIES, MIN_COMMAND_RUN_TIME, MAX_COMMAND_RUN_TIME, MAX_COMMAND_OUTPUT_LENGTH +from const.code_execution import MIN_COMMAND_RUN_TIME, MAX_COMMAND_RUN_TIME, MAX_COMMAND_OUTPUT_LENGTH interrupted = False @@ -108,6 +105,7 @@ def execute_command(project, command, timeout=None, force=False): answer = ask_user( project, f'Can I execute the command: `' + yellow_bold(command) + f'` with {timeout}ms timeout?', + False, hint='If yes, just press ENTER' ) diff --git a/pilot/main.py b/pilot/main.py index 8f46e15..0fb7ceb 100644 --- a/pilot/main.py +++ b/pilot/main.py @@ -1,17 +1,14 @@ # main.py from __future__ import print_function, unicode_literals import builtins -import json import os import sys import traceback from dotenv import load_dotenv load_dotenv() -from termcolor import colored from helpers.ipc import IPCClient from const.ipc import MESSAGE_TYPE -from utils.utils import json_serial from utils.style import red from helpers.Project import Project diff --git a/pilot/utils/arguments.py b/pilot/utils/arguments.py index e4409eb..27d8614 100644 --- a/pilot/utils/arguments.py +++ b/pilot/utils/arguments.py @@ -4,8 +4,8 @@ import re import sys import uuid from getpass import getuser -from termcolor import colored from database.database import get_app, get_app_by_user_workspace +from utils.style import green_bold def get_arguments(): @@ -44,18 +44,18 @@ def get_arguments(): arguments['name'] = app.name # Add any other fields from the App model you wish to include - print(colored('\n------------------ LOADING PROJECT ----------------------', 'green', attrs=['bold'])) - print(colored(f'{app.name} (app_id={arguments["app_id"]})', 'green', attrs=['bold'])) - print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold'])) + print(green_bold('\n------------------ LOADING PROJECT ----------------------')) + print(green_bold(f'{app.name} (app_id={arguments["app_id"]})')) + print(green_bold('--------------------------------------------------------------\n')) except ValueError as e: print(e) # Handle the error as needed, possibly exiting the script else: arguments['app_id'] = str(uuid.uuid4()) - print(colored('\n------------------ STARTING NEW PROJECT ----------------------', 'green', attrs=['bold'])) + print(green_bold('\n------------------ STARTING NEW PROJECT ----------------------')) print("If you wish to continue with this project in future run:") - print(colored(f'python {sys.argv[0]} app_id={arguments["app_id"]}', 'green', attrs=['bold'])) - print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold'])) + print(green_bold(f'python {sys.argv[0]} app_id={arguments["app_id"]}')) + print(green_bold('--------------------------------------------------------------\n')) if 'email' not in arguments: arguments['email'] = get_email() diff --git a/pilot/utils/questionary.py b/pilot/utils/questionary.py index e678992..89eb741 100644 --- a/pilot/utils/questionary.py +++ b/pilot/utils/questionary.py @@ -1,9 +1,8 @@ from prompt_toolkit.styles import Style import questionary from utils.style import yellow_bold - +import re from database.database import save_user_input, get_saved_user_input -from const.ipc import MESSAGE_TYPE custom_style = Style.from_dict({ 'question': '#FFFFFF bold', # the color and style of the question @@ -14,6 +13,11 @@ custom_style = Style.from_dict({ }) +def remove_ansi_codes(s: str) -> str: + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + return ansi_escape.sub('', s) + + def styled_select(*args, **kwargs): kwargs["style"] = custom_style # Set style here return questionary.select(*args, **kwargs).unsafe_ask() # .ask() is included here @@ -34,6 +38,7 @@ def styled_text(project, question, ignore_user_input_count=False): config = { 'style': custom_style, } + question = remove_ansi_codes(question) # Colorama and questionary are not compatible and styling doesn't work response = questionary.text(question, **config).unsafe_ask() # .ask() is included here else: response = print(question, type='user_input_request') diff --git a/pilot/utils/style.py b/pilot/utils/style.py index c36af9b..f1ebaf5 100644 --- a/pilot/utils/style.py +++ b/pilot/utils/style.py @@ -1,4 +1,3 @@ -from termcolor import colored from colorama import Fore, Style def red(text):