nathanpeck / clui

Command Line UI toolkit for Node.js
MIT License
1.66k stars 40 forks source link

Excess new lines when using Line.output #8

Closed Riobe closed 7 years ago

Riobe commented 9 years ago

Line#output calls process.stdout.write with an added new line. This causes, at least on Windows, there to be two new lines after every line because process.stdout.write outputs with a new line already. Could this excess new line either be removed or be controlled by an option for if it's there or not?

For instance, the constructor for Line could be:

// Chainable wrapper for line content
Line: function (defaultBuffer, opts) {
  var lineContent = "";
  var self = this;
  if (defaultBuffer instanceof helpers.LineBuffer) {
      self.defaultBuffer = defaultBuffer;
  }

  // Allow the user to send in options as the first argument if they aren't
  // supplying a default buffer.
  self.options = self.defaultBuffer ?
      opts:
      defaultBuffer;

  self.options = self.options || {};

  // Default new line option to true to maintain old behavior.
  if (!self.options.hasOwnProperty('newLine')) {
      self.options.newLine = true;
  }

And then the output could look like:

// Output a line directly to the screen.
this.output = function () {
  process.stdout.write(lineContent + (self.options.newLine ? '\n' : ''));
  return self;
};

I'm not sure which way you want to go with this, but I would love the ability to suppress that newline. I'm happy to created a pull request for it if you want, once you specify which way you want to go with things.

Riobe commented 7 years ago

I'm going to assume this will never be replied to so I'm closing it. A simple "no thanks" would have been nice though.