This commit is contained in:
Eugene Pankov 2021-01-02 20:24:26 +01:00
parent 4d9cc91e91
commit 3365b143d8
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
9 changed files with 23 additions and 16 deletions

View File

@ -5,7 +5,7 @@ export function parseArgs (argv: string[], cwd: string): any {
argv = argv.slice(1) argv = argv.slice(1)
} }
return require('yargs') return require('yargs/yargs')(argv.slice(1))
.usage('terminus [command] [arguments]') .usage('terminus [command] [arguments]')
.command('open [directory]', 'open a shell in a directory', { .command('open [directory]', 'open a shell in a directory', {
directory: { type: 'string', 'default': cwd }, directory: { type: 'string', 'default': cwd },
@ -41,5 +41,5 @@ export function parseArgs (argv: string[], cwd: string): any {
type: 'boolean', type: 'boolean',
}) })
.help('help') .help('help')
.parse(argv.slice(1)) .parse()
} }

View File

@ -42,7 +42,6 @@ module.exports = {
mz: 'commonjs mz', mz: 'commonjs mz',
npm: 'commonjs npm', npm: 'commonjs npm',
path: 'commonjs path', path: 'commonjs path',
yargs: 'commonjs yargs',
util: 'commonjs util', util: 'commonjs util',
'source-map-support': 'commonjs source-map-support', 'source-map-support': 'commonjs source-map-support',
'windows-swca': 'commonjs windows-swca', 'windows-swca': 'commonjs windows-swca',
@ -54,4 +53,6 @@ module.exports = {
'process.type': '"main"', 'process.type': '"main"',
}), }),
], ],
// Ignore warnings due to yarg's dynamic module loading
ignoreWarnings: [/node_modules\/yargs/],
} }

View File

@ -52,7 +52,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
super.ngOnInit() super.ngOnInit()
setImmediate(() => { setImmediate(() => {
this.setTitle(this.connection.name) this.setTitle(this.connection!.name)
}) })
} }
@ -65,7 +65,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
this.session = this.injector.get(SerialService).createSession(this.connection) this.session = this.injector.get(SerialService).createSession(this.connection)
this.session.serviceMessage$.subscribe(msg => { this.session.serviceMessage$.subscribe(msg => {
this.write(`\r\n${colors.black.bgWhite(' serial ')} ${msg}\r\n`) this.write(`\r\n${colors.black.bgWhite(' serial ')} ${msg}\r\n`)
this.session.resize(this.size.columns, this.size.rows) this.session?.resize(this.size.columns, this.size.rows)
}) })
this.attachSessionHandlers() this.attachSessionHandlers()
this.write(`Connecting to `) this.write(`Connecting to `)
@ -108,7 +108,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent {
name: x.toString(), result: x, name: x.toString(), result: x,
}))) })))
this.serialPort.update({ baudRate: rate }) this.serialPort.update({ baudRate: rate })
this.connection.baudrate = rate this.connection!.baudrate = rate
} }
ngOnDestroy () { ngOnDestroy () {

View File

@ -127,7 +127,7 @@ export class SerialService {
(this.app.getParentTab(tab) ?? tab).color = connection.color (this.app.getParentTab(tab) ?? tab).color = connection.color
} }
setTimeout(() => { setTimeout(() => {
this.app.activeTab.emitFocused() this.app.activeTab?.emitFocused()
}) })
return tab return tab
} catch (error) { } catch (error) {

View File

@ -177,7 +177,7 @@ export class SSHSession extends BaseSession {
if (match) { if (match) {
this.logger.info('Executing script: "' + cmd + '"') this.logger.info('Executing script: "' + cmd + '"')
this.shell.write(cmd + '\n') this.shell!.write(cmd + '\n')
this.scripts = this.scripts.filter(x => x !== script) this.scripts = this.scripts.filter(x => x !== script)
} else { } else {
if (script.optional) { if (script.optional) {
@ -380,7 +380,7 @@ export class SSHSession extends BaseSession {
for (const script of this.scripts) { for (const script of this.scripts) {
if (!script.expect) { if (!script.expect) {
console.log('Executing script:', script.send) console.log('Executing script:', script.send)
this.shell.write(script.send + '\n') this.shell!.write(script.send + '\n')
this.scripts = this.scripts.filter(x => x !== script) this.scripts = this.scripts.filter(x => x !== script)
} else { } else {
break break

View File

@ -33,6 +33,10 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
} }
ngOnInit (): void { ngOnInit (): void {
if (!this.connection) {
throw new Error('Connection not set')
}
this.logger = this.log.create('terminalTab') this.logger = this.log.create('terminalTab')
this.enableDynamicTitle = !this.connection.disableDynamicTitle this.enableDynamicTitle = !this.connection.disableDynamicTitle
@ -58,7 +62,7 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
super.ngOnInit() super.ngOnInit()
setImmediate(() => { setImmediate(() => {
this.setTitle(this.connection.name) this.setTitle(this.connection!.name)
}) })
} }
@ -150,7 +154,7 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
showPortForwarding (): void { showPortForwarding (): void {
const modal = this.ngbModal.open(SSHPortForwardingModalComponent).componentInstance as SSHPortForwardingModalComponent const modal = this.ngbModal.open(SSHPortForwardingModalComponent).componentInstance as SSHPortForwardingModalComponent
modal.session = this.session modal.session = this.session!
} }
async reconnect (): Promise<void> { async reconnect (): Promise<void> {
@ -163,14 +167,14 @@ export class SSHTabComponent extends BaseTerminalTabComponent {
if (!this.session?.open) { if (!this.session?.open) {
return true return true
} }
if (!(this.connection.warnOnClose ?? this.config.store.ssh.warnOnClose)) { if (!(this.connection?.warnOnClose ?? this.config.store.ssh.warnOnClose)) {
return true return true
} }
return (await this.electron.showMessageBox( return (await this.electron.showMessageBox(
this.hostApp.getWindow(), this.hostApp.getWindow(),
{ {
type: 'warning', type: 'warning',
message: `Disconnect from ${this.connection.host}?`, message: `Disconnect from ${this.connection?.host}?`,
buttons: ['Cancel', 'Disconnect'], buttons: ['Cancel', 'Disconnect'],
defaultId: 1, defaultId: 1,
} }

View File

@ -44,14 +44,14 @@ export class WinSCPContextMenu extends TabContextMenuItemProvider {
if (!this.getPath()) { if (!this.getPath()) {
return [] return []
} }
if (!(tab instanceof SSHTabComponent)) { if (!(tab instanceof SSHTabComponent) || !tab.connection) {
return [] return []
} }
return [ return [
{ {
label: 'Launch WinSCP', label: 'Launch WinSCP',
click: (): void => { click: (): void => {
this.launchWinSCP(tab.connection) this.launchWinSCP(tab.connection!)
}, },
}, },
] ]

View File

@ -171,7 +171,7 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/
argv = argv.slice(1) argv = argv.slice(1)
} }
if (require('yargs').parse(argv.slice(1))._[0] !== 'open'){ if (require('yargs/yargs')(argv.slice(1)).parse()._[0] !== 'open'){
app.ready$.subscribe(() => { app.ready$.subscribe(() => {
terminal.openTab() terminal.openTab()
}) })

View File

@ -74,4 +74,6 @@ module.exports = {
'ngx-toastr', 'ngx-toastr',
/^terminus-/, /^terminus-/,
], ],
// Ignore warnings due to yarg's dynamic module loading
ignoreWarnings: [/node_modules\/yargs/],
} }