Просмотр исходного кода

Add CLI hiding & command text editing, update Riot

New Riot means we no longer have to disassociate display `output` before
setting it to a new context, though there is apparently a performance
difference.
Weiyi Lou 10 лет назад
Родитель
Сommit
fb1567d3cb
2 измененных файлов с 57 добавлено и 26 удалено
  1. 0 1
      js/vendor/riot+compiler.min.js
  2. 57 25
      tags/terminal.tag

Разница между файлами не показана из-за своего большого размера
+ 0 - 1
js/vendor/riot+compiler.min.js


+ 57 - 25
tags/terminal.tag

@@ -7,7 +7,7 @@
  *
  *
  * ## Dependencies
  * ## Dependencies
  *
  *
- * - riot.js (http://riotjs.com/)
+ * - Riot 2.3+ (http://riotjs.com/)
  *
  *
  * ## Usage
  * ## Usage
  *
  *
@@ -53,12 +53,16 @@
  *
  *
  * The observable provides events to make things happen:
  * The observable provides events to make things happen:
  *
  *
- *     events.trigger('disp_add', text)      // Append `text` to the display
- *     events.trigger('disp_set', text)      // Display only `text`
- *     events.trigger('disp_clear')          // Clear the display
- *     events.trigger('prompt_set', text)    // Change the prompt to `text`
- *     events.trigger('prompt_hide')         // Hide the command prompt
- *     events.trigger('prompt_show')         // Show the command prompt
+ *     events.trigger('disp_add', text)   // Append `text` to the display
+ *     events.trigger('disp_set', text)   // Display only `text`
+ *     events.trigger('disp_clear')       // Clear the display
+ *     events.trigger('prompt_set', text) // Change the prompt to `text`
+ *     events.trigger('prompt_hide')      // Hide the command prompt
+ *     events.trigger('prompt_show')      // Show the command prompt
+ *     events.trigger('cmd_add', text)    // Append `text` to the command line
+ *     events.trigger('cmd_set', text)    // Set the command line to `text`
+ *     events.trigger('cli_hide')         // Hide the command line and prompt
+ *     events.trigger('cli_show')         // Show the command line and prompt
  *
  *
  * There is also an event to swap between sets of displays and prompts:
  * There is also an event to swap between sets of displays and prompts:
  *
  *
@@ -131,7 +135,6 @@
     if (!(name in self.contexts)) {
     if (!(name in self.contexts)) {
       self.contexts[name] = []
       self.contexts[name] = []
     }
     }
-    self.update({ output: [] }) // Cleanly disassociate current output first.
     self.update({ output: self.contexts[name] })
     self.update({ output: self.contexts[name] })
   })
   })
 
 
@@ -150,8 +153,8 @@
 </display>
 </display>
 
 
 <commandline>
 <commandline>
-  <form autocomplete='off' onsubmit={ process }>
-    <raw name='lhs' content={ prompt.text } show={ prompt.visible }>
+  <form autocomplete='off' onsubmit={ process } show={ visible }>
+    <raw name='lhs' content={ prompt } show={ prompt_visible }>
     </raw><input type='text' name='command' />
     </raw><input type='text' name='command' />
   </form>
   </form>
 
 
@@ -169,41 +172,70 @@
   var ev = opts.events
   var ev = opts.events
   var self = this
   var self = this
   this.contexts = {}
   this.contexts = {}
-  this.prompt = this.contexts['default'] = {
-    text: opts.prompt || '$ ',
-    visible: true
-  }
+  this.current = 'default'
+  this.visible = true
+  this.prompt = opts.prompt || '$ '
+  this.prompt_visible = true
 
 
   this.on('mount', function() {
   this.on('mount', function() {
     this.command.focus()
     this.command.focus()
   })
   })
 
 
-  ev.on('prompt_set', function(value) {
-    self.prompt.text = value
-    self.tags.lhs.write(value)
+  ev.on('prompt_set', function(text) {
+    self.prompt = text
+    self.tags.lhs.write(text)
   })
   })
 
 
   ev.on('prompt_hide', function() {
   ev.on('prompt_hide', function() {
-    self.prompt.visible = false
-    self.update()
+    self.update({ prompt_visible: false })
   })
   })
 
 
   ev.on('prompt_show', function() {
   ev.on('prompt_show', function() {
-    self.prompt.visible = true
-    self.update()
+    self.update({ prompt_visible: true })
+  })
+
+  ev.on('cmd_add', function(text) {
+    self.command.value += text
+  })
+
+  ev.on('cmd_set', function(text) {
+    self.command.value = text
+  })
+
+  ev.on('cli_hide', function() {
+    self.update({ visible: false })
+  })
+
+  ev.on('cli_show', function() {
+    self.update({ visible: true })
+    self.command.focus()
   })
   })
 
 
   ev.on('context_swap', function(name) {
   ev.on('context_swap', function(name) {
     name = name || 'default'
     name = name || 'default'
     if (!(name in self.contexts)) {
     if (!(name in self.contexts)) {
-      self.contexts[name] = { text: '', visible: true }
+      self.contexts[name] = { visible: true, prompt: '', prompt_visible: true }
+    }
+    // Save current values.
+    self.contexts[self.current] = {
+      visible: self.visible,
+      prompt: self.prompt,
+      prompt_visible: self.prompt_visible
+    }
+    // Load next context.
+    self.visible = self.contexts[name].visible
+    self.prompt = self.contexts[name].prompt
+    self.prompt_visible = self.contexts[name].prompt_visible
+    // Update the display.
+    self.current = name
+    self.tags.lhs.write(self.prompt)
+    if (self.visible) {
+      self.command.focus()
     }
     }
-    self.prompt = self.contexts[name]
-    self.tags.lhs.write(self.prompt.text)
   })
   })
 
 
   process() {
   process() {
-    var prompt = this.prompt.visible ? this.prompt.text : ''
+    var prompt = this.prompt_visible ? this.prompt : ''
     var command = this.encode(this.command.value)
     var command = this.encode(this.command.value)
     ev.trigger('disp_add', prompt + command + '\n')
     ev.trigger('disp_add', prompt + command + '\n')
     ev.trigger('cmd_entered', command)
     ev.trigger('cmd_entered', command)

Некоторые файлы не были показаны из-за большого количества измененных файлов