Skip to content

Commit 9de9b78

Browse files
committed
feat: update CLI header to include version and author, enhance config handling for Windows
1 parent c4656b3 commit 9de9b78

4 files changed

Lines changed: 48 additions & 37 deletions

File tree

src/fortscript/cli/cli.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
11
import os
2+
from importlib.metadata import version
23

3-
from rich import box
4-
from rich.align import Align
54
from rich.console import Console
6-
from rich.panel import Panel
75
from rich.text import Text
86

97
from fortscript import FortScript
108

9+
try:
10+
__version__ = version('fortscript')
11+
except Exception:
12+
__version__ = 'unknown'
1113

12-
def print_banner():
13-
"""Prints a styled banner for the FortScript system."""
14-
title = Text()
15-
title.append('FORT', style='bold color(220)')
16-
title.append('SCRIPT', style='bold color(87)')
17-
18-
credit = Text('\nby WesleyyDev', style='italic color(245)')
19-
20-
content = Text.assemble(title, credit, justify='center')
21-
22-
banner = Panel(
23-
Align.center(content, vertical='middle'),
24-
box=box.DOUBLE,
25-
border_style='bright_blue',
26-
padding=(1, 10),
27-
title='[bold white]🚀 System Loaded[/]',
28-
subtitle='[dim]v0.2[/]',
29-
)
30-
Console().print(banner)
14+
console = Console()
3115

3216

3317
def main():
3418
"""Main entry point for the CLI."""
35-
# Import the main class relative to this package or absolute
19+
# Header minimalista e elegante
20+
header = Text()
21+
header.append('', style='default')
22+
header.append('FORT', style='bold color(220)')
23+
header.append('SCRIPT', style='bold color(87)')
24+
header.append(f' v{__version__} by WesleyQDev', style='dim')
25+
console.print(header)
26+
3627

37-
print_banner()
38-
# Use config from the same directory as cli.py
28+
# Path for the global config
3929
config_path = os.path.join(
4030
os.path.dirname(os.path.abspath(__file__)), 'config.yaml'
4131
)
4232

43-
# Ensure config exists or handle it?
44-
# For now, keeping original behavior but user might want robustness later.
45-
4633
app = FortScript(config_path=config_path)
4734
app.run()
4835

src/fortscript/cli/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
projects:
22
# - name: ProjectA
33
# path: C:\Users\dev\project\main.py
4+
- name: Obsidian
5+
path: C:\Users\wesle\AppData\Local\Programs\Obsidian\Obsidian.exe2
46

57
heavy_processes:
68
# - name: Fortnite

src/fortscript/main.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def __init__(self, config_path='config.yaml'):
6868
self.active_processes = []
6969

7070
self.ram_threshold = self.config.get('ram_threshold', 80)
71+
72+
73+
self.is_windows = os.name == 'nt'
7174

7275
def load_config(self, path):
7376
"""
@@ -86,6 +89,7 @@ def load_config(self, path):
8689
def start_scripts(self):
8790
"""Starts all projects defined in the configuration."""
8891
self.active_processes = [] # Clear the list before starting
92+
8993
for project in self.projects:
9094
project_name = project.get('name')
9195
script_path = project.get('path')
@@ -94,7 +98,7 @@ def start_scripts(self):
9498
# Check if the script is Python
9599
if script_path.endswith('.py'):
96100
try:
97-
if os.name == 'nt':
101+
if self.is_windows:
98102
venv_python = os.path.join(
99103
project_dir, '.venv', 'Scripts', 'python.exe'
100104
)
@@ -149,13 +153,27 @@ def start_scripts(self):
149153
)
150154

151155
# Invalid extension handling
156+
elif script_path.endswith('.exe') and self.is_windows:
157+
try:
158+
command = ['cmd.exe', '/c', str(script_path)]
159+
160+
proc = subprocess.Popen(
161+
command,
162+
cwd=str(project_dir),
163+
creationflags=subprocess.CREATE_NEW_CONSOLE,
164+
)
165+
self.active_processes.append(proc)
166+
167+
except Exception as e:
168+
print(
169+
f'[bold red]Error executing {project_name}:[/bold red]'
170+
f'{e}'
171+
)
152172
else:
153173
print(
154-
f'[yellow]Warning:[/yellow] The project {project_name}'
155-
'was skipped (invalid extension).'
156-
'\n Try again with a script:[red] [.py, .js, .ts or .exe]'
174+
f"\n[yellow]Warning:[/yellow] The project [bold]{project_name}[/bold] was skipped (invalid extension).\n"
175+
f"Try again with a script: [red][.py, .exe][/red] or a Node.js project with a [red]package.json[/red] in the folder."
157176
)
158-
159177
def stop_scripts(self):
160178
"""Terminates active scripts and their child processes."""
161179
print(
@@ -190,6 +208,7 @@ def process_manager(self):
190208
current_ram = self.ram_monitoring.get_percent()
191209
is_ram_critical = current_ram > self.ram_threshold
192210

211+
193212
if (is_heavy_process_open or is_ram_critical) and script_running:
194213
if is_heavy_process_open:
195214
detected = [k for k, v in status_dict.items() if v]
@@ -212,8 +231,8 @@ def process_manager(self):
212231
and not script_running
213232
):
214233
print(
215-
f"""[bold green]System stable (RAM: {current_ram}%).
216-
Restarting scripts...[/bold green]"""
234+
f'\n[bold green]System stable (RAM: {current_ram}%).'
235+
'Starting scripts...[/bold green]'
217236
)
218237
self.start_scripts()
219238
script_running = True
@@ -222,9 +241,12 @@ def process_manager(self):
222241
# or just pass
223242
pass
224243

244+
print()
245+
if not self.active_processes:
246+
print("[bold red]No valid scripts found to start. FortScript is shutting down.[/bold red]")
247+
break
225248
time.sleep(5)
226249

227250
def run(self):
228251
"""Runs the main application loop."""
229-
print('Running...')
230252
self.process_manager()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)