Narnia's Psychedelic Mushrooms

    cli-features

    1.2.2 • Public • Published

     ┌─┐┬   ┬          ┌─┐┌─┐  ┌─┐┌┬┐ ┬   ┬ ┬─┐┌─┐┌─┐
     │     │   │  ───    ├┤  ├┤   ├─┤  │   │  │ ├┬┘├┤   └─┐
     └─┘┴─┘┴           └     └─┘ ┴  ┴   ┴   └─┘ ┴└─└─┘└─┘

    Convenient interface for communicating with user from command line

    Main memo

    • Install: npm install concolor
    • Require:
    const { Questioner, EscSequences } = require('cli-features');

    Base Usage

    const { Questioner } = require('cli-features');
    
    const { generalQuestion } = new Questioner({
      input: process.stdin,
      output: process.stdout,
    });
    
    generalQuestion('What is your name?').then(console.log);
    wait for .gif

    General question

    Examples: 1_generalQuestion.js

    wait for .gif

    Alternative question

    alternativeQuestion(

    • 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
        }

    ) => string || array[string] - selected points

    Examples: 2_alternativeQuestion.js

    wait for .gif

    ESC sequences

    Remember!!! Esc sequences must be printed, otherwise there will be no effect!!!

    EscSequences{

    • 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, dy number) - 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, y number) - moves the cursor to the point corresponding to the coordinates x, y
        }
    • 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, isBright boolean) - set text foreground color, if isBright is true, then another color pad will be used
      • setBackgroundColor (color number || string, isBright boolean) - set text background color, if isBright is true, then another color pad will be used
      • setTheme ({ options = array[string], foregroundColor number || string, isForeColorBright boolean, backgroundColor number || string, isBackColorBright boolean, }) - 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

    Install

    npm i cli-features

    DownloadsWeekly Downloads

    2

    Version

    1.2.2

    License

    MIT

    Unpacked Size

    39.2 kB

    Total Files

    19

    Last publish

    Collaborators

    • avatar