Skip to content

Commit e8658d7

Browse files
committed
add a prompt for asking if another random is needed
1 parent d47c056 commit e8658d7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/prompt.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,11 @@ exports.randomInteractive = {
5252
symbol: '>',
5353
menu: []
5454
}
55+
56+
exports.randomAgain = {
57+
type: 'confirm',
58+
query: bold().blue(' - Would you like to try another random?'),
59+
handle: 'redo',
60+
accept: 'y',
61+
deny: 'n'
62+
}

src/wiclipedia.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ async function _searchAgain() {
160160
}
161161
}
162162

163+
/**
164+
* Check if the user wants to make another research
165+
*/
166+
async function _randomAgain() {
167+
const input = await qoa.confirm(prompt.randomAgain)
168+
if (input.redo) {
169+
process.stdout.write('\u001Bc') // Clear the console
170+
displayRandomArticlesList()
171+
}
172+
173+
if (!input.redo) {
174+
process.exit(1)
175+
}
176+
}
177+
163178
/**
164179
* Bootstrap the app
165180
*/
@@ -222,7 +237,8 @@ const displayRandomArticlesList = async () => {
222237
await _checkUserAnswers(input, lang)
223238
const response = await fetch.getArticle(input.userPick, lang)
224239
_displayArticle(response)
225-
prompt.historyInteractive.menu = []
240+
prompt.randomInteractive.menu = []
241+
_randomAgain()
226242
}
227243

228244
exports.displayRandomArticlesList = displayRandomArticlesList

0 commit comments

Comments
 (0)