You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not quite sure this is the implementation, but probably something close to this.
I'd actually much prefer to have inline autocomplete, like fish, but I've done that before and it's no small feat - certainly outside of the "almost bare metal" approach of AjScript.
/** * @param {String} query * @param {Object} options * @param {Array<String>} [options.choices] * @param {Boolean} [options.mask] */process._prompt=asyncfunction(query,options){letReadline=require("readline");letcompleter;if(options?.choices){/** * @param {String} line */completer=function(line){letcompletions=options.choices||[];lethits=completions.filter(function(c){returnc.startsWith(line);});if(!hits.length){hits=completions;}return[hits,line];};}letrl=Readline.createInterface({input: process.stdin,output: process.stdout,
completer,});if(options?.mask){rl.input.on("keypress",function(_char,_modifiers){// _char = "e"// _modifiers = { sequence: 'e', name: 'e', ctrl: false, meta: false, shift: false }letlen=rl.line.length;// place cursor at the beginning of the promptReadline.moveCursor(rl.output,-len,0);// clear right of the cursor / promptReadline.clearLine(rl.output,1);// mask with "*"rl.output.write("*".repeat(len));});}letanswer=awaitnewPromise(function(resolve){returnrl.question(query??"",resolve);});// TODO what if we need control over closing?// ex: Promise.race([getPrompt, getFsEvent, getSocketEvent]);rl.close();returnanswer;};
I'm not quite sure this is the implementation, but probably something close to this.
I'd actually much prefer to have inline autocomplete, like
fish
, but I've done that before and it's no small feat - certainly outside of the "almost bare metal" approach of AjScript.Inspired by https://github.com/google/zx/blob/51fb6d5d710fcd0bfcc7bc905066ac0fa042467c/index.mjs#L143.
The text was updated successfully, but these errors were encountered: