From f93e9428ea0e9272de7a9af2f8a2b519e08328ac Mon Sep 17 00:00:00 2001 From: talmobi Date: Fri, 27 Sep 2024 21:46:51 +0300 Subject: [PATCH] fix: selectOne timing with pipes (non TTY) and with library (NodeJS) --- bin/cli.js | 3 ++- src/main.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index c7fc078..a467b91 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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 ) @@ -114,6 +114,7 @@ function run () list.push( line ) } ) + api._selectOneActive = true api.update( list ) } ) diff --git a/src/main.js b/src/main.js index 3060d5d..221dd71 100644 --- a/src/main.js +++ b/src/main.js @@ -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 ) @@ -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 @@ -984,7 +983,7 @@ 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() @@ -992,6 +991,7 @@ function queryUser ( opts, callback ) handleKeypress( '', { name: 'return' } ) }) } + _opts._selectOneActive = false // print the matches _printedMatches = 0