update: website look
This commit is contained in:
parent
01c8eb3b27
commit
ae81d8467c
@ -22,11 +22,18 @@ body {
|
||||
}
|
||||
|
||||
#container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
text-align: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
align-content: center;
|
||||
#container > * {
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
[data-tooltip] {
|
||||
@ -71,10 +78,11 @@ input {
|
||||
white-space: preserve;
|
||||
color: var(--color);
|
||||
|
||||
padding: 2em;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#switch_theme {
|
||||
#switch_theme, #help {
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
@ -91,3 +99,9 @@ input {
|
||||
max-width: 50%;
|
||||
max-height: 50%;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 798px) {
|
||||
#container {
|
||||
flex-direction: column !important;
|
||||
}
|
||||
}
|
@ -14,14 +14,15 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div>
|
||||
<h1>welcome to my website</h1>
|
||||
<h2 id="switch_theme">switch theme</h2>
|
||||
|
||||
<p>press <kbd>Enter</kbd> to run command</p>
|
||||
<p>use 'help' to list all commands</p>
|
||||
|
||||
<p>use <span id="help">'help'</span> to list all commands</p>
|
||||
<span>[guest@website ~]$ </span>
|
||||
<input type="text" id="command">
|
||||
</div>
|
||||
<div id="result">
|
||||
|
||||
</div>
|
||||
|
65
js/script.js
65
js/script.js
@ -4,6 +4,36 @@ function updateAge() {
|
||||
age.textContent = difference.toFixed(4);
|
||||
}
|
||||
|
||||
// process command function
|
||||
function processCommand() {
|
||||
const [commandName, ...args] = command.value.split(' ') || [command.value]
|
||||
const suppliedCommand = COMMANDS.find(c => c.name === commandName)
|
||||
|
||||
if (!suppliedCommand) {
|
||||
result.textContent = 'invalid command';
|
||||
return
|
||||
}
|
||||
|
||||
const { arguments, output } = suppliedCommand;
|
||||
for (const i in arguments) {
|
||||
const argument = arguments[i]
|
||||
|
||||
if (argument.required && !args[i]) {
|
||||
result.textContent = `argument ${argument.name} is missing`;
|
||||
return
|
||||
}
|
||||
|
||||
const errorMessage = argument.check(argument.multiword ? args.join(' ') : args[i])
|
||||
|
||||
if (typeof errorMessage === 'string') {
|
||||
result.textContent = `error while executing ${suppliedCommand.name}: ${errorMessage}`;
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
result.innerHTML = output(...args).replaceAll(TAB, '')
|
||||
}
|
||||
|
||||
// wrapper for setInterval
|
||||
const runEvery = (task, ms) => {
|
||||
task()
|
||||
@ -37,34 +67,7 @@ command?.addEventListener('focusout', () => {
|
||||
})
|
||||
|
||||
command?.addEventListener('keydown', e => {
|
||||
if (e.key === 'Enter') {
|
||||
const [commandName, ...args] = e.target.value.split(' ') || [e.target.value]
|
||||
const command = COMMANDS.find(c => c.name === commandName)
|
||||
|
||||
if (!command) {
|
||||
result.textContent = 'invalid command';
|
||||
return
|
||||
}
|
||||
|
||||
const { arguments, output } = command;
|
||||
for (const i in arguments) {
|
||||
const argument = arguments[i]
|
||||
|
||||
if (argument.required && !args[i]) {
|
||||
result.textContent = `argument ${argument.name} is missing`;
|
||||
return
|
||||
}
|
||||
|
||||
const errorMessage = argument.check(argument.multiword ? args.join(' ') : args[i])
|
||||
|
||||
if (typeof errorMessage === 'string') {
|
||||
result.textContent = `error while executing ${command.name}: ${errorMessage}`;
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
result.innerHTML = output(...args).replaceAll(TAB, '')
|
||||
}
|
||||
if (e.key === 'Enter') processCommand()
|
||||
})
|
||||
|
||||
// run all tasks
|
||||
@ -75,3 +78,9 @@ command?.focus()
|
||||
const theme = localStorage.getItem('theme');
|
||||
if (theme === 'dark')
|
||||
document.body.classList.add('dark')
|
||||
|
||||
// listen to help tooltip
|
||||
help.addEventListener('click', () => {
|
||||
command.value = 'help';
|
||||
processCommand();
|
||||
})
|
Loading…
Reference in New Issue
Block a user