optimize and add "--help" option

master
adb 4 years ago
parent d89117a4a5
commit ef9d8eb8b2

@ -1,11 +1,12 @@
let commands = [
{
name: "unknown",
output:[
{color: "white", content: "\nthe command you entered is undefined!\n\n", delay: 100},
output(input){return[
{color: "white", content: `the command "${input[0]}" you entered is undefined!\n`, delay: 100},
{
color: "white",
content:
input.find(arr => arr === "--help")?
"try something like:\n" +
"\n" +
" - Mastodon > social\n" +
@ -13,19 +14,20 @@ let commands = [
" - Matrix > element\n" +
" - Etherpad > ether\n" +
" - short url > surl\n" +
" - Jitsi > meet\n",
" - Jitsi > meet\n":
"show examples with \"welcome --help\"",
delay: 200
},
]
]}
},
{
name: "welcome",
output:[
output(input){ return[
{color: "white", content: "\nWelcome to:\n", delay: 100},
{
color: "green",
content: function(){
let fontSize = window.getComputedStyle(document.body,null).fontSize.split("px")[0];
let fontSize = window.getComputedStyle(document.body,null).fontSize.split("px", 1);
return window.innerWidth/fontSize<35?
" __ \n" +
" /\\ \\ \n" +
@ -54,7 +56,7 @@ let commands = [
}(),
delay: 300
},
{
input.find(arr => arr === "--help")?{
color: "white",
content:
"free services on this server:\n" +
@ -66,8 +68,8 @@ let commands = [
" - short url > surl\n" +
" - Jitsi > meet\n",
delay: 500
}
]
}:{color: "white", content: "show examples with \"welcome --help\"", delay: 600}
]}
},
{
name: ["ls", "la", "list"],
@ -133,14 +135,6 @@ let commands = [
{color: "white", content: "forwarding", delay: 400},
{color: "white", content: " ...", forward: "https://meet.adb.sh", delay: 600}
]
},
{
name: ["test"],
output(input){ return[
{color: "blue", content: "\nJitsi", delay: 100},
{color: "white", content: " is loading\n", delay: 200},
{color: "white", content: input, delay: 400}
]}
}
]
@ -153,18 +147,10 @@ export default {
methods:{
renderCommand(input){
let toRender = this.getCommand(input).output
let payload = [];
if (typeof toRender === "function"){
payload = toRender(input)
}else{
toRender.forEach(part =>
payload.push(typeof part === "function"?part(input):part)
)
}
return payload;
return typeof toRender === "function"?toRender(input.split(" ")):toRender;
},
getCommand(input) {
input = input.split(" ")[0];
input = input.split(" ", 1)[0];
let command = commands.find(
command => Array.isArray(command.name)?command.name.find(
altName => altName === input):command.name === input);

Loading…
Cancel
Save