Fixing terminal to only boot if required

This commit is contained in:
Dan 2025-12-09 14:28:30 +00:00
parent 6315c36efc
commit 1d9bc87f1b
6 changed files with 250 additions and 234 deletions

View file

@ -1,6 +1,5 @@
// Core Commands Module
// These are essential commands for the terminal
if (window.terminal) {
// Help command
window.terminal.registerCommand("help", "Display available commands", () => {
window.terminal.print("Available commands:", "success");
@ -8,7 +7,8 @@ window.terminal.registerCommand("help", "Display available commands", () => {
const commands = Object.keys(window.terminal.commands).sort();
commands.forEach((cmd) => {
const desc = window.terminal.commands[cmd].description || "No description";
const desc =
window.terminal.commands[cmd].description || "No description";
window.terminal.print(` ${cmd.padEnd(15)} - ${desc}`);
});
window.terminal.print("");
@ -20,9 +20,13 @@ window.terminal.registerCommand("clear", "Clear the terminal screen", () => {
});
// Echo command
window.terminal.registerCommand("echo", "Echo text to the terminal", (args) => {
window.terminal.registerCommand(
"echo",
"Echo text to the terminal",
(args) => {
window.terminal.print(args.join(" "));
});
},
);
// History command
window.terminal.registerCommand("history", "Show command history", () => {
@ -39,3 +43,4 @@ window.terminal.registerCommand("history", "Show command history", () => {
window.terminal.print(` ${idx + 1}. ${cmd}`);
});
});
}

View file

@ -1,7 +1,5 @@
// Custom Commands Module
// Add your custom commands here!
// This file is a template for creating your own commands
if (window.terminal) {
// Example: Weather command (placeholder)
// window.terminal.registerCommand(
// "weather",
@ -77,7 +75,9 @@ window.terminal.registerCommand("colors", "Display available colors", () => {
'<span class="success">● Success (bright green)</span>',
);
window.terminal.printHTML('<span class="info">● Info (blue)</span>');
window.terminal.printHTML('<span class="warning">● Warning (orange)</span>');
window.terminal.printHTML(
'<span class="warning">● Warning (orange)</span>',
);
});
// ADD YOUR OWN COMMANDS BELOW THIS LINE
@ -99,3 +99,4 @@ window.terminal.registerCommand('commandname', 'Command description', (args) =>
window.terminal.printHTML('<strong>HTML content</strong>');
});
*/
}

View file

@ -1,6 +1,5 @@
// Navigation Commands Module
// Commands for navigating to different pages or URLs
if (window.terminal) {
// Navigate to URL command
window.terminal.registerCommand("goto", "Navigate to a URL", (args) => {
if (args.length === 0) {
@ -59,3 +58,4 @@ window.terminal.registerCommand(
window.terminal.registerCommand("about", "About this site", () => {
window.location.href = "/about/";
});
}

View file

@ -1,6 +1,7 @@
// Utility Commands Module
// Useful utility commands
if (window.terminal) {
// Time command
window.terminal.registerCommand("time", "Display current time", () => {
const now = new Date();
@ -95,3 +96,4 @@ window.terminal.registerCommand("greet", "Greet the user", (args) => {
const name = args.length > 0 ? args.join(" ") : "User";
window.terminal.printSuccess(`Hello, ${name}! Welcome to the terminal.`);
});
}

View file

@ -1,16 +1,21 @@
// Terminal Initialization Script
// This script creates the terminal instance immediately
// so command modules can register commands
// This script creates the terminal instance only if terminal element exists
// Create global terminal instance immediately
window.terminal = new TerminalShell();
// Boot the terminal when DOM is ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () => {
terminal.boot();
});
} else {
// DOM already loaded
// Function to initialize terminal
function initTerminal() {
// Check if terminal element exists
if (document.getElementById("terminal")) {
// Boot the terminal
terminal.boot();
}
}
// Wait for DOM to be ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initTerminal);
} else {
// DOM already loaded
initTerminal();
}

View file

@ -1,15 +1,18 @@
// Terminal Shell System
class TerminalShell {
constructor() {
this.output = document.getElementById("output");
this.input = document.getElementById("input");
this.inputContainer = document.getElementById("input-container");
this.history = [];
this.historyIndex = -1;
this.commands = {};
if (document.getElementById("terminal")) {
this.output = document.getElementById("output");
this.input = document.getElementById("input");
this.inputContainer = document.getElementById("input-container");
this.setupEventListeners();
}
}
// Boot sequence
async boot() {