pgsh.js 6.2 KB

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