Skip to content

derhuerst/tree-select-prompt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-select-prompt

A prompt to select an item from a tree.

asciicast

npm version dependency status dev dependency status ISC-licensed

tree-select-prompt uses cli-styles to have a look & feel consistent with other prompts.

Installing

npm install tree-select-prompt

Usage

const treeSelectPrompt = require('tree-select-prompt')

const choices = [
	{title: 'File "A"', value: 'file-a.jpg'},
	{title: 'File "B"', value: 'file-b.pdf'},
	{title: 'Directory "Stuff"', value: 'stuff', children: [
		{title: 'File "C"',  value: 'stuff/file-c.txt'},
		{title: 'File "D"',   value: 'stuff/file-d.js'}
	]},
	{title: 'File "E"',  value: 'file-e.css'}
]

// All these are optional.
const opts = {
	  hint:    '– Space to expand. Return to select.'
	, cursor:  0
}

treeSelectPrompt('Please choose a file.', choices, opts)
.on('data', (item) => console.log('Changed to', item))
.on('abort', (item) => console.log('Aborted with', item))
.on('submit', (item) => console.log('Submitted with', item))

Related

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.