Comparing version 0.10.0 to 0.11.0
{ | ||
"name": "node-fzf", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "fzf ( junegunn/fzf ) inspired cli utility for node", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
@@ -35,4 +35,17 @@ [![npm](https://img.shields.io/npm/v/node-fzf.svg?maxAge=3600&style=flat-square)](https://www.npmjs.com/package/node-fzf) | ||
const opts = { | ||
/* required */ | ||
list: [ 'whale', 'giraffe', 'monkey' ], | ||
mode: 'normal' || 'fuzzy' // ( 'fuzzy', by default ) | ||
/* optional (and defaults) */ | ||
// filtering mode (user can change modes by pressing ctrl-s) | ||
mode: 'fuzzy' || 'normal', | ||
// prefill user input | ||
prefill: '', | ||
// text before each displayed line, list index supplied as arg | ||
prelinehook: function ( index ) { return '' } | ||
// text after each displayed line, list index supplied as arg | ||
postlinehook: function ( index ) { return '' } | ||
} | ||
@@ -39,0 +52,0 @@ |
@@ -78,4 +78,2 @@ // Gracefully restore the CLI cursor on exit | ||
let _input = '' | ||
// user defined vertical scrolling | ||
@@ -120,3 +118,3 @@ let scrollOffset = 0 | ||
// quit, exit, cancel, abort | ||
buffer = undefined | ||
inputBuffer = undefined | ||
@@ -127,5 +125,5 @@ result = { | ||
// common alternatives for the same thing | ||
query: buffer, | ||
search: buffer, | ||
input: buffer | ||
query: inputBuffer, | ||
search: inputBuffer, | ||
input: inputBuffer | ||
} | ||
@@ -149,7 +147,7 @@ } | ||
// input buffer | ||
let buffer = '' | ||
let inputBuffer = _opts.prefill || '' | ||
// input cursor position ( only horizontal ) | ||
// relative to input buffer | ||
let cursorPosition = 0 | ||
let cursorPosition = inputBuffer.length | ||
@@ -229,3 +227,3 @@ // number of items printed on screen, usually ~7 | ||
{ | ||
const slice = buffer.slice( 0, cursorPosition ) | ||
const slice = inputBuffer.slice( 0, cursorPosition ) | ||
const m = slice.match( /\S+\s*$/ ) // last word | ||
@@ -269,3 +267,3 @@ if ( m && m.index > 0 ) { | ||
{ | ||
const slice = buffer.slice( cursorPosition ) | ||
const slice = inputBuffer.slice( cursorPosition ) | ||
const m = slice.match( /^\S+\s*/ ) // first word | ||
@@ -276,3 +274,3 @@ if ( m && m.index >= 0 && m[ 0 ] && m[ 0 ].length >= 0 ) { | ||
} else { | ||
cursorPosition = buffer.length | ||
cursorPosition = inputBuffer.length | ||
} | ||
@@ -301,3 +299,3 @@ } | ||
case 'e': // end of line | ||
cursorPosition = buffer.length | ||
cursorPosition = inputBuffer.length | ||
return render() | ||
@@ -308,4 +306,4 @@ break | ||
{ | ||
const a = buffer.slice( 0, cursorPosition ) | ||
const b = buffer.slice( cursorPosition ) | ||
const a = inputBuffer.slice( 0, cursorPosition ) | ||
const b = inputBuffer.slice( cursorPosition ) | ||
const m = a.match( /\S+\s*$/ ) // last word | ||
@@ -315,6 +313,6 @@ if ( m && m.index > 0 ) { | ||
cursorPosition = m.index | ||
buffer = a.slice( 0, cursorPosition ).concat( b ) | ||
inputBuffer = a.slice( 0, cursorPosition ).concat( b ) | ||
} else { | ||
cursorPosition = 0 | ||
buffer = b | ||
inputBuffer = b | ||
} | ||
@@ -350,5 +348,5 @@ } | ||
{ | ||
const a = buffer.slice( 0, cursorPosition - 1 ) | ||
const b = buffer.slice( cursorPosition ) | ||
buffer = a.concat( b ) | ||
const a = inputBuffer.slice( 0, cursorPosition - 1 ) | ||
const b = inputBuffer.slice( cursorPosition ) | ||
inputBuffer = a.concat( b ) | ||
@@ -377,4 +375,4 @@ cursorPosition-- | ||
cursorPosition++ | ||
if ( cursorPosition > buffer.length ) { | ||
cursorPosition = buffer.length | ||
if ( cursorPosition > inputBuffer.length ) { | ||
cursorPosition = inputBuffer.length | ||
} | ||
@@ -419,5 +417,5 @@ return render() | ||
// common alternatives for the same thing | ||
query: buffer, | ||
search: buffer, | ||
input: buffer | ||
query: inputBuffer, | ||
search: inputBuffer, | ||
input: inputBuffer | ||
} | ||
@@ -451,9 +449,9 @@ | ||
if ( c ) { | ||
const a = buffer.slice( 0, cursorPosition ) | ||
const b = buffer.slice( cursorPosition ) | ||
buffer = a.concat( c, b ) | ||
const a = inputBuffer.slice( 0, cursorPosition ) | ||
const b = inputBuffer.slice( cursorPosition ) | ||
inputBuffer = a.concat( c, b ) | ||
cursorPosition++ | ||
if ( cursorPosition > buffer.length ) { | ||
cursorPosition = buffer.length | ||
if ( cursorPosition > inputBuffer.length ) { | ||
cursorPosition = inputBuffer.length | ||
} | ||
@@ -822,3 +820,3 @@ } | ||
_matches = [] // reset matches | ||
const words = buffer.split( /\s+/ ).filter( function ( word ) { return word.length > 0 } ) | ||
const words = inputBuffer.split( /\s+/ ).filter( function ( word ) { return word.length > 0 } ) | ||
for ( let i = 0; i < words.length; i++ ) { | ||
@@ -869,3 +867,3 @@ const word = words[ i ] | ||
stdout.write( buffer ) | ||
stdout.write( inputBuffer ) | ||
@@ -890,3 +888,3 @@ // do not print the list at all when `nolist` is set | ||
const words = buffer.split( /\s+/ ).filter( function ( word ) { return word.length > 0 } ) | ||
const words = inputBuffer.split( /\s+/ ).filter( function ( word ) { return word.length > 0 } ) | ||
@@ -1046,3 +1044,3 @@ const indexMap = {} // as map to prevent duplicates indexes | ||
const cursorOffset = stringWidth( buffer.slice( 0, cursorPosition ) ) | ||
const cursorOffset = stringWidth( inputBuffer.slice( 0, cursorPosition ) ) | ||
@@ -1049,0 +1047,0 @@ const cursorLeftPadding = stringWidth( lastInputLabel ) |
39463
166
940