intercept-stdout icon indicating copy to clipboard operation
intercept-stdout copied to clipboard

Feature request: mute

Open karlpokus opened this issue 9 years ago • 6 comments

Thanks for sharing your module! I'm looking for a way to both intercept and mute the log. By commenting out this line I think it would work.

Would you be interested in a PR or should I fork?

karlpokus avatar Jul 03 '16 09:07 karlpokus

Not returning in the interceptor should work, shouldn't it?

SimenB avatar Jul 13 '16 09:07 SimenB

I think SimenB is basically right, you can see the first example (output is muted) in the README compared to the 2nd one under the modification section (the 'intercepter' returns a manipulated string). Although, I think process.stdout.write is still being called regardless, but I am not sure this has an effect.

sfarthin avatar Jul 13 '16 12:07 sfarthin

@SimenB Nor sure what you mean by Not returning in the interceptor. Commenting out captured_text += txt or removing the callback altogether does not work.

@sfarthin But the log is not muted in the first example. The part below logs a and b.

var intercept = require("intercept-stdout"),
    captured_text = "";

var unhook_intercept = intercept(function(txt) {
    captured_text += txt;
});

console.log("a");
unhook_intercept(); // Let's stop capturing stdout.
console.log("b");

Nevermind. I made something that mutes the log (although I think I lost the streaming aspect but that's fine by me).

karlpokus avatar Jul 14 '16 07:07 karlpokus

@karlpokus correct. @sfarthin was talking about 2nd example in the readme.

It's not obvious from the readme, but after studying tests I realised that to suppress output empty string should be returned (not undefined).

let unhook_intercept = intercept(function (line) {
    // ...
    return ''
})

@sfarthin could be useful to mention that not returning a string will result in print of the original string.

fedor avatar Sep 29 '16 16:09 fedor

Sounds good, would you mind doing a PR?

sfarthin avatar Sep 29 '16 17:09 sfarthin

This sort of can be closed. The readme has the info but on the npm site, the changes to the readme are not there.

LaurentGoderre avatar Jul 31 '18 18:07 LaurentGoderre