|
|
@@ -13,6 +13,7 @@ export class AppComponent { |
|
|
|
commandControl: FormControl = new FormControl(''); |
|
|
|
commands: { command: string, line: string }[] = []; |
|
|
|
displayedCommands: { command: string, line: string }[] = []; |
|
|
|
commandHistory: { commands: string[], index: number } = {commands: [], index: 0}; |
|
|
|
|
|
|
|
@ViewChild('logMessagesContainer') logMessagesView: ElementRef; |
|
|
|
|
|
|
@@ -27,6 +28,7 @@ export class AppComponent { |
|
|
|
try { |
|
|
|
const command = this.commandControl.value; |
|
|
|
this.commandControl.setValue(''); |
|
|
|
this.addCommandToHistory(command); |
|
|
|
const res = await this.http.post('http://localhost:8019/command', command, {responseType: 'text'}).toPromise(); |
|
|
|
this.logMessages += res + "\n"; |
|
|
|
} catch (e) { |
|
|
@@ -41,10 +43,33 @@ export class AppComponent { |
|
|
|
|
|
|
|
async getCommandList() { |
|
|
|
const res = await this.http.post('http://localhost:8019/commands', '', {responseType: 'text'}).toPromise(); |
|
|
|
this.commands = res.split('\n').map(cmd => ({command: cmd.split(' - ')[0], line: cmd})); |
|
|
|
this.commands = res.trim().split('\n').map(cmd => ({command: cmd.split(' - ')[0], line: cmd})); |
|
|
|
} |
|
|
|
|
|
|
|
wait(ms) { |
|
|
|
return new Promise(resolve => setTimeout(resolve, ms)); |
|
|
|
} |
|
|
|
|
|
|
|
previousCommand() { |
|
|
|
const hist = this.commandHistory; |
|
|
|
if (hist.index <= 0) return; |
|
|
|
hist.index--; |
|
|
|
this.commandControl.setValue(hist.commands[hist.index]); |
|
|
|
} |
|
|
|
|
|
|
|
nextCommand() { |
|
|
|
const hist = this.commandHistory; |
|
|
|
if (hist.index >= hist.commands.length - 1) return; |
|
|
|
hist.index++; |
|
|
|
this.commandControl.setValue(hist.commands[hist.index]); |
|
|
|
} |
|
|
|
|
|
|
|
addCommandToHistory(command: string) { |
|
|
|
const hist = this.commandHistory; |
|
|
|
if (hist.commands.length == 0) hist.commands.push(''); |
|
|
|
hist.commands[hist.commands.length - 1] = command; |
|
|
|
hist.commands.push(''); //Empty to enter new commands |
|
|
|
if (hist.commands.length > 50) hist.commands.shift(); |
|
|
|
hist.index = hist.commands.length - 1; |
|
|
|
} |
|
|
|
} |