mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
added ability to download a file using cat
This commit is contained in:
parent
c38dd412e7
commit
ded2aa9739
1 changed files with 36 additions and 6 deletions
|
|
@ -77,11 +77,34 @@ Options:
|
||||||
|
|
||||||
clite.commands.load('cat',function(args,env,io) {
|
clite.commands.load('cat',function(args,env,io) {
|
||||||
var files = [];
|
var files = [];
|
||||||
|
var download = false;
|
||||||
var pending = 0;
|
var pending = 0;
|
||||||
|
|
||||||
|
function help() {
|
||||||
|
io.write(`
|
||||||
|
Usage: cat [OPTION] <FILE> [FILE]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-? Print this help information
|
||||||
|
-d Download the file data, instead of printing it
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
for (var i=1; i<args.length; i++) {
|
for (var i=1; i<args.length; i++) {
|
||||||
if (args[i][0] == '-') {
|
if (args[i][0] == '-') {
|
||||||
io.error('unknown argument: '+args[i]);
|
for (var j=1; j<args[i].length; j++) {
|
||||||
|
switch (args[i][j]) {
|
||||||
|
case '?':
|
||||||
|
help();
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
download = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
io.error('unknown argument: '+args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}else if (args[i][0] == '/') {
|
}else if (args[i][0] == '/') {
|
||||||
files.push(args[i]);
|
files.push(args[i]);
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -99,7 +122,18 @@ clite.commands.load('cat',function(args,env,io) {
|
||||||
}else{
|
}else{
|
||||||
var d = clite.io.readAll(fd);
|
var d = clite.io.readAll(fd);
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
io.write(d);
|
if (download) {
|
||||||
|
var link = document.createElement("a");
|
||||||
|
link.target = '_blank';
|
||||||
|
link.download = fd.node.name;
|
||||||
|
var blob = new Blob([d], {type: "text/plain"});
|
||||||
|
link.href = URL.createObjectURL(blob);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}else{
|
||||||
|
io.write(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pending--;
|
pending--;
|
||||||
|
|
@ -128,9 +162,5 @@ clite.commands.load('cat',function(args,env,io) {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
clite.commands.load('download',function(args,env,io) {
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
// insert commands above this line
|
// insert commands above this line
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue