mirror of
https://github.com/Eugeny/tabby.git
synced 2025-02-17 14:49:39 +08:00
expose TerminalService
This commit is contained in:
parent
1c62f3074c
commit
41b6e1d54e
@ -108,8 +108,9 @@ export async function findPlugins (): Promise<IPluginInfo[]> {
|
||||
continue
|
||||
}
|
||||
|
||||
if (foundPlugins.some(x => x.name === pluginName)) {
|
||||
console.info(`Plugin ${pluginName} already exists`)
|
||||
if (foundPlugins.some(x => x.name === pluginName.substring('terminus-'.length))) {
|
||||
console.info(`Plugin ${pluginName} already exists, overriding`)
|
||||
foundPlugins = foundPlugins.filter(x => x.name !== pluginName.substring('terminus-'.length))
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "terminus-community-color-schemes",
|
||||
"version": "1.0.0-alpha.16-8-gfc060ac",
|
||||
"version": "1.0.0-alpha.23-6-g1c62f30",
|
||||
"description": "Community color schemes for Terminus",
|
||||
"keywords": [
|
||||
"terminus-plugin"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "terminus-core",
|
||||
"version": "1.0.0-alpha.16-8-gfc060ac",
|
||||
"version": "1.0.0-alpha.23-6-g1c62f30",
|
||||
"description": "Terminus core",
|
||||
"keywords": [
|
||||
"terminus-plugin"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "terminus-plugin-manager",
|
||||
"version": "1.0.0-alpha.16-8-gfc060ac",
|
||||
"version": "1.0.0-alpha.23-6-g1c62f30",
|
||||
"description": "Terminus' plugin manager",
|
||||
"keywords": [
|
||||
"terminus-plugin"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "terminus-settings",
|
||||
"version": "1.0.0-alpha.16-8-gfc060ac",
|
||||
"version": "1.0.0-alpha.23-6-g1c62f30",
|
||||
"description": "Terminus terminal settings page",
|
||||
"keywords": [
|
||||
"terminus-plugin"
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "terminus-terminal",
|
||||
"version": "1.0.0-alpha.16-8-gfc060ac",
|
||||
"version": "1.0.0-alpha.23-6-g1c62f30",
|
||||
"description": "Terminus' terminal emulation core",
|
||||
"keywords": [
|
||||
"terminus-plugin"
|
||||
|
@ -2,6 +2,7 @@ import { Observable } from 'rxjs'
|
||||
import { TerminalTabComponent } from './components/terminalTab.component'
|
||||
export { TerminalTabComponent }
|
||||
export { IChildProcess } from './services/sessions.service'
|
||||
export { TerminalService } from './services/terminal.service'
|
||||
|
||||
export abstract class TerminalDecorator {
|
||||
// tslint:disable-next-line no-empty
|
||||
|
@ -2,11 +2,10 @@ import { AsyncSubject } from 'rxjs'
|
||||
import * as fs from 'mz/fs'
|
||||
import * as path from 'path'
|
||||
import { Injectable, Inject } from '@angular/core'
|
||||
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService, ConfigService, HostAppService, ElectronService, Logger, LogService } from 'terminus-core'
|
||||
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, ConfigService, HostAppService, ElectronService, Logger, LogService } from 'terminus-core'
|
||||
|
||||
import { IShell, ShellProvider } from './api'
|
||||
import { SessionsService } from './services/sessions.service'
|
||||
import { TerminalTabComponent } from './components/terminalTab.component'
|
||||
import { TerminalService } from './services/terminal.service'
|
||||
|
||||
@Injectable()
|
||||
export class ButtonProvider extends ToolbarButtonProvider {
|
||||
@ -14,8 +13,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
||||
private logger: Logger
|
||||
|
||||
constructor (
|
||||
private app: AppService,
|
||||
private sessions: SessionsService,
|
||||
private terminal: TerminalService,
|
||||
private config: ConfigService,
|
||||
log: LogService,
|
||||
hostApp: HostAppService,
|
||||
@ -57,27 +55,9 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
||||
}
|
||||
|
||||
async openNewTab (cwd?: string): Promise<void> {
|
||||
if (!cwd && this.app.activeTab instanceof TerminalTabComponent) {
|
||||
cwd = await this.app.activeTab.session.getWorkingDirectory()
|
||||
}
|
||||
let shells = await this.shells$.first().toPromise()
|
||||
let 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)
|
||||
let sessionOptions = await this.sessions.prepareNewSession({
|
||||
command: shell.command,
|
||||
args: shell.args || [],
|
||||
cwd,
|
||||
env,
|
||||
})
|
||||
|
||||
this.logger.log('Using session options:', sessionOptions)
|
||||
|
||||
this.app.openNewTab(
|
||||
TerminalTabComponent,
|
||||
{ sessionOptions }
|
||||
)
|
||||
this.terminal.openTab(shell, cwd)
|
||||
}
|
||||
|
||||
provide (): IToolbarButton[] {
|
||||
|
@ -71,5 +71,7 @@ const _collapseToEnd = Selection.prototype.collapseToEnd
|
||||
Selection.prototype.collapseToEnd = function () {
|
||||
try {
|
||||
_collapseToEnd.apply(this)
|
||||
} catch (err) { ; }
|
||||
} catch (err) {
|
||||
// tslint-disable-line
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import { TerminalSettingsTabComponent } from './components/terminalSettingsTab.c
|
||||
import { ColorPickerComponent } from './components/colorPicker.component'
|
||||
|
||||
import { SessionsService } from './services/sessions.service'
|
||||
import { TerminalService } from './services/terminal.service'
|
||||
|
||||
import { ScreenPersistenceProvider } from './persistence/screen'
|
||||
import { TMuxPersistenceProvider } from './persistence/tmux'
|
||||
@ -42,6 +43,8 @@ import { hterm } from './hterm'
|
||||
],
|
||||
providers: [
|
||||
SessionsService,
|
||||
TerminalService,
|
||||
|
||||
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },
|
||||
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
|
||||
{ provide: SettingsTabProvider, useClass: TerminalSettingsTabProvider, multi: true },
|
||||
|
40
terminus-terminal/src/services/terminal.service.ts
Normal file
40
terminus-terminal/src/services/terminal.service.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { AppService, Logger, LogService } from 'terminus-core'
|
||||
import { IShell } from '../api'
|
||||
import { SessionsService } from './sessions.service'
|
||||
import { TerminalTabComponent } from '../components/terminalTab.component'
|
||||
|
||||
@Injectable()
|
||||
export class TerminalService {
|
||||
private logger: Logger
|
||||
|
||||
constructor (
|
||||
private app: AppService,
|
||||
private sessions: SessionsService,
|
||||
log: LogService,
|
||||
) {
|
||||
this.logger = log.create('terminal')
|
||||
}
|
||||
|
||||
async openTab (shell: IShell, cwd?: string): Promise<TerminalTabComponent> {
|
||||
if (!cwd && this.app.activeTab instanceof TerminalTabComponent) {
|
||||
cwd = await this.app.activeTab.session.getWorkingDirectory()
|
||||
}
|
||||
let env: any = Object.assign({}, process.env, shell.env || {})
|
||||
|
||||
this.logger.log(`Starting shell ${shell.name}`, shell)
|
||||
let sessionOptions = await this.sessions.prepareNewSession({
|
||||
command: shell.command,
|
||||
args: shell.args || [],
|
||||
cwd,
|
||||
env,
|
||||
})
|
||||
|
||||
this.logger.log('Using session options:', sessionOptions)
|
||||
|
||||
return this.app.openNewTab(
|
||||
TerminalTabComponent,
|
||||
{ sessionOptions }
|
||||
) as TerminalTabComponent
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user