frontend.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Observable, Subject, AsyncSubject, ReplaySubject, BehaviorSubject } from 'rxjs'
  2. import { ResizeEvent } from '../api'
  3. import { ConfigService, ThemesService, HotkeysService } from 'terminus-core'
  4. /**
  5. * Extend to add support for a different VT frontend implementation
  6. */
  7. export abstract class Frontend {
  8. configService: ConfigService
  9. themesService: ThemesService
  10. hotkeysService: HotkeysService
  11. enableResizing = true
  12. protected ready = new AsyncSubject<void>()
  13. protected title = new ReplaySubject<string>(1)
  14. protected alternateScreenActive = new BehaviorSubject<boolean>(false)
  15. protected mouseEvent = new Subject<MouseEvent>()
  16. protected bell = new Subject<void>()
  17. protected contentUpdated = new Subject<void>()
  18. protected input = new Subject<string>()
  19. protected resize = new ReplaySubject<ResizeEvent>(1)
  20. protected dragOver = new Subject<DragEvent>()
  21. protected drop = new Subject<DragEvent>()
  22. get ready$ (): Observable<void> { return this.ready }
  23. get title$ (): Observable<string> { return this.title }
  24. get alternateScreenActive$ (): Observable<boolean> { return this.alternateScreenActive }
  25. get mouseEvent$ (): Observable<MouseEvent> { return this.mouseEvent }
  26. get bell$ (): Observable<void> { return this.bell }
  27. get contentUpdated$ (): Observable<void> { return this.contentUpdated }
  28. get input$ (): Observable<string> { return this.input }
  29. get resize$ (): Observable<ResizeEvent> { return this.resize }
  30. get dragOver$ (): Observable<DragEvent> { return this.dragOver }
  31. get drop$ (): Observable<DragEvent> { return this.drop }
  32. abstract attach (host: HTMLElement): void
  33. detach (host: HTMLElement): void { } // tslint:disable-line
  34. destroy (): void {
  35. for (let o of [
  36. this.ready,
  37. this.title,
  38. this.alternateScreenActive,
  39. this.mouseEvent,
  40. this.bell,
  41. this.contentUpdated,
  42. this.input,
  43. this.resize,
  44. this.dragOver,
  45. this.drop,
  46. ]) {
  47. o.complete()
  48. }
  49. }
  50. abstract getSelection (): string
  51. abstract copySelection (): void
  52. abstract clearSelection (): void
  53. abstract focus (): void
  54. abstract write (data: string): void
  55. abstract clear (): void
  56. abstract visualBell (): void
  57. abstract scrollToBottom (): void
  58. abstract configure (): void
  59. abstract setZoom (zoom: number): void
  60. }