tabby/app/src/terminal/buttonProvider.ts

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-03-24 21:24:12 +00:00
import { Injectable } from '@angular/core'
2017-03-29 12:04:01 +00:00
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService } from 'api'
2017-03-24 21:24:12 +00:00
import { SessionsService } from './services/sessions'
import { TerminalTab } from './tab'
@Injectable()
2017-03-25 17:12:43 +00:00
export class ButtonProvider extends ToolbarButtonProvider {
2017-03-24 21:24:12 +00:00
constructor (
private app: AppService,
private sessions: SessionsService,
2017-03-29 12:04:01 +00:00
hotkeys: HotkeysService,
2017-03-24 21:24:12 +00:00
) {
2017-03-25 17:12:43 +00:00
super()
2017-03-29 12:04:01 +00:00
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
if (hotkey == 'new-tab') {
this.app.openTab(await this.getNewTab())
}
})
}
async getNewTab (): Promise<TerminalTab> {
2017-04-02 15:33:55 +00:00
let cwd = null
if (this.app.activeTab instanceof TerminalTab) {
cwd = await this.app.activeTab.session.getWorkingDirectory()
}
return new TerminalTab(await this.sessions.createNewSession({ command: 'zsh', cwd }))
2017-03-24 21:24:12 +00:00
}
provide (): IToolbarButton[] {
return [{
icon: 'plus',
title: 'New terminal',
2017-03-25 20:00:16 +00:00
click: async () => {
2017-03-29 12:04:01 +00:00
this.app.openTab(await this.getNewTab())
2017-03-24 21:24:12 +00:00
}
}]
}
}