Skip to content

Commit 1d2e437

Browse files
committed
- Colorized intro prompt. interactive
1 parent f0c972a commit 1d2e437

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
lines changed

docs/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,12 @@
150150
**What's new?**
151151

152152
- Busy bar disabled when `--quiet` issued in *generate* mode. #12 Thanks to @johnd0e
153-
- `interactive` takes action on `$ pytgpt` otherwise one has to explictly declare the action. #11
153+
- `interactive` takes action on `$ pytgpt` otherwise one has to explictly declare the action. #11
154+
155+
## v0.2.8
156+
157+
**What's new?**
158+
159+
- Auto-quiet on output redirection. Thanks to @johnd0e
160+
- Dropped support for output redirection. #12
161+
- Colorized command prompt. <kbd>interactive</kbd>

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<a href="https://github.com/Simatwa/python-tgpt/actions/workflows/python-test.yml"><img src="https://github.com/Simatwa/python-tgpt/actions/workflows/python-test.yml/badge.svg" alt="Python Test"/></a>
99
-->
1010
<a href="https://github.com/Simatwa/python-tgpt/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/static/v1?logo=GPL&color=Blue&message=MIT&label=License"/></a>
11-
<a href="https://pypi.org/project/python-tgpt"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=0.2.7&color=green"/></a>
11+
<a href="https://pypi.org/project/python-tgpt"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=0.2.8&color=green"/></a>
1212
<a href="https://github.com/psf/black"><img alt="Black" src="https://img.shields.io/static/v1?logo=Black&label=Code-style&message=Black"/></a>
1313
<a href="#"><img alt="Passing" src="https://img.shields.io/static/v1?logo=Docs&label=Docs&message=Passing&color=green"/></a>
1414
<a href="https://github.com/Simatwa/python-tgpt/actions/workflows/python-package.yml"><img src="https://github.com/Simatwa/python-tgpt/actions/workflows/python-package.yml/badge.svg"/></a>

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ clipman==3.1.0
55
pyperclip==1.8.2
66
appdirs==1.4.4
77
webchatgpt==0.2.6
8-
GoogleBard==1.4.0
8+
GoogleBard==1.4.0
9+
colorama==0.4.6

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setup(
1616
name="python-tgpt",
17-
version="0.2.7",
17+
version="0.2.8",
1818
license="MIT",
1919
author="Smartwa",
2020
maintainer="Smartwa",
@@ -45,6 +45,7 @@
4545
"appdirs==1.4.4",
4646
"webchatgpt==0.2.6",
4747
"GoogleBard==1.4.0",
48+
"colorama==0.4.6",
4849
],
4950
python_requires=">=3.9",
5051
keywords=[

src/pytgpt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .utils import appdir
22

3-
__version__ = "0.2.7"
3+
__version__ = "0.2.8"
44
__author__ = "Smartwa"
55
__repo__ = "https://github.com/Simatwa/python-tgpt"
66

src/pytgpt/console.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import re
1313
import sys
1414
import platform
15+
import datetime
16+
import time
1517
from time import sleep
1618
from threading import Thread as thr
1719
from functools import wraps
@@ -27,6 +29,10 @@
2729
from pytgpt.utils import default_path
2830
from pytgpt.utils import AwesomePrompts
2931
from WebChatGPT.console import chat as webchatgpt
32+
from colorama import Fore
33+
from colorama import init as init_colorama
34+
35+
init_colorama(autoreset=True)
3036

3137
getExc = lambda e: e.args[1] if len(e.args) > 1 else str(e)
3238

@@ -207,7 +213,6 @@ def main(*args, **kwargs):
207213

208214
class Main(cmd.Cmd):
209215
intro = f"Welcome to AI Chat in terminal. Type 'help' or 'h' for usage info \n Submit any bug at {pytgpt.__repo__}/issues/new"
210-
prompt = f"╭─[{getpass.getuser().capitalize()}@TGPT](v{pytgpt.__version__})\n╰─>"
211216

212217
def __init__(
213218
self,
@@ -360,6 +365,33 @@ def __init__(
360365
self.quiet = quiet
361366
self.vertical_overflow = "ellipsis"
362367
self.disable_stream = False
368+
self.provider = provider
369+
self.disable_coloring = False
370+
self.__init_time = time.time()
371+
self.__start_time = time.time()
372+
self.__end_time = time.time()
373+
374+
@property
375+
def prompt(self):
376+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
377+
find_range = lambda start, end: round(end - start, 1)
378+
379+
if not self.disable_coloring:
380+
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}"
386+
)
387+
else:
388+
return (
389+
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]"
393+
"\n╰─>"
394+
)
363395

364396
def output_bond(
365397
self,
@@ -625,6 +657,7 @@ def default(self, line, exit_on_error: bool = False):
625657
if line.startswith("./"):
626658
os.system(line[2:])
627659
else:
660+
self.__start_time = time.time()
628661
try:
629662

630663
def generate_response():
@@ -677,6 +710,8 @@ def for_non_stream():
677710
logging.error(getExc(e))
678711
if exit_on_error:
679712
sys.exit(1)
713+
finally:
714+
self.__end_time = time.time()
680715

681716
def do_sys(self, line):
682717
"""Execute system commands
@@ -854,6 +889,9 @@ def tgpt2_():
854889
is_flag=True,
855890
help="Postfix prompt with last copied text",
856891
)
892+
@click.option(
893+
"-nc", "--no-coloring", is_flag=True, help="Disable intro prompt font-coloring"
894+
)
857895
@click.help_option("-h", "--help")
858896
def interactive(
859897
model,
@@ -881,6 +919,7 @@ def interactive(
881919
quiet,
882920
new,
883921
with_copied,
922+
no_coloring,
884923
):
885924
"""Chat with AI interactively"""
886925
clear_history_file(filepath, new)
@@ -905,6 +944,7 @@ def interactive(
905944
busy_bar.spin_index = busy_bar_index
906945
bot.code_theme = code_theme
907946
bot.color = font_color
947+
bot.disable_coloring = no_coloring
908948
bot.prettify = prettify
909949
bot.vertical_overflow = vertical_overflow
910950
bot.disable_stream = whole

0 commit comments

Comments
 (0)