terminal.tag 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <terminal>
  2. <history welcome={ welcome } />
  3. <commandline prompt={ prompt } />
  4. var shell = { 'process': function() { return ''; } }
  5. this.shell = window[opts.shell] ? window[opts.shell] : shell
  6. this.welcome = this.shell.welcome ? this.shell.welcome : opts.welcome
  7. this.prompt = this.shell.prompt ? this.shell.prompt : opts.prompt
  8. process(prompt, input) {
  9. var input = he.encode(input)
  10. var output = prompt + ' ' + input + '\n'
  11. output += this.shell.process(input)
  12. this.tags.history.add(output)
  13. this.tags.commandline.setprompt(this.shell.prompt)
  14. this.tags.commandline.command.value = ''
  15. }
  16. </terminal>
  17. <commandline>
  18. <form autocomplete='off' onsubmit={ process }>
  19. <raw name='lhs' content={ prompt } /><input type='text' name='command' />
  20. </form>
  21. <style>
  22. input[name='command'] {
  23. background: transparent;
  24. border: none; outline: none;
  25. padding: 0; margin: 0;
  26. width: 90%;
  27. }
  28. </style>
  29. this.on('mount', function() {
  30. document.getElementsByName('command')[0].focus()
  31. })
  32. setprompt(value) {
  33. if (value) {
  34. if (typeof this.tags.lhs.write != 'undefined') {
  35. this.tags.lhs.write(value)
  36. }
  37. this.update({ 'prompt': value })
  38. }
  39. }
  40. process(e) {
  41. this.parent.process(this.prompt, this.command.value)
  42. }
  43. this.prompt = '$ '
  44. this.setprompt(opts.prompt)
  45. </commandline>
  46. <history>
  47. <div each={ hist }>
  48. <raw content={ content } />
  49. </div>
  50. add(output) {
  51. if (output) {
  52. output = output.replace(/(?:\r\n|\r|\n)/g, '<br />');
  53. this.hist.push({ 'content': output })
  54. this.update()
  55. }
  56. }
  57. this.hist = []
  58. this.add(opts.welcome)
  59. </history>
  60. <raw>
  61. <span></span>
  62. write(value) {
  63. this.root.innerHTML = value
  64. }
  65. this.write(opts.content)
  66. </raw>