Add support for command history, Firebase deploy
This commit is contained in:
parent
78827bc703
commit
31719ecdee
7 changed files with 52 additions and 4 deletions
5
.firebaserc
Normal file
5
.firebaserc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"projects": {
|
||||||
|
"default": "tb-console"
|
||||||
|
}
|
||||||
|
}
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -44,3 +44,5 @@ testem.log
|
||||||
# System Files
|
# System Files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
**.cache
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# TBConsoleClient
|
# TBConsoleClient
|
||||||
|
|
||||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.3.
|
A console client [website](https://tb-console.web.app/) that can be used to enter commands in Techblox. You need to install the [TBConsole](https://git.exmods.org/NorbiPeti/TBConsole) mod for it to work.
|
||||||
|
|
||||||
## Development server
|
## Development server
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
"optimization": true,
|
"optimization": true,
|
||||||
"outputHashing": "all",
|
"outputHashing": "all",
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"extractCss": true,
|
|
||||||
"namedChunks": false,
|
"namedChunks": false,
|
||||||
"extractLicenses": true,
|
"extractLicenses": true,
|
||||||
"vendorChunk": false,
|
"vendorChunk": false,
|
||||||
|
|
16
firebase.json
Normal file
16
firebase.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"hosting": {
|
||||||
|
"public": "dist/TBConsoleClient",
|
||||||
|
"ignore": [
|
||||||
|
"firebase.json",
|
||||||
|
"**/.*",
|
||||||
|
"**/node_modules/**"
|
||||||
|
],
|
||||||
|
"rewrites": [
|
||||||
|
{
|
||||||
|
"source": "**",
|
||||||
|
"destination": "/index.html"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,8 @@
|
||||||
<form>
|
<form>
|
||||||
<mat-form-field fxFlex="100">
|
<mat-form-field fxFlex="100">
|
||||||
<input matInput type="text" placeholder="Enter a command..." [formControl]="commandControl"
|
<input matInput type="text" placeholder="Enter a command..." [formControl]="commandControl"
|
||||||
[matAutocomplete]="commandCompletion" (focus)="commands || getCommandList()"/>
|
[matAutocomplete]="commandCompletion" (focus)="commands.length || getCommandList()"
|
||||||
|
(keyup.arrowUp)="previousCommand()" (keyup.arrowDown)="nextCommand()"/>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-autocomplete #commandCompletion="matAutocomplete">
|
<mat-autocomplete #commandCompletion="matAutocomplete">
|
||||||
<mat-option *ngFor="let cmd of displayedCommands" [value]="cmd.command">
|
<mat-option *ngFor="let cmd of displayedCommands" [value]="cmd.command">
|
||||||
|
|
|
@ -13,6 +13,7 @@ export class AppComponent {
|
||||||
commandControl: FormControl = new FormControl('');
|
commandControl: FormControl = new FormControl('');
|
||||||
commands: { command: string, line: string }[] = [];
|
commands: { command: string, line: string }[] = [];
|
||||||
displayedCommands: { command: string, line: string }[] = [];
|
displayedCommands: { command: string, line: string }[] = [];
|
||||||
|
commandHistory: { commands: string[], index: number } = {commands: [], index: 0};
|
||||||
|
|
||||||
@ViewChild('logMessagesContainer') logMessagesView: ElementRef;
|
@ViewChild('logMessagesContainer') logMessagesView: ElementRef;
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ export class AppComponent {
|
||||||
try {
|
try {
|
||||||
const command = this.commandControl.value;
|
const command = this.commandControl.value;
|
||||||
this.commandControl.setValue('');
|
this.commandControl.setValue('');
|
||||||
|
this.addCommandToHistory(command);
|
||||||
const res = await this.http.post('http://localhost:8019/command', command, {responseType: 'text'}).toPromise();
|
const res = await this.http.post('http://localhost:8019/command', command, {responseType: 'text'}).toPromise();
|
||||||
this.logMessages += res + "\n";
|
this.logMessages += res + "\n";
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -41,10 +43,33 @@ export class AppComponent {
|
||||||
|
|
||||||
async getCommandList() {
|
async getCommandList() {
|
||||||
const res = await this.http.post('http://localhost:8019/commands', '', {responseType: 'text'}).toPromise();
|
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) {
|
wait(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue