┌─┐┬ ┬ ┌─┐┌─┐ ┌─┐┌┬┐ ┬ ┬ ┬─┐┌─┐┌─┐
│ │ │ ─── ├┤ ├┤ ├─┤ │ │ │ ├┬┘├┤ └─┐
└─┘┴─┘┴ └ └─┘ ┴ ┴ ┴ └─┘ ┴└─└─┘└─┘
Convenient interface for communicating with user from command line
- Install:
npm install concolor
- Require:
const { Questioner, EscSequences } = require('cli-features');
- How you can use it:
const { Questioner } = require('cli-features');
const { generalQuestion } = new Questioner({
input: process.stdin,
output: process.stdout,
});
generalQuestion('What is your name?').then(console.log);
Examples: 1_generalQuestion.js
- questionStr:
string
- the line that will be printed at the start of the poll. (mandatory) - answers:
array[string] || object{string: boolean}
- possible answer options. If answers is an object, then instead of choosing one option, it becomes possible to select several (you can also specify which options will be enabled by default, by specifying the true key). (mandatory) - options: {
- maxLength:
number
- the maximum length of the list, after exceeding which, the list will be partially displayed - startWith:
number
- starting element index - isRounded:
boolean
- indicates whether the list looped back
}
- maxLength:
Examples: 2_alternativeQuestion.js
Remember!!! Esc sequences must be printed, otherwise there will be no effect!!!
- movement {
- moveRelX (dx
number
) - moves the cursor along the x-axis by dx columns - moveRelY (dy
number
) - moves the cursor along the y-axis by dy rows - moveRel (dx
number
, dynumber
) - moves the cursor along the x-axis by dx columns and along the y-axis by dy rows - moveAbsX (x
number
) - moves the cursor to the point corresponding to the coordinate x - moveAbsY (y
number
) - moves the cursor to the point corresponding to the coordinate y - moveAbs (x
number
, ynumber
) - moves the cursor to the point corresponding to the coordinates x, y
}
- moveRelX (dx
- visibility {
- setInvisibleMode () - makes the cursor invisible
- setVisibleMode () - makes the cursor visible
}
- deleting {
- deleteStartToCur () - clears the line from the current cursor position to the end of the line
- deleteCurToEnd () - clears the line from the beginning of the line to the current cursor position
- deleteAllLine () - clears the whole line
}
- decoration {
- normal - character after which everything printed will have its original form
- bold (string
string
) - makes the text bold - underlined (string
string
) - makes text underlined - invert (string
string
) - inverts the color of the text - setForegroundColor (color
number || string
, isBrightboolean
) - set text foreground color, if isBright is true, then another color pad will be used - setBackgroundColor (color
number || string
, isBrightboolean
) - set text background color, if isBright is true, then another color pad will be used - setTheme ({
options =
array[string]
, foregroundColornumber || string
, isForeColorBrightboolean
, backgroundColornumber || string
, isBackColorBrightboolean
, }) - foregroundColor and isForeColorBright correspond to color and isBright from setForegroundColor (), so do backgroundColor and isBackColorBright, in options you can pass something like['bold', 'underlined']
, to styling the text
}Possible colors: 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
Their numbers: 0, 1, 2, 3, 4, 5, 6, 7
Examples: escSequences.test.js