Browse Source

Tidy up shell, remove he.js

Weiyi Lou 10 năm trước cách đây
mục cha
commit
fbab467f56
2 tập tin đã thay đổi với 59 bổ sung31 xóa
  1. 0 1
      index.html
  2. 59 30
      js/pgsh.js

+ 0 - 1
index.html

@@ -11,7 +11,6 @@
     <terminal shell='pgsh'></terminal>
 
     <script src='js/vendor/riot+compiler.min.js'></script>
-    <script src='js/vendor/he.js'></script>
     <script src='js/pgsh.js'></script>
     <script src='tags/terminal.tag' type='riot/tag'></script>
     <script>riot.mount('terminal')</script>

+ 59 - 30
js/pgsh.js

@@ -4,10 +4,12 @@ function pgsh(ev) {
   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 command = self.active ? self.active : parts.splice(0, 1).toString()
     var args = parts
     if (command in self.commands) {
       self.commands[command].run(args)
+    } else if (command) {
+      show(command + ' not found')
     }
   })
 
@@ -15,21 +17,21 @@ function pgsh(ev) {
     ev.trigger('disp_add', text)
   }
 
-  this.prompt = '<span style="color:blueviolet">pgs </span><span style="color:green">$ </span>'
-  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.prompt = '<span style="color:blueviolet">pgs </span>' +
+    '<span style="color:green">$ </span>'
+  var welc = '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.welcome = welc
   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())
+        var me = 'Site by Weiyi Lou ' + new Date().getFullYear() + '\n\n'
+        show(me)
       }
     },
     'clear': {
@@ -42,14 +44,19 @@ Type `help` for list of commands\n\
       '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 <a target="_blank" href="http://riotjs.com/">Riot.js</a>')
+        var ve = 'Parsley Gardens Shell (pgsh) 1.0.0 Built with ' +
+          '<a target="_blank" href="http://riotjs.com/">Riot.js</a>'
+        show(ve)
       }
     },
     '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 <a target="_blank" href="https://code.parsleygardens.net/explore/projects">code.parsleygardens.net</a>')
+        var repo = 'Self-Hosted Code Repository at <a target="_blank" ' +
+          'href="https://code.parsleygardens.net/explore/projects">' +
+        'code.parsleygardens.net</a>'
+        show(repo)
       }
     },
     'hello': {
@@ -69,17 +76,30 @@ Type `help` for list of commands\n\
       'help': 'Link to Artist\nUsage: magic',
       'run': function(args) {
         if (args.length > 0) { show(this.help); return }
-        show('Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>')
+        var art = 'Animation and Illustration at <a target="_blank" ' +
+          'href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
+        show(art)
       }
     },
     'su': {
-      'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
+      'help': 'Gain 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', '<span style="color:tomato">root </span><span style="color:red">% </span>')
-          show('With Great Power comes Great')
+          if (!self.su_warned) {
+            self.su_warned = true
+            var wa = 'We trust you have received the usual lecture from the ' +
+              'local System Administrator.\n' +
+              'It usually boils down to these three things:\n\n' +
+              '    #1) Respect the privacy of others.\n' +
+              '    #2) Think before you type.\n' +
+              '    #3) With great power comes great\n\n'
+            show(wa)
+          }
+          var p = '<span style="color:tomato">root </span>'
+          p += '<span style="color:red">% </span>'
+          ev.trigger('prompt_set', p)
         }
       }
     },
@@ -109,7 +129,7 @@ Type `help` for list of commands\n\
     },
     'questions': {
       'help': 'Answer some questions!\nUsage: questions',
-      'run': function(input) {
+      'run': function(args) {
         if (!self.active) {
           self.active = 'questions'
           ev.trigger('disp_hide')
@@ -117,41 +137,50 @@ Type `help` for list of commands\n\
           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<span style="color:#555">(Type "exit" to end)</span>\n\n')
-          var rand = Math.floor(Math.random() * this.questions.length);
-          show(this.questions[rand])
-        } else {
+        if (args == 'exit') {
+          self.active = ''
           ev.trigger('disp_restore')
           ev.trigger('prompt_show')
           show('Thanks for answering questions!')
-          self.active = ''
+          return
         }
+        var output = 'You answered with "' + args + '"!\nNext question!\n' +
+          '<span style="color:#555">(Type "exit" to end)</span>\n\n'
+        ev.trigger('disp_set', output)
+        var rand = Math.floor(Math.random() * this.questions.length);
+        show(this.questions[rand])
       },
       'questions': [
-        'Isn\'t <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ" target="_blank">this song</a> the best?',
-        'Iggledy Piggledy',
+        'Isn\'t <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"' +
+        ' target="_blank">this song</a> 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?'
+        'Butts twelve by pies?',
+        'I say there, Monstrosity. Do you know the times?',
+        '...is essay-writing an exercise in masking ignorance?',
+        'What is the name of the spaces. Between the teeth. Of a comb?',
+        'Why are you dressed up like Ship\'s Captain?'
       ]
     },
     'help': {
-      'help': 'List available commands or view information for a given command\nUsage: help [command]',
+      '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)
+          show('No information for: ' + 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.')
+          show('Available commands:\n' + commands.sort().join(' ') +
+               '\n\n`help [command]` for more information.')
         }
       }
     }