-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathx4md.py
More file actions
159 lines (132 loc) · 5.11 KB
/
Copy pathx4md.py
File metadata and controls
159 lines (132 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
import time
import shutil
import colorama
import subprocess
import threading
from colorama import Fore, Style, Back
x4_logo = r"""
██ ██ ██ ██
██ ██ ██ ██
███ ███████
██ ██ ██
██ ██ ██
X4 Compute
"""
colorama.init(autoreset=True)
# === X4MD Color Scheme ===
prompt_color = Fore.RED
path_color = Fore.GREEN
welcome_color = Fore.RED
error_color = Fore.LIGHTRED_EX
output_color = Fore.WHITE
background_color = Back.BLACK
extra_color = Fore.GREEN
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def show_startup():
clear_screen()
columns, rows = shutil.get_terminal_size()
current_time = time.strftime("%H:%M", time.localtime()) # Get current time
text = f"X4MD IN // {current_time}"
x = (columns - len(text)) // 2
y = rows // 2
print("\n" * (y - 1), end='')
print(" " * x, end='')
for char in text:
print(Fore.RED + char, end='', flush=True)
time.sleep(0.2) # Slow typing effect
time.sleep(2)
clear_screen()
def show_reverse_exit():
clear_screen()
columns, rows = shutil.get_terminal_size()
current_time = time.strftime("%H:%M", time.localtime()) # Get current time
text = f"X4MD OUT // {current_time}"
x = (columns - len(text)) // 2
y = rows // 2
print("\n" * (y - 1), end='')
print(" " * x, end='')
for char in text:
print(Fore.RED + char, end='', flush=True)
time.sleep(0.2) # Slow typing effect
time.sleep(2)
clear_screen()
def print_centered(text, color=Fore.RED):
lines = text.strip('\n').split('\n')
columns, rows = shutil.get_terminal_size()
vertical_padding = (rows - len(lines)) // 2
print("\n" * vertical_padding, end='') # vertical centering
for line in lines:
print(color + line.center(columns) + Style.RESET_ALL)
def run_x4_ai():
print(Fore.CYAN + "⚙️ Initializing X4 AI Interface...\n" + Style.RESET_ALL)
try:
process = subprocess.Popen(
["ollama", "run", "X4"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1
)
def read_output():
for line in iter(process.stdout.readline, ''):
if line.strip():
print(Fore.LIGHTGREEN_EX + line.strip() + Style.RESET_ALL)
# Start reading output in a background thread
output_thread = threading.Thread(target=read_output, daemon=True)
output_thread.start()
while True:
user_input = input(Fore.RED + "x4 >> " + Style.RESET_ALL)
if user_input.lower() in ["exit", "quit"]:
process.terminate()
print(Fore.YELLOW + "🛑 Exiting X4 AI Interface..." + Style.RESET_ALL)
break
process.stdin.write(user_input + "\n")
process.stdin.flush()
except FileNotFoundError:
print(Fore.RED + "[X4MD Error] Ollama not found in PATH." + Style.RESET_ALL)
def main():
show_startup()
while True:
cwd = os.getcwd()
drive, path = os.path.splitdrive(cwd)
# Format the prompt
prompt = f"{prompt_color}x4md{Style.RESET_ALL}>> {path_color}{drive}{path}{Style.RESET_ALL}\n> "
command = input(prompt)
if command.strip().lower() == "speak time":
current_time = time.strftime("%I:%M %p") # e.g., "03:45 PM"
os.system(f'powershell -c "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\'The time is {current_time}\')"')
continue
if command.strip().lower() == "speak x4":
clear_screen()
print_centered(x4_logo)
x4_intro = (
"Greetings, I am X4. "
"A next-generation terminal intelligence system, "
"carefully engineered by Brijraj Singh Bhati to assist you in tasks related to TET protocols, Quantum Codecraft & Alloy Design. "
"My neural framework is optimized for precision, speed, and adaptation. "
)
os.system(f'powershell -c "Add-Type –AssemblyName System.Speech; '
f'(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\'{x4_intro}\')"')
clear_screen()
continue
if command.strip().lower() in ["exit", "quit"]:
show_reverse_exit() # Show the reverse animation on exit
break
if command.lower() == "x4":
print(Fore.CYAN + "Launching X4 AI Interface...")
subprocess.run(["ollama", "run", "X4"])
continue
# Check if it's a drive change command
if command.strip().endswith(":"):
new_drive = command.strip().upper()
if os.path.exists(f"{new_drive}:\\"):
os.chdir(f"{new_drive}:\\")
else:
print(error_color + f"[!] Drive {new_drive}: not found." + Style.RESET_ALL)
else:
os.system(command)
if __name__ == "__main__":
main()