| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | const c = require('kleur');
|
|---|
| 4 | const figures = require('./figures');
|
|---|
| 5 |
|
|---|
| 6 | // rendering user input.
|
|---|
| 7 | const styles = Object.freeze({
|
|---|
| 8 | password: { scale: 1, render: input => '*'.repeat(input.length) },
|
|---|
| 9 | emoji: { scale: 2, render: input => '😃'.repeat(input.length) },
|
|---|
| 10 | invisible: { scale: 0, render: input => '' },
|
|---|
| 11 | default: { scale: 1, render: input => `${input}` }
|
|---|
| 12 | });
|
|---|
| 13 | const render = type => styles[type] || styles.default;
|
|---|
| 14 |
|
|---|
| 15 | // icon to signalize a prompt.
|
|---|
| 16 | const symbols = Object.freeze({
|
|---|
| 17 | aborted: c.red(figures.cross),
|
|---|
| 18 | done: c.green(figures.tick),
|
|---|
| 19 | exited: c.yellow(figures.cross),
|
|---|
| 20 | default: c.cyan('?')
|
|---|
| 21 | });
|
|---|
| 22 |
|
|---|
| 23 | const symbol = (done, aborted, exited) =>
|
|---|
| 24 | aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default;
|
|---|
| 25 |
|
|---|
| 26 | // between the question and the user's input.
|
|---|
| 27 | const delimiter = completing =>
|
|---|
| 28 | c.gray(completing ? figures.ellipsis : figures.pointerSmall);
|
|---|
| 29 |
|
|---|
| 30 | const item = (expandable, expanded) =>
|
|---|
| 31 | c.gray(expandable ? (expanded ? figures.pointerSmall : '+') : figures.line);
|
|---|
| 32 |
|
|---|
| 33 | module.exports = {
|
|---|
| 34 | styles,
|
|---|
| 35 | render,
|
|---|
| 36 | symbols,
|
|---|
| 37 | symbol,
|
|---|
| 38 | delimiter,
|
|---|
| 39 | item
|
|---|
| 40 | };
|
|---|