Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Issue/39 autocomplete #172

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/app/desktop/windows/terminal/terminal-states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function reportError(error) {
}

export abstract class CommandTerminalState implements TerminalState {
abstract commands: { [name: string]: { executor: (args: string[]) => void, description: string } };
abstract commands: { [name: string]: { executor: (args: string[]) => void, description: string, hidden?: boolean } };

protocol: string[] = [];

Expand Down Expand Up @@ -51,8 +51,12 @@ export abstract class CommandTerminalState implements TerminalState {

autocomplete(content: string): string {
return content
? Object.keys(this.commands)
.filter(n => !['chaozz'].includes(n))
? this.getHistory()
.reverse()
.find(n => n.startsWith(content)) ||
Object.entries(this.commands)
.filter(command => !('hidden' in command[1]))
.map(([name]) => name)
.sort()
.find(n => n.startsWith(content))
: '';
Expand All @@ -76,7 +80,7 @@ export class DefaultTerminalState extends CommandTerminalState {
},
'status': {
executor: this.status.bind(this),
description: 'displays the number of online plyers'
description: 'displays the number of online players'
},
'hostname': {
executor: this.hostname.bind(this),
Expand Down Expand Up @@ -174,7 +178,8 @@ export class DefaultTerminalState extends CommandTerminalState {
// easter egg
'chaozz': {
executor: () => this.terminal.outputText('"mess with the best, die like the rest :D`" - chaozz'),
description: ''
description: '',
hidden: true
}
};

Expand Down Expand Up @@ -239,8 +244,8 @@ export class DefaultTerminalState extends CommandTerminalState {
help() {
const table = document.createElement('table');
Object.entries(this.commands)
.filter(command => !('hidden' in command[1]))
.map(([name, value]) => ({ name: name, description: value.description }))
.filter(command => !['chaozz'].includes(command.name))
.map(command => `<tr><td>${command.name}</td><td>${command.description}</td></tr>`)
.forEach(row => {
table.innerHTML += row;
Expand Down