mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-29 15:59:54 +00:00
more cleanup
This commit is contained in:
parent
d6f163b048
commit
7d25816751
@ -21,7 +21,7 @@ export class SSHSession extends BaseSession {
|
||||
|
||||
constructor (private shell: any, conn: SSHConnection) {
|
||||
super()
|
||||
this.scripts = conn.scripts ? [...conn.scripts] : []
|
||||
this.scripts = conn.scripts || []
|
||||
}
|
||||
|
||||
start () {
|
||||
@ -31,23 +31,21 @@ export class SSHSession extends BaseSession {
|
||||
let dataString = data.toString()
|
||||
this.emitOutput(dataString)
|
||||
|
||||
if (this.scripts && this.scripts.length > 0) {
|
||||
if (this.scripts) {
|
||||
let found = false
|
||||
for (let i = 0; i < this.scripts.length; i++) {
|
||||
if (dataString.indexOf(this.scripts[i].expect) >= 0) {
|
||||
console.log("Executing: " + this.scripts[i].send)
|
||||
this.shell.write(this.scripts[i].send + "\n")
|
||||
this.scripts.splice(i, 1)
|
||||
i--
|
||||
for (let script of this.scripts) {
|
||||
if (dataString.includes(script.expect)) {
|
||||
console.log('Executing script:', script.send)
|
||||
this.shell.write(script.send + '\n')
|
||||
this.scripts = this.scripts.filter(x => x !== script)
|
||||
found = true
|
||||
}
|
||||
else {
|
||||
break;
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
this.executeScripts()
|
||||
this.executeUnconditionalScripts()
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -58,23 +56,7 @@ export class SSHSession extends BaseSession {
|
||||
}
|
||||
})
|
||||
|
||||
this.executeScripts()
|
||||
}
|
||||
|
||||
executeScripts () {
|
||||
if (this.scripts && this.scripts.length > 0) {
|
||||
for (let i = 0; i < this.scripts.length; i++) {
|
||||
if (!this.scripts[i].expect) {
|
||||
console.log("Executing: " + this.scripts[i].send)
|
||||
this.shell.write(this.scripts[i].send + "\n")
|
||||
this.scripts.splice(i, 1)
|
||||
i--
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.executeUnconditionalScripts()
|
||||
}
|
||||
|
||||
resize (columns, rows) {
|
||||
@ -100,6 +82,20 @@ export class SSHSession extends BaseSession {
|
||||
async getWorkingDirectory (): Promise<string> {
|
||||
return null
|
||||
}
|
||||
|
||||
private executeUnconditionalScripts () {
|
||||
if (this.scripts) {
|
||||
for (let script of this.scripts) {
|
||||
if (!script.expect) {
|
||||
console.log('Executing script:', script.send)
|
||||
this.shell.write(script.send + '\n')
|
||||
this.scripts = this.scripts.filter(x => x !== script)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface ISSHConnectionGroup {
|
||||
|
@ -4,7 +4,6 @@
|
||||
ng-template(ngbTabTitle)
|
||||
| Basic Setting
|
||||
ng-template(ngbTabContent)
|
||||
h4 Basic Setting
|
||||
.form-group
|
||||
label Name
|
||||
input.form-control(
|
||||
@ -59,52 +58,50 @@
|
||||
ng-template(ngbTabTitle)
|
||||
| Login Scripts
|
||||
ng-template(ngbTabContent)
|
||||
h4 Login Scripts
|
||||
.list-group
|
||||
table
|
||||
tr
|
||||
th String to wait
|
||||
th String to be sent
|
||||
th Actions
|
||||
tr(*ngFor='let script of connection.scripts')
|
||||
td
|
||||
input.form-control(
|
||||
type='text',
|
||||
value='{{script.expect}}',
|
||||
)
|
||||
td
|
||||
input.form-control(
|
||||
type='text',
|
||||
value='{{script.send}}',
|
||||
)
|
||||
td
|
||||
.input-group.flex-nowrap
|
||||
button.btn.btn-outline-info.ml-0((click)='up(script)')
|
||||
i.fa.fa-arrow-up
|
||||
button.btn.btn-outline-info.ml-0((click)='down(script)')
|
||||
i.fa.fa-arrow-down
|
||||
button.btn.btn-outline-danger.ml-0((click)='delete(script)')
|
||||
i.fa.fa-trash-o
|
||||
tr
|
||||
td
|
||||
input.form-control(
|
||||
table
|
||||
tr
|
||||
th String to expect
|
||||
th String to be sent
|
||||
th Actions
|
||||
tr(*ngFor='let script of connection.scripts')
|
||||
td
|
||||
input.form-control(
|
||||
type='text',
|
||||
placeholder='Enter a string to wait',
|
||||
[(ngModel)]='newScript.expect'
|
||||
value='{{script.expect}}',
|
||||
)
|
||||
td
|
||||
input.form-control(
|
||||
td
|
||||
input.form-control(
|
||||
type='text',
|
||||
placeholder='Enter a string to be sent',
|
||||
[(ngModel)]='newScript.send'
|
||||
value='{{script.send}}',
|
||||
)
|
||||
td
|
||||
.input-group.flex-nowrap
|
||||
button.btn.btn-outline-info.ml-0((click)='add()')
|
||||
i.fa.fa-save
|
||||
button.btn.btn-outline-danger.ml-0((click)='clear()')
|
||||
i.fa.fa-trash-o
|
||||
|
||||
td
|
||||
.input-group.flex-nowrap
|
||||
button.btn.btn-outline-info.ml-0((click)='moveScriptUp(script)')
|
||||
i.fa.fa-arrow-up
|
||||
button.btn.btn-outline-info.ml-0((click)='moveScriptDown(script)')
|
||||
i.fa.fa-arrow-down
|
||||
button.btn.btn-outline-danger.ml-0((click)='deleteScript(script)')
|
||||
i.fa.fa-trash-o
|
||||
tr
|
||||
td
|
||||
input.form-control(
|
||||
type='text',
|
||||
placeholder='Enter a string to expect',
|
||||
[(ngModel)]='newScript.expect'
|
||||
)
|
||||
td
|
||||
input.form-control(
|
||||
type='text',
|
||||
placeholder='Enter a string to be sent',
|
||||
[(ngModel)]='newScript.send'
|
||||
)
|
||||
td
|
||||
.input-group.flex-nowrap
|
||||
button.btn.btn-outline-info.ml-0((click)='addScript()')
|
||||
i.fa.fa-check
|
||||
button.btn.btn-outline-danger.ml-0((click)='clearScript()')
|
||||
i.fa.fa-trash-o
|
||||
|
||||
.modal-footer
|
||||
button.btn.btn-outline-primary((click)='save()') Save
|
||||
button.btn.btn-outline-danger((click)='cancel()') Cancel
|
||||
|
@ -15,7 +15,7 @@ export class EditConnectionModalComponent {
|
||||
private electron: ElectronService,
|
||||
private hostApp: HostAppService,
|
||||
) {
|
||||
this.newScript = { expect: "", send: ""}
|
||||
this.newScript = { expect: '', send: '' }
|
||||
}
|
||||
|
||||
selectPrivateKey () {
|
||||
@ -38,37 +38,38 @@ export class EditConnectionModalComponent {
|
||||
this.modalInstance.dismiss()
|
||||
}
|
||||
|
||||
up (script: LoginScript) {
|
||||
moveScriptUp (script: LoginScript) {
|
||||
let index = this.connection.scripts.indexOf(script)
|
||||
if (index > 0) {
|
||||
this.connection.scripts.splice(index, 1);
|
||||
this.connection.scripts.splice(index - 1, 0, script);
|
||||
this.connection.scripts.splice(index, 1)
|
||||
this.connection.scripts.splice(index - 1, 0, script)
|
||||
}
|
||||
}
|
||||
|
||||
down (script: LoginScript) {
|
||||
moveScriptDown (script: LoginScript) {
|
||||
let index = this.connection.scripts.indexOf(script)
|
||||
if (index >= 0 && index < this.connection.scripts.length - 1) {
|
||||
this.connection.scripts.splice(index, 1);
|
||||
this.connection.scripts.splice(index + 1, 0, script);
|
||||
this.connection.scripts.splice(index, 1)
|
||||
this.connection.scripts.splice(index + 1, 0, script)
|
||||
}
|
||||
}
|
||||
|
||||
delete (script: LoginScript) {
|
||||
deleteScript (script: LoginScript) {
|
||||
if (confirm(`Delete?`)) {
|
||||
this.connection.scripts = this.connection.scripts.filter(x => x !== script)
|
||||
}
|
||||
}
|
||||
|
||||
add () {
|
||||
if (!this.connection.scripts)
|
||||
addScript () {
|
||||
if (!this.connection.scripts) {
|
||||
this.connection.scripts = []
|
||||
this.connection.scripts.push(Object.assign({}, this.newScript))
|
||||
this.clear();
|
||||
}
|
||||
this.connection.scripts.push({...this.newScript})
|
||||
this.clearScript()
|
||||
}
|
||||
|
||||
clear () {
|
||||
this.newScript.expect = ""
|
||||
this.newScript.send = ""
|
||||
clearScript () {
|
||||
this.newScript.expect = ''
|
||||
this.newScript.send = ''
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ export class SSHModalComponent {
|
||||
|
||||
let connections = this.connections
|
||||
if (this.quickTarget) {
|
||||
connections = connections.filter(connection => (connection.name + connection.group).toLowerCase().indexOf(this.quickTarget) >= 0)
|
||||
connections = connections.filter(connection => (connection.name + connection.group).toLowerCase().includes(this.quickTarget))
|
||||
}
|
||||
|
||||
for (let connection of connections) {
|
||||
|
@ -61,7 +61,7 @@ export class SSHSettingsTabComponent {
|
||||
editGroup (group: ISSHConnectionGroup) {
|
||||
let modal = this.ngbModal.open(PromptModalComponent)
|
||||
modal.componentInstance.prompt = 'New group name'
|
||||
modal.componentInstance.value = group
|
||||
modal.componentInstance.value = group.name
|
||||
modal.result.then(result => {
|
||||
if (result) {
|
||||
for (let connection of this.connections.filter(x => x.group === group.name)) {
|
||||
|
@ -55,7 +55,7 @@ export class SSHService {
|
||||
modal.componentInstance.password = true
|
||||
try {
|
||||
privateKeyPassphrase = await modal.result
|
||||
} catch (_err) { }
|
||||
} catch (_err) { } // tslint:disable-line
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user