function pgsh(ev) {
var self = this
ev.on('cmd_entered', function(input) {
// First word is the command, all others are arguments.
var parts = input.trim().split(' ')
var command = self.active ? self.active : parts.splice(0, 1)
var args = parts
if (command in self.commands) {
self.commands[command].run(args)
}
})
var show = function(text) {
ev.trigger('disp_add', text)
}
this.prompt = 'pgs $ '
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) { show(this.help); return }
show('Site by Weiyi Lou ' + new Date().getFullYear())
}
},
'clear': {
'help': 'Clears the screen\nUsage: clear',
'run' : function(args) {
ev.trigger('disp_clear')
}
},
'version': {
'help': 'Shell Information\nUsage: version',
'run': function(args) {
if (args.length > 0) { show(this.help); return }
show('Parsley Gardens Shell (pgsh) 1.0.0. Built with Riot.js')
}
},
'git': {
'help': 'Link to Code Repository\nUsage: git',
'run': function(args) {
if (args.length > 0) { show(this.help); return }
show('Self-Hosted Code Repository at code.parsleygardens.net')
}
},
'hello': {
'help': 'Say hello to the computer\nUsage: hello [name]',
'run': function(args) {
address = args.join(' ').trim()
if (address.length == 0) {
show('Hello to you too')
} else if (address == 'pgsh') {
show('Hello human')
} else {
show('My name is not "' + address + '"')
}
}
},
'magic': {
'help': 'Link to Artist\nUsage: magic',
'run': function(args) {
if (args.length > 0) { show(this.help); return }
show('Animation and Illustration at slightlymagic.com.au')
}
},
'su': {
'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
'run': function(args) {
if (args.length > 0) { show(this.help); return }
if (!self.su) {
self.su = true
ev.trigger('prompt_set', 'root % ')
show('With Great Power comes Great')
}
}
},
'exit': {
'help': 'Leave the current context\nUsage: exit',
'run': function(args) {
if (args.length > 0) { show(this.help); return }
if (self.su) {
self.su = false
ev.trigger('prompt_set', self.prompt)
return
}
show('Close browser window to exit')
}
},
'search': {
'help': 'Search the Web (with a Duck)\nUsage: search [query]',
'run': function(args) {
if (!args.join(' ').trim()) { show(this.help); return }
ev.trigger('prompt_hide')
show('Searching for "' + args.join(' ') + '" in new window...')
setTimeout(function() {
window.open('https://duckduckgo.com/?q=' + args.join('+'), '_blank')
ev.trigger('prompt_show')
}, 1000)
}
},
'questions': {
'help': 'Answer some questions!\nUsage: questions',
'run': function(input) {
if (!self.active) {
self.active = 'questions'
ev.trigger('disp_hide')
ev.trigger('prompt_hide')
show('Welcome to the questions. Do you want to continue?')
return
}
if (input != 'exit') {
ev.trigger('disp_set', 'You answered with "' + input + '"!\nNext question!\n(Type "exit" to end)\n\n')
var rand = Math.floor(Math.random() * this.questions.length);
show(this.questions[rand])
} else {
ev.trigger('disp_restore')
ev.trigger('prompt_show')
show('Thanks for answering questions!')
self.active = ''
}
},
'questions': [
'Isn\'t this song 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) {
command = args.join(' ').trim()
if (command in self.commands) {
show(self.commands[command].help)
} else if (command) {
show('Command not found: ' + command)
} else {
var commands = [];
for(var name in self.commands) {
commands.push(name)
}
show('Available commands:\n' + commands.sort().join(' ') + '\n\n`help [command]` for more information.')
}
}
}
}
}