From 53fedffe871fb97a555c350241a533bffc4c296f Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Wed, 8 Nov 2023 17:21:02 +1000 Subject: [PATCH] fix shell prompt bug, add file type detector, start to work on more commands --- clite/commands.js | 8 ++++++++ clite/core.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/clite/commands.js b/clite/commands.js index 56c5afa..1c74318 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -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 } diff --git a/clite/core.js b/clite/core.js index 1bbcbfd..38eb0a2 100644 --- a/clite/core.js +++ b/clite/core.js @@ -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; } }