Skip to content

Commit 284976c

Browse files
committed
feat: enhance README.md with detailed configuration options and examples for FortScript
1 parent 28bbc17 commit 284976c

File tree

1 file changed

+221
-68
lines changed

1 file changed

+221
-68
lines changed

README.md

Lines changed: 221 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,21 @@ Have you ever left a bot, an API, or a script running in the background while ga
3030

3131
**FortScript solves this automatically.** It pauses your scripts when you open a game or resource-heavy application, and resumes them when you close it. Simple as that.
3232

33+
**Cross-platform:** FortScript was developed to work on any operating system, whether Windows, Linux, or MacOS.
34+
3335
### How it works
3436

35-
1. You define which scripts you want to manage (Python bots, Node.js projects, etc.)
37+
1. You define which scripts you want to manage (Python bots, Node.js projects, executables, etc.)
3638
2. You define which applications are "heavy" (games, video editors, etc.)
3739
3. FortScript monitors and does the rest: pauses when needed, resumes when possible.
3840

41+
**Callback Events (optional):** You can configure functions that will run automatically when scripts are paused or resumed:
42+
43+
- **`on_pause`**: Function executed when scripts are paused (e.g., send notification, save state).
44+
- **`on_resume`**: Function executed when scripts are resumed (e.g., reconnect services, log return).
45+
46+
This is useful for integrating with notification systems, custom logs, or any action you want to perform at those moments.
47+
3948
## Installation
4049

4150
FortScript can be used in **two ways**: as a Python library or via command line (CLI). Both come in the same package.
@@ -72,128 +81,265 @@ pipx install fortscript
7281

7382
## Configuration
7483

75-
Regardless of how you use FortScript (code or CLI), configuration is done through a `config.yaml` file:
84+
FortScript can be configured in **two ways**: via a YAML file or directly through arguments in Python code.
85+
86+
### Option 1: YAML File
87+
88+
Create a file named `fortscript.yaml` in your project root:
7689

7790
```yaml
78-
# Scripts that FortScript will manage
91+
# ====================================
92+
# FORTSCRIPT CONFIGURATION
93+
# ====================================
94+
95+
# Scripts/projects that FortScript will manage
96+
# FortScript starts these processes automatically
7997
projects:
80-
- name: "My Discord Bot"
81-
path: "./bot/main.py"
98+
- name: "My Discord Bot" # Friendly name (appears in logs)
99+
path: "./bot/main.py" # Python script (.py)
100+
82101
- name: "Node API"
83-
path: "./api/package.json"
102+
path: "./api/package.json" # Node.js project (package.json)
103+
104+
- name: "Local Server"
105+
path: "./server/app.exe" # Windows executable (.exe)
84106

85107
# Applications that will pause the scripts above
108+
# When any of these processes are detected, scripts stop
86109
heavy_processes:
87-
- name: "GTA V"
88-
process: "gta5"
110+
- name: "GTA V" # Friendly name
111+
process: "gta5" # Process name (without .exe)
112+
89113
- name: "OBS Studio"
90114
process: "obs64"
91115

92-
# Pause scripts if RAM exceeds this limit (%)
93-
ram_threshold: 85
116+
- name: "Cyberpunk 2077"
117+
process: "cyberpunk2077"
118+
119+
- name: "Premiere Pro"
120+
process: "premiere"
121+
122+
# RAM threshold to pause scripts (%)
123+
# If system RAM exceeds this value, scripts are paused
124+
ram_threshold: 90
125+
126+
# Safe RAM limit to resume scripts (%)
127+
# Scripts only return when RAM falls below this value
128+
# This avoids constant toggling (hysteresis)
129+
ram_safe: 80
130+
131+
# Log level (DEBUG, INFO, WARNING, ERROR)
132+
# Use DEBUG to see detailed information during development
133+
log_level: "INFO"
134+
```
135+
136+
### Option 2: Code Arguments
137+
138+
You can pass all configurations directly in Python code without needing a YAML file:
139+
140+
```python
141+
from fortscript import FortScript
142+
143+
app = FortScript(
144+
projects=[
145+
{"name": "My Bot", "path": "./bot/main.py"},
146+
{"name": "Node API", "path": "./api/package.json"},
147+
],
148+
heavy_process=[
149+
{"name": "GTA V", "process": "gta5"},
150+
{"name": "OBS Studio", "process": "obs64"},
151+
],
152+
ram_threshold=90,
153+
ram_safe=80,
154+
log_level="INFO",
155+
)
156+
157+
app.run()
94158
```
95159

96-
**Explanation:**
97-
- `projects`: List of scripts/projects that FortScript will start and manage.
98-
- `heavy_processes`: When any of these applications open, scripts are paused.
99-
- `ram_threshold`: If system RAM exceeds this value, scripts are also paused.
160+
> **Tip:** You can combine both! Arguments passed in code override values from the YAML file.
100161
101162
### Supported project types
102163

