Skip to content

Commit 55bfc73

Browse files
authored
Add files via upload
1 parent 742cd41 commit 55bfc73

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

js/service/shell/commands.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const processor = require('./index.js');
2222
const { log, warn } = $$.logger;
2323
const { HEIGHT } = require('../../core/tty/vga.js');
2424

25+
const padEnd = (s, len, str = " ") => (s + str.repeat(Math.ceil((len - s.length) / str.length))).split(0, len);
26+
2527
debug('Loading commands...');
2628

2729
const cmds = {
@@ -77,10 +79,10 @@ const cmds = {
7779
'description': 'Show this message or show usage of the command =)',
7880
'usage': 'help <command> |OR| help |OR| help -p[=n] |OR| help --page[=n]',
7981
run (_args, f, res) {
80-
let args = _args.trim();
82+
let args = _args.trim().split(/\s+/);
8183

82-
if (!args || args.split(/\s+/)[0].startsWith("-p") || args.split(/\s+/)[0].startsWith("--page")) {
83-
let tmp_page = args.split(/\s+/)[0].slice(3 + 4 * Number(args.split(/\s+/)[0].startsWith("--page"))) - 1 || 0;
84+
if (!args || args[0].startsWith("-p") || args[0].startsWith("--page")) {
85+
let tmp_page = args[0].slice(3 + 4 * Number(args[0].startsWith("--page"))) - 1 || 0;
8486
if(tmp_page == -1) tmp_page = 0;
8587
const height = HEIGHT - 4;
8688
const commandList = Array.from(processor.getCommands()).sort();
@@ -103,7 +105,7 @@ const cmds = {
103105
}
104106
// f.stdio.write(out);
105107
} else {
106-
args = args.split(/\s+/)[0]; // Safety
108+
args = args[0]; // Safety
107109
f.stdio.setColor('lightcyan');
108110
f.stdio.write(processor.getUsage(args));
109111
}
@@ -182,10 +184,10 @@ const cmds = {
182184
maxLength = Math.max(maxLength, app.length + 1);
183185
}
184186
for(const app of list_){
185-
list.push(app + " ".repeat(maxLength - app.length) + "| " + fs.readFileSync("/system/js/apps/" + app + "/description.txt", "utf-8").replace("\n", "")); //костыль, не знаю, почему, но иногда появляется перенос строки в конце описания
187+
list.push(padEnd(app, maxLength) + "| " + fs.readFileSync(`/system/js/apps/${app}/description.txt`, "utf-8").replace("\n", "")); //костыль, не знаю, почему, но иногда появляется перенос строки в конце описания
186188
}
187189
if(args[0] === "-l" || args[0] === "--list") args[0] = "-l=1";
188-
const tmp_page = args[0].slice(Number(args[0].slice(0, 6) == "--list") * 4 + 3) - 1; //Получаем номер страницы мз первого аргумента
190+
const tmp_page = args[0].slice(args[0].search(/=/) + 1) - 1;
189191
const height = HEIGHT - 12;
190192
if(tmp_page + 1 > Math.ceil(list.length / height)){
191193
f.stdio.setColor('red');

0 commit comments

Comments
 (0)