antonmedv / fx

Terminal JSON viewer & processor
https://fx.wtf
MIT License
19.08k stars 438 forks source link

fix: stdout and stderr behavior #225

Closed baygeldin closed 1 year ago

baygeldin commented 2 years ago

I had a problem with piping fx to xargs, specifically things like this weren't working properly:

global.list = json => (json.forEach(x => console.log(x)), undefined)

Whenever I tried to use console.log reducers were acting weirdly, for example:

image

After some investigation I've realized that stderr from reducer processes was being mixed with stdout (which was the main issue) and also that pretty printing was misbehaving when stdout contained anything other than the reduced object.

So, I've cleaned up the code a little and now it works like this:

image

Also, reducers now can return an object regardless of whether console.log was used or not. It looks like this:

image