Skip to content

Commit e1e76c6

Browse files
AtkinsSJKernelDeimos
authored andcommitted
feat(backend): Add tab-completion to server console command names
1 parent ecb9978 commit e1e76c6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/backend/src/services/CommandService.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class Command {
2323
this.spec_ = spec;
2424
}
2525

26+
get id() {
27+
return this.spec_.id;
28+
}
29+
2630
async execute(args, log) {
2731
log = log ?? console;
2832
const { id, name, description, handler } = this.spec_;
@@ -79,8 +83,12 @@ class CommandService extends BaseService {
7983
const args = text.split(/\s+/);
8084
await this.executeCommand(args, log);
8185
}
86+
87+
get commandNames() {
88+
return this.commands_.map(command => command.id);
89+
}
8290
}
8391

8492
module.exports = {
8593
CommandService
86-
};
94+
};

packages/backend/src/services/DevConsoleService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ class DevConsoleService extends BaseService {
131131
output: process.stdout,
132132
prompt: 'puter> ',
133133
terminal: true,
134+
completer: line => {
135+
// We only complete service and command names
136+
if ( line.includes(' ') )
137+
return;
138+
139+
const results = commands.commandNames
140+
.filter(name => name.startsWith(line))
141+
.map(name => `${name} `); // Add a space after to make typing arguments more convenient
142+
return [ results, line ];
143+
},
134144
});
135145
rl.on('line', async (input) => {
136146
this._before_cmd();

0 commit comments

Comments
 (0)