aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-simplegui.js
blob: 78fa9b5a6c9774f0fceba5061f1fe1ff14545e6d (plain)
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
// Extracted from newOS4 index.html — SimpleGUIModule
        class SimpleGUIModule {
            constructor() { this.commands = {}; this.terminal = null; this.guiElements = {}; }
            getHelpInfo() {
                return {
                    'gui': 'gui — Show the GUI builder overview',
                    'gui-button': 'gui-button <label> <command> — Add a clickable button',
                    'gui-input': 'gui-input <placeholder> <varName> — Add a text input field',
                    'gui-text': 'gui-text <content> — Add a text element',
                    'gui-clear': 'gui-clear — Clear all GUI elements',
                    'gui-run': 'gui-run <command> — Run a terminal command from the GUI'
                };
            }
            registerCommands() {
                this.commands['gui'] = () => this.showGUI();
                this.commands['gui-button'] = (args) => this.createButton(args);
                this.commands['gui-input'] = (args) => this.createInput(args);
                this.commands['gui-text'] = (args) => this.createText(args);
                this.commands['gui-clear'] = () => this.clearGUI();
                this.commands['gui-run'] = (args) => this.runCommand(args);
            }
            showGUI() {
                this.terminal.print("=== Simple GUI Builder ===", "info");
                this.terminal.print("Commands: gui-button, gui-input, gui-text, gui-clear", "info");
            }
            createButton(args) {
                if (args.length < 2) {
                    this.terminal.print("Usage: gui-button <label> <command>", "warning"); return;
                }
                const label = args[0], command = args.slice(1).join(' ');
                const id = 'gui-btn-' + Date.now();
                this.terminal.printHTML(`<div style="margin: 5px 0;">
                    <button class="qa-btn" onclick="${command}" id="${id}">${label}</button>
                </div>`);
                this.guiElements[id] = { type: 'button', label, command };
                this.terminal.print(`Button '${label}' created`, "success");
            }
            createInput(args) {
                if (args.length < 2) {
                    this.terminal.print("Usage: gui-input <placeholder> <varName>", "warning"); return;
                }
                const placeholder = args[0], varName = args[1], id = 'gui-input-' + Date.now();
                this.terminal.printHTML(`<div style="margin: 5px 0;">
                    <input type="text" id="${id}" placeholder="${placeholder}" 
                           style="background: #0a0a0a; border: 1px solid #005500; 
                                  color: #00ff00; padding: 8px; width: 100%;" />
                </div>`);
                this.guiElements[id] = { type: 'input', placeholder, varName };
                this.terminal.print(`Input '${placeholder}' created (var: ${varName})`, "success");
            }
            createText(args) {
                if (!args[0]) {
                    this.terminal.print("Usage: gui-text <content>", "warning"); return;
                }
                const content = args.join(' ');
                this.terminal.printHTML(`<div style="margin: 5px 0; padding: 8px; 
                    background: #111111; border-left: 3px solid #00aaff;">${content}</div>`);
                this.terminal.print("Text element created", "success");
            }
            clearGUI() { this.guiElements = {}; this.terminal.print("GUI elements cleared", "success"); }
            runCommand(args) {
                if (!args[0]) {
                    this.terminal.print("Usage: gui-run <command>", "warning"); return;
                }
                this.terminal.executeCommand(args.join(' '));
            }
        }