mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 14:34:54 +00:00
started separating terminus-electron and terminus-web
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injector } from '@angular/core'
|
||||
import { Observable, Subject, AsyncSubject, ReplaySubject, BehaviorSubject } from 'rxjs'
|
||||
import { ResizeEvent } from '../api/interfaces'
|
||||
import { ConfigService, ThemesService, HotkeysService } from 'terminus-core'
|
||||
|
||||
export interface SearchOptions {
|
||||
regex?: boolean
|
||||
@@ -13,10 +13,6 @@ export interface SearchOptions {
|
||||
* Extend to add support for a different VT frontend implementation
|
||||
*/
|
||||
export abstract class Frontend {
|
||||
configService: ConfigService
|
||||
themesService: ThemesService
|
||||
hotkeysService: HotkeysService
|
||||
|
||||
enableResizing = true
|
||||
protected ready = new AsyncSubject<void>()
|
||||
protected title = new ReplaySubject<string>(1)
|
||||
@@ -40,6 +36,8 @@ export abstract class Frontend {
|
||||
get dragOver$ (): Observable<DragEvent> { return this.dragOver }
|
||||
get drop$ (): Observable<DragEvent> { return this.drop }
|
||||
|
||||
constructor (protected injector: Injector) { }
|
||||
|
||||
destroy (): void {
|
||||
for (const o of [
|
||||
this.ready,
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { Injector } from '@angular/core'
|
||||
import { ConfigService, getCSSFontFamily, ThemesService } from 'terminus-core'
|
||||
import { Frontend, SearchOptions } from './frontend'
|
||||
import { hterm, preferenceManager } from './hterm'
|
||||
import { getCSSFontFamily } from 'terminus-core'
|
||||
|
||||
/** @hidden */
|
||||
export class HTermFrontend extends Frontend {
|
||||
@@ -13,6 +14,15 @@ export class HTermFrontend extends Frontend {
|
||||
private configuredBackgroundColor = 'transparent'
|
||||
private zoom = 0
|
||||
|
||||
private configService: ConfigService
|
||||
private themesService: ThemesService
|
||||
|
||||
constructor (injector: Injector) {
|
||||
super(injector)
|
||||
this.configService = injector.get(ConfigService)
|
||||
this.themesService = injector.get(ThemesService)
|
||||
}
|
||||
|
||||
async attach (host: HTMLElement): Promise<void> {
|
||||
if (!this.initialized) {
|
||||
this.init()
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { getCSSFontFamily } from 'terminus-core'
|
||||
import { Injector } from '@angular/core'
|
||||
import { ConfigService, getCSSFontFamily, HostAppService, HotkeysService, Platform, PlatformService } from 'terminus-core'
|
||||
import { Frontend, SearchOptions } from './frontend'
|
||||
import { Terminal, ITheme } from 'xterm'
|
||||
import { FitAddon } from 'xterm-addon-fit'
|
||||
@@ -39,8 +40,18 @@ export class XTermFrontend extends Frontend {
|
||||
private opened = false
|
||||
private resizeObserver?: any
|
||||
|
||||
constructor () {
|
||||
super()
|
||||
private configService: ConfigService
|
||||
private hotkeysService: HotkeysService
|
||||
private platformService: PlatformService
|
||||
private hostApp: HostAppService
|
||||
|
||||
constructor (injector: Injector) {
|
||||
super(injector)
|
||||
this.configService = injector.get(ConfigService)
|
||||
this.hotkeysService = injector.get(HotkeysService)
|
||||
this.platformService = injector.get(PlatformService)
|
||||
this.hostApp = injector.get(HostAppService)
|
||||
|
||||
this.xterm = new Terminal({
|
||||
allowTransparency: true,
|
||||
windowsMode: process.platform === 'win32',
|
||||
@@ -88,9 +99,11 @@ export class XTermFrontend extends Frontend {
|
||||
}
|
||||
|
||||
this.xterm.attachCustomKeyEventHandler((event: KeyboardEvent) => {
|
||||
if (event.getModifierState('Meta') && event.key.toLowerCase() === 'v') {
|
||||
event.preventDefault()
|
||||
return false
|
||||
if (this.hostApp.platform !== Platform.Web) {
|
||||
if (event.getModifierState('Meta') && event.key.toLowerCase() === 'v') {
|
||||
event.preventDefault()
|
||||
return false
|
||||
}
|
||||
}
|
||||
if (event.getModifierState('Meta') && event.key.startsWith('Arrow')) {
|
||||
return false
|
||||
@@ -167,6 +180,10 @@ export class XTermFrontend extends Frontend {
|
||||
host.addEventListener('mousedown', event => this.mouseEvent.next(event))
|
||||
host.addEventListener('mouseup', event => this.mouseEvent.next(event))
|
||||
host.addEventListener('mousewheel', event => this.mouseEvent.next(event as MouseEvent))
|
||||
host.addEventListener('contextmenu', event => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
})
|
||||
|
||||
this.resizeObserver = new window['ResizeObserver'](() => setTimeout(() => this.resizeHandler()))
|
||||
this.resizeObserver.observe(host)
|
||||
@@ -190,12 +207,12 @@ export class XTermFrontend extends Frontend {
|
||||
copySelection (): void {
|
||||
const text = this.getSelection()
|
||||
if (text.length < 1024 * 32) {
|
||||
require('@electron/remote').clipboard.write({
|
||||
this.platformService.setClipboard({
|
||||
text: this.getSelection(),
|
||||
html: this.getSelectionAsHTML(),
|
||||
})
|
||||
} else {
|
||||
require('@electron/remote').clipboard.write({
|
||||
this.platformService.setClipboard({
|
||||
text: this.getSelection(),
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user