| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- function pgsh() {
- this.prompt = '<span style="color:blueviolet">pgs </span><span style="color:green">$ </span>'
- this.welcome = '\
- Linux parsleygardens.net 3.4.5-6-7-i286 #8 PGS Vimputer 3.4.56-7 i286 \n\
- \n\
- ~ Welcome to Parsley Gardens! ~\n\
- "He maketh me to lie down in green pa..."\n\
- \n\
- Type `help` for list of commands\n\
- \n'
- this.commands = {
- 'about': {
- 'help': 'Author Information\nUsage: about',
- 'run': function(args) {
- if (args.length > 0) { return this.help }
- return 'Site by Weiyi Lou ' + new Date().getFullYear()
- }
- },
- 'clear': {
- 'help': 'Clears the screen\nUsage: clear',
- 'run' : function(args, shell, terminal) {
- terminal.display.clear()
- }
- },
- 'version': {
- 'help': 'Shell Information\nUsage: version',
- 'run': function(args) {
- if (args.length > 0) { return this.help }
- return 'Parsley Gardens Shell (pgsh) 1.0.0. Built with <a target="_blank" href="http://riotjs.com/">Riot.js</a>'
- }
- },
- 'git': {
- 'help': 'Link to Code Repository\nUsage: git',
- 'run': function(args) {
- if (args.length > 0) { return this.help }
- return 'Self-Hosted Code Repository at <a target="_blank" href="https://code.parsleygardens.net/explore/projects">code.parsleygardens.net</a>'
- }
- },
- 'hello': {
- 'help': 'Say hello to the computer\nUsage: hello [name]',
- 'run': function(args) {
- address = args.join(' ').trim()
- if (address.length == 0) {
- return 'Hello to you too'
- } else if (address == 'pgsh') {
- return 'Hello human'
- } else {
- return 'My name is not "' + address + '"'
- }
- }
- },
- 'magic': {
- 'help': 'Link to Artist\nUsage: magic',
- 'run': function(args) {
- if (args.length > 0) { return this.help }
- return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
- }
- },
- 'su': {
- 'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
- 'run': function(args, shell, terminal) {
- if (args.length > 0) { return this.help }
- var output = ''
- if (!shell.su) {
- terminal.commandline.setPrompt('<span style="color:tomato">root </span><span style="color:red">% </span>')
- shell.su = true
- output = 'With Great Power comes Great'
- }
- return output
- }
- },
- 'exit': {
- 'help': 'Leave the current context\nUsage: exit',
- 'run': function(args, shell, terminal) {
- if (args.length > 0) { return this.help }
- var output = 'Close browser window to exit'
- if (shell.su) {
- terminal.commandline.setPrompt(shell.prompt)
- shell.su = false
- output = ''
- }
- return output
- }
- },
- 'search': {
- 'help': 'Search the Web (with a Duck)\nUsage: search [query]',
- 'run': function(args, shell, terminal) {
- if (!args.join(' ').trim()) { return this.help }
- terminal.commandline.hidePrompt()
- setTimeout(function() {
- window.open('https://duckduckgo.com/?q=' + args.join('+'), '_blank')
- terminal.commandline.showPrompt()
- terminal.update()
- }, 1000)
- return 'Searching for "' + args.join(' ') + '" in new window...'
- }
- },
- 'questions': {
- 'help': 'Answer some questions!\nUsage: questions',
- 'run': function() {
- return {
- 'run': function(input, terminal) {
- if (!this.running) {
- this.running = true
- terminal.display.hide()
- terminal.display.add('Welcome to the questions. Do you want to continue?')
- terminal.commandline.hidePrompt()
- return
- }
- if (input != 'exit') {
- terminal.display.set('You answered with "' + input + '"!\nNext question!\n<span style="color:#555">(Type "exit" to end)</span>\n\n')
- var rand = Math.floor(Math.random() * this.questions.length);
- terminal.display.add(this.questions[rand])
- } else {
- terminal.display.restore()
- terminal.display.add('Thanks for answering questions!')
- terminal.commandline.showPrompt()
- terminal.returnToShell()
- }
- },
- 'questions': [
- 'Isn\'t <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" target="_blank">this song</a> the best?',
- 'Iggledy Piggledy',
- '1 + 2 = ?',
- 'Am I a sandwich?',
- 'Where were you at 3:15am on April 14th?',
- "Don't you mean prism?",
- 'Buts twelve by pies?'
- ]
- }
- }
- },
- 'help': {
- 'help': 'List available commands or view information for a given command\nUsage: help [command]',
- 'run': function(args, shell) {
- command = args.join(' ').trim()
- if (command in shell.commands) {
- return shell.commands[command].help
- } else if (command) {
- return 'Command not found: ' + command
- } else {
- var commands = [];
- for(var name in shell.commands) {
- commands.push(name)
- }
- return 'Available commands:\n' + commands.sort().join(' ') + '\n\n`help [command]` for more information.'
- }
- }
- }
- }
- this.run = function(input, terminal) {
- var parts = input.trim().split(' ')
- // First word is the command, all others are arguments.
- var command = parts.splice(0, 1)
- var args = parts
- var output = ''
- if (command in this.commands) {
- output = this.commands[command].run(args, this, terminal)
- }
- return output
- }
- }
|