103-
| Type | Extension | Behavior |
104-
|------|-----------|----------|
105-
| Python | `.py` | Automatically detects `.venv` in the script's folder |
106-
| Node.js | `package.json` | Runs `npm run start` |
164+
| Type | Extension/File | Behavior |
165+
| ---------- | ---------------- | --------------------------------------------------- |
166+
| Python | `.py` | Automatically detects `.venv` in the script's folder|
167+
| Node.js | `package.json` | Runs `npm run start` |
168+
| Executable | `.exe` | Runs directly (Windows) |
107169

108170
---
109171

110172
## How to Use
111173

112-
### Option 1: Via Python code
174+
### Option 1: Basic setup (YAML file only)
113175

114-
Ideal for integrating FortScript into an existing project or having programmatic control:
176+
The simplest way to use FortScript:
115177

116178
```python
117179
from fortscript import FortScript
118180

119-
app = FortScript(config_path="config.yaml")
181+
# Loads settings from fortscript.yaml
182+
app = FortScript()
120183
app.run()
121184
```
122185

123-
### Option 2: Via CLI (terminal)
186+
### Option 2: With event callbacks
124187

125-
Ideal for quick use without writing code:
188+
Run custom functions when scripts are paused or resumed:
126189

127-
```bash
128-
# Navigate to the folder with your config.yaml
129-
cd my_project
190+
```python
191+
from fortscript import FortScript
192+
193+
def when_paused():
194+
print("🎮 Gaming mode active! Scripts paused.")
195+
196+
def when_resumed():
197+
print("💻 Back to work! Scripts resumed.")
198+
199+
app = FortScript(
200+
config_path="fortscript.yaml",
201+
on_pause=when_paused,
202+
on_resume=when_resumed,
203+
)
204+
205+
app.run()
206+
```
207+
208+
### Option 3: Complete Configuration (Dynamic Python)
209+
210+
To keep your code organized, you can separate project and process lists into variables.
211+
212+
```python
213+
from fortscript import FortScript
214+
215+
# 1. Define your callbacks
216+
def notify_pause():
217+
print("⏸️ Scripts paused!")
218+
219+
def notify_resume():
220+
print("▶️ Scripts resumed!")
221+
222+
# 2. Define your projects
223+
my_projects = [
224+
{"name": "Discord Bot", "path": "./bot/main.py"},
225+
{"name": "Express API", "path": "./api/package.json"},
226+
{"name": "Server", "path": "./server/app.exe"},
227+
]
228+
229+
# 3. Define heavy processes
230+
my_processes = [
231+
{"name": "GTA V", "process": "gta5"},
232+
{"name": "Cyberpunk 2077", "process": "cyberpunk2077"},
233+
{"name": "Chrome (Heavy)", "process": "chrome"},
234+
]
235+
236+
# 4. Initialize FortScript
237+
app = FortScript(
238+
projects=my_projects,
239+
heavy_process=my_processes,
240+
ram_threshold=90,
241+
ram_safe=80,
242+
on_pause=notify_pause,
243+
on_resume=notify_resume,
244+
log_level="DEBUG",
245+
)
130246

