Create assets/js/terminal/apps/command-name.js:
class CommandNameApp {
constructor(terminal, filesystem, windowManager, os) {
this.terminal = terminal;
this.filesystem = filesystem;
this.windowManager = windowManager;
this.os = os;
}
async run(args) {
const width = this.terminal.cols || 60;
// Command implementation
this.terminal.write('\r\n\x1b[1;36mCommand Output\x1b[0m\r\n');
// Handle arguments
if (args.length === 0) {
this.terminal.write('Usage: command-name [options]\r\n');
return;
}
// Process command
// ...
}
}
window.CommandNameApp = CommandNameApp;
case 'command-name':
case 'cmd': // Optional alias
await this.runCommand('command-name', args);
break;
const appMap = {
// ... existing commands
'command-name': CommandNameApp,
};
const commands = [
// ... existing commands
'command-name',
];
Edit assets/js/terminal/apps/help.js:
const core = [
// ... existing commands
{ cmd: 'command-name', desc: 'Description of command' },
];
Add to _layouts/terminal.html:
<script src="/assets/js/terminal/apps/command-name.js"></script>
async run(args) {
this.terminal.write('\r\nHello from command!\r\n');
}
async run(args) {
if (args.length === 0) {
this.terminal.write('\x1b[1;31mError: Missing argument\x1b[0m\r\n');
return;
}
const arg = args[0];
// Process argument
}
async run(args) {
const path = args[0] || this.os.currentPath;
const resolvedPath = this.filesystem.resolvePath(this.os.currentPath, path);
if (!this.filesystem.exists(resolvedPath)) {
this.terminal.write(`\x1b[1;31mError: Path not found\x1b[0m\r\n`);
return;
}
// Use filesystem
}
async run(args) {
const data = window.JEKYLL_DATA?.terminal;
if (!data) {
this.terminal.write('\x1b[1;31mError: Data not available\x1b[0m\r\n');
return;
}
// Use data
}
async run(args) {
try {
this.terminal.write('\r\n\x1b[1;33mLoading...\x1b[0m\r\n');
const response = await fetch('https://api.example.com/data');
const data = await response.json();
// Process and display data
this.terminal.write(`\x1b[1;32mData loaded\x1b[0m\r\n`);
} catch (error) {
this.terminal.write(`\x1b[1;31mError: ${error.message}\x1b[0m\r\n`);
}
}
this.terminal.cols for responsive outputSee existing commands in assets/js/terminal/apps/ for reference:
whoami.js - Simple data displaycompanies.js - Complex data with navigationrepos.js - API integrationhack.js - Interactive gameopm.js - Complex command with subcommands