From d8604b3e3bbe4963d6c12d00f5c079084a86f53c Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Tue, 12 Dec 2023 20:09:17 +1000 Subject: [PATCH] so many shell bugs - builtins freeze the shell --- clite/commands.js | 23 ++++++++++------------- clite/core.js | 15 ++++++++++++++- clite/libterm.js | 6 ++++-- clite/shell.js | 32 +++++++++++--------------------- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/clite/commands.js b/clite/commands.js index ae9ed17..d194fa5 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -18,9 +18,7 @@ touch - create a new file less - simple text file viewer file - determines the file type -Under Development: -view - file viewer -edit - text file editor +And many more. Running any command with the argument -? will give you help for that program. Or you can run help to get the same info. @@ -28,8 +26,7 @@ Or you can run help to get the same info. As a basic guide for guests: Use ls to see what content is available, eg: ls web Use view or less to view the content, eg: view web/about - - `); +`); return 0; }); @@ -117,7 +114,7 @@ Options: one = true; break; default: - stdio.write(io.stderr,'unknown argument: -'+args[i][j]); + stdio.fprintf(io.stderr,'unknown argument: -%c\n',args[i][j]); } } }else{ @@ -133,12 +130,12 @@ Options: stdio.printf(dir+':'); var fd = stdio.open(dir,stdio.flags.O_RDONLY|stdio.flags.O_SYNC); if (!fd) { - stdio.write(io.stderr,'cannot open directory: '+dir); + stdio.fprintf(io.stderr,'cannot open directory: %s\n',dir); return; } var st = stdio.fstatat(fd,stdio.flags.AT_SYMLINK_NOFOLLOW); if (!st) { - stdio.write(io.stderr,'cannot read file: '+dir); + stdio.fprintf(io.stderr,'cannot read file: %s\n',dir); stdio.close(fd); return; } @@ -153,13 +150,13 @@ Options: continue; var efd = stdio.open(dir+'/'+e,stdio.flags.O_RDONLY|stdio.flags.O_NOFOLLOW|stdio.flags.O_SYNC); if (!efd) { - stdio.write(io.stderr,'cannot read contents: '+dir); + stdio.fprintf(io.stderr,'cannot read contents: %s\n',dir); break; } var est = stdio.fstatat(efd,stdio.flags.AT_SYMLINK_NOFOLLOW); if (!est) { stdio.close(efd); - stdio.write(io.stderr,'cannot read content: '+dir); + stdio.fprintf(io.stderr,'cannot read content: %s\n',dir); break; } writeNodeData(est,efd); @@ -1047,7 +1044,7 @@ Options: } if (file == null) { - stdio.write(io.stderr,'no file specified'); + stdio.write(io.stderr,'no file specified\n'); return 1; } @@ -1055,7 +1052,7 @@ Options: var txt = short+': '; if (!st) { - stdio.fprintf(io.stderr,'cannot open file: %s',file); + stdio.fprintf(io.stderr,'cannot open file: %s\n',file); return 1; }else{ switch (st.type) { @@ -1092,7 +1089,7 @@ Options: } } - stdio.printf(txt); + stdio.printf('%s\n',txt); return 0; }); diff --git a/clite/core.js b/clite/core.js index e9a5756..fac0393 100644 --- a/clite/core.js +++ b/clite/core.js @@ -2298,8 +2298,21 @@ clite.tty = { if (!l) return; - t.rcb(l); + var f = t.rcb; t.rcb = null; + + f(l); + }, + fake:function(str) { + for (var i=0; i=clite.tty.data.ttys.length) diff --git a/clite/libterm.js b/clite/libterm.js index 2cd8ea9..cbac6be 100644 --- a/clite/libterm.js +++ b/clite/libterm.js @@ -6,11 +6,13 @@ return Object.create({ // clears the terminal clear:function() { - clite.term.clear(); + var ctty = 0; + clite.tty.clear(ctty); }, ttyctrl:function(fn,v) { - return clite.term.ttyctrl(fn,v); + return false; + //return clite.term.ttyctrl(fn,v); } }); diff --git a/clite/shell.js b/clite/shell.js index 1cfab6f..6deed86 100644 --- a/clite/shell.js +++ b/clite/shell.js @@ -14,28 +14,22 @@ clite.commands.load('sh',function(args,env,io) { }, cd:function(args,io) { var dir = env.HOME; - if (args.length > 1) { + if (args.length > 1) dir = clite.resolvePath(args[1]); - } var fd = stdio.open(dir,stdio.flags.O_SEARCH|stdio.flags.O_DIRECTORY); if (!fd) { - stdio.write(io.stderr,'invalid directory: '+dir); - return; - } - // shouldn't need this now - if (!fd.node.data.isdir) { - stdio.write(io.stderr,'invalid directory: '+dir); + stdio.fprintf(io.stderr,'invalid directory: %s\n',dir); return; } stdio.close(fd); env.PWD = dir; }, pwd:function(args,io) { - stdio.write(io.stdout,env.PWD); + stdio.fprintf(io.stdout,'%s\n',env.PWD); }, echo:function(args,io) { args.shift(); - var txt = args.join(' '); + var txt = args.join(' ')+'\n'; stdio.write(io.stdout,txt); }, which:function(args,io) { @@ -47,31 +41,31 @@ clite.commands.load('sh',function(args,env,io) { var path = resolvePATH(args[1]); if (!path) return; - stdio.write(io.stdout,args[1]+' is '+path); + stdio.fprintf(io.stdout,'%s is %s\n',args[1],path); } }, type:function(args,io) { if (args.length <2) return; if (typeof macro[args[1]] != 'undefined') { - stdio.write(io.stdout,args[1]+' is a shell builtin'); + stdio.fprintf(io.stdout,'%s is a shell builtin\n',args[1]); }else{ var path = resolvePATH(args[1]); if (!path) return; - stdio.write(io.stdout,args[1]+' is '+path); + stdio.fprintf(io.stdout,'%s is %s\n',args[1],path); } }, whoami:function(args,io) { - stdio.write(io.stdout,env.USER); + stdio.fprintf(io.stdout,'%s\n',env.USER); }, alias:function(args,io) { - stdio.write(io.stdout,'unimplemented'); + stdio.fprintf(io.stdout,'unimplemented\n'); }, export:function(args,io) { if (args.length == 1) { Object.keys(env).forEach(function(key) { - stdio.write(io.stdout,key+'='+env[key]); + stdio.fprintf(io.stdout,'%s=%s\n',key,env[key]); }); return; } @@ -203,7 +197,7 @@ clite.commands.load('sh',function(args,env,io) { } function tabfill() { - var c = term.ttyctrl('iget'); + var c = '';//term.ttyctrl('iget'); var parts = clite.strToArgs(c); var ai = parts.length-1; if (ai < 0) @@ -370,10 +364,6 @@ clite.commands.load('sh',function(args,env,io) { if (has_exited) return; writePrompt(); - // ensure input is enabled - term.ttyctrl('show'); - // and that we're on the main framebuffer - term.ttyctrl('alt',false); // then read from stdin stdio.read(io.stdin,input); }