Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-fzf

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-fzf - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

2

package.json
{
"name": "node-fzf",
"version": "0.0.2",
"version": "0.0.3",
"description": "fzf ( junegunn/fzf ) inspired cli utility for node",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -44,2 +44,6 @@ const keypress = require( 'keypress' )

function getMaxWidth () {
return clc.windowSize.width - 7
}
const debug = false

@@ -205,12 +209,60 @@

const item = list[ i ]
const matches = fuzzyMatches( fuzz, item )
const normalizedItem = item.split( /\s+/ ).join( ' ' )
const matches = fuzzyMatches( fuzz, normalizedItem )
if ( matches.length === fuzz.length ) {
// matches
let t = item
let t = normalizedItem
const paintBucket = [] // characters to colorize at the end
for ( let i = 0; i < matches.length; i++ ) {
const index = matches[ matches.length - ( i + 1 ) ]
const index = matches[ i ]
paintBucket.push( { index: index, clc: clcFgMatchGreen } )
}
const c = clcFgMatchGreen( t[ index ] )
const len = t.length
const maxLen = getMaxWidth() // terminal width
// shift left until the last matched fuzzy character is visible
const lastMatchIndex = matches[ matches.length - 1 ]
const marginRight = Math.ceil( clc.windowSize.width * 0.4 )
let matchMarginRight = ( lastMatchIndex + marginRight )
// limit too much unnecessary empty margin
if ( matchMarginRight > ( t.length + 8 ) ) matchMarginRight = ( t.length + 8 )
const shiftRight = ( maxLen - matchMarginRight )
let shiftAmount = 0
let startIndex = 0
let endIndex = t.length
if ( shiftRight < 0 ) {
// we need to shift so that the matched text and margin is in view
shiftAmount = -shiftRight
t = '...' + t.slice( shiftAmount )
startIndex = 3
}
if ( t.length > maxLen ) {
t = t.slice( 0, maxLen ) + '...'
endIndex = maxLen
}
// colorise fuzzy matched characters
// in reverse because invisible ANSI color characters increases
// string length
paintBucket.sort( function ( a, b ) {
return b.index - a.index
} )
for ( let i = 0; i < paintBucket.length; i++ ) {
const paint = paintBucket[ i ]
const index = paint.index - shiftAmount + startIndex
// skip fuzzy chars that have shifted out of view
if ( index < startIndex ) continue
if ( index > endIndex ) continue
const c = paint.clc( t[ index ] )
t = t.slice( 0, index ) + c + t.slice( index + 1 )

@@ -222,3 +274,3 @@ }

original: item,
colored: t
text: t // what shows up on terminal/screen
} )

@@ -299,4 +351,11 @@ }

const startIndex = Math.max( 0, offset - maxPrintLength + Math.ceil( MIN_HEIGHT * 0.25 ) )
let paddingBottom = 2 // 1 extra padding at the bottom when scrolling down
if ( matches.length <= MIN_HEIGHT ) {
// no extra padding at the bottom since there is no room for it
// - othewise first match is cut off and will not be visible
paddingBottom = 1
}
const startIndex = Math.max( 0, offset - maxPrintLength + paddingBottom )
const matchLimit = Math.min( maxPrintLength + startIndex, matches.length )

@@ -310,3 +369,3 @@

const item = match.colored
const item = match.text

@@ -313,0 +372,0 @@ const itemSelected = (

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