|
|
@@ -7,7 +7,7 @@
|
|
|
*
|
|
|
* ## Dependencies
|
|
|
*
|
|
|
- * - riot.js (http://riotjs.com/)
|
|
|
+ * - Riot 2.3+ (http://riotjs.com/)
|
|
|
*
|
|
|
* ## Usage
|
|
|
*
|
|
|
@@ -53,12 +53,16 @@
|
|
|
*
|
|
|
* 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:
|
|
|
*
|
|
|
@@ -131,7 +135,6 @@
|
|
|
if (!(name in self.contexts)) {
|
|
|
self.contexts[name] = []
|
|
|
}
|
|
|
- self.update({ output: [] }) // Cleanly disassociate current output first.
|
|
|
self.update({ output: self.contexts[name] })
|
|
|
})
|
|
|
|
|
|
@@ -150,8 +153,8 @@
|
|
|
</display>
|
|
|
|
|
|
<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' />
|
|
|
</form>
|
|
|
|
|
|
@@ -169,41 +172,70 @@
|
|
|
var ev = opts.events
|
|
|
var self = this
|
|
|
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.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() {
|
|
|
- self.prompt.visible = false
|
|
|
- self.update()
|
|
|
+ self.update({ prompt_visible: false })
|
|
|
})
|
|
|
|
|
|
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) {
|
|
|
name = name || 'default'
|
|
|
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() {
|
|
|
- var prompt = this.prompt.visible ? this.prompt.text : ''
|
|
|
+ var prompt = this.prompt_visible ? this.prompt : ''
|
|
|
var command = this.encode(this.command.value)
|
|
|
ev.trigger('disp_add', prompt + command + '\n')
|
|
|
ev.trigger('cmd_entered', command)
|