mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-04 22:14:55 +00:00
.
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import 'rxjs'
|
||||
import { Observable } from 'rxjs'
|
||||
import * as fs from 'fs-promise'
|
||||
const fontManager = require('font-manager')
|
||||
import * as path from 'path'
|
||||
const equal = require('deep-equal')
|
||||
const fontManager = require('font-manager')
|
||||
const { exec } = require('child-process-promise')
|
||||
|
||||
import { Component, Inject } from '@angular/core'
|
||||
import { ConfigService, HostAppService, Platform } from 'terminus-core'
|
||||
import { TerminalColorSchemeProvider, ITerminalColorScheme } from '../api'
|
||||
|
||||
let Registry = null
|
||||
try {
|
||||
Registry = require('winreg')
|
||||
} catch (_) { }
|
||||
|
||||
interface IShell {
|
||||
name: string
|
||||
@@ -58,6 +62,19 @@ export class TerminalSettingsTabComponent {
|
||||
if (await fs.exists(wslPath)) {
|
||||
this.shells.push({ name: 'Bash on Windows', command: wslPath })
|
||||
}
|
||||
|
||||
let cygwinPath = await new Promise<string>(resolve => {
|
||||
let reg = new Registry({ hive: Registry.HKLM, key: "\\Software\\Cygwin\\setup" })
|
||||
reg.get('rootdir', (err, item) => {
|
||||
if (err) {
|
||||
resolve(null)
|
||||
}
|
||||
resolve(item.value)
|
||||
})
|
||||
})
|
||||
if (cygwinPath) {
|
||||
this.shells.push({ name: 'Cygwin', command: path.join(cygwinPath, 'bin', 'bash.exe') })
|
||||
}
|
||||
}
|
||||
if (this.hostApp.platform == Platform.Linux || this.hostApp.platform == Platform.macOS) {
|
||||
this.shells = (await fs.readFile('/etc/shells', 'utf-8'))
|
||||
|
@@ -16,6 +16,7 @@ import { hterm, preferenceManager } from '../hterm'
|
||||
export class TerminalTabComponent extends BaseTabComponent {
|
||||
hterm: any
|
||||
configSubscription: Subscription
|
||||
sessionCloseSubscription: Subscription
|
||||
bell$ = new Subject()
|
||||
size$ = new ReplaySubject<ResizeEvent>(1)
|
||||
input$ = new Subject<string>()
|
||||
@@ -70,7 +71,7 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
})
|
||||
this.write(data)
|
||||
})
|
||||
this.session.closed$.first().subscribe(() => {
|
||||
this.sessionCloseSubscription = this.session.closed$.subscribe(() => {
|
||||
this.app.closeTab(this)
|
||||
})
|
||||
|
||||
@@ -225,6 +226,7 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
decorator.detach(this)
|
||||
})
|
||||
this.configSubscription.unsubscribe()
|
||||
this.sessionCloseSubscription.unsubscribe()
|
||||
this.size$.complete()
|
||||
this.input$.complete()
|
||||
this.output$.complete()
|
||||
@@ -232,7 +234,10 @@ export class TerminalTabComponent extends BaseTabComponent {
|
||||
this.alternateScreenActive$.complete()
|
||||
this.mouseEvent$.complete()
|
||||
this.bell$.complete()
|
||||
}
|
||||
|
||||
this.session.gracefullyDestroy()
|
||||
async destroy () {
|
||||
super.destroy()
|
||||
await this.session.destroy()
|
||||
}
|
||||
}
|
||||
|
@@ -56,7 +56,9 @@ export class Session {
|
||||
})
|
||||
|
||||
this.pty.on('close', () => {
|
||||
this.close()
|
||||
if (this.open) {
|
||||
this.destroy()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,41 +76,40 @@ export class Session {
|
||||
this.pty.write(data)
|
||||
}
|
||||
|
||||
sendSignal (signal) {
|
||||
kill (signal?: string) {
|
||||
this.pty.kill(signal)
|
||||
}
|
||||
|
||||
close () {
|
||||
this.open = false
|
||||
this.closed$.next()
|
||||
this.pty.end()
|
||||
}
|
||||
|
||||
gracefullyDestroy () {
|
||||
return new Promise((resolve) => {
|
||||
this.sendSignal('SIGTERM')
|
||||
if (!this.open) {
|
||||
resolve()
|
||||
this.destroy()
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
if (this.open) {
|
||||
this.sendSignal('SIGKILL')
|
||||
this.destroy()
|
||||
async gracefullyKillProcess (): Promise<void> {
|
||||
if (process.platform == 'win32') {
|
||||
this.kill()
|
||||
} else {
|
||||
await new Promise((resolve) => {
|
||||
this.kill('SIGTERM')
|
||||
setImmediate(() => {
|
||||
if (!this.open) {
|
||||
resolve()
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
if (this.open) {
|
||||
this.kill('SIGKILL')
|
||||
}
|
||||
resolve()
|
||||
}, 1000)
|
||||
}
|
||||
resolve()
|
||||
}, 1000)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
destroy () {
|
||||
if (open) {
|
||||
this.close()
|
||||
async destroy (): Promise<void> {
|
||||
if (this.open) {
|
||||
this.open = false
|
||||
this.closed$.next()
|
||||
this.destroyed$.next()
|
||||
this.output$.complete()
|
||||
await this.gracefullyKillProcess()
|
||||
}
|
||||
this.destroyed$.next()
|
||||
this.pty.destroy()
|
||||
this.output$.complete()
|
||||
}
|
||||
|
||||
async getWorkingDirectory (): Promise<string> {
|
||||
|
Reference in New Issue
Block a user