Skip to content

Commit 11ccd3f

Browse files
committed
Enhance colored command prompt
1 parent 91ec5a0 commit 11ccd3f

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/pytgpt/console.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,22 +374,35 @@ def __init__(
374374
@property
375375
def prompt(self):
376376
current_time = datetime.datetime.now().strftime("%H:%M:%S")
377-
find_range = lambda start, end: round(end - start, 1)
378377

379-
if not self.disable_coloring:
378+
def find_range(start, end, hms: bool = False):
379+
in_seconds = round(end - start, 1)
380380
return (
381-
f"{Fore.LIGHTGREEN_EX}╭─[{Fore.CYAN}{getpass.getuser().capitalize()}@pyTGPT]{Fore.MAGENTA}({self.provider})"
382-
f"{Fore.BLUE}~[{current_time}-"
383-
f"{Fore.RED}T'{find_range(self.__init_time, time.time())}s,"
384-
f"{Fore.YELLOW}L'{find_range(self.__start_time, self.__end_time)}s]"
385-
f"\n╰─>{Fore.RESET}"
381+
str(datetime.timedelta(seconds=in_seconds)).split(".")[0].zfill(8)
382+
if hms
383+
else in_seconds
386384
)
385+
386+
if not self.disable_coloring:
387+
cmd_prompt = (
388+
f"╭─[`{Fore.CYAN}{getpass.getuser().capitalize()}@pyTGPT]`"
389+
f"(`{Fore.MAGENTA}{self.provider})`"
390+
f"~[`{Fore.LIGHTWHITE_EX}🕒{Fore.BLUE}{current_time}-`"
391+
f"{Fore.LIGHTWHITE_EX}💻{Fore.RED}{find_range(self.__init_time, time.time(), True)}-`"
392+
f"{Fore.LIGHTWHITE_EX}{Fore.YELLOW}{find_range(self.__start_time, self.__end_time)}s]`"
393+
f"\n╰─>"
394+
)
395+
whitelist = ["[", "]", "~", "-", "(", ")"]
396+
for character in whitelist:
397+
cmd_prompt = cmd_prompt.replace(character + "`", Fore.RESET + character)
398+
return cmd_prompt
399+
387400
else:
388401
return (
389402
f"╭─[{getpass.getuser().capitalize()}@pyTGPT]({self.provider})"
390-
f"~[{current_time}-"
391-
f"T'{find_range(self.__init_time, time.time())}s,"
392-
f"L'{find_range(self.__start_time, self.__end_time)}s]"
403+
f"~[🕒{current_time}"
404+
f"-💻{find_range(self.__init_time, time.time(), True)}"
405+
f"-⚡{find_range(self.__start_time, self.__end_time)}s]"
393406
"\n╰─>"
394407
)
395408

@@ -921,7 +934,7 @@ def interactive(
921934
with_copied,
922935
no_coloring,
923936
):
924-
"""Chat with AI interactively"""
937+
"""Chat with AI interactively (Default)"""
925938
clear_history_file(filepath, new)
926939
bot = Main(
927940
max_tokens,
@@ -1153,7 +1166,7 @@ def generate(
11531166
new,
11541167
with_copied,
11551168
):
1156-
"""Generate a quick response with AI (Default)"""
1169+
"""Generate a quick response with AI"""
11571170
bot = Main(
11581171
max_tokens,
11591172
temperature,

0 commit comments

Comments
 (0)