pgsh.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. function pgsh() {
  2. this.prompt = '<span style="color:blueviolet">pgs </span><span style="color:green">$ </span>'
  3. this.welcome = '\
  4. Linux parsleygardens.net 3.4.5-6-7-i286 #8 PGS Vimputer 3.4.56-7 i286 \n\
  5. \n\
  6. ~ Welcome to Parsley Gardens! ~\n\
  7. "He maketh me to lie down in green pa..."\n\
  8. \n\
  9. Type "help" for list of commands\n\
  10. \n'
  11. this.commands = {
  12. 'about': {
  13. 'help': 'Author Information\nUsage: about',
  14. 'run': function(args) {
  15. if (args.length > 0) { return this.help }
  16. return 'Site by Weiyi Lou ' + new Date().getFullYear()
  17. }
  18. },
  19. 'clear': {
  20. 'help': 'Clears the screen\nUsage: clear',
  21. 'run' : function(args, shell, terminal) {
  22. terminal.display.clear()
  23. }
  24. },
  25. 'version': {
  26. 'help': 'Shell Information\nUsage: version',
  27. 'run': function(args) {
  28. if (args.length > 0) { return this.help }
  29. return 'Parsley Gardens Shell (pgsh) 1.0.0. Built with <a target="_blank" href="http://riotjs.com/">Riot.js</a>'
  30. }
  31. },
  32. 'git': {
  33. 'help': 'Link to Code Repository\nUsage: git',
  34. 'run': function(args) {
  35. if (args.length > 0) { return this.help }
  36. return 'Self-Hosted Code Repository at <a target="_blank" href="https://code.parsleygardens.net/explore/projects">code.parsleygardens.net</a>'
  37. }
  38. },
  39. 'hello': {
  40. 'help': 'Usage: hello [name]',
  41. 'run': function(args) {
  42. address = args.join(' ').trim()
  43. if (address.length == 0) {
  44. return 'Hello to you too'
  45. } else if (address == 'pgsh') {
  46. return 'Hello human'
  47. } else {
  48. return 'My name is not "' + address + '"'
  49. }
  50. }
  51. },
  52. 'magic': {
  53. 'help': 'Link to Artist\nUsage: magic',
  54. 'run': function(args) {
  55. if (args.length > 0) { return this.help }
  56. return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
  57. }
  58. },
  59. 'su': {
  60. 'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
  61. 'run': function(args, shell, terminal) {
  62. if (args.length > 0) { return this.help }
  63. var output = ''
  64. if (!shell.su) {
  65. terminal.commandline.setPrompt('<span style="color:tomato">root </span><span style="color:red">% </span>')
  66. shell.su = true
  67. output = 'With Great Power comes Great'
  68. }
  69. return output
  70. }
  71. },
  72. 'exit': {
  73. 'help': 'Usage: exit',
  74. 'run': function(args, shell, terminal) {
  75. if (args.length > 0) { return this.help }
  76. var output = 'Close browser window to exit'
  77. if (shell.su) {
  78. terminal.commandline.setPrompt(shell.prompt)
  79. shell.su = false
  80. output = ''
  81. }
  82. return output
  83. }
  84. },
  85. 'search': {
  86. 'help': 'Search the web\nUsage: search [query]',
  87. 'run': function(args, shell, terminal) {
  88. terminal.commandline.hidePrompt()
  89. setTimeout(function() {
  90. window.open('https://duckduckgo.com/?q=' + args.join('+'), '_blank')
  91. terminal.commandline.showPrompt()
  92. terminal.update()
  93. }, 1000)
  94. return 'Searching for "' + args.join(' ') + '" in new window...'
  95. }
  96. },
  97. 'questions': {
  98. 'help': 'Answer some questions!\nUsage: questions',
  99. 'run': function() {
  100. return {
  101. 'run': function(input, terminal) {
  102. if (!this.running) {
  103. this.running = true
  104. terminal.display.hide()
  105. terminal.display.add('Welcome to the questions. Do you wish to continue?')
  106. terminal.commandline.hidePrompt()
  107. return
  108. }
  109. if (input != 'exit') {
  110. terminal.display.set('You answered the last question with "' + input + '"!\nWould you like another question?\n(Type "exit" to end)')
  111. } else {
  112. this.running = false
  113. terminal.display.restore()
  114. terminal.display.add('Thanks for answering questions!')
  115. terminal.commandline.showPrompt()
  116. terminal.returnToShell()
  117. }
  118. }
  119. }
  120. }
  121. },
  122. 'help': {
  123. 'help': 'List all commands or view information for a command\nUsage: help [command]',
  124. 'run': function(args, shell) {
  125. command = args.join(' ').trim()
  126. if (command in shell.commands) {
  127. return shell.commands[command].help
  128. } else {
  129. var output = (command) ? 'Command not found: ' + command + '\n' : ''
  130. var commands = [];
  131. for(var name in shell.commands) {
  132. if (name !== 'Parent') { commands.push(name) }
  133. }
  134. output += 'Available commands:\n' + commands.sort().join(' ')
  135. return output
  136. }
  137. }
  138. }
  139. }
  140. this.run = function(input, terminal) {
  141. var parts = input.trim().split(' ')
  142. // First word is the command, all others are arguments.
  143. var command = parts.splice(0, 1)
  144. var args = parts
  145. var output = ''
  146. if (command in this.commands) {
  147. output = this.commands[command].run(args, this, terminal)
  148. }
  149. return output
  150. }
  151. }