36 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| const helpMsg = `
 | |
| This is a non interactive Webshell including some additional features 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 exit the interactive shell.
 | |
| `
 | |
| // const helpMsg = 'This is a non interactive Webshell including some additional features to ease communications between server and client.\n  Available Commands:\n    upload\t\t\t\tUpload files to the server through the file selector of the browser.\n    download <file>\t\t\tDownload files from the server to your local download directory.\n    theme <theme>\t\t\tChange the colorscheme of the shell. Type theme to get an overview of all colorschemes.\n    start-interactive\t\t\tOpens a bash shell in an interactive terminal. Type ctrl+d to exi the interactive shell.'
 | |
| 
 | |
| 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;
 | |
|     }
 | |
| 
 | |
| });
 |