From d89117a4a5505c62cd5b352d8a6d8c355929399d Mon Sep 17 00:00:00 2001 From: adb Date: Thu, 11 Feb 2021 21:50:03 +0100 Subject: [PATCH] optimize and rearrange history object --- src/components/console.vue | 33 ++++++++++++++++---------------- src/render-commands.js | 39 +++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/components/console.vue b/src/components/console.vue index 40f0637..1246f51 100644 --- a/src/components/console.vue +++ b/src/components/console.vue @@ -1,38 +1,37 @@ diff --git a/src/render-commands.js b/src/render-commands.js index a5e36a4..dd158b5 100644 --- a/src/render-commands.js +++ b/src/render-commands.js @@ -24,7 +24,7 @@ let commands = [ {color: "white", content: "\nWelcome to:\n", delay: 100}, { color: "green", - content(){ + content: function (){ let fontSize = window.getComputedStyle(document.body,null).fontSize.split("px")[0]; return window.innerWidth/fontSize<35? " __ \n" + @@ -51,7 +51,7 @@ let commands = [ " \\/____/\\/___/\\ \\___/ \\/_/ \\/____/\\/_/ \\/__//___/ \\/_/\\/_/ \\/_/\\/_/\n" + " /\\___/\n" + " \\/__/ @adb.sh\n\n"; - }, + }(), delay: 300 }, { @@ -133,33 +133,38 @@ 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} + ]} } ] -let history = [{ - host: "[cybre.town]$ ", - command: "welcome --help", - output: [] -}] - export default { data(){ return { - commands, - history + commands } }, methods:{ renderCommand(input){ - history[history.length-1].output = this.getCommand(input).output; - history.push({ - host: "[cybre.town]$ ", - command: "", - output: [] - }) + 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; }, getCommand(input) { - input = (input?input:history[history.length-1].command).split(" ")[0]; + input = input.split(" ")[0]; let command = commands.find( command => Array.isArray(command.name)?command.name.find( altName => altName === input):command.name === input);