Skip to content

Commit 3711e9a

Browse files
committed
Add platform detection and improve terminal clear command
1 parent 3a54960 commit 3711e9a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

main.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import pickle
66
import time
7+
import platform
78
from datetime import datetime
89
from matplotlib import pyplot as plt
910

@@ -62,6 +63,20 @@ def formatTimestamp(ts):
6263
return datetime.fromtimestamp(float(ts)).strftime("%Y-%m-%d %H:%M:%S")
6364
except Exception:
6465
return str(ts)
66+
67+
def detect_platform():
68+
system = platform.system().lower()
69+
70+
if system == 'windows':
71+
return "windows"
72+
elif system == 'linux':
73+
if os.path.exists("/data/data/com.termux"):
74+
return "android"
75+
return "linux"
76+
elif system == 'darwin':
77+
return "macos"
78+
else:
79+
return "unknown"
6580

6681
class Menu_Manager:
6782
def __init__(self):
@@ -145,7 +160,7 @@ def renderMenu(self, task):
145160
collums, lines = os.get_terminal_size()
146161
headerHeight = 1
147162
bodyHeight = lines - headerHeight
148-
os.system('cls')
163+
os.system('clear' if platform != 'windows' else 'cls')
149164
self.printHeader(headerHeight, collums)
150165
return self.printBody(bodyHeight, collums, task)
151166

@@ -369,6 +384,7 @@ def main():
369384
global base_dir
370385
global log
371386
global menu
387+
global platform
372388

373389
global working_dir
374390
global resultsPath
@@ -391,6 +407,8 @@ def main():
391407
log.append("Initializing...")
392408
base_dir = os.path.dirname(os.path.abspath(__file__))
393409
menu = Menu_Manager()
410+
platform = utils.detect_platform()
411+
log.append(f"Detected platform: {platform}")
394412
while True:
395413
if working_dir is None:
396414
task = {"type": "options", "name": "Main Menu", "options": {1: "Create New Simulation", 2: "Load Existing Simulation", 3: "Exit"}}

0 commit comments

Comments
 (0)