Преглед на файлове

Initial commit

Pretend command line created using RiotJS.
Weiyi Lou преди 10 години
ревизия
fc5ef3123d
променени са 7 файла, в които са добавени 201 реда и са изтрити 0 реда
  1. 8 0
      README.md
  2. 9 0
      css/style.css
  3. 20 0
      index.html
  4. 50 0
      js/pgsh.js
  5. 30 0
      js/vendor/he.js
  6. 1 0
      js/vendor/riot+compiler.min.js
  7. 83 0
      tags/terminal.tag

+ 8 - 0
README.md

@@ -0,0 +1,8 @@
+# Parsley Gardens Command Line Interface
+
+It is really just the main website of [parsleygardens.net][].
+
+Built with [Riot.js][].
+
+[parsleygardens.net]: http://www.parsleygardens.net
+[Riot.js]: http://riotjs.com/

+ 9 - 0
css/style.css

@@ -0,0 +1,9 @@
+* {
+  font-family: 'Courier New', Courier, Monospace;
+  font-size: 1em;
+  color: #DDD;
+}
+
+body {
+  background: #222;
+}

+ 20 - 0
index.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN' 'http://www.w3.org/TR/REC-html40/loose.dtd'>
+<html>
+  <head>
+    <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>
+    <title>
+      Prompt
+    </title>
+    <link rel='stylesheet' type='text/css' href='css/style.css' />
+    <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>
+  </head>
+<body>
+  <div class='sc-content'>
+    <terminal shell='pgsh' welcome='Linux parsleygardens.net 3.4.5-6-7-i286 #8 PGS Vimputer 3.4.56-7 i286<br /><br />~ Welcome to Parsley Gardens! ~<br />"He maketh me to lie down in green pa..."<br /><br />Enter "help" for list of commands'></terminal>
+  </div>
+</body>
+</html>

+ 50 - 0
js/pgsh.js

@@ -0,0 +1,50 @@
+function pgsh() {
+  this.prompt = '$'
+  this.responses = {
+    'about': function() {
+      return 'This website belongs to Weiyi Lou ' + new Date().getFullYear()
+    },
+    'version': function() {
+      return 'Parsley Gardens Shell (pgsh) 1.0.0'
+    },
+    'git': function() {
+      return 'Self-Hosted Code repository at <a target="_blank" href="https://code.parsleygardens.net">code.parsleygardens.net</a>'
+    },
+    'hello': function() {
+      return 'Hello to you too'
+    },
+    'magic': function() {
+      return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
+    },
+    'su': function() {
+      this.Parent.prompt = '%'
+      return 'With Great Power comes Great'
+    },
+    'exit': function() {
+      if (this.Parent.prompt == '%') {
+        this.Parent.prompt = '$'
+        return ''
+      }
+      return 'Close browser window to exit'
+    },
+    'help': function() {
+      var functions = [];
+      for(var name in this.Parent.responses) {
+        if (name !== 'Parent') {
+          functions.push(name);
+        }
+      }
+      functions.sort();
+      return 'Available commands:\n' + functions.join(' ')
+    }
+  }
+  this.process = function(input) {
+    var output = ''
+    if (input in this.responses) {
+      this.responses.Parent = this
+      output += this.responses[input]()
+    }
+    return output
+  }
+}
+var pgsh = new pgsh()

Файловите разлики са ограничени, защото са твърде много
+ 30 - 0
js/vendor/he.js


Файловите разлики са ограничени, защото са твърде много
+ 1 - 0
js/vendor/riot+compiler.min.js


+ 83 - 0
tags/terminal.tag

@@ -0,0 +1,83 @@
+<terminal>
+  <history welcome={ opts.welcome } />
+  <commandline prompt={ opts.prompt }/>
+
+  this.on('mount', function() {
+    this.setshell()
+    this.tags.commandline.setprompt(this.shell.prompt)
+  })
+
+  setshell() {
+    var shell = { 'process': function() { return ''; } }
+    if (opts.shell !== undefined && window[opts.shell] !== undefined) {
+      shell = window[opts.shell]
+    }
+    this.shell = shell
+  }
+
+  process(prompt, input) {
+    var input = he.encode(input)
+    var output = prompt + ' ' + input + '\n'
+    output += this.shell.process(input)
+    this.tags.history.add(output)
+    this.tags.commandline.setprompt(this.shell.prompt)
+    this.tags.commandline.command.value = ''
+  }
+</terminal>
+
+<commandline>
+  <form autocomplete='off' onsubmit={ process }>
+    { prompt } <input type='text' id='command' />
+  </form>
+
+  <style>
+    #command {
+      background: transparent;
+      border: none; outline: none;
+      padding: 0; margin: 0;
+      width: 90%;
+    }
+  </style>
+
+  this.on('mount', function() {
+    document.getElementById('command').focus()
+  })
+
+  setprompt(value) {
+    if (value) {
+      this.prompt = value
+      this.update()
+    }
+  }
+
+  this.prompt = '$'
+  this.setprompt(opts.prompt)
+
+  process(e) {
+    this.parent.process(this.prompt, this.command.value)
+  }
+</commandline>
+
+<history>
+  <div each={ hist }>
+    <raw content={ content } />
+  </div>
+
+  this.hist = []
+
+  add(output) {
+    output = output.replace(/(?:\r\n|\r|\n)/g, '<br />');
+    this.hist.push({ 'content': output })
+    this.update()
+  }
+
+  if ( opts.welcome !== undefined) {
+    this.add(opts.welcome)
+  }
+</history>
+
+<raw>
+  <span></span>
+
+  this.root.innerHTML = opts.content
+</raw>

Някои файлове не бяха показани, защото твърде много файлове са промени