summaryrefslogtreecommitdiff
path: root/lambda-calcul
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul')
-rw-r--r--lambda-calcul/javascript/index.js30
1 files changed, 26 insertions, 4 deletions
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!'));