mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-20 02:18:01 +00:00
rxjs cleanup
This commit is contained in:
@@ -11,8 +11,8 @@ export abstract class TerminalDecorator {
|
||||
}
|
||||
|
||||
export interface ResizeEvent {
|
||||
width: number
|
||||
height: number
|
||||
columns: number
|
||||
rows: number
|
||||
}
|
||||
|
||||
export interface SessionOptions {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Subject, Subscription } from 'rxjs'
|
||||
import { Observable, Subject, Subscription } from 'rxjs'
|
||||
import { first } from 'rxjs/operators'
|
||||
import { ToastrService } from 'ngx-toastr'
|
||||
import { Component, NgZone, Inject, Optional, ViewChild, HostBinding, Input } from '@angular/core'
|
||||
@@ -33,14 +33,18 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
termContainer: TermContainer
|
||||
sessionCloseSubscription: Subscription
|
||||
hotkeysSubscription: Subscription
|
||||
size: ResizeEvent
|
||||
output$ = new Subject<string>()
|
||||
htermVisible = false
|
||||
shell: IShell
|
||||
private output = new Subject<string>()
|
||||
private bellPlayer: HTMLAudioElement
|
||||
private contextMenu: any
|
||||
private termContainerSubscriptions: Subscription[] = []
|
||||
|
||||
get input$ (): Observable<string> { return this.termContainer.input$ }
|
||||
get output$ (): Observable<string> { return this.output }
|
||||
get resize$ (): Observable<ResizeEvent> { return this.termContainer.resize$ }
|
||||
get alternateScreenActive$ (): Observable<boolean> { return this.termContainer.alternateScreenActive$ }
|
||||
|
||||
constructor (
|
||||
private zone: NgZone,
|
||||
private app: AppService,
|
||||
@@ -129,7 +133,7 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
// this.session.output$.bufferTime(10).subscribe((datas) => {
|
||||
this.session.output$.subscribe(data => {
|
||||
this.zone.run(() => {
|
||||
this.output$.next(data)
|
||||
this.output.next(data)
|
||||
this.write(data)
|
||||
})
|
||||
})
|
||||
@@ -181,7 +185,7 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
this.output$.subscribe(() => {
|
||||
this.output.subscribe(() => {
|
||||
this.displayActivity()
|
||||
})
|
||||
}, 1000)
|
||||
@@ -278,7 +282,6 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
this.termContainer.resize$.subscribe(({columns, rows}) => {
|
||||
console.log(`Resizing to ${columns}x${rows}`)
|
||||
this.zone.run(() => {
|
||||
this.size = { width: columns, height: rows }
|
||||
if (this.session.open) {
|
||||
this.session.resize(columns, rows)
|
||||
}
|
||||
@@ -341,7 +344,7 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
if (this.sessionCloseSubscription) {
|
||||
this.sessionCloseSubscription.unsubscribe()
|
||||
}
|
||||
this.output$.complete()
|
||||
this.output.complete()
|
||||
}
|
||||
|
||||
async destroy () {
|
||||
|
@@ -20,32 +20,33 @@ export abstract class BaseSession {
|
||||
name: string
|
||||
recoveryId: string
|
||||
truePID: number
|
||||
output$: Observable<string>
|
||||
closed$: Observable<void>
|
||||
destroyed$: Observable<void>
|
||||
protected output_ = new Subject<string>()
|
||||
protected closed_ = new Subject<void>()
|
||||
protected destroyed_ = new Subject<void>()
|
||||
protected output = new Subject<string>()
|
||||
protected closed = new Subject<void>()
|
||||
protected destroyed = new Subject<void>()
|
||||
private initialDataBuffer = ''
|
||||
private initialDataBufferReleased = false
|
||||
|
||||
get output$ (): Observable<string> { return this.output }
|
||||
get closed$ (): Observable<void> { return this.closed }
|
||||
get destroyed$ (): Observable<void> { return this.destroyed }
|
||||
|
||||
constructor () {
|
||||
this.output$ = this.output_.asObservable()
|
||||
this.closed$ = this.closed_.asObservable()
|
||||
this.destroyed$ = this.destroyed_.asObservable()
|
||||
this.output$ = this.output.asObservable()
|
||||
this.closed$ = this.closed.asObservable()
|
||||
this.destroyed$ = this.destroyed.asObservable()
|
||||
}
|
||||
|
||||
emitOutput (data: string) {
|
||||
if (!this.initialDataBufferReleased) {
|
||||
this.initialDataBuffer += data
|
||||
} else {
|
||||
this.output_.next(data)
|
||||
this.output.next(data)
|
||||
}
|
||||
}
|
||||
|
||||
releaseInitialDataBuffer () {
|
||||
this.initialDataBufferReleased = true
|
||||
this.output_.next(this.initialDataBuffer)
|
||||
this.output.next(this.initialDataBuffer)
|
||||
this.initialDataBuffer = null
|
||||
}
|
||||
|
||||
@@ -60,9 +61,9 @@ export abstract class BaseSession {
|
||||
async destroy (): Promise<void> {
|
||||
if (this.open) {
|
||||
this.open = false
|
||||
this.closed_.next()
|
||||
this.destroyed_.next()
|
||||
this.output_.complete()
|
||||
this.closed.next()
|
||||
this.destroyed.next()
|
||||
this.output.complete()
|
||||
await this.gracefullyKillProcess()
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,11 @@ import { TerminalTabComponent } from '../components/terminalTab.component'
|
||||
|
||||
@Injectable()
|
||||
export class TerminalService {
|
||||
shells$: Observable<IShell[]>
|
||||
private shells_ = new AsyncSubject<IShell[]>()
|
||||
private shells = new AsyncSubject<IShell[]>()
|
||||
private logger: Logger
|
||||
|
||||
get shells$ (): Observable<IShell[]> { return this.shells }
|
||||
|
||||
constructor (
|
||||
private app: AppService,
|
||||
private sessions: SessionsService,
|
||||
@@ -27,11 +28,11 @@ export class TerminalService {
|
||||
}
|
||||
|
||||
async reloadShells () {
|
||||
this.shells_ = new AsyncSubject<IShell[]>()
|
||||
this.shells$ = this.shells_.asObservable()
|
||||
this.shells = new AsyncSubject<IShell[]>()
|
||||
this.shells$ = this.shells.asObservable()
|
||||
let shellLists = await Promise.all(this.config.enabledServices(this.shellProviders).map(x => x.provide()))
|
||||
this.shells_.next(shellLists.reduce((a, b) => a.concat(b)))
|
||||
this.shells_.complete()
|
||||
this.shells.next(shellLists.reduce((a, b) => a.concat(b)))
|
||||
this.shells.complete()
|
||||
}
|
||||
|
||||
async openTab (shell?: IShell, cwd?: string): Promise<TerminalTabComponent> {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Observable, Subject, AsyncSubject, ReplaySubject, BehaviorSubject } from 'rxjs'
|
||||
import { ResizeEvent } from '../api'
|
||||
|
||||
export abstract class TermContainer {
|
||||
enableResizing = true
|
||||
@@ -9,7 +10,7 @@ export abstract class TermContainer {
|
||||
protected bell = new Subject<void>()
|
||||
protected contentUpdated = new Subject<void>()
|
||||
protected input = new Subject<string>()
|
||||
protected resize = new ReplaySubject<{columns: number, rows: number}>(1)
|
||||
protected resize = new ReplaySubject<ResizeEvent>(1)
|
||||
protected dragOver = new Subject<DragEvent>()
|
||||
protected drop = new Subject<DragEvent>()
|
||||
|
||||
@@ -20,7 +21,7 @@ export abstract class TermContainer {
|
||||
get bell$ (): Observable<void> { return this.bell }
|
||||
get contentUpdated$ (): Observable<void> { return this.contentUpdated }
|
||||
get input$ (): Observable<string> { return this.input }
|
||||
get resize$ (): Observable<{columns: number, rows: number}> { return this.resize }
|
||||
get resize$ (): Observable<ResizeEvent> { return this.resize }
|
||||
get dragOver$ (): Observable<DragEvent> { return this.dragOver }
|
||||
get drop$ (): Observable<DragEvent> { return this.drop }
|
||||
|
||||
|
Reference in New Issue
Block a user