pgsh.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. function pgsh(ev) {
  2. var self = this
  3. ev.on('cmd_entered', function(input) {
  4. // First word is the command, all others are arguments.
  5. var parts = input.trim().split(' ')
  6. var command = self.active ? self.active : parts.splice(0, 1).toString()
  7. var args = parts
  8. if (command in self.commands) {
  9. self[command](args)
  10. } else if (command) {
  11. show(command + ' not found')
  12. }
  13. })
  14. var show = function(text) { ev.trigger('disp_add', text) }
  15. var set = function(text) { ev.trigger('disp_set', text) }
  16. this.prompt = '<span style="color:blueviolet">pgs </span>' +
  17. '<span style="color:green">$ </span>'
  18. this.prompt_su = '<span style="color:tomato">root </span>' +
  19. '<span style="color:red">% </span>'
  20. this.welcome = 'Linux parsleygardens.net 3.4.5-6-7-i286 #8 PGS Vimputer ' +
  21. '3.4.56-7 i286\n\n' +
  22. '~ Welcome to Parsley Gardens! ~\n' +
  23. '"He maketh me to lie down in green pa..."\n\n' +
  24. 'Type `help` for list of commands\n\n'
  25. this.commands = {
  26. 'about': 'Author Information',
  27. 'clear': 'Clears the screen',
  28. 'version': 'Shell Information',
  29. 'git': 'Link to Code Repository',
  30. 'hello': 'Say hello to the computer\nUsage: hello [name]',
  31. 'magic': 'Link to Artist',
  32. 'su': 'Gain Phenomenal Cosmic Power',
  33. 'exit': 'Leave the current context',
  34. 'search': 'Search the Web (with a Duck)\nUsage: search [query]',
  35. 'questions': 'Answer some questions!',
  36. 'help': 'List commands or view information for one\nUsage: help [command]'
  37. }
  38. /**
  39. * The Commands
  40. */
  41. this.about = function(args) {
  42. show('Site by Weiyi Lou ' + new Date().getFullYear() + '\n')
  43. }
  44. this.clear = function(args) {
  45. ev.trigger('disp_clear')
  46. }
  47. this.version = function(args) {
  48. show('Parsley Gardens Shell (pgsh) 1.0.0 Built with ' +
  49. '<a target="_blank" href="http://riotjs.com/">Riot</a>')
  50. }
  51. this.git = function(args) {
  52. show('Code Repository at <a target="_blank" ' +
  53. 'href="https://code.parsleygardens.net/explore/projects">' +
  54. 'code.parsleygardens.net</a>')
  55. }
  56. this.hello = function(args) {
  57. address = args.join(' ').trim()
  58. if (address.length == 0) {
  59. show('Hello to you too')
  60. } else if (address == 'pgsh') {
  61. show('Hello human')
  62. } else {
  63. show('My name is not "' + address + '"')
  64. }
  65. }
  66. this.magic = function(args) {
  67. show('Animation and Illustration at <a target="_blank" ' +
  68. 'href="http://slightlymagic.com.au">slightlymagic.com.au</a>')
  69. }
  70. this.su = function(args) {
  71. if (self.su_active !== true) {
  72. self.su_active = true
  73. if (!self.su_warned) {
  74. self.su_warned = true
  75. show('We trust you have received the usual lecture from the ' +
  76. 'local System Administrator.\n' +
  77. 'It usually boils down to these three things:\n\n' +
  78. ' #1) Respect the privacy of others.\n' +
  79. ' #2) Think before you type.\n' +
  80. ' #3) With great power comes great\n\n')
  81. }
  82. ev.trigger('prompt_set', self.prompt_su)
  83. }
  84. }
  85. this.exit = function(args) {
  86. if (self.su_active) {
  87. self.su_active = false
  88. ev.trigger('prompt_set', self.prompt)
  89. return
  90. }
  91. show('Close browser window to exit')
  92. }
  93. this.search = function(args) {
  94. if (!args.join(' ').trim()) { return show(self.commands.search) }
  95. ev.trigger('prompt_hide')
  96. show('Searching for "' + args.join(' ') + '" in new window...')
  97. setTimeout(function() {
  98. window.open('https://duckduckgo.com/?q=' + args.join('+'), '_blank')
  99. ev.trigger('prompt_show')
  100. }, 1000)
  101. }
  102. this.questions = function(args) {
  103. if (!self.active) {
  104. self.active = 'questions'
  105. ev.trigger('context_swap', 'questions')
  106. set('Welcome to the questions. Do you want to continue?')
  107. return
  108. }
  109. if (args == 'exit') {
  110. self.active = ''
  111. ev.trigger('context_swap')
  112. show('Thanks for answering questions!')
  113. return
  114. }
  115. var questions = [
  116. 'Isn\'t <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"' +
  117. ' target="_blank">this song</a> the best?',
  118. '1 + 2 = ?',
  119. 'Am I a sandwich?',
  120. 'Where were you at 3:15am on April 14th?',
  121. "Don't you mean prism?",
  122. 'Butts twelve by pies?',
  123. 'I say there, Monstrosity. Do you know the times?',
  124. '...is essay-writing an exercise in masking ignorance?',
  125. 'What is the name of the spaces between the teeth of a comb?',
  126. 'Why are you dressed up like Ship\'s Captain?'
  127. ]
  128. set('You answered with "' + args + '"!\nNext question!\n' +
  129. '<span style="color:#555">(Type "exit" to end)</span>\n\n')
  130. var rand = Math.floor(Math.random() * questions.length);
  131. show(questions[rand])
  132. }
  133. this.help = function(args) {
  134. command = args.join(' ').trim()
  135. if (command in self.commands) {
  136. show(self.commands[command])
  137. } else if (command) {
  138. show('No information for: ' + command)
  139. } else {
  140. var commands = [];
  141. for(var name in self.commands) {
  142. commands.push(name)
  143. }
  144. show('Available commands:\n' + commands.sort().join(' ') +
  145. '\n\n`help [command]` for more information.')
  146. }
  147. }
  148. }