Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the current output #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

fizker
Copy link

@fizker fizker commented Oct 3, 2016

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.

@@ -44,6 +44,10 @@ module.exports = function(stream) {
stream.write('');
};

log.keepContent = function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keepContent vs keepOutput

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't .newLine or something similar be more clear?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants