From 0346d52e02722d39500e057cb7da92d9c2cb508f Mon Sep 17 00:00:00 2001 From: anseki Date: Mon, 10 Aug 2015 14:02:15 +0900 Subject: [PATCH] Add guide and sample to README --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a71d36..70d5e14 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ var readlineSync = require('readline-sync'); var userName = readlineSync.question('May I have your name? :'); console.log('Hi ' + userName + '!'); -// Handle the secret text. +// Handle the secret text (e.g. password). var favFood = readlineSync.question('What is your favorite food? :', { - hideEchoBack: true + hideEchoBack: true // The typed text on screen is hidden by `*` (default). }); console.log('Oh, ' + userName + ' loves ' + favFood + '!'); ``` @@ -31,7 +31,7 @@ What is your favorite food? :**** Oh, CookieMonster loves tofu! ``` -* Get user's response without Enter key: +* Get user's response by a single key without Enter key: ```js var readlineSync = require('readline-sync'); @@ -87,12 +87,71 @@ console.log('\nA value the user requested: ' + value); ![sample](screen_03.gif) +* Command line tool: + +```js +readlineSync.promptCLLoop({ + add: function(target, into) { + console.log(target + ' is added into ' + into + '.'); + }, + remove: function(target) { + console.log(target + ' is removed.'); + }, + bye: function() { return true; } +}); +console.log('Exited'); +``` + +```console +> add pic01.png archive +pic01.png is added into archive. +> delete pic01.png +Requested command is not available. +> remove pic01.png +pic01.png is removed. +> bye +Exited +``` + ## Installation ```shell npm install readline-sync ``` +## Quick Start + +** How does the user input? ** + +- [Type a reply to a question, and press an Enter key](#quick_start-a) (A) +- [Type a keyword like a command in prompt, and press an Enter key](#quick_start-b) (B) +- [Press a single key without Enter key](#quick_start-c) (C) + +** (A) What does the user input? ** + +- [E-mail address](#utility_methods-questionemail) +- [New password](#utility_methods-questionnewpassword) +- [Integer number](#utility_methods-questionint) +- [Floating-point number](#utility_methods-questionfloat) +- [Local file/directory path](#utility_methods-questionpath) +- [Others](#basic_methods-question) + +** (B) What does your script do? ** + +- [Receive a parsed command-name and arguments](#utility_methods-promptcl) +- [Receive an input repeatedly](#utility_methods-promptloop) +- [Receive a parsed command-name and arguments repeatedly](#utility_methods-promptclloop) +- [Receive an input with prompt that is similar to that of the user's shell](#utility_methods-promptsimshell) +- [Others](#basic_methods-prompt) + +** (C) What does the user do? ** + +- [Say "Yes" or "No"](#utility_methods-keyinyn) +- [Say "Yes" or "No" explicitly](#utility_methods-keyinynstrict) +- [Make the running of script continue when ready](#utility_methods-keyinpause) +- [Choose an item from a list](#utility_methods-keyinselect) +- [Others](#basic_methods-keyin) + ## Basic Methods These are used to control details of the behavior. It is recommended to use the [Utility Methods](#utility_methods) instead of Basic Methods if it satisfy your request.