Conversation
index.js
Outdated
| stream.write(''); | ||
| }; | ||
|
|
||
| log.keepContent = function() { |
There was a problem hiding this comment.
Wouldn't .newLine or something similar be more clear?
There was a problem hiding this comment.
I started with calling it keepLines, but decided that keepOutput was better. And then I wrote keepContent. I guess I'm doing too much at the same time ;).
As for the other suggestion, it does not actually create any lines. If you do log('abc');log.keepOutput();log('def'), the result will be abcdef. If you omit the keepOutput(), it will be def. In order to add lines, you need to add the newline manually.
Also, I ran into this issue when outputting multiple lines. The following example ends up with abc\ndef\n:
a('abc\n')
console.log('')
a('def\n')Whereas the following ends up with abc\nghi\n, because my console.log() only adds one new line, and the previous output had two:
a('abc\n\def\n')
console.log('')
a('ghi\n')The thing I was working on worked perfectly with the console.log('') hack until I outputted multiple lines, after which it just worked weirdly.
Anyway, long story short, I still think that keepOutput() is the most accurate name. I will update the PR to actually use that term for now.
There is plenty of use-cases for keeping the current output, such as showing progress while a task is running and then keeping the result when starting the next task.
Unfortunately, in the current version of tool, it is not easy. This change makes it very easy.