terminal.tag 1.7 KB

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