Skip to content

Commit 392904a

Browse files
committed
use prompt_toolkit for text coloring too
1 parent 9e7b9ba commit 392904a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

oneping/interface/prompt.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
from ..chat import Chat
44
from ..utils import sprint
55

6-
from rich import print as rprint
7-
from prompt_toolkit import prompt
6+
from prompt_toolkit import prompt, print_formatted_text, HTML
87

9-
def print_header(name, color='green'):
10-
rprint(f'[bold {color}]{name}>[/bold {color}] ', end='')
8+
def make_header(name, color='green'):
9+
return HTML(f'<{color}>{name}></{color}> ')
1110

1211
def loop(provider='local', name=None, **kwargs):
1312
# get name
@@ -20,16 +19,15 @@ def loop(provider='local', name=None, **kwargs):
2019
# main prompt loop
2120
while True:
2221
# get query
23-
print_header('user', 'red')
24-
query = prompt()
22+
query = prompt(make_header('user', 'ansigreen'))
2523

2624
# skip if empty
2725
if query.strip() == '':
2826
continue
2927

3028
# stream reply
3129
print()
32-
print_header(name, 'blue')
30+
print_formatted_text(make_header(name, 'ansired'), end='')
3331
for s in chat.stream(query):
3432
sprint(s)
3533
print('\n')

0 commit comments

Comments
 (0)