anc95 / inquirer-file-tree-selection

inquirer prompt for select a file or dir by file tree
49 stars 26 forks source link

Error: Invalid count value on Windows #16

Closed mritzco closed 3 years ago

mritzco commented 3 years ago

Hi,

I'm getting an error on Windows on a couple of computers, error happens because prefix.length is too large for root directory.

Apparently the issue is that on Windows the symbol: is replaced for ( )

index.js #172

showValue = ' '.repeat(indent - prefix.length + 2) + prefix + itemPath.name + (itemPath.type === 'directory' ? path.sep : '')  + '\n'

Testing code, add before line #172

const ind = indent - prefix.length + 2;
console.log(ind, indent, prefix.length, prefix, itemPath.name);
// Linux prints:    0 2 4 ↓ ◯  .(root directory)
// Windows prints: -2 2 6 ↓ ( )   .(root directory)

// temporary fix
showValue = ' '.repeat(ind < 0 ? 0 : ind) + prefix + itemPath.name + (itemPath.type === 'directory' ? path.sep : '')  + '\n'

Not sure what would be the best way to solve this issue as it comes from figures: https://www.npmjs.com/package/figures

I'll make a clone with the quick fix and can submit a pull request if this patch is the better option.

anc95 commented 3 years ago

thanks ❤️