Skip to content

Commit

Permalink
fix: selectOne timing with pipes (non TTY) and with library (NodeJS)
Browse files Browse the repository at this point in the history
  • Loading branch information
talmobi committed Sep 27, 2024
1 parent 215c911 commit f93e942
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function run ()
keepRight: !!argv['keep-right'],
}


opts._selectOneActive = false
const api = nfzf( opts, function ( result ) {
if ( result.selected ) {
console.log( result.selected.value )
Expand Down Expand Up @@ -114,6 +114,7 @@ function run ()
list.push( line )
} )

api._selectOneActive = true
api.update( list )
} )

Expand Down
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,6 @@ function queryUser ( opts, callback )

function render ()
{
render._count = render._count || 0
render._count++

const width = stdout.columns || clc.windowSize.width
const height = stdout.rows || clc.windowSize.height
// console.log( 'window height: ' + height )
Expand Down Expand Up @@ -852,6 +849,8 @@ function queryUser ( opts, callback )
// get rid of dirt when being pushed above MIN_HEIGHT
// from the bottom of the terminal
cleanDirtyScreen()

if (_opts._selectOneActive === undefined) _opts._selectOneActive = true
}
render.init = true

Expand Down Expand Up @@ -984,14 +983,15 @@ function queryUser ( opts, callback )
_selectedItem = _matches[ 0 ]
}

if (render._count === 1 && _matches.length === 1 && _opts.selectOne ) {
if (_opts._selectOneActive && _matches.length === 1 && _opts.selectOne ) {
// console.log(' === attempting to select one === ')
_selectedItem = _matches[ 0 ]
cleanDirtyScreen()
process.nextTick(function () {
handleKeypress( '', { name: 'return' } )
})
}
_opts._selectOneActive = false

// print the matches
_printedMatches = 0
Expand Down

0 comments on commit f93e942

Please sign in to comment.