1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-23 18:44:20 +03:00

shorter notification for copying

This commit is contained in:
Eugene Pankov 2021-03-10 22:08:11 +01:00
parent 0bf870738e
commit 836014c270
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
8 changed files with 55 additions and 39 deletions

View File

@ -2,14 +2,16 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
padding: 20px; padding: 20px 0 50px;
.toast { .toast {
box-shadow: 0 1px 0 rgba(0,0,0,.25); box-shadow: 0 1px 0 rgba(0,0,0,.25);
padding: 10px; padding: 7px 12px;
background-image: none; background-image: none;
width: auto; width: auto;
flex-basis: auto; flex-basis: auto;
border-radius: 0.5rem;
font-size: 0.75rem;
&.toast-error { &.toast-error {
background-color: #BD362F; background-color: #BD362F;

View File

@ -17,6 +17,7 @@ export { Logger, LogService } from '../services/log.service'
export { HomeBaseService } from '../services/homeBase.service' export { HomeBaseService } from '../services/homeBase.service'
export { HotkeysService } from '../services/hotkeys.service' export { HotkeysService } from '../services/hotkeys.service'
export { HostAppService, Platform } from '../services/hostApp.service' export { HostAppService, Platform } from '../services/hostApp.service'
export { NotificationsService } from '../services/notifications.service'
export { ShellIntegrationService } from '../services/shellIntegration.service' export { ShellIntegrationService } from '../services/shellIntegration.service'
export { ThemesService } from '../services/themes.service' export { ThemesService } from '../services/themes.service'
export { TabsService } from '../services/tabs.service' export { TabsService } from '../services/tabs.service'

View File

@ -0,0 +1,23 @@
import { Injectable } from '@angular/core'
import { ToastrService } from 'ngx-toastr'
@Injectable({ providedIn: 'root' })
export class NotificationsService {
private constructor (
private toastr: ToastrService,
) { }
notice (text: string): void {
this.toastr.info(text, undefined, {
timeOut: 1000,
})
}
info (text: string, details?: string): void {
this.toastr.info(text, details)
}
error (text: string, details?: string): void {
this.toastr.error(text, details)
}
}

View File

@ -1,7 +1,6 @@
import { Injectable, NgZone } from '@angular/core' import { Injectable, NgZone } from '@angular/core'
import SerialPort from 'serialport' import SerialPort from 'serialport'
import { ToastrService } from 'ngx-toastr' import { LogService, AppService, SelectorOption, ConfigService, NotificationsService } from 'terminus-core'
import { LogService, AppService, SelectorOption, ConfigService } from 'terminus-core'
import { SettingsTabComponent } from 'terminus-settings' import { SettingsTabComponent } from 'terminus-settings'
import { SerialConnection, SerialSession, SerialPortInfo, BAUD_RATES } from '../api' import { SerialConnection, SerialSession, SerialPortInfo, BAUD_RATES } from '../api'
import { SerialTabComponent } from '../components/serialTab.component' import { SerialTabComponent } from '../components/serialTab.component'
@ -11,7 +10,7 @@ export class SerialService {
private constructor ( private constructor (
private log: LogService, private log: LogService,
private zone: NgZone, private zone: NgZone,
private toastr: ToastrService, private notifications: NotificationsService,
private app: AppService, private app: AppService,
private config: ConfigService, private config: ConfigService,
) { } ) { }
@ -51,7 +50,7 @@ export class SerialService {
serial.on('error', error => { serial.on('error', error => {
this.zone.run(() => { this.zone.run(() => {
if (connected) { if (connected) {
this.toastr.error(error.toString()) this.notifications.error(error.toString())
} else { } else {
reject(error) reject(error)
} }
@ -65,7 +64,7 @@ export class SerialService {
try { try {
serial.open() serial.open()
} catch (e) { } catch (e) {
this.toastr.error(e.message) this.notifications.error(e.message)
reject(e) reject(e)
} }
}) })
@ -142,7 +141,7 @@ export class SerialService {
}) })
return tab return tab
} catch (error) { } catch (error) {
this.toastr.error(`Could not connect: ${error}`) this.notifications.error(`Could not connect: ${error}`)
throw error throw error
} }
} }

View File

@ -9,8 +9,7 @@ import * as fs from 'mz/fs'
import { execFile } from 'mz/child_process' import { execFile } from 'mz/child_process'
import * as path from 'path' import * as path from 'path'
import * as sshpk from 'sshpk' import * as sshpk from 'sshpk'
import { ToastrService } from 'ngx-toastr' import { HostAppService, Platform, Logger, LogService, ElectronService, AppService, SelectorOption, ConfigService, NotificationsService } from 'terminus-core'
import { HostAppService, Platform, Logger, LogService, ElectronService, AppService, SelectorOption, ConfigService } from 'terminus-core'
import { SettingsTabComponent } from 'terminus-settings' import { SettingsTabComponent } from 'terminus-settings'
import { ALGORITHM_BLACKLIST, SSHConnection, SSHSession } from '../api' import { ALGORITHM_BLACKLIST, SSHConnection, SSHSession } from '../api'
import { PromptModalComponent } from '../components/promptModal.component' import { PromptModalComponent } from '../components/promptModal.component'
@ -39,7 +38,7 @@ export class SSHService {
private ngbModal: NgbModal, private ngbModal: NgbModal,
private hostApp: HostAppService, private hostApp: HostAppService,
private passwordStorage: PasswordStorageService, private passwordStorage: PasswordStorageService,
private toastr: ToastrService, private notifications: NotificationsService,
private app: AppService, private app: AppService,
private config: ConfigService, private config: ConfigService,
) { ) {
@ -70,7 +69,7 @@ export class SSHService {
privateKey = (await fs.readFile(privateKeyPath)).toString() privateKey = (await fs.readFile(privateKeyPath)).toString()
} catch (error) { } catch (error) {
logCallback?.(colors.bgRed.black(' X ') + 'Could not read the private key file') logCallback?.(colors.bgRed.black(' X ') + 'Could not read the private key file')
this.toastr.error('Could not read the private key file') this.notifications.error('Could not read the private key file')
} }
if (privateKey) { if (privateKey) {
@ -166,7 +165,7 @@ export class SSHService {
this.zone.run(() => { this.zone.run(() => {
if (connected) { if (connected) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string // eslint-disable-next-line @typescript-eslint/no-base-to-string
this.toastr.error(error.toString()) this.notifications.error(error.toString())
} else { } else {
reject(error) reject(error)
} }
@ -289,7 +288,7 @@ export class SSHService {
}, },
} as any) } as any)
} catch (e) { } catch (e) {
this.toastr.error(e.message) this.notifications.error(e.message)
return reject(e) return reject(e)
} }
@ -411,7 +410,7 @@ export class SSHService {
return tab return tab
} catch (error) { } catch (error) {
this.toastr.error(`Could not connect: ${error}`) this.notifications.error(`Could not connect: ${error}`)
throw error throw error
} }
} }

