context menu (fixes #42)

This commit is contained in:
Eugene Pankov
2017-09-09 21:42:48 +02:00
parent 558c72bb42
commit e255ca7737
8 changed files with 974 additions and 23 deletions

View File

@@ -1,25 +1,37 @@
import { Injectable } from '@angular/core'
import { AppService, Logger, LogService } from 'terminus-core'
import { IShell } from '../api'
import { AsyncSubject } from 'rxjs'
import { Injectable, Inject } from '@angular/core'
import { AppService, Logger, LogService, ConfigService } from 'terminus-core'
import { IShell, ShellProvider } from '../api'
import { SessionsService } from './sessions.service'
import { TerminalTabComponent } from '../components/terminalTab.component'
@Injectable()
export class TerminalService {
shells$ = new AsyncSubject<IShell[]>()
private logger: Logger
constructor (
private app: AppService,
private sessions: SessionsService,
private config: ConfigService,
@Inject(ShellProvider) shellProviders: ShellProvider[],
log: LogService,
) {
this.logger = log.create('terminal')
Promise.all(shellProviders.map(x => x.provide())).then(shellLists => {
this.shells$.next(shellLists.reduce((a, b) => a.concat(b)))
this.shells$.complete()
})
}
async openTab (shell: IShell, cwd?: string): Promise<TerminalTabComponent> {
async openTab (shell?: IShell, cwd?: string): Promise<TerminalTabComponent> {
if (!cwd && this.app.activeTab instanceof TerminalTabComponent) {
cwd = await this.app.activeTab.session.getWorkingDirectory()
}
if (!shell) {
let shells = await this.shells$.toPromise()
shell = shells.find(x => x.id === this.config.store.terminal.shell) || shells[0]
}
let env: any = Object.assign({}, process.env, shell.env || {})
this.logger.log(`Starting shell ${shell.name}`, shell)
@@ -34,7 +46,7 @@ export class TerminalService {
return this.app.openNewTab(
TerminalTabComponent,
{ sessionOptions }
{ sessionOptions, shell }
) as TerminalTabComponent
}
}