gontrol/static/help-command.js

39 lines
1.4 KiB
JavaScript

const helpMsg = `
This is a shell in the browser, a web shell.
It includes a non-interactive shell with an optional interactive mode.
Furthermore, additional commands to ease communications between server
and client.
Available Commands:
upload Upload files to the server through the file selector of the browser.
download <file> Download files from the server to your local download directory.
theme <theme> Change the colorscheme of the shell. Type theme to get an overview of all colorschemes.
start-interactive Opens a bash shell in an interactive terminal. Type ctrl+d to go back to non-interactive mode.
`
document.addEventListener("DOMContentLoaded", function() {
const input = document.getElementById("command-input");
const terminal = document.getElementById("terminal");
input.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
const command = input.value.trim();
if (command.startsWith("help")) {
event.preventDefault();
addLogEntry(helpMsg, 'info');
input.value = '';
}
}
});
function addLogEntry(message, type) {
const logEntry = document.createElement("div");
logEntry.classList.add(type === 'error' ? 'error' : 'info');
logEntry.textContent = message;
terminal.appendChild(logEntry);
terminal.scrollTop = terminal.scrollHeight;
}
});