mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
handle next and prev commands
This commit is contained in:
parent
58cf016410
commit
24c30e0603
2 changed files with 28 additions and 11 deletions
|
@ -29,16 +29,26 @@ export class AppComponent implements OnInit {
|
|||
|
||||
updateInstructions(step) {
|
||||
let totalSteps = this.instructionsArray.length - 1;
|
||||
if (step === 'next' && this.counter < totalSteps) {
|
||||
this.counter += 1;
|
||||
}
|
||||
else if (step === 'prev' && this.counter > 0) {
|
||||
let originalCounter = this.counter;
|
||||
let error = Math.random();
|
||||
if (step === 'next') {
|
||||
if (originalCounter === totalSteps) {
|
||||
// if the user has reached the end of the demo, send
|
||||
// a unique response to back to ensure correct handling in ui
|
||||
this.response = 'Message: ' + error + ': you have reached the end of the demo';
|
||||
} else {
|
||||
this.counter += 1;
|
||||
this.response = 'moving forward to step ' + this.counter;
|
||||
}
|
||||
} else if (step === 'prev') {
|
||||
this.counter -= 1;
|
||||
if (this.counter < 0) {
|
||||
this.counter = 0;
|
||||
this.response = 'Message: ' + error + ': you have reached the beginning of the demo';
|
||||
} else {
|
||||
this.response = 'moving back to step ' + this.counter;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.counter = 0;
|
||||
}
|
||||
|
||||
this.instructions = this.instructionsArray[this.counter]['_body'];
|
||||
}
|
||||
|
||||
|
|
|
@ -97,9 +97,16 @@ export class XtermTerminalComponent implements OnInit {
|
|||
this.last = this.previousCommands.length - 2
|
||||
}
|
||||
if (this.buffer === this.previousCommands[this.last]) {
|
||||
this.term.writeln(this.currentResponse);
|
||||
this.setPrompt();
|
||||
}
|
||||
// if the command is next or last, we still want to emit
|
||||
// the value, since the parent component is responsible
|
||||
// for interpreting that value and displaying the correct instructions
|
||||
if (this.buffer.match(/^next\s*/) || this.buffer.match(/^prev\s*/)) {
|
||||
this.command.emit(this.buffer);
|
||||
} else {
|
||||
this.term.writeln(this.currentResponse);
|
||||
this.setPrompt();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.command.emit(this.buffer);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue