|
|
@@ -18,7 +18,6 @@
|
|
|
* <terminal shell='myshellclass' welcome='text' prompt='text'></terminal>
|
|
|
*
|
|
|
* <script src='riot+compiler.min.js'></script>
|
|
|
- * <script src='he.js'></script>
|
|
|
* <script src='myshell.js'></script>
|
|
|
* <script src='terminal.tag' type='riot/tag'></script>
|
|
|
* <script>riot.mount('terminal')</script>
|
|
|
@@ -26,7 +25,6 @@
|
|
|
* ## Dependencies
|
|
|
*
|
|
|
* - riot.js (http://riotjs.com/)
|
|
|
- * - he.js (https://github.com/mathiasbynens/he) for HTML Entity conversion.
|
|
|
*
|
|
|
* ## Making A Shell Class
|
|
|
*
|
|
|
@@ -114,7 +112,7 @@
|
|
|
|
|
|
add(text) {
|
|
|
if (text) {
|
|
|
- text = this.preserveWhiteSpace(text)
|
|
|
+ text = text.replace(/\r\n|\r|\n/g, '<br />')
|
|
|
this.output.push({ 'content': text })
|
|
|
this.update()
|
|
|
}
|
|
|
@@ -124,16 +122,6 @@
|
|
|
this.output.length = 0
|
|
|
this.update()
|
|
|
}
|
|
|
-
|
|
|
- preserveWhiteSpace(text) {
|
|
|
- text = text.replace(/\r\n|\r|\n/g, '<br />')
|
|
|
- // Search for tags or whitespace. Escape whitespace, leave tags.
|
|
|
- text = text.replace(/<[^<]+>|( )/g, function(match, group1) {
|
|
|
- if (group1 == " ") { return ' ' }
|
|
|
- return match
|
|
|
- })
|
|
|
- return text
|
|
|
- }
|
|
|
</display>
|
|
|
|
|
|
<commandline>
|
|
|
@@ -142,11 +130,11 @@
|
|
|
</form>
|
|
|
|
|
|
<style>
|
|
|
- input[name='command'] {
|
|
|
+ commandline input[name='command'] {
|
|
|
background: transparent;
|
|
|
border: none; outline: none;
|
|
|
padding: 0; margin: 0;
|
|
|
- width: 90%;
|
|
|
+ width: 70%;
|
|
|
}
|
|
|
</style>
|
|
|
|
|
|
@@ -161,7 +149,6 @@
|
|
|
|
|
|
ev.on('prompt_set', function(value) {
|
|
|
self.prompt = value
|
|
|
- // `write()` is called to actually update the `raw` tag's html.
|
|
|
self.tags.lhs.write(value)
|
|
|
})
|
|
|
|
|
|
@@ -175,19 +162,31 @@
|
|
|
|
|
|
process() {
|
|
|
var prompt = this.visible ? this.prompt : ''
|
|
|
- var command = he.encode(this.command.value)
|
|
|
+ var command = this.encode(this.command.value)
|
|
|
this.command.value = ''
|
|
|
ev.trigger('disp_add', prompt + command + '\n')
|
|
|
ev.trigger('cmd_entered', command)
|
|
|
}
|
|
|
+
|
|
|
+ encode(text) {
|
|
|
+ return text.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')
|
|
|
+ }
|
|
|
</commandline>
|
|
|
|
|
|
<raw>
|
|
|
<span></span>
|
|
|
|
|
|
- // Initialise HTML from tag options and expose `write()` for updating.
|
|
|
+ <style>
|
|
|
+ raw { white-space: pre-wrap }
|
|
|
+ </style>
|
|
|
+
|
|
|
+ // Set the initial html using the `content` option.
|
|
|
+ this.on('mount', function() {
|
|
|
+ this.write(opts.content)
|
|
|
+ })
|
|
|
+
|
|
|
+ // Call `write()` manually to update the html.
|
|
|
write(text) {
|
|
|
this.root.innerHTML = text
|
|
|
}
|
|
|
- this.write(opts.content)
|
|
|
</raw>
|