Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
FunnyDoggs authored Feb 26, 2024
1 parent 396ce49 commit 37d6554
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
font-family: monospace;
font-size: 16px;
caret-color: white;
width: 100%;
}
</style>
<title>Linux Emulator</title>
Expand All @@ -38,7 +39,6 @@
const terminal = document.getElementById('terminal');
const inputElement = document.createElement('input');
inputElement.setAttribute('type', 'text');
inputElement.style.width = '100%';
terminal.appendChild(inputElement);

let commandHistory = [];
Expand All @@ -49,6 +49,7 @@
event.preventDefault();
const command = inputElement.value.trim();
if (command !== '') {
displayInput(command);
handleCommand(command);
commandHistory.unshift(command);
historyIndex = -1;
Expand All @@ -69,40 +70,6 @@
}
});

const localStorageKey = 'linux_emulator_fs';
let fileSystem = JSON.parse(localStorage.getItem(localStorageKey)) || {
'/': {
type: 'directory',
contents: {
home: {
type: 'directory',
contents: {
user: {
type: 'directory',
contents: {
file1: { type: 'file', content: 'Content of file1' },
file2: { type: 'file', content: 'Content of file2' },
script.sh: { type: 'file', content: 'echo "Shell script output"' },
},
},
},
},
bin: {
type: 'directory',
contents: {
echo: { type: 'executable', execute: echoCommand },
ls: { type: 'executable', execute: lsCommand },
cat: { type: 'executable', execute: catCommand },
runscript: { type: 'executable', execute: runScriptCommand },
touch: { type: 'executable', execute: touchCommand },
write: { type: 'executable', execute: writeCommand },
exit: { type: 'executable', execute: exitCommand },
},
},
},
},
};

function handleCommand(command) {
const [cmd, ...args] = command.split(' ');
switch (cmd.toLowerCase()) {
Expand Down Expand Up @@ -205,10 +172,18 @@
currentDirectory = directory;
}

function displayInput(command) {
const inputElement = document.createElement('div');
inputElement.className = 'input';
inputElement.textContent = '$ ' + command;
terminal.appendChild(inputElement);
}

function displayOutput(output) {
const outputElement = document.createElement('div');
outputElement.className = 'output';
outputElement.textContent = output;
terminal.insertBefore(outputElement, inputElement);
terminal.appendChild(outputElement);
}

function echoCommand(args) {
Expand Down

0 comments on commit 37d6554

Please sign in to comment.