Skip to content

Commit 6d41ec8

Browse files
authored
updated "install" and "help" commands
1 parent 0752485 commit 6d41ec8

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

js/service/shell/commands.js

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,31 @@ const cmds = {
7474
},
7575
'help': {
7676
'description': 'Show this message or show usage of the command =)',
77-
'usage': 'help <command>',
77+
'usage': 'help <command> |OR| help |OR| help -p[=n] |OR| help --page[=n]',
7878
run (_args, f, res) {
7979
let args = _args.trim();
8080

81-
if (!args) {
82-
f.stdio.writeLine('Commands list:');
81+
if (!args || args.split(/\s+/)[0].startsWith("-p") || args.split(/\s+/)[0].startsWith("--page")) {
82+
var tmp_page = args.split(/\s+/)[0].slice(3 + 4 * Number(args.split(/\s+/)[0].startsWith("--page"))) - 1 || 0;
83+
if(tmp_page == -1) tmp_page = 0;
84+
var list = Array.from(processor.getCommands()).sort();
85+
if(tmp_page < 0 || tmp_page + 1 > Math.ceil(list.length / (vga.HEIGHT - 4))){
86+
f.stdio.setColor('red');
87+
f.stdio.write("Invalid page!");
88+
return res(1);
89+
}
90+
91+
f.stdio.writeLine(`Commands list (page ${tmp_page + 1}/${Math.ceil(list.length / (vga.HEIGHT - 4))}):`);
8392
// let out = 'Commands list:\n';
84-
for (const i of processor.getCommands()) {
93+
94+
for (var i = tmp_page * (vga.HEIGHT - 4); i < (tmp_page + 1) * (vga.HEIGHT - 4); i++) {
8595
// out += `${i}: ${processor.getDescription(i)}\n`;
96+
if(i == list.length) break;
97+
var _i = list[i];
8698
f.stdio.setColor('yellow');
87-
f.stdio.write(i);
99+
f.stdio.write(_i);
88100
f.stdio.setColor('white');
89-
f.stdio.writeLine(`: ${processor.getDescription(i)}`);
101+
f.stdio.writeLine(`: ${processor.getDescription(_i)}`);
90102
}
91103
// f.stdio.write(out);
92104
} else {
@@ -153,17 +165,61 @@ const cmds = {
153165
},
154166
'install': {
155167
'description': 'Install applications',
156-
'usage': 'install <app>',
168+
'usage': 'install <app> |OR| install --list[=n] |OR| install -l[=n]',
157169
run (app, f, res) {
158-
if ($$.appman.install(app.trim())) {
170+
if(app.trim().split(/\s+/)[0].slice(0, 2) == "-l" || app.trim().split(/\s+/)[0].slice(0, 6) == "--list"){
171+
const fs = require('fs');
172+
fs.readdir("/system/js/apps/", "utf-8", (err, list_) => {
173+
if(err){
174+
f.stdio.writeError("Unknown error!");
175+
debug(error);
176+
return res(1);
177+
}
178+
var list = [], ml = 1;
179+
for(var i = 0; i < list_.length; i++){
180+
ml = Math.max(ml, list_[i].length + 1);
181+
}
182+
for(var i = 0; i < list_.length; i++){
183+
list.push(list_[i] + " ".repeat(ml - list_[i].length) + "| " + fs.readFileSync("/system/js/apps/" + list_[i] + "/description.txt", "utf-8"));
184+
}
185+
if(app.trim().split(/\s+/)[0] == "-l" || app.trim().split(/\s+/)[0] == "--list") app = "-l=1";
186+
var tmp_page = app.trim().slice(Number(app.trim().split(/\s+/)[0].slice(0, 6) == "--list") * 4 + 3) - 1;
187+
if(tmp_page + 1 > Math.ceil(list.length / (vga.HEIGHT - 12))){
188+
f.stdio.setColor('red');
189+
f.stdio.writeLine("Invalid page!");
190+
return res(1);
191+
}
192+
f.stdio.setColor('magenta');
193+
f.stdio.writeLine(`Applications list (page: ${tmp_page + 1}/${Math.ceil(list.length / (vga.HEIGHT - 12))})
194+
`);
195+
f.stdio.setColor('yellow');
196+
for(var i = tmp_page * (vga.HEIGHT - 12); i < (tmp_page + 1) * (vga.HEIGHT - 12); i++){
197+
if(i == list.length) break;
198+
f.stdio.writeLine(list[i]);
199+
}
200+
f.stdio.setColor('cyan');
201+
f.stdio.writeLine(`
202+
-----
203+
Notice: when you are installing an app, it loads into RAM and uninstalls after rebooting.`);
204+
f.stdio.setColor('blue');
205+
f.stdio.writeLine(`
206+
To start an installed app, type:
207+
start <app>`);
208+
});
209+
return res(0);
210+
}
211+
if ($$.appman.install(app.trim().split(/\s+/)[0])) {
212+
159213
f.stdio.setColor('green');
160214
f.stdio.writeLine(`App ${app} installed successful!`);
161215

162216
return res(0);
163-
}
164-
f.stdio.writeError(`Error happened during ${app} installation`);
217+
218+
}else{
219+
f.stdio.writeError(`Error happened during ${app} installation`);
165220

166-
return res(1);
221+
return res(1);
222+
}
167223
},
168224
},
169225
'speaker': {

0 commit comments

Comments
 (0)