hotkeys for specific shells

This commit is contained in:
Eugene Pankov
2018-10-12 17:59:22 +02:00
parent cc610e158e
commit 9b6a09129c
10 changed files with 128 additions and 25 deletions

View File

@@ -2,6 +2,11 @@ import { ConfigProvider, Platform } from 'terminus-core'
export class TerminalConfigProvider extends ConfigProvider {
defaults = {
hotkeys: {
shell: {
__nonStructural: true,
},
},
terminal: {
frontend: 'hterm',
autoOpen: false,

View File

@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core'
import { IHotkeyDescription, HotkeyProvider } from 'terminus-core'
import { TerminalService } from './services/terminal.service'
@Injectable()
export class TerminalHotkeyProvider extends HotkeyProvider {
@@ -61,4 +62,16 @@ export class TerminalHotkeyProvider extends HotkeyProvider {
name: 'Intelligent Ctrl-C (copy/abort)',
},
]
constructor (
private terminal: TerminalService,
) { super() }
async provide (): Promise<IHotkeyDescription[]> {
let shells = await this.terminal.shells$.toPromise()
return this.hotkeys.concat(shells.map(shell => ({
id: `shell.${shell.id}`,
name: `New tab: ${shell.name}`
})))
}
}

View File

@@ -148,11 +148,16 @@ export default class TerminalModule {
if (hotkey === 'new-tab') {
terminal.openTab()
}
})
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
if (hotkey === 'new-window') {
hostApp.newWindow()
}
if (hotkey.startsWith('shell.')) {
let shells = await terminal.shells$
let shell = shells.find(x => x.id === hotkey.split('.')[1])
if (shell) {
terminal.openTab(shell)
}
}
})
hostApp.cliOpenDirectory$.subscribe(async directory => {
if (await fs.exists(directory)) {

View File

@@ -27,10 +27,14 @@ export class TerminalService {
})
}
async getShells (): Promise<IShell[]> {
let shellLists = await Promise.all(this.config.enabledServices(this.shellProviders).map(x => x.provide()))
return shellLists.reduce((a, b) => a.concat(b))
}
async reloadShells () {
this.shells = new AsyncSubject<IShell[]>()
let shellLists = await Promise.all(this.config.enabledServices(this.shellProviders).map(x => x.provide()))
this.shells.next(shellLists.reduce((a, b) => a.concat(b)))
this.shells.next(await this.getShells())
this.shells.complete()
}

View File

@@ -15,7 +15,7 @@ export class CustomShellProvider extends ShellProvider {
let args = this.config.store.terminal.customShell.split(' ')
return [{
id: 'custom',
name: 'Custom',
name: 'Custom shell',
command: args[0],
args: args.slice(1),
}]