defunctzombie / node-process

process information for node.js and browsers
MIT License
122 stars 62 forks source link

process.stdout.write and process.stderr.write #24

Closed EyalAr closed 9 years ago

EyalAr commented 9 years ago

tl;dr: I realize you want to keep this module small. Feel free to reject this PR; in which case I'll maintain my own shim.

This PR adds write methods to process.stdout / process.stderr which simulate the corresponding methods in Node.

The new write methods:

  1. Simulate printing without a new line
  2. Can handle control chars (‘\r’, ‘\b’, ‘\n’)
  3. Use console.log / console.error as proxies for stdout.write / stderr.write

Example:

process.stdout.write("hello");
process.stdout.write("world\n");
process.stdout.write("foo");
process.stdout.write("\rbar\bz\n");

Will print (exactly as in Node):

helloworld
baz

While doing the same with console.log will print:

hello
world

foo
barz

Note:

Prints are buffered until a '\n' char is encountered. So process.stdout.write('foo') will print nothing.

defunctzombie commented 9 years ago

Hm. I would be much more inclined to include things like this if this module was not auto loaded by browserify. The issue right now is that any extra code into this module will increase the bundle size for basically everyone. Is that correct @substack?