tabby/terminus-terminal/buttonProvider.ts
Eugene Pankov 0ea346a6ae wip
2017-04-11 02:22:48 +02:00

43 lines
1.2 KiB
TypeScript

import { Injectable } from '@angular/core'
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService } from 'terminus-core'
import { SessionsService } from './services/sessions'
import { TerminalTabComponent } from './components/terminalTab'
@Injectable()
export class ButtonProvider extends ToolbarButtonProvider {
constructor (
private app: AppService,
private sessions: SessionsService,
hotkeys: HotkeysService,
) {
super()
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
if (hotkey == 'new-tab') {
this.openNewTab()
}
})
}
async openNewTab (): Promise<void> {
let cwd = null
if (this.app.activeTab instanceof TerminalTabComponent) {
cwd = await this.app.activeTab.session.getWorkingDirectory()
}
this.app.openNewTab(
TerminalTabComponent,
{ session: await this.sessions.createNewSession({ command: 'zsh', cwd }) }
)
}
provide (): IToolbarButton[] {
return [{
icon: 'plus',
title: 'New terminal',
click: async () => {
this.openNewTab()
}
}]
}
}