XtermVue.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <div class="xterm" />
  3. </template>
  4. <script>
  5. import 'xterm/css/xterm.css'
  6. import { Terminal } from 'xterm'
  7. import { FitAddon } from 'xterm-addon-fit'
  8. import { WebLinksAddon } from 'xterm-addon-web-links'
  9. import { Unicode11Addon } from 'xterm-addon-unicode11'
  10. export default {
  11. mounted() {
  12. this.$term = new Terminal({})
  13. this.$fitAddon = new FitAddon()
  14. this.$term.loadAddon(this.$fitAddon)
  15. this.$term.loadAddon(new WebLinksAddon())
  16. this.$term.loadAddon(new Unicode11Addon())
  17. this.$term.unicode.activeVersion = '11'
  18. this.$term.open(this.$el)
  19. this.$fitAddon.fit()
  20. this.$term.onTitleChange((title) => this.$emit('title-change', title))
  21. },
  22. methods: {
  23. fit() {
  24. this.$fitAddon.fit()
  25. },
  26. focus() {
  27. this.$term.focus()
  28. },
  29. blur() {
  30. this.$term.blur()
  31. },
  32. paste(data){
  33. this.$term.paste(data)
  34. }
  35. }
  36. }
  37. </script>
  38. <style scoped>
  39. .xterm {
  40. height: 100%;
  41. width: 100%;
  42. }
  43. </style>