From 386416094b8b62efcbcf0b4de6d93a15c60296ab Mon Sep 17 00:00:00 2001 From: Utopiah Date: Fri, 12 May 2023 11:29:22 +0200 Subject: [PATCH] REPL completion --- index.js | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 75cf8bd..2c2a288 100644 --- a/index.js +++ b/index.js @@ -278,6 +278,7 @@ app.get('/sshconfig', (req, res) => { // note that stopping this process removes the mounts function mountAll(){ // might have to scanpeers() first + if (foundPeers.length==0) return getSshConfig().map( l => { let cs = 'sshfs ' + l.name + ':' if (l.custom) @@ -382,19 +383,29 @@ const webServer = https.createServer(credentials, app); // const webServer = http.createServer(app); // Listen on port webServer.listen(port, () => { - console.log("listening on "+protocol+"://localhost:" + port); + console.log("listening on "+protocol+"://localhost:" + port) + getCommand() }); // REPL testing const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, - output: process.stdout + output: process.stdout, + completer: completer }); +// https://nodejs.org/api/readline.html#use-of-the-completer-function +function completer(line) { + const completions = help().split('\n'); + const hits = completions.filter((c) => c.startsWith(line)); + // Show all completions if none found + return [hits.length ? hits : completions, line]; +} + let command = '' function getCommand(){ - rl.question("REPL: ", function(command) { + rl.question(process.title+" REPL: ", function(command) { if (command == "close") { rl.close(); } else { @@ -408,7 +419,6 @@ function getCommand(){ } }); } -getCommand() function help(){ return ` @@ -416,7 +426,28 @@ help() execConfiguredCommand(cmdName) getSshConfig() mountAll() -scanpeers()` +scanpeers() +foundPeers +port +protocol +subclass +publicKeyPath +publicKey +md5fromPub +process.title +filename +fileSaveFullPath +minfilename +minfileSaveFullPath +sshconfigpath +propath +localServices +configFilePath +utilsCmd +instructions +auth_instructions +process.title +` } rl.on("close", function() {