mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
fix shell prompt bug, add file type detector, start to work on more commands
This commit is contained in:
parent
34848dd74f
commit
53fedffe87
2 changed files with 57 additions and 1 deletions
|
|
@ -237,5 +237,13 @@ clite.commands.load('less',function(args,env,io) {
|
|||
return 0;
|
||||
});
|
||||
|
||||
clite.commands.load('view',function(args,env,io) {
|
||||
return 0;
|
||||
});
|
||||
|
||||
clite.commands.load('edit',function(args,env,io) {
|
||||
return 0;
|
||||
});
|
||||
|
||||
// insert commands above this line
|
||||
}
|
||||
|
|
|
|||
|
|
@ -912,7 +912,8 @@ clite.shell = {
|
|||
clite.shell.prompt.data = txt;
|
||||
},
|
||||
pop:function() {
|
||||
clite.shell.prompt.data = clite.shell.prompt.list.pop();
|
||||
if (clite.shell.prompt.list.length > 0)
|
||||
clite.shell.prompt.data = clite.shell.prompt.list.pop();
|
||||
},
|
||||
generate:function() {
|
||||
var p = clite.shell.env.USER+':'+clite.shell.env.PWD;
|
||||
|
|
@ -1045,5 +1046,52 @@ clite.lib = {
|
|||
if (s.length > 0)
|
||||
parts.push(s);
|
||||
return parts;//txt.split(' ');
|
||||
},
|
||||
getFileType:function(fd) {
|
||||
// returns an int identifier for the file type:
|
||||
// 0: unknown
|
||||
// 1: text file
|
||||
// 2: executable/binary (function)
|
||||
// 3: directory
|
||||
// 4: link
|
||||
// 5: device
|
||||
// 6: unloaded remote file
|
||||
// 7: shell script
|
||||
// 8: image
|
||||
if (fd.node.data.content == null) {
|
||||
if (fd.node.data.remote != null)
|
||||
return 6;
|
||||
return 0;
|
||||
}
|
||||
if (fd.node.data.islink)
|
||||
return 4;
|
||||
if (fd.node.data.isdir)
|
||||
return 3;
|
||||
if (fd.node.data.isdev)
|
||||
return 5;
|
||||
const type = typeof fd.node.data.content;
|
||||
switch (type) {
|
||||
case 'string': // text file
|
||||
if (fd.node.data.content.substring(0,2) == '#!')
|
||||
return 7;
|
||||
return 1;
|
||||
break;
|
||||
case 'function': // executable
|
||||
return 2;
|
||||
break;
|
||||
case 'object':
|
||||
if (Array.isArray(fd.node.data.content)) // directory
|
||||
return 3;
|
||||
if (fd.node.data.content instanceof HTMLImageElement)
|
||||
return 8;
|
||||
case 'symbol':
|
||||
case 'boolean':
|
||||
case 'number':
|
||||
case 'bigint':
|
||||
case 'undefined':
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue