From 37d26e407f903e87bbf4c247c8385b662319b620 Mon Sep 17 00:00:00 2001 From: Emmanuel Gaillot Date: Sat, 20 Dec 2025 21:48:03 +0100 Subject: Wait for user input before ending MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … In preparation for unregistering user at the end. --- lambda-calcul/javascript/index.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'lambda-calcul/javascript') diff --git a/lambda-calcul/javascript/index.js b/lambda-calcul/javascript/index.js index a71697d..5c080d1 100644 --- a/lambda-calcul/javascript/index.js +++ b/lambda-calcul/javascript/index.js @@ -1,15 +1,37 @@ +const { createInterface } = require('readline/promises'); + const LC = require('./src/client'); const playerName = process.env.PLAYER_NAME || 'A shy user'; -client = LC.newClient({ +const client = LC.newClient({ playerName, challengerURL: process.env.CHALLENGER_URL, }); -client.start() - .then(token => console.log(`${playerName} has registered with token ${token}`) || token) - .then(client.nextChallenge) +let token; + +const solveNextChallenge = (token) => client + .nextChallenge(token) .then(challenge => console.log(`Next challenge: ${challenge}`) || challenge) .then(client.solve) .then(solution => console.log(`… solved into: ${solution}`)); + +const waitForEnterToBePressed = () => { + const readlineInterface = createInterface({ + input: process.stdin, + output: process.stdout, + }); + + return readlineInterface.question('Done. Press Enter to finish.') + .then(() => readlineInterface.close()); +}; + +client.start() + .then(t => { + token = t; + console.log(`${playerName} has registered with token ${t}`); + }) + .then(() => solveNextChallenge(token)) + .then(() => waitForEnterToBePressed()) + .then(() => console.log('Done done!')); -- cgit v1.3.1