Fixing terminal to only boot if required
This commit is contained in:
parent
6315c36efc
commit
1d9bc87f1b
6 changed files with 250 additions and 234 deletions
|
|
@ -1,31 +1,35 @@
|
||||||
// Core Commands Module
|
// Core Commands Module
|
||||||
// These are essential commands for the terminal
|
if (window.terminal) {
|
||||||
|
// Help command
|
||||||
// Help command
|
window.terminal.registerCommand("help", "Display available commands", () => {
|
||||||
window.terminal.registerCommand("help", "Display available commands", () => {
|
|
||||||
window.terminal.print("Available commands:", "success");
|
window.terminal.print("Available commands:", "success");
|
||||||
window.terminal.print("");
|
window.terminal.print("");
|
||||||
|
|
||||||
const commands = Object.keys(window.terminal.commands).sort();
|
const commands = Object.keys(window.terminal.commands).sort();
|
||||||
commands.forEach((cmd) => {
|
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(` ${cmd.padEnd(15)} - ${desc}`);
|
||||||
});
|
});
|
||||||
window.terminal.print("");
|
window.terminal.print("");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clear command
|
// Clear command
|
||||||
window.terminal.registerCommand("clear", "Clear the terminal screen", () => {
|
window.terminal.registerCommand("clear", "Clear the terminal screen", () => {
|
||||||
window.terminal.clear();
|
window.terminal.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Echo command
|
// 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(" "));
|
window.terminal.print(args.join(" "));
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// History command
|
// History command
|
||||||
window.terminal.registerCommand("history", "Show command history", () => {
|
window.terminal.registerCommand("history", "Show command history", () => {
|
||||||
if (window.terminal.history.length === 0) {
|
if (window.terminal.history.length === 0) {
|
||||||
window.terminal.print("No commands in history");
|
window.terminal.print("No commands in history");
|
||||||
return;
|
return;
|
||||||
|
|
@ -38,4 +42,5 @@ window.terminal.registerCommand("history", "Show command history", () => {
|
||||||
.forEach((cmd, idx) => {
|
.forEach((cmd, idx) => {
|
||||||
window.terminal.print(` ${idx + 1}. ${cmd}`);
|
window.terminal.print(` ${idx + 1}. ${cmd}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,74 +1,72 @@
|
||||||
// Custom Commands Module
|
// Custom Commands Module
|
||||||
// Add your custom commands here!
|
if (window.terminal) {
|
||||||
// This file is a template for creating your own commands
|
// Example: Weather command (placeholder)
|
||||||
|
// window.terminal.registerCommand(
|
||||||
|
// "weather",
|
||||||
|
// "Show weather information",
|
||||||
|
// (args) => {
|
||||||
|
// const city = args.length > 0 ? args.join(" ") : "your location";
|
||||||
|
// window.terminal.printInfo(`Fetching weather for ${city}...`);
|
||||||
|
// window.terminal.print("☀️ Sunny, 72°F");
|
||||||
|
// window.terminal.print("");
|
||||||
|
// window.terminal.printWarning(
|
||||||
|
// "Note: This is a placeholder. Integrate with a real weather API!",
|
||||||
|
// );
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
|
||||||
// Example: Weather command (placeholder)
|
// Example: Random quote
|
||||||
// window.terminal.registerCommand(
|
// window.terminal.registerCommand("quote", "Display a random quote", () => {
|
||||||
// "weather",
|
// const quotes = [
|
||||||
// "Show weather information",
|
// "The only way to do great work is to love what you do. - Steve Jobs",
|
||||||
// (args) => {
|
// "Innovation distinguishes between a leader and a follower. - Steve Jobs",
|
||||||
// const city = args.length > 0 ? args.join(" ") : "your location";
|
// "Stay hungry, stay foolish. - Steve Jobs",
|
||||||
// window.terminal.printInfo(`Fetching weather for ${city}...`);
|
// "First, solve the problem. Then, write the code. - John Johnson",
|
||||||
// window.terminal.print("☀️ Sunny, 72°F");
|
// ];
|
||||||
// window.terminal.print("");
|
|
||||||
// window.terminal.printWarning(
|
|
||||||
// "Note: This is a placeholder. Integrate with a real weather API!",
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Example: Random quote
|
// const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
|
||||||
// window.terminal.registerCommand("quote", "Display a random quote", () => {
|
// window.terminal.printSuccess(randomQuote);
|
||||||
// const quotes = [
|
// });
|
||||||
// "The only way to do great work is to love what you do. - Steve Jobs",
|
|
||||||
// "Innovation distinguishes between a leader and a follower. - Steve Jobs",
|
|
||||||
// "Stay hungry, stay foolish. - Steve Jobs",
|
|
||||||
// "First, solve the problem. Then, write the code. - John Johnson",
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
|
// Example: List command (demonstrates dynamic content)
|
||||||
// window.terminal.printSuccess(randomQuote);
|
// window.terminal.registerCommand(
|
||||||
// });
|
// "list",
|
||||||
|
// "List items in a collection",
|
||||||
|
// (args) => {
|
||||||
|
// if (args.length === 0) {
|
||||||
|
// window.terminal.printError("Usage: list <category>");
|
||||||
|
// window.terminal.print("Available categories: files, users, tasks");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
// Example: List command (demonstrates dynamic content)
|
// const category = args[0].toLowerCase();
|
||||||
// window.terminal.registerCommand(
|
|
||||||
// "list",
|
|
||||||
// "List items in a collection",
|
|
||||||
// (args) => {
|
|
||||||
// if (args.length === 0) {
|
|
||||||
// window.terminal.printError("Usage: list <category>");
|
|
||||||
// window.terminal.print("Available categories: files, users, tasks");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const category = args[0].toLowerCase();
|
// switch (category) {
|
||||||
|
// case "files":
|
||||||
|
// window.terminal.print("Files:", "info");
|
||||||
|
// window.terminal.print(" 📄 document.txt");
|
||||||
|
// window.terminal.print(" 📄 notes.md");
|
||||||
|
// window.terminal.print(" 📁 projects/");
|
||||||
|
// break;
|
||||||
|
// case "users":
|
||||||
|
// window.terminal.print("Users:", "info");
|
||||||
|
// window.terminal.print(" 👤 admin");
|
||||||
|
// window.terminal.print(" 👤 guest");
|
||||||
|
// break;
|
||||||
|
// case "tasks":
|
||||||
|
// window.terminal.print("Tasks:", "info");
|
||||||
|
// window.terminal.print(" ✓ Complete terminal setup");
|
||||||
|
// window.terminal.print(" ☐ Add more commands");
|
||||||
|
// window.terminal.print(" ☐ Customize appearance");
|
||||||
|
// break;
|
||||||
|
// default:
|
||||||
|
// window.terminal.printError(`Unknown category: ${category}`);
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// );
|
||||||
|
|
||||||
// switch (category) {
|
// Example: Color command (demonstrates HTML output)
|
||||||
// case "files":
|
window.terminal.registerCommand("colors", "Display available colors", () => {
|
||||||
// window.terminal.print("Files:", "info");
|
|
||||||
// window.terminal.print(" 📄 document.txt");
|
|
||||||
// window.terminal.print(" 📄 notes.md");
|
|
||||||
// window.terminal.print(" 📁 projects/");
|
|
||||||
// break;
|
|
||||||
// case "users":
|
|
||||||
// window.terminal.print("Users:", "info");
|
|
||||||
// window.terminal.print(" 👤 admin");
|
|
||||||
// window.terminal.print(" 👤 guest");
|
|
||||||
// break;
|
|
||||||
// case "tasks":
|
|
||||||
// window.terminal.print("Tasks:", "info");
|
|
||||||
// window.terminal.print(" ✓ Complete terminal setup");
|
|
||||||
// window.terminal.print(" ☐ Add more commands");
|
|
||||||
// window.terminal.print(" ☐ Customize appearance");
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// window.terminal.printError(`Unknown category: ${category}`);
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Example: Color command (demonstrates HTML output)
|
|
||||||
window.terminal.registerCommand("colors", "Display available colors", () => {
|
|
||||||
window.terminal.print("Available terminal colors:", "info");
|
window.terminal.print("Available terminal colors:", "info");
|
||||||
window.terminal.print("");
|
window.terminal.print("");
|
||||||
window.terminal.printHTML("<span>● Standard (green)</span>");
|
window.terminal.printHTML("<span>● Standard (green)</span>");
|
||||||
|
|
@ -77,14 +75,16 @@ window.terminal.registerCommand("colors", "Display available colors", () => {
|
||||||
'<span class="success">● Success (bright green)</span>',
|
'<span class="success">● Success (bright green)</span>',
|
||||||
);
|
);
|
||||||
window.terminal.printHTML('<span class="info">● Info (blue)</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
|
// ADD YOUR OWN COMMANDS BELOW THIS LINE
|
||||||
// ========================================
|
// ========================================
|
||||||
|
|
||||||
// Template for new command:
|
// Template for new command:
|
||||||
/*
|
/*
|
||||||
window.terminal.registerCommand('commandname', 'Command description', (args) => {
|
window.terminal.registerCommand('commandname', 'Command description', (args) => {
|
||||||
// args is an array of arguments
|
// args is an array of arguments
|
||||||
// Example: if user types "mycommand hello world"
|
// Example: if user types "mycommand hello world"
|
||||||
|
|
@ -99,3 +99,4 @@ window.terminal.registerCommand('commandname', 'Command description', (args) =>
|
||||||
window.terminal.printHTML('<strong>HTML content</strong>');
|
window.terminal.printHTML('<strong>HTML content</strong>');
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
// Navigation Commands Module
|
// Navigation Commands Module
|
||||||
// Commands for navigating to different pages or URLs
|
if (window.terminal) {
|
||||||
|
// Navigate to URL command
|
||||||
// Navigate to URL command
|
window.terminal.registerCommand("goto", "Navigate to a URL", (args) => {
|
||||||
window.terminal.registerCommand("goto", "Navigate to a URL", (args) => {
|
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
window.terminal.printError("Usage: goto <url>");
|
window.terminal.printError("Usage: goto <url>");
|
||||||
window.terminal.print("Examples:");
|
window.terminal.print("Examples:");
|
||||||
|
|
@ -17,10 +16,10 @@ window.terminal.registerCommand("goto", "Navigate to a URL", (args) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = url.startsWith("http") ? url : `https://${url}`;
|
window.location.href = url.startsWith("http") ? url : `https://${url}`;
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Open in new tab command
|
// Open in new tab command
|
||||||
window.terminal.registerCommand("open", "Open URL in new tab", (args) => {
|
window.terminal.registerCommand("open", "Open URL in new tab", (args) => {
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
window.terminal.printError("Usage: open <url>");
|
window.terminal.printError("Usage: open <url>");
|
||||||
window.terminal.print("Examples:");
|
window.terminal.print("Examples:");
|
||||||
|
|
@ -34,28 +33,29 @@ window.terminal.registerCommand("open", "Open URL in new tab", (args) => {
|
||||||
|
|
||||||
const fullUrl = url.startsWith("http") ? url : `https://${url}`;
|
const fullUrl = url.startsWith("http") ? url : `https://${url}`;
|
||||||
window.open(fullUrl, "_blank");
|
window.open(fullUrl, "_blank");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reload page command
|
// Reload page command
|
||||||
window.terminal.registerCommand("reload", "Reload the current page", () => {
|
window.terminal.registerCommand("reload", "Reload the current page", () => {
|
||||||
window.terminal.printInfo("Reloading page...");
|
window.terminal.printInfo("Reloading page...");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}, 500);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
// PAGE NAVIGATION
|
// PAGE NAVIGATION
|
||||||
|
|
||||||
window.terminal.registerCommand(
|
window.terminal.registerCommand(
|
||||||
"latest",
|
"latest",
|
||||||
"View the latest post, regardles of section",
|
"View the latest post, regardles of section",
|
||||||
() => {
|
() => {
|
||||||
let latestPostLink = document.getElementById("latest-post-link");
|
let latestPostLink = document.getElementById("latest-post-link");
|
||||||
window.location.href = latestPostLink.textContent;
|
window.location.href = latestPostLink.textContent;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// About command
|
// About command
|
||||||
window.terminal.registerCommand("about", "About this site", () => {
|
window.terminal.registerCommand("about", "About this site", () => {
|
||||||
window.location.href = "/about/";
|
window.location.href = "/about/";
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
// Utility Commands Module
|
// Utility Commands Module
|
||||||
// Useful utility commands
|
// Useful utility commands
|
||||||
|
|
||||||
// Time command
|
if (window.terminal) {
|
||||||
window.terminal.registerCommand("time", "Display current time", () => {
|
// Time command
|
||||||
|
window.terminal.registerCommand("time", "Display current time", () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
window.terminal.print(`Current time: ${now.toLocaleString()}`);
|
window.terminal.print(`Current time: ${now.toLocaleString()}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculator command
|
// Calculator command
|
||||||
window.terminal.registerCommand("calc", "Simple calculator", (args) => {
|
window.terminal.registerCommand("calc", "Simple calculator", (args) => {
|
||||||
if (args.length === 0) {
|
if (args.length === 0) {
|
||||||
window.terminal.printError("Usage: calc <expression>");
|
window.terminal.printError("Usage: calc <expression>");
|
||||||
window.terminal.print("Example: calc 5 + 3");
|
window.terminal.print("Example: calc 5 + 3");
|
||||||
|
|
@ -23,36 +24,36 @@ window.terminal.registerCommand("calc", "Simple calculator", (args) => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
window.terminal.printError("Invalid expression");
|
window.terminal.printError("Invalid expression");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Demo command
|
// Demo command
|
||||||
// window.terminal.registerCommand("demo", "Show demo content", () => {
|
// window.terminal.registerCommand("demo", "Show demo content", () => {
|
||||||
// window.terminal.printSuccess("=== Demo Content ===");
|
// window.terminal.printSuccess("=== Demo Content ===");
|
||||||
// window.terminal.print("");
|
// window.terminal.print("");
|
||||||
// window.terminal.print("This is regular text");
|
// window.terminal.print("This is regular text");
|
||||||
// window.terminal.printInfo("This is info text");
|
// window.terminal.printInfo("This is info text");
|
||||||
// window.terminal.printWarning("This is warning text");
|
// window.terminal.printWarning("This is warning text");
|
||||||
// window.terminal.printError("This is error text");
|
// window.terminal.printError("This is error text");
|
||||||
// window.terminal.print("");
|
// window.terminal.print("");
|
||||||
// window.terminal.printHTML(
|
// window.terminal.printHTML(
|
||||||
// 'You can also use <strong>HTML</strong> with <a href="#">links</a>!',
|
// 'You can also use <strong>HTML</strong> with <a href="#">links</a>!',
|
||||||
// );
|
// );
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// ASCII art command
|
// ASCII art command
|
||||||
// window.terminal.registerCommand("ascii", "Display ASCII art", () => {
|
// window.terminal.registerCommand("ascii", "Display ASCII art", () => {
|
||||||
// const art = `
|
// const art = `
|
||||||
// _____ _ _
|
// _____ _ _
|
||||||
// |_ _|__ _ __ _ __ ___ (_)_ __ __ _| |
|
// |_ _|__ _ __ _ __ ___ (_)_ __ __ _| |
|
||||||
// | |/ _ \\ '__| '_ \` _ \\| | '_ \\ / _\` | |
|
// | |/ _ \\ '__| '_ \` _ \\| | '_ \\ / _\` | |
|
||||||
// | | __/ | | | | | | | | | | | (_| | |
|
// | | __/ | | | | | | | | | | | (_| | |
|
||||||
// |_|\\___|_| |_| |_| |_|_|_| |_|\\__,_|_|
|
// |_|\\___|_| |_| |_| |_|_|_| |_|\\__,_|_|
|
||||||
// `;
|
// `;
|
||||||
// window.terminal.print(art, "success");
|
// window.terminal.print(art, "success");
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// ASCII art command
|
// ASCII art command
|
||||||
window.terminal.registerCommand("nerv", "Display NERV logo", () => {
|
window.terminal.registerCommand("nerv", "Display NERV logo", () => {
|
||||||
const art = `
|
const art = `
|
||||||
# ## %*###
|
# ## %*###
|
||||||
#******************
|
#******************
|
||||||
|
|
@ -88,10 +89,11 @@ window.terminal.registerCommand("nerv", "Display NERV logo", () => {
|
||||||
|
|
||||||
`;
|
`;
|
||||||
window.terminal.print(art, "success");
|
window.terminal.print(art, "success");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Greet command
|
// Greet command
|
||||||
window.terminal.registerCommand("greet", "Greet the user", (args) => {
|
window.terminal.registerCommand("greet", "Greet the user", (args) => {
|
||||||
const name = args.length > 0 ? args.join(" ") : "User";
|
const name = args.length > 0 ? args.join(" ") : "User";
|
||||||
window.terminal.printSuccess(`Hello, ${name}! Welcome to the terminal.`);
|
window.terminal.printSuccess(`Hello, ${name}! Welcome to the terminal.`);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,21 @@
|
||||||
// Terminal Initialization Script
|
// Terminal Initialization Script
|
||||||
// This script creates the terminal instance immediately
|
// This script creates the terminal instance only if terminal element exists
|
||||||
// so command modules can register commands
|
|
||||||
|
|
||||||
// Create global terminal instance immediately
|
|
||||||
window.terminal = new TerminalShell();
|
window.terminal = new TerminalShell();
|
||||||
|
|
||||||
// Boot the terminal when DOM is ready
|
// Function to initialize terminal
|
||||||
if (document.readyState === "loading") {
|
function initTerminal() {
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
// Check if terminal element exists
|
||||||
|
if (document.getElementById("terminal")) {
|
||||||
|
// Boot the terminal
|
||||||
terminal.boot();
|
terminal.boot();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for DOM to be ready
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", initTerminal);
|
||||||
} else {
|
} else {
|
||||||
// DOM already loaded
|
// DOM already loaded
|
||||||
terminal.boot();
|
initTerminal();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
// Terminal Shell System
|
// Terminal Shell System
|
||||||
class TerminalShell {
|
class TerminalShell {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.output = document.getElementById("output");
|
|
||||||
this.input = document.getElementById("input");
|
|
||||||
this.inputContainer = document.getElementById("input-container");
|
|
||||||
this.history = [];
|
this.history = [];
|
||||||
this.historyIndex = -1;
|
this.historyIndex = -1;
|
||||||
this.commands = {};
|
this.commands = {};
|
||||||
|
|
||||||
|
if (document.getElementById("terminal")) {
|
||||||
|
this.output = document.getElementById("output");
|
||||||
|
this.input = document.getElementById("input");
|
||||||
|
this.inputContainer = document.getElementById("input-container");
|
||||||
|
|
||||||
this.setupEventListeners();
|
this.setupEventListeners();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Boot sequence
|
// Boot sequence
|
||||||
async boot() {
|
async boot() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue