-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_RobCo.py
132 lines (115 loc) · 3.59 KB
/
cmd_RobCo.py
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
import sys
import time
import os
import func_RobCo
import termS_RobCo
import sys_RobCo
# Clear screen
clear = lambda: os.system('clear')
# ----- char
def char(userInput):
for char_ in userInput:
print(char_, end='')
sys.stdout.flush()
time.sleep(0.01)
print("")
def input_char(userInput):
for char_ in userInput:
print(char_, end='')
sys.stdout.flush()
time.sleep(0.01)
# ----- read/view/write
def read_specific_line(filename, line_number):
try:
with open(filename, 'r') as file:
lines = file.readlines()
if line_number <= len(lines):
return lines[line_number - 1].strip()
else:
print("Line number exceeds the total number of lines in the file.")
return None
except FileNotFoundError:
print(f"The file {filename} was not found.")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
def view_file(file_path):
if os.path.exists(file_path):
with open(file_path, 'r') as file:
for line in file:
print(line, end='')
time.sleep(0.01)
else:
char(f"File '{file_path}' does not exist.")
def write_file(file_path):
if os.path.exists(file_path):
with open(file_path, 'w') as file:
file.write("")
char(f"File '{file_path}' successfully cleared")
else:
char(f"File '{file_path}' does not exist")
# ----- commands_i
def handle_command(command):
if command.startswith("view p- "):
file_path = command[len("view p- "):].strip()
termS_RobCo.empty()
view_file(file_path)
return True
if command.startswith("clear p- "):
file_path = command[len("clear p- "):].strip()
termS_RobCo.empty()
write_file(file_path)
sys_RobCo.log(1, 19, "@" + file_path)
return True
if command.startswith("print "):
text_to_print = command[len("print "):].strip()
termS_RobCo.empty()
print(text_to_print)
return True
if command.startswith("char "):
termS_RobCo.empty()
text_to_char = command[len("char "):].strip()
char(text_to_char)
return True
if command.startswith("d=") and "char" in command:
delay_str = command[len("d="):].split()[0]
try:
delay = float(delay_str) # Convert delay to a float
except ValueError:
print("Invalid delay value.")
return
text_start_index = command.find("char") + len("char")
text_to_char = command[text_start_index:].strip()
# Print each character with delay
termS_RobCo.empty()
for char_ in text_to_char:
print(char_, end='', flush=True)
time.sleep(delay)
print()
return True
if command == "exit":
termS_RobCo.empty()
char("exiting terminal\n")
time.sleep(2.5)
termS_RobCo.slide_up()
exit()
if command == "restart":
python = sys.executable
os.execl(python, python, *sys.argv)
if command == "shutdown":
termS_RobCo.empty()
char("Are you sure you want to shut down the system? (y/n) \n ")
confirmation = input("!> ")
if confirmation == "y":
sys_RobCo.log(1, 12, "shutdown_m")
func_RobCo.shutdown()
else:
termS_RobCo.empty()
char("Shutdown cancelled")
return True
if command == "credits":
termS_RobCo.credits_()
return True
else:
return False