View File

@ -1,11 +1,10 @@
import type { MenuItemConstructorOptions } from 'electron' import type { MenuItemConstructorOptions } from 'electron'
import { Observable, Subject, Subscription } from 'rxjs' import { Observable, Subject, Subscription } from 'rxjs'
import { first } from 'rxjs/operators' import { first } from 'rxjs/operators'
import { ToastrService } from 'ngx-toastr'
import colors from 'ansi-colors' import colors from 'ansi-colors'
import { NgZone, OnInit, OnDestroy, Injector, ViewChild, HostBinding, Input, ElementRef, InjectFlags } from '@angular/core' import { NgZone, OnInit, OnDestroy, Injector, ViewChild, HostBinding, Input, ElementRef, InjectFlags } from '@angular/core'
import { trigger, transition, style, animate, AnimationTriggerMetadata } from '@angular/animations' import { trigger, transition, style, animate, AnimationTriggerMetadata } from '@angular/animations'
import { AppService, ConfigService, BaseTabComponent, ElectronService, HostAppService, HotkeysService, Platform, LogService, Logger, TabContextMenuItemProvider, SplitTabComponent } from 'terminus-core' import { AppService, ConfigService, BaseTabComponent, ElectronService, HostAppService, HotkeysService, NotificationsService, Platform, LogService, Logger, TabContextMenuItemProvider, SplitTabComponent } from 'terminus-core'
import { BaseSession, SessionsService } from '../services/sessions.service' import { BaseSession, SessionsService } from '../services/sessions.service'
import { TerminalFrontendService } from '../services/terminalFrontend.service' import { TerminalFrontendService } from '../services/terminalFrontend.service'
@ -15,11 +14,6 @@ import { ResizeEvent } from './interfaces'
import { TerminalDecorator } from './decorator' import { TerminalDecorator } from './decorator'
/** @hidden */
export interface ToastrServiceProxy {
info: (_: string) => void
error: (_: string) => void
}
/** /**
* A class to base your custom terminal tabs on * A class to base your custom terminal tabs on
*/ */
@ -82,7 +76,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
protected sessions: SessionsService protected sessions: SessionsService
protected electron: ElectronService protected electron: ElectronService
protected terminalContainersService: TerminalFrontendService protected terminalContainersService: TerminalFrontendService
protected toastr: ToastrServiceProxy protected notifications: NotificationsService
protected log: LogService protected log: LogService
protected decorators: TerminalDecorator[] = [] protected decorators: TerminalDecorator[] = []
protected contextMenuProviders: TabContextMenuItemProvider[] protected contextMenuProviders: TabContextMenuItemProvider[]
@ -137,7 +131,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
this.sessions = injector.get(SessionsService) this.sessions = injector.get(SessionsService)
this.electron = injector.get(ElectronService) this.electron = injector.get(ElectronService)
this.terminalContainersService = injector.get(TerminalFrontendService) this.terminalContainersService = injector.get(TerminalFrontendService)
this.toastr = injector.get(ToastrService) this.notifications = injector.get(NotificationsService)
this.log = injector.get(LogService) this.log = injector.get(LogService)
this.decorators = injector.get<any>(TerminalDecorator, null, InjectFlags.Optional) as TerminalDecorator[] this.decorators = injector.get<any>(TerminalDecorator, null, InjectFlags.Optional) as TerminalDecorator[]
this.contextMenuProviders = injector.get<any>(TabContextMenuItemProvider, null, InjectFlags.Optional) as TabContextMenuItemProvider[] this.contextMenuProviders = injector.get<any>(TabContextMenuItemProvider, null, InjectFlags.Optional) as TabContextMenuItemProvider[]
@ -154,7 +148,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
if (this.frontend?.getSelection()) { if (this.frontend?.getSelection()) {
this.frontend.copySelection() this.frontend.copySelection()
this.frontend.clearSelection() this.frontend.clearSelection()
this.toastr.info('Copied') this.notifications.notice('Copied')
} else { } else {
this.sendInput('\x03') this.sendInput('\x03')
} }
@ -162,7 +156,7 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
case 'copy': case 'copy':
this.frontend?.copySelection() this.frontend?.copySelection()
this.frontend?.clearSelection() this.frontend?.clearSelection()
this.toastr.info('Copied') this.notifications.notice('Copied')
break break
case 'paste': case 'paste':
this.paste() this.paste()
@ -454,9 +448,9 @@ export class BaseTerminalTabComponent extends BaseTabComponent implements OnInit
} }
if (cwd) { if (cwd) {
this.electron.clipboard.writeText(cwd) this.electron.clipboard.writeText(cwd)
this.toastr.info('Copied') this.notifications.notice('Copied')
} else { } else {
this.toastr.error('Shell does not support current path detection') this.notifications.error('Shell does not support current path detection')
} }
} }