131-
# Run
247+
app.run()
248+
```
249+
250+
### Option 4: Via CLI (terminal)
251+
252+
Ideal for quick use or basic testing.
253+
254+
```bash
132255
fort
133256
```
134257

135-
> **Note:** The CLI currently runs FortScript from the `config.yaml`. Additional commands like `fort add` are planned for future versions.
258+
> **Warning:** Currently, the CLI looks for settings in the package's internal file (`src/fortscript/cli/fortscript.yaml`), which limits local customization via CLI. For real projects, using a Python script (Options 1 to 3) is recommended until local CLI config support is implemented.
136259
137260
---
138261

139-
## Practical Example
262+
## Practical Example: Gaming Mode
263+
264+
Imagine you are a developer who runs work scripts (bots, APIs, automations) during the day but wants to play at night without the PC lagging.
140265

141-
Imagine you have the following project structure:
266+
In this example, we use FortScript's built-in game list (`GAMES`) so you don't have to configure each game manually.
267+
268+
### Project Structure
142269

143270
```text
144271
my_project/
145272
├── discord_bot/
146273
│ ├── .venv/
147-
│ └── main.py
148-
├── express_api/
274+
│ └── main.py # RAM-consuming bot
275+
├── local_api/
149276
│ ├── node_modules/
150-
│ └── package.json
151-
├── config.yaml
152-
└── manager.py
277+
│ └── package.json # Local Express API
278+
└── gaming_mode.py # Your manager script
153279
```
154280

155-
The `manager.py` would be:
281+
### `gaming_mode.py` file
156282

157283
```python
158-
from fortscript import FortScript
159-
160-
app = FortScript(config_path="config.yaml")
161-
app.run()
284+
import os
285+
from fortscript import FortScript, GAMES
286+
287+
# Project paths
288+
base_dir = os.path.dirname(os.path.abspath(__file__))
289+
bot_path = os.path.join(base_dir, "discord_bot", "main.py")
290+
api_path = os.path.join(base_dir, "local_api", "package.json")
291+
292+
# Projects to manage
293+
my_projects = [
294+
{"name": "Discord Bot", "path": bot_path},
295+
{"name": "Local API", "path": api_path},
296+
]
297+
298+
# Combining the default game list with custom processes
299+
# GAMES already includes GTA, Valorant, CS2, LOL, Fortnite, etc.
300+
my_heavy_processes = GAMES + [
301+
{"name": "Video Editor", "process": "premiere"},
302+
{"name": "C++ Compiler", "process": "cl"}
303+
]
304+
305+
def on_pause():
306+
print("=" * 50)
307+
print("🎮 GAMING MODE ACTIVE! Scripts paused to free up resources.")
308+
print("=" * 50)
309+
310+
def on_resume():
311+
print("=" * 50)
312+
print("💻 WORK MODE - Resuming your scripts...")
313+
print("=" * 50)
314+
315+
# Initialize FortScript
316+
app = FortScript(
317+
projects=my_projects,
318+
heavy_process=my_heavy_processes,
319+
ram_threshold=85,
320+
ram_safe=75,
321+
on_pause=on_pause,
322+
on_resume=on_resume,
323+
)
324+
325+
if __name__ == "__main__":
326+
print("🎯 FortScript: Gaming Mode Started")
327+
app.run()
162328
```
163329

164-
When you open GTA V, FortScript automatically:
165-
1. Pauses the Discord bot
166-
2. Pauses the Express API
167-
3. Displays the pause reason in the terminal
168-
169-
When you close GTA V, everything resumes automatically.
170-
171330
---
172331

173332
## Roadmap
333+
> If you have an idea, feel free to suggest new features by creating an `issue`.
174334
175335
### Library
176336

177-
- [ ] **`.exe` support**: Manage executables directly.
178-
- [ ] **Configuration via arguments**: Pass `projects`, `heavy_processes`, and `ram_threshold` directly in code, without needing a YAML file.
179-
- [ ] **Custom functions**: Manage Python functions beyond external files.
180-
- [ ] **Games module**: Pre-defined list of popular games.
181-
182-
**Games module preview:**
183-
184-
```python
185-
from fortscript import FortScript
186-
from fortscript.games import GAMES
187-
188-
# GAMES contains dozens of popular games
189-
app = FortScript(heavy_processes=GAMES)
190-
app.run()
191-
```
192-
193-
| Included games | |
194-
|----------------|---|
195-
| Minecraft, GTA V, Fortnite | Counter-Strike 2, Valorant, League of Legends |
196-
| Roblox, Apex Legends | ...and many more |
337+
- [ ] **Custom Functions**: Manage Python functions by creating separate threads.
338+
- [ ] **Per-Project Conditions**: Allow a specific project to pause only if a specific app opens.
339+
- [ ] **Graceful Shutdown**: Try a graceful shutdown (SIGINT/CTRL+C) before forcing process termination.
340+
- [ ] **Dead Process Handling**: Periodically check if started processes are still alive.
341+
- [ ] **Project Abstraction**: Refactor into classes (`PythonProject`, `NodeProject`) to easily add new languages.
342+
- [ ] **Type Hinting**: Improve typing across all methods for better IDE support.
197343

198344
### CLI
199345

@@ -209,8 +355,15 @@ app.run()
209355

210356
- [x] Automatic pause when detecting heavy applications
211357
- [x] Automatic pause by RAM limit
358+
- [x] Built-in list with 150+ games and apps (`from fortscript import GAMES`)
359+
- [x] Resuming with hysteresis (ram_safe vs ram_threshold)
212360
- [x] Python script support with `.venv` detection
213361
- [x] Node.js project support via `npm run start`
362+
- [x] Windows executable support (`.exe`)
363+
- [x] Configuration via YAML file (`fortscript.yaml`)
364+
- [x] Configuration via code arguments
365+
- [x] Event callbacks (`on_pause` and `on_resume`)
366+
- [x] Configurable log levels (DEBUG, INFO, WARNING, ERROR)
214367
- [x] Safe process termination (tree-kill)
215368

216369
---
@@ -227,4 +380,4 @@ MIT - See [LICENSE](LICENSE) for details.
227380

228381
<div align="center">
229382
Made with ❤️ by <a href="https://github.com/WesleyQDev">WesleyQDev</a>
230-
</div>
383+
</div>

0 commit comments

Comments
 (0)