From deb4b963cdb5c0dbcd6a9a75fda98fc653988d6c Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 5 Jul 2017 18:46:16 +0200 Subject: [PATCH 1/4] copy hotkey for macOS (fixes #61) --- .../src/components/terminalTab.component.ts | 6 ++++++ terminus-terminal/src/config.ts | 9 +++++++++ terminus-terminal/src/hotkeys.ts | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/terminus-terminal/src/components/terminalTab.component.ts b/terminus-terminal/src/components/terminalTab.component.ts index 311b7848..619e2df4 100644 --- a/terminus-terminal/src/components/terminalTab.component.ts +++ b/terminus-terminal/src/components/terminalTab.component.ts @@ -69,6 +69,12 @@ export class TerminalTabComponent extends BaseTabComponent { this.session.releaseInitialDataBuffer() }) this.hotkeysSubscription = this.hotkeys.matchedHotkey.subscribe(hotkey => { + if (!this.hasFocus) { + return + } + if (hotkey === 'copy') { + this.hterm.copySelectionToClipboard() + } if (hotkey === 'zoom-in') { this.zoomIn() } diff --git a/terminus-terminal/src/config.ts b/terminus-terminal/src/config.ts index 914a8224..03da5eba 100644 --- a/terminus-terminal/src/config.ts +++ b/terminus-terminal/src/config.ts @@ -44,6 +44,9 @@ export class TerminalConfigProvider extends ConfigProvider { shell: '~default-shell~', }, hotkeys: { + 'copy': [ + '⌘-C', + ], 'zoom-in': [ '⌘-=', '⌘-Shift-+', @@ -69,6 +72,9 @@ export class TerminalConfigProvider extends ConfigProvider { shell: '~clink~', }, hotkeys: { + 'copy': [ + 'Ctrl-Shift-C', + ], 'zoom-in': [ 'Ctrl-=', 'Ctrl-Shift-+', @@ -93,6 +99,9 @@ export class TerminalConfigProvider extends ConfigProvider { shell: '~default-shell~', }, hotkeys: { + 'copy': [ + 'Ctrl-Shift-C', + ], 'zoom-in': [ 'Ctrl-=', 'Ctrl-Shift-+', diff --git a/terminus-terminal/src/hotkeys.ts b/terminus-terminal/src/hotkeys.ts index 0d30ffe5..da8faa1d 100644 --- a/terminus-terminal/src/hotkeys.ts +++ b/terminus-terminal/src/hotkeys.ts @@ -4,6 +4,10 @@ import { IHotkeyDescription, HotkeyProvider } from 'terminus-core' @Injectable() export class TerminalHotkeyProvider extends HotkeyProvider { hotkeys: IHotkeyDescription[] = [ + { + id: 'copy', + name: 'Copy to clipboard', + }, { id: 'zoom-in', name: 'Zoom in', From f4eb03fee0f38c9b9148cdd35144f05dd4778a65 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 5 Jul 2017 19:05:45 +0200 Subject: [PATCH 2/4] proper macOS menu (fixes #39) --- app/main.js | 82 +++++++++++++++---- terminus-core/src/services/hostApp.service.ts | 2 + terminus-settings/src/buttonProvider.ts | 22 +++-- 3 files changed, 83 insertions(+), 23 deletions(-) diff --git a/app/main.js b/app/main.js index 194531dc..09e5295a 100644 --- a/app/main.js +++ b/app/main.js @@ -108,25 +108,79 @@ setupWindowManagement = () => { setupMenu = () => { - var template = [{ + let template = [{ label: "Application", submenu: [ - { type: "separator" }, - { label: "Quit", accelerator: "CmdOrCtrl+Q", click: () => { - app.window.webContents.send('host:quit-request') - }} + { role: 'about', label: 'About Terminus' }, + { type: 'separator' }, + { + label: 'Preferences', + accelerator: 'Cmd+,', + click () { + app.window.webContents.send('host:preferences-menu') + } + }, + { type: 'separator' }, + { role: 'services', submenu: [] }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideothers' }, + { role: 'unhide' }, + { type: 'separator' }, + { + label: 'Quit', + accelerator: 'Cmd+Q', + click () { + app.window.webContents.send('host:quit-request') + } + } ] - }, - { + }, + { label: "Edit", submenu: [ - { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" }, - { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" }, - { type: "separator" }, - { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, - { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, - { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, - { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" } + {role: 'undo'}, + {role: 'redo'}, + {type: 'separator'}, + {role: 'cut'}, + {role: 'copy'}, + {role: 'paste'}, + {role: 'pasteandmatchstyle'}, + {role: 'delete'}, + {role: 'selectall'} + ] + }, + { + label: 'View', + submenu: [ + {role: 'reload'}, + {role: 'forcereload'}, + {role: 'toggledevtools'}, + {type: 'separator'}, + {role: 'resetzoom'}, + {role: 'zoomin'}, + {role: 'zoomout'}, + {type: 'separator'}, + {role: 'togglefullscreen'} + ] + }, + { + role: 'window', + submenu: [ + {role: 'close'}, + {role: 'minimize'}, + {role: 'zoom'}, + {type: 'separator'}, + {role: 'front'} + ] + }, + { + role: 'help', + submenu: [ + { + label: 'Website', + click () { electron.shell.openExternal('https://eugeny.github.io/terminus') } + } ] }] diff --git a/terminus-core/src/services/hostApp.service.ts b/terminus-core/src/services/hostApp.service.ts index 22e8dfc4..5c066963 100644 --- a/terminus-core/src/services/hostApp.service.ts +++ b/terminus-core/src/services/hostApp.service.ts @@ -19,6 +19,7 @@ export class HostAppService { platform: Platform nodePlatform: string quitRequested = new EventEmitter() + preferencesMenu$ = new Subject() ready = new EventEmitter() shown = new EventEmitter() secondInstance$ = new Subject<{ argv: string[], cwd: string }>() @@ -39,6 +40,7 @@ export class HostAppService { }[this.nodePlatform] electron.ipcRenderer.on('host:quit-request', () => this.zone.run(() => this.quitRequested.emit())) + electron.ipcRenderer.on('host:preferences-menu', () => this.zone.run(() => this.preferencesMenu$.next())) electron.ipcRenderer.on('uncaughtException', ($event, err) => { this.logger.error('Unhandled exception:', err) diff --git a/terminus-settings/src/buttonProvider.ts b/terminus-settings/src/buttonProvider.ts index 534dd2a3..3f2c23db 100644 --- a/terminus-settings/src/buttonProvider.ts +++ b/terminus-settings/src/buttonProvider.ts @@ -1,14 +1,16 @@ import { Injectable } from '@angular/core' -import { ToolbarButtonProvider, IToolbarButton, AppService } from 'terminus-core' +import { ToolbarButtonProvider, IToolbarButton, AppService, HostAppService } from 'terminus-core' import { SettingsTabComponent } from './components/settingsTab.component' @Injectable() export class ButtonProvider extends ToolbarButtonProvider { constructor ( + hostApp: HostAppService, private app: AppService, ) { super() + hostApp.preferencesMenu$.subscribe(() => this.open()) } provide (): IToolbarButton[] { @@ -16,14 +18,16 @@ export class ButtonProvider extends ToolbarButtonProvider { icon: 'sliders', title: 'Settings', weight: 10, - click: () => { - let settingsTab = this.app.tabs.find((tab) => tab instanceof SettingsTabComponent) - if (settingsTab) { - this.app.selectTab(settingsTab) - } else { - this.app.openNewTab(SettingsTabComponent) - } - } + click: () => this.open(), }] } + + open (): void { + let settingsTab = this.app.tabs.find((tab) => tab instanceof SettingsTabComponent) + if (settingsTab) { + this.app.selectTab(settingsTab) + } else { + this.app.openNewTab(SettingsTabComponent) + } + } } From c087a969d6310784a5f0893fba71711ccd8f05e1 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 5 Jul 2017 19:31:58 +0200 Subject: [PATCH 3/4] cmd-k to clear the terminal (fixes #39) --- .../src/components/terminalTab.component.ts | 8 ++++++++ terminus-terminal/src/config.ts | 9 +++++++++ terminus-terminal/src/hotkeys.ts | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/terminus-terminal/src/components/terminalTab.component.ts b/terminus-terminal/src/components/terminalTab.component.ts index 619e2df4..d2286f08 100644 --- a/terminus-terminal/src/components/terminalTab.component.ts +++ b/terminus-terminal/src/components/terminalTab.component.ts @@ -75,6 +75,9 @@ export class TerminalTabComponent extends BaseTabComponent { if (hotkey === 'copy') { this.hterm.copySelectionToClipboard() } + if (hotkey === 'clear') { + this.clear() + } if (hotkey === 'zoom-in') { this.zoomIn() } @@ -234,6 +237,11 @@ export class TerminalTabComponent extends BaseTabComponent { this.io.writeUTF8(data) } + clear () { + this.hterm.wipeContents() + this.hterm.onVTKeystroke('\f') + } + async configure (): Promise { let config = this.config.store preferenceManager.set('font-family', config.terminal.font) diff --git a/terminus-terminal/src/config.ts b/terminus-terminal/src/config.ts index 03da5eba..f36103bb 100644 --- a/terminus-terminal/src/config.ts +++ b/terminus-terminal/src/config.ts @@ -47,6 +47,9 @@ export class TerminalConfigProvider extends ConfigProvider { 'copy': [ '⌘-C', ], + 'clear': [ + '⌘-K', + ], 'zoom-in': [ '⌘-=', '⌘-Shift-+', @@ -75,6 +78,9 @@ export class TerminalConfigProvider extends ConfigProvider { 'copy': [ 'Ctrl-Shift-C', ], + 'clear': [ + 'Ctrl-L', + ], 'zoom-in': [ 'Ctrl-=', 'Ctrl-Shift-+', @@ -102,6 +108,9 @@ export class TerminalConfigProvider extends ConfigProvider { 'copy': [ 'Ctrl-Shift-C', ], + 'clear': [ + 'Ctrl-L', + ], 'zoom-in': [ 'Ctrl-=', 'Ctrl-Shift-+', diff --git a/terminus-terminal/src/hotkeys.ts b/terminus-terminal/src/hotkeys.ts index da8faa1d..dc19d04c 100644 --- a/terminus-terminal/src/hotkeys.ts +++ b/terminus-terminal/src/hotkeys.ts @@ -8,6 +8,10 @@ export class TerminalHotkeyProvider extends HotkeyProvider { id: 'copy', name: 'Copy to clipboard', }, + { + id: 'clear', + name: 'Clear terminal', + }, { id: 'zoom-in', name: 'Zoom in', From a6f7f7aa05cc9649563459e1e162157311ce877e Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 5 Jul 2017 21:13:41 +0200 Subject: [PATCH 4/4] re-re-fixed custom npm path detection --- terminus-plugin-manager/src/services/pluginManager.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terminus-plugin-manager/src/services/pluginManager.service.ts b/terminus-plugin-manager/src/services/pluginManager.service.ts index 8452f478..14d78d77 100644 --- a/terminus-plugin-manager/src/services/pluginManager.service.ts +++ b/terminus-plugin-manager/src/services/pluginManager.service.ts @@ -41,6 +41,9 @@ export class PluginManagerService { async detectPath () { this.npmPath = this.config.store.npm + if (await fs.exists(this.npmPath)) { + return + } if (this.hostApp.platform !== Platform.Windows) { let searchPaths = (await exec('bash -c -l "echo $PATH"'))[0].toString().trim().split(':') for (let searchPath of searchPaths) {