How to use the readline-sync.keyIn function in readline-sync

To help you get started, we’ve selected a few readline-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DannyNemer / aang / test / updateTestSuite.js View on Github external
}

		// Hide the `topResult` action in action list (because this update does not overwrite `topResult`).
		delete actions.e
	}

	// Print prompt choices.
	util.log()
	for (var actionKey in actions) {
		util.log(actionKey, '-', actions[actionKey])
	}

	// Require user to input one of the specified action keys.
	var actionKeys = Object.keys(actions)
	var query = '(' + (testIndex + 1) + ' of ' + tests.length + ') Overwrite this test [' + actionKeys + ']? '
	var actionKey = readlineSync.keyIn(util.colors.bold.blue(query), {
		limit: actionKeys,
		caseSensitive: true,
	})

	switch (actionKey) {
		case 'y':
			// Overwrite this entire test.
			return true
		case 'e':
			// Restore original `topResult` in new test.
			util.log('Original `topResult` restored.')
			newTest.topResult = existingTest.topResult
			return true
		case 'n':
			// Skip this test.
			return false