fully implement --no-pretty

This commit is contained in:
Paul Gauthier 2023-05-08 08:29:14 -07:00
parent 862b3c5cc1
commit e1fd8b0edc

View file

@ -42,7 +42,7 @@ class Coder:
fnames = dict() fnames = dict()
last_modified = 0 last_modified = 0
def __init__(self, use_gpt_4, files, colorize): def __init__(self, use_gpt_4, files, pretty):
if use_gpt_4: if use_gpt_4:
self.main_model = "gpt-4" self.main_model = "gpt-4"
else: else:
@ -53,8 +53,12 @@ class Coder:
self.check_for_local_edits(True) self.check_for_local_edits(True)
self.console = Console() self.pretty = pretty
self.colorize = colorize
if pretty:
self.console = Console()
else:
self.console = Console(force_terminal=True, no_color=True)
def files_modified(self): def files_modified(self):
for fname, mtime in self.fnames.items(): for fname, mtime in self.fnames.items():
@ -79,10 +83,18 @@ class Coder:
return prompt return prompt
def get_input(self): def get_input(self):
self.console.rule() if self.pretty:
self.console.rule()
else:
print()
inp = "" inp = ""
num_control_c = 0 num_control_c = 0
print(Fore.GREEN, end="\r") if self.pretty:
print(Fore.GREEN, end="\r")
else:
print()
while not inp.strip(): while not inp.strip():
try: try:
inp = input("> ") inp = input("> ")
@ -96,7 +108,10 @@ class Coder:
self.console.print("[bold red]^C again to quit") self.console.print("[bold red]^C again to quit")
### ###
print(Style.RESET_ALL) if self.pretty:
print(Style.RESET_ALL)
else:
print()
readline.write_history_file(history_file) readline.write_history_file(history_file)
return inp return inp
@ -216,7 +231,7 @@ class Coder:
if show_progress: if show_progress:
return self.show_send_progress(completion, show_progress) return self.show_send_progress(completion, show_progress)
elif self.colorize: elif self.pretty:
return self.show_send_output_color(completion) return self.show_send_output_color(completion)
else: else:
return self.show_send_output_plain(completion) return self.show_send_output_plain(completion)
@ -385,20 +400,20 @@ def main():
help="Only use gpt-3.5-turbo, not gpt-4", help="Only use gpt-3.5-turbo, not gpt-4",
) )
parser.add_argument( parser.add_argument(
"--no-color", "--no-pretty",
action="store_false", action="store_false",
dest="colorize", dest="pretty",
default=True, default=True,
help="Disable colorized output of GPT responses", help="Disable prettyd output of GPT responses",
) )
args = parser.parse_args() args = parser.parse_args()
use_gpt_4 = not args.gpt_3_5_turbo use_gpt_4 = not args.gpt_3_5_turbo
fnames = args.files fnames = args.files
colorize = args.colorize pretty = args.pretty
coder = Coder(use_gpt_4, fnames, colorize) coder = Coder(use_gpt_4, fnames, pretty)
coder.run() coder.run()