optimize and add "--help" option
This commit is contained in:
		
							parent
							
								
									d89117a4a5
								
							
						
					
					
						commit
						ef9d8eb8b2
					
				| @ -1,11 +1,12 @@ | |||||||
| let commands = [ | let commands = [ | ||||||
|   { |   { | ||||||
|     name: "unknown", |     name: "unknown", | ||||||
|     output:[ |     output(input){return[ | ||||||
|       {color: "white", content: "\nthe command you entered is undefined!\n\n", delay: 100}, |       {color: "white", content: `the command "${input[0]}" you entered is undefined!\n`, delay: 100}, | ||||||
|       { |       { | ||||||
|         color: "white", |         color: "white", | ||||||
|         content: |         content: | ||||||
|  |         input.find(arr => arr === "--help")? | ||||||
|           "try something like:\n" + |           "try something like:\n" + | ||||||
|           "\n" + |           "\n" + | ||||||
|           "    - Mastodon   > social\n" + |           "    - Mastodon   > social\n" + | ||||||
| @ -13,19 +14,20 @@ let commands = [ | |||||||
|           "    - Matrix     > element\n" + |           "    - Matrix     > element\n" + | ||||||
|           "    - Etherpad   > ether\n" + |           "    - Etherpad   > ether\n" + | ||||||
|           "    - short url  > surl\n" + |           "    - short url  > surl\n" + | ||||||
|           "    - Jitsi      > meet\n", |           "    - Jitsi      > meet\n": | ||||||
|  |           "show examples with \"welcome --help\"", | ||||||
|         delay: 200 |         delay: 200 | ||||||
|       }, |       }, | ||||||
|     ] |     ]} | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     name: "welcome", |     name: "welcome", | ||||||
|     output:[ |     output(input){ return[ | ||||||
|       {color: "white", content: "\nWelcome to:\n", delay: 100}, |       {color: "white", content: "\nWelcome to:\n", delay: 100}, | ||||||
|       { |       { | ||||||
|         color: "green", |         color: "green", | ||||||
|         content: function (){ |         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? |           return window.innerWidth/fontSize<35? | ||||||
|             "            __  \n" + |             "            __  \n" + | ||||||
|             "           /\\ \\  \n" + |             "           /\\ \\  \n" + | ||||||
| @ -54,7 +56,7 @@ let commands = [ | |||||||
|         }(), |         }(), | ||||||
|         delay: 300 |         delay: 300 | ||||||
|       }, |       }, | ||||||
|       { |       input.find(arr => arr === "--help")?{ | ||||||
|         color: "white", |         color: "white", | ||||||
|         content: |         content: | ||||||
|           "free services on this server:\n" + |           "free services on this server:\n" + | ||||||
| @ -66,8 +68,8 @@ let commands = [ | |||||||
|           "    - short url  > surl\n" + |           "    - short url  > surl\n" + | ||||||
|           "    - Jitsi      > meet\n", |           "    - Jitsi      > meet\n", | ||||||
|         delay: 500 |         delay: 500 | ||||||
|       } |       }:{color: "white", content: "show examples with \"welcome --help\"", delay: 600} | ||||||
|     ] |     ]} | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     name: ["ls", "la", "list"], |     name: ["ls", "la", "list"], | ||||||
| @ -133,14 +135,6 @@ let commands = [ | |||||||
|       {color: "white", content: "forwarding", delay: 400}, |       {color: "white", content: "forwarding", delay: 400}, | ||||||
|       {color: "white", content: " ...", forward: "https://meet.adb.sh", delay: 600} |       {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:{ |   methods:{ | ||||||
|     renderCommand(input){ |     renderCommand(input){ | ||||||
|       let toRender = this.getCommand(input).output |       let toRender = this.getCommand(input).output | ||||||
|       let payload = []; |       return typeof toRender === "function"?toRender(input.split(" ")):toRender; | ||||||
|       if (typeof toRender === "function"){ |  | ||||||
|         payload = toRender(input) |  | ||||||
|       }else{ |  | ||||||
|         toRender.forEach(part => |  | ||||||
|           payload.push(typeof part === "function"?part(input):part) |  | ||||||
|         ) |  | ||||||
|       } |  | ||||||
|       return payload; |  | ||||||
|     }, |     }, | ||||||
|     getCommand(input) { |     getCommand(input) { | ||||||
|       input = input.split(" ")[0]; |       input = input.split(" ", 1)[0]; | ||||||
|       let command = commands.find( |       let command = commands.find( | ||||||
|         command => Array.isArray(command.name)?command.name.find( |         command => Array.isArray(command.name)?command.name.find( | ||||||
|           altName => altName === input):command.name === input); |           altName => altName === input):command.name === input); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user