1919from rich .markdown import Markdown
2020from rich .console import Console
2121from rich .live import Live
22+ from rich .table import Table
2223from rich .prompt import Prompt
2324from typing import Iterator
2425from pytgpt .utils import Optimizers
@@ -185,7 +186,7 @@ def main(*args, **kwargs):
185186
186187
187188class Main (cmd .Cmd ):
188- intro = f"Welcome to AI Chat in terminal. Type 'help' or '? ' for usage info \n Submit any bug at { pytgpt .__repo__ } /issues/new"
189+ intro = f"Welcome to AI Chat in terminal. Type 'help' or 'h ' for usage info \n Submit any bug at { pytgpt .__repo__ } /issues/new"
189190 prompt = f"╭─[{ getpass .getuser ().capitalize ()} @TGPT](v{ pytgpt .__version__ } )\n ╰─>"
190191
191192 def __init__ (
@@ -368,11 +369,52 @@ def output_bond(
368369 json .dump (text , fh , indent = 4 )
369370 click .secho (f"Successfuly saved to `{ save_to } `" , fg = "green" )
370371
372+ def do_h (self , line ):
373+ """Show help info in tabular form"""
374+ table = Table (
375+ title = "Help info" ,
376+ show_lines = True ,
377+ )
378+ table .add_column ("No." , style = "white" , justify = "center" )
379+ table .add_column ("Command" , style = "yellow" , justify = "left" )
380+ table .add_column ("Function" , style = "cyan" )
381+ command_methods = [
382+ getattr (self , method )
383+ for method in dir (self )
384+ if callable (getattr (self , method )) and method .startswith ("do_" )
385+ ]
386+ command_methods .append (self .default )
387+ command_methods .reverse ()
388+ for no , method in enumerate (command_methods ):
389+ table .add_row (
390+ str (no + 1 ),
391+ method .__name__ [3 :] if not method == self .default else method .__name__ ,
392+ method .__doc__ ,
393+ )
394+ Console ().print (table )
395+
371396 @busy_bar .run ("Settings saved" )
372397 def do_settings (self , line ):
373398 """Configre settings"""
399+ self .prettify = click .confirm (
400+ "\n Prettify markdown response" , default = self .prettify
401+ )
402+ busy_bar .spin_index = click .prompt (
403+ "Spin bar index [0:/, 1:■█■■■, 2:⣻]" ,
404+ default = busy_bar .spin_index ,
405+ type = click .IntRange (0 , 2 ),
406+ )
407+ self .color = click .prompt ("Response stdout font color" , default = self .color )
408+ self .code_theme = Prompt .ask (
409+ "Enter code_theme" , choices = rich_code_themes , default = self .code_theme
410+ )
411+ self .vertical_overflow = Prompt .ask (
412+ "\n Vertical overflow behaviour" ,
413+ choices = ["ellipsis" , "visible" , "crop" ],
414+ default = self .vertical_overflow ,
415+ )
374416 self .bot .max_tokens_to_sample = click .prompt (
375- "Maximum tokens to sample" ,
417+ "\n Maximum tokens to sample" ,
376418 type = click .INT ,
377419 default = self .bot .max_tokens_to_sample ,
378420 )
@@ -392,18 +434,6 @@ def do_settings(self, line):
392434 self .bot .model = click .prompt (
393435 "Model name" , type = click .STRING , default = self .bot .model
394436 )
395- self .code_theme = Prompt .ask (
396- "Enter code_theme" , choices = rich_code_themes , default = self .code_theme
397- )
398- self .prettify = click .confirm (
399- "\n Prettify markdown response" , default = self .prettify
400- )
401- busy_bar .spin_index = click .prompt (
402- "Spin bar index [0:/, 1:■█■■■, 2:⣻]" ,
403- default = busy_bar .spin_index ,
404- type = click .IntRange (0 , 2 ),
405- )
406- self .color = click .prompt ("Response stdout font color" , default = self .color )
407437
408438 @busy_bar .run (help = "System error" )
409439 def do_copy_this (self , line ):
0 commit comments