mirror of
https://github.com/Eugeny/tabby
synced 2024-11-15 01:17:14 +00:00
43 lines
1.2 KiB
TypeScript
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()
|
|
}
|
|
}]
|
|
}
|
|
}
|