View File

@ -1,7 +1,6 @@
import { Component, Input, Output, EventEmitter } from '@angular/core' import { Component, Input, Output, EventEmitter } from '@angular/core'
import { ToastrService } from 'ngx-toastr'
import { Frontend, SearchOptions } from '../frontends/frontend' import { Frontend, SearchOptions } from '../frontends/frontend'
import { ConfigService } from 'terminus-core' import { ConfigService, NotificationsService } from 'terminus-core'
@Component({ @Component({
selector: 'search-panel', selector: 'search-panel',
@ -20,7 +19,7 @@ export class SearchPanelComponent {
@Output() close = new EventEmitter() @Output() close = new EventEmitter()
constructor ( constructor (
private toastr: ToastrService, private notifications: NotificationsService,
public config: ConfigService, public config: ConfigService,
) { } ) { }
@ -35,7 +34,7 @@ export class SearchPanelComponent {
} }
if (!this.frontend.findNext(this.query, { ...this.options, incremental: incremental || undefined })) { if (!this.frontend.findNext(this.query, { ...this.options, incremental: incremental || undefined })) {
this.notFound = true this.notFound = true
this.toastr.error('Not found') this.notifications.notice('Not found')
} }
} }
@ -45,7 +44,7 @@ export class SearchPanelComponent {
} }
if (!this.frontend.findPrevious(this.query, { ...this.options, incremental: incremental || undefined })) { if (!this.frontend.findPrevious(this.query, { ...this.options, incremental: incremental || undefined })) {
this.notFound = true this.notFound = true
this.toastr.error('Not found') this.notifications.notice('Not found')
} }
} }

View File

@ -1,7 +1,6 @@
import { MenuItemConstructorOptions } from 'electron' import { MenuItemConstructorOptions } from 'electron'
import { Injectable, NgZone, Optional, Inject } from '@angular/core' import { Injectable, NgZone, Optional, Inject } from '@angular/core'
import { ToastrService } from 'ngx-toastr' import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, TabHeaderComponent, SplitTabComponent, NotificationsService } from 'terminus-core'
import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, TabHeaderComponent, SplitTabComponent } from 'terminus-core'
import { TerminalTabComponent } from './components/terminalTab.component' import { TerminalTabComponent } from './components/terminalTab.component'
import { UACService } from './services/uac.service' import { UACService } from './services/uac.service'
import { TerminalService } from './services/terminal.service' import { TerminalService } from './services/terminal.service'
@ -14,7 +13,7 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
constructor ( constructor (
private config: ConfigService, private config: ConfigService,
private zone: NgZone, private zone: NgZone,
private toastr: ToastrService, private notifications: NotificationsService,
) { ) {
super() super()
} }
@ -39,7 +38,7 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
profile, profile,
] ]
this.config.save() this.config.save()
this.toastr.info('Saved') this.notifications.info('Saved')
}), }),
}, },
] ]
@ -141,7 +140,7 @@ export class CopyPasteContextMenu extends TabContextMenuItemProvider {
constructor ( constructor (
private zone: NgZone, private zone: NgZone,
private toastr: ToastrService, private notifications: NotificationsService,
) { ) {
super() super()
} }
@ -158,7 +157,7 @@ export class CopyPasteContextMenu extends TabContextMenuItemProvider {
this.zone.run(() => { this.zone.run(() => {
setTimeout(() => { setTimeout(() => {
tab.frontend?.copySelection() tab.frontend?.copySelection()
this.toastr.info('Copied') this.notifications.notice('Copied')
}) })
}) })
}, },