handle next and prev commands

This commit is contained in:
Victoria Jeffrey 2016-09-01 11:19:04 -04:00 committed by Christoph Hartmann
parent 58cf016410
commit 24c30e0603
2 changed files with 28 additions and 11 deletions

View file

@ -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'];
}

View file

@ -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);
}