Skip to content

Commit 539b73a

Browse files
committed
Added workaround for colors
1 parent 27f2f8f commit 539b73a

3 files changed

Lines changed: 38 additions & 35 deletions

File tree

.github/workflows/python-publish.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ jobs:
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip
31-
pip install colorama
32-
pip install -r requirements.txt
3331
pip install build
3432
- name: Build package
3533
run: python -m build

setup.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
from setuptools import setup, find_packages
22
from setuptools.command.install import install
33
import os
4-
import colorama
54

65
DB_PATH = os.path.expanduser('~/.snapshell/system_info.db')
76

87
class CustomInstallCommand(install):
98
def run(self):
109

10+
# ANSI escape codes for colors
11+
GREEN = '\033[92m'
12+
YELLOW = '\033[93m'
13+
RESET = '\033[0m'
14+
1115
# Prompt user for GROQ API key
12-
colorama.init(autoreset=True)
13-
print(colorama.Fore.GREEN + "Please enter your GROQ API key:")
14-
groq_api_key = input(colorama.Fore.YELLOW + "> ")
16+
print(GREEN + "Please enter your GROQ API key:" + RESET)
17+
groq_api_key = input(YELLOW + "> " + RESET)
1518

1619
# Detect the user's shell
1720
user_shell = os.environ.get('SHELL', '/bin/bash')
@@ -27,24 +30,21 @@ def run(self):
2730
# Set the GROQ API key in the user's shell config file
2831
with open(shell_config_path, "a") as shell_config:
2932
shell_config.write(f'\nexport HELPER_GROQ_API_KEY="{groq_api_key}"\n')
30-
print(colorama.Fore.GREEN + f"Added GROQ API key to {shell_config_path}")
33+
print(GREEN + f"Added GROQ API key to {shell_config_path}" + RESET)
3134

3235
# Reload shell configuration
3336
os.system(f'source {shell_config_path}')
3437
from snapshell.database import create_database, update_database
35-
print(colorama.Fore.YELLOW + f"Setting up the database... at {DB_PATH}")
38+
print(YELLOW + f"Setting up the database... at {DB_PATH}" + RESET)
3639
create_database()
3740
install.run(self)
3841
update_database()
3942

40-
print(colorama.Fore.GREEN + "Database successfully created\n")
41-
print(colorama.Fore.GREEN + "use the tool as snapshell\n")
42-
#restart the shell
43+
print(GREEN + "Database successfully created\n" + RESET)
44+
print(GREEN + "use the tool as snapshell\n" + RESET)
45+
# Restart the shell
4346
os.execvp(user_shell, [user_shell])
4447

45-
46-
47-
4848
else:
4949
print(f"Unrecognized shell: {user_shell}. Please manually add the following lines to your shell configuration file:")
5050
print(f'export HELPER_GROQ_API_KEY="{groq_api_key}"')
@@ -65,7 +65,6 @@ def run(self):
6565
'requests',
6666
'instructor',
6767
'pydantic',
68-
'colorama',
6968
'tqdm',
7069
],
7170
entry_points={

snapshell/cli.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import argparse
2-
from colorama import Fore, Style, init
32
from .llm_api import suggest_command
43
from .database import update_database, DB_PATH
54
import sqlite3
65
import 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

1016
def 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

3036
def 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

3844
def 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

8995
if __name__ == "__main__":

0 commit comments

Comments
 (0)