From 38cda117e2fd67bfa2342ee0dafb627bfae1eb6b Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sat, 7 Oct 2017 17:47:04 +0200 Subject: [PATCH] option to auto-start a terminal tab (fixes #107) --- .../src/components/appRoot.component.ts | 2 ++ terminus-core/src/services/app.service.ts | 10 ++++++-- .../terminalSettingsTab.component.pug | 23 +++++++++++++++++++ terminus-terminal/src/config.ts | 1 + terminus-terminal/src/index.ts | 14 +++++++++-- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/terminus-core/src/components/appRoot.component.ts b/terminus-core/src/components/appRoot.component.ts index 68b9778b..cc9a1d6d 100644 --- a/terminus-core/src/components/appRoot.component.ts +++ b/terminus-core/src/components/appRoot.component.ts @@ -150,6 +150,8 @@ export class AppRootComponent { if (this.app.tabs.length === 0) { this.app.openDefaultTab() } + + this.app.emitReady() } @HostListener('dragover') diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 757cae87..ba1db30e 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -1,4 +1,4 @@ -import { Subject } from 'rxjs' +import { Subject, AsyncSubject } from 'rxjs' import { Injectable, ComponentFactoryResolver, Injector, Optional } from '@angular/core' import { DefaultTabProvider } from '../api/defaultTabProvider' import { BaseTabComponent } from '../components/baseTab.component' @@ -12,7 +12,8 @@ export class AppService { activeTab: BaseTabComponent lastTabIndex = 0 logger: Logger - tabsChanged$ = new Subject() + tabsChanged$ = new Subject() + ready$ = new AsyncSubject() constructor ( private componentFactoryResolver: ComponentFactoryResolver, @@ -97,4 +98,9 @@ export class AppService { } this.tabsChanged$.next() } + + emitReady () { + this.ready$.next(null) + this.ready$.complete() + } } diff --git a/terminus-terminal/src/components/terminalSettingsTab.component.pug b/terminus-terminal/src/components/terminalSettingsTab.component.pug index a514e16e..9f8f28cd 100644 --- a/terminus-terminal/src/components/terminalSettingsTab.component.pug +++ b/terminus-terminal/src/components/terminalSettingsTab.component.pug @@ -287,3 +287,26 @@ *ngFor='let provider of persistenceProviders', [ngValue]='provider.id' ) {{provider.displayName}} + + .form-group + label Auto-open a terminal on app start + br + div( + '[(ngModel)]'='config.store.terminal.autoOpen', + (ngModelChange)='config.save()', + ngbRadioGroup + ) + label.btn.btn-secondary(ngbButtonLabel) + input( + type='radio', + ngbButton, + [value]='false' + ) + | Off + label.btn.btn-secondary(ngbButtonLabel) + input( + type='radio', + ngbButton, + [value]='true' + ) + | On diff --git a/terminus-terminal/src/config.ts b/terminus-terminal/src/config.ts index ab921caf..c7f71ef2 100644 --- a/terminus-terminal/src/config.ts +++ b/terminus-terminal/src/config.ts @@ -3,6 +3,7 @@ import { ConfigProvider, Platform } from 'terminus-core' export class TerminalConfigProvider extends ConfigProvider { defaults = { terminal: { + autoOpen: false, fontSize: 14, linePadding: 0, bell: 'off', diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index 7b40852f..29cc1591 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -3,7 +3,7 @@ import { BrowserModule } from '@angular/platform-browser' import { FormsModule } from '@angular/forms' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' -import { ToolbarButtonProvider, TabRecoveryProvider, ConfigProvider, HotkeysService, HotkeyProvider } from 'terminus-core' +import { ToolbarButtonProvider, TabRecoveryProvider, ConfigProvider, HotkeysService, HotkeyProvider, AppService, ConfigService } from 'terminus-core' import { SettingsTabProvider } from 'terminus-settings' import { TerminalTabComponent } from './components/terminalTab.component' @@ -78,7 +78,12 @@ import { hterm } from './hterm' ], }) export default class TerminalModule { - constructor (hotkeys: HotkeysService) { + constructor ( + app: AppService, + config: ConfigService, + hotkeys: HotkeysService, + terminal: TerminalService, + ) { let events = [ { name: 'keydown', @@ -103,6 +108,11 @@ export default class TerminalModule { hotkeys.emitKeyEvent(nativeEvent) } }) + if (config.store.terminal.autoOpen) { + app.ready$.subscribe(() => { + terminal.openTab() + }) + } } }