This commit is contained in:
LeonOstrez
2023-09-29 22:37:35 +01:00
parent 4c1fe834a8
commit f5feb6274d
5 changed files with 17 additions and 18 deletions

View File

@@ -4,17 +4,14 @@ import signal
import threading import threading
import queue import queue
import time import time
import uuid
import platform 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 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.TooDeepRecursionError import TooDeepRecursionError
from helpers.exceptions.TokenLimitError import TokenLimitError from helpers.exceptions.TokenLimitError import TokenLimitError
from prompts.prompts import ask_user from prompts.prompts import ask_user
from utils.questionary import styled_text from const.code_execution import MIN_COMMAND_RUN_TIME, MAX_COMMAND_RUN_TIME, MAX_COMMAND_OUTPUT_LENGTH
from const.code_execution import MAX_COMMAND_DEBUG_TRIES, MIN_COMMAND_RUN_TIME, MAX_COMMAND_RUN_TIME, MAX_COMMAND_OUTPUT_LENGTH
interrupted = False interrupted = False
@@ -108,6 +105,7 @@ def execute_command(project, command, timeout=None, force=False):
answer = ask_user( answer = ask_user(
project, project,
f'Can I execute the command: `' + yellow_bold(command) + f'` with {timeout}ms timeout?', f'Can I execute the command: `' + yellow_bold(command) + f'` with {timeout}ms timeout?',
False,
hint='If yes, just press ENTER' hint='If yes, just press ENTER'
) )

View File

@@ -1,17 +1,14 @@
# main.py # main.py
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import builtins import builtins
import json
import os import os
import sys import sys
import traceback import traceback
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()
from termcolor import colored
from helpers.ipc import IPCClient from helpers.ipc import IPCClient
from const.ipc import MESSAGE_TYPE from const.ipc import MESSAGE_TYPE
from utils.utils import json_serial
from utils.style import red from utils.style import red
from helpers.Project import Project from helpers.Project import Project

View File

@@ -4,8 +4,8 @@ import re
import sys import sys
import uuid import uuid
from getpass import getuser from getpass import getuser
from termcolor import colored
from database.database import get_app, get_app_by_user_workspace from database.database import get_app, get_app_by_user_workspace
from utils.style import green_bold
def get_arguments(): def get_arguments():
@@ -44,18 +44,18 @@ def get_arguments():
arguments['name'] = app.name arguments['name'] = app.name
# Add any other fields from the App model you wish to include # Add any other fields from the App model you wish to include
print(colored('\n------------------ LOADING PROJECT ----------------------', 'green', attrs=['bold'])) print(green_bold('\n------------------ LOADING PROJECT ----------------------'))
print(colored(f'{app.name} (app_id={arguments["app_id"]})', 'green', attrs=['bold'])) print(green_bold(f'{app.name} (app_id={arguments["app_id"]})'))
print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold'])) print(green_bold('--------------------------------------------------------------\n'))
except ValueError as e: except ValueError as e:
print(e) print(e)
# Handle the error as needed, possibly exiting the script # Handle the error as needed, possibly exiting the script
else: else:
arguments['app_id'] = str(uuid.uuid4()) 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("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(green_bold(f'python {sys.argv[0]} app_id={arguments["app_id"]}'))
print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold'])) print(green_bold('--------------------------------------------------------------\n'))
if 'email' not in arguments: if 'email' not in arguments:
arguments['email'] = get_email() arguments['email'] = get_email()

View File

@@ -1,9 +1,8 @@
from prompt_toolkit.styles import Style from prompt_toolkit.styles import Style
import questionary import questionary
from utils.style import yellow_bold from utils.style import yellow_bold
import re
from database.database import save_user_input, get_saved_user_input from database.database import save_user_input, get_saved_user_input
from const.ipc import MESSAGE_TYPE
custom_style = Style.from_dict({ custom_style = Style.from_dict({
'question': '#FFFFFF bold', # the color and style of the question '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): def styled_select(*args, **kwargs):
kwargs["style"] = custom_style # Set style here kwargs["style"] = custom_style # Set style here
return questionary.select(*args, **kwargs).unsafe_ask() # .ask() is included 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 = { config = {
'style': custom_style, '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 response = questionary.text(question, **config).unsafe_ask() # .ask() is included here
else: else:
response = print(question, type='user_input_request') response = print(question, type='user_input_request')

View File

@@ -1,4 +1,3 @@
from termcolor import colored
from colorama import Fore, Style from colorama import Fore, Style
def red(text): def red(text):