pgsh.js 5.3 KB

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