Socket
Socket
Sign inDemoInstall

cli-list-select

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-list-select

Simple command line interactive list


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

CI

cli-list-select

Simple command line interactive list

Install

npm i cli-list-select

Description

Package exports single function

const list = require('cli-list-select');

Function is async and has 2 arguments.

Function arguments

NameTypeDescription
itemsany[]items to be displayed
options?Optionoptions

Returns Result

Options

FieldTypeDefaultDescription
printItem(item: any, index: number, isFocused: bool, isChecked: bool) => stringStringfunction that provides string representation for an item
indexnumber0initial focus position
singleCheckboolfalsetells if only one item can be checked
checksnumber[] | number[] | NaNinitially checked items
handlersHandlers{}custom key handlers

Handlers

It is a map.

FieldTypeDescription
keystringkey name
value(arg: HandlerArg) => voidkey handler

Default handlers are

KeyHandler
upmove focus to previous item
downmove focus to next item
spacetoggle check of the focused item
returnclose the list

HandlerArg

FieldTypeDescription
indexnumbercurrent focus
setIndex(index: number) => voidfunction that sets current focus
toggleCheck(index: number) => voidfunction that toggles check state of an item
end(note: any) => voidfunction that closes the list

Result

FieldTypeDescription
indexnumberfocus
checksnumber[] | numberchecked items
noteanynote returned in the end function

Call

Just print a list

await list(['A', 'B', 'C']);
-[ ] A
 [ ] B
 [ ] C

Set initial focus

await list(['A', 'B', 'C'], { index: 1 });
 [ ] A
-[ ] B
 [ ] C

Check an item

 [*] A
-[*] B
 [ ] C

Single check mode

await list(['A', 'B', 'C'], { singleCheck: true });
 [ ] A
-[*] B
 [ ] C

Initial checks

await list(['A', 'B', 'C'], { checks: [0, 2] });
-[*] A
 [ ] B
 [*] C

Custom print

await list([{ data: 'A' }, { data: 'B' }, { data: 'C' }], {
    printItem: item => `<${item.data}>`
});
-[ ] <A>
 [ ] <B>
 [ ] <C>

Custom handlers

await list(['A', 'B', 'C'], {
    handlers: {
        'q': ({ end }) => end('Q'),
    },
});

Examples

Keywords

FAQs

Package last updated on 09 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc