11import argparse
2- from colorama import Fore , Style , init
32from .llm_api import suggest_command
43from .database import update_database , DB_PATH
54import sqlite3
65import os
76
8- init (autoreset = True ) # Initialize colorama
7+ # ANSI escape codes for colors
8+ RESET = "\033 [0m"
9+ CYAN = "\033 [36m"
10+ GREEN = "\033 [32m"
11+ WHITE = "\033 [37m"
12+ BLUE = "\033 [34m"
13+ YELLOW = "\033 [33m"
14+ RED = "\033 [31m"
915
1016def view_history ():
1117 conn = sqlite3 .connect (DB_PATH )
@@ -15,16 +21,16 @@ def view_history():
1521 conn .close ()
1622
1723 if not results :
18- print (f"{ Fore . YELLOW } No history found.{ Style . RESET_ALL } " )
24+ print (f"{ YELLOW } No history found.{ RESET } " )
1925 return
2026
21- print (f"{ Fore . CYAN } Command History:{ Style . RESET_ALL } " )
27+ print (f"{ CYAN } Command History:{ RESET } " )
2228 for entry in results :
2329 user_input , command , explanation , timestamp = entry
24- print (f"{ Fore . GREEN } User Input: { user_input } { Style . RESET_ALL } " )
25- print (f"{ Fore . WHITE } Command: { command } { Style . RESET_ALL } " )
26- print (f"{ Fore . BLUE } Explanation: { explanation } { Style . RESET_ALL } " )
27- print (f"{ Fore . YELLOW } Timestamp: { timestamp } { Style . RESET_ALL } " )
30+ print (f"{ GREEN } User Input: { user_input } { RESET } " )
31+ print (f"{ WHITE } Command: { command } { RESET } " )
32+ print (f"{ BLUE } Explanation: { explanation } { RESET } " )
33+ print (f"{ YELLOW } Timestamp: { timestamp } { RESET } " )
2834 print ("-" * 40 )
2935
3036def clear_history ():
@@ -33,7 +39,7 @@ def clear_history():
3339 cursor .execute ('DELETE FROM command_suggestions' )
3440 conn .commit ()
3541 conn .close ()
36- print (f"{ Fore . GREEN } Command history cleared successfully.{ Style . RESET_ALL } " )
42+ print (f"{ GREEN } Command history cleared successfully.{ RESET } " )
3743
3844def main ():
3945 parser = argparse .ArgumentParser (description = "Auto-complete Linux commands using an LLM." )
@@ -43,9 +49,9 @@ def main():
4349 args = parser .parse_args ()
4450
4551 if args .update_db :
46- print (f"{ Fore . YELLOW } Updating database...{ Style . RESET_ALL } " )
52+ print (f"{ YELLOW } Updating database...{ RESET } " )
4753 update_database ()
48- print (f"{ Fore . GREEN } Database updated successfully.{ Style . RESET_ALL } " )
54+ print (f"{ GREEN } Database updated successfully.{ RESET } " )
4955
5056 if args .view_history :
5157 view_history ()
@@ -55,24 +61,24 @@ def main():
5561 clear_history ()
5662 return
5763
58- print (f"{ Fore . CYAN } Welcome to the Linux Command Tool. Type 'exit' to quit.{ Style . RESET_ALL } " )
64+ print (f"{ CYAN } Welcome to the Linux Command Tool. Type 'exit' to quit.{ RESET } " )
5965
6066 conversation_history = []
6167
6268 while True :
63- user_input = input (f"{ Fore . CYAN } Enter your command query: { Style . RESET_ALL } " )
69+ user_input = input (f"{ CYAN } Enter your command query: { RESET } " )
6470
6571 if user_input .lower () == 'exit' :
66- print (f"{ Fore . CYAN } Exiting the Linux Command Tool. Goodbye!{ Style . RESET_ALL } " )
72+ print (f"{ CYAN } Exiting the Linux Command Tool. Goodbye!{ RESET } " )
6773 break
6874
6975 try :
70- print (f"{ Fore . CYAN } Fetching command suggestion...{ Style . RESET_ALL } " )
76+ print (f"{ CYAN } Fetching command suggestion...{ RESET } " )
7177 suggestion = suggest_command (user_input , conversation_history )
72- print (f"{ Fore . GREEN } Suggested Command: \n { Style . RESET_ALL } " )
73- print (f"{ Fore . WHITE } { suggestion .command } { Style . RESET_ALL } \n " )
74- print (f"{ Fore . BLUE } Explanation: { suggestion .explanation } { Style . RESET_ALL } \n " )
75- print (f"{ Fore . YELLOW } Warning: This is a suggestion. Review and execute at your own risk.{ Style . RESET_ALL } " )
78+ print (f"{ GREEN } Suggested Command: \n { RESET } " )
79+ print (f"{ WHITE } { suggestion .command } { RESET } \n " )
80+ print (f"{ BLUE } Explanation: { suggestion .explanation } { RESET } \n " )
81+ print (f"{ YELLOW } Warning: This is a suggestion. Review and execute at your own risk.{ RESET } " )
7682
7783 # Update conversation history
7884 conversation_history .append ({"role" : "user" , "content" : user_input })
@@ -83,7 +89,7 @@ def main():
8389 conversation_history = conversation_history [- 16 :]
8490
8591 except ValueError as e :
86- print (f"{ Fore . RED } { e } { Style . RESET_ALL } " )
92+ print (f"{ RED } { e } { RESET } " )
8793 print ("-" * 40 ,"\n " )
8894
8995if __name__ == "__main__" :
0 commit comments