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

Undesirable space before spinner symbol when prefixText is empty string #122

Closed
ngocdaothanh opened this issue Sep 13, 2019 · 2 comments · Fixed by #124
Closed

Undesirable space before spinner symbol when prefixText is empty string #122

ngocdaothanh opened this issue Sep 13, 2019 · 2 comments · Fixed by #124

Comments

@ngocdaothanh
Copy link

I set prefixText like this:

spinner.prefixText = 'Loading';
spinner.spinner = 'simpleDots';
spinner.start();
...
spinner.stop();

Then, I set prefixText to an empty string and reuse the spinner:

spinner.prefixText = '';
spinner.spinner = 'dots';
spinner.start();

This time, before the spinner symbol, there's one undesirable space.

The cause is this code in the frame method (https://github.com/sindresorhus/ora/blob/master/index.js#L119):

const fullPrefixText = typeof this.prefixText === 'string' ? this.prefixText + ' ' : '';

Initially, prefixText is undefined so the code worked. But after it's set to an empty string, it doesn't work as expected.

I'm using TypeScript. Setting like this will cause syntax error (https://github.com/sindresorhus/ora/blob/master/index.d.ts#L127):

spinner.prefixText = undefined;

I have to do like this (not very nice):

this.spinner.prefixText = undefined as any;
@sindresorhus
Copy link
Owner

// @stroncium

stroncium added a commit to stroncium/ora that referenced this issue Sep 13, 2019
@stroncium
Copy link
Contributor

If we check for empty string here, it will be impossible to maintain consistent behavior(which is having the space). So, the options are:

  • remove default space and require users to pass full prefix(with space)
  • allow undefined as value

Implemented 2nd option for now.

@sindresorhus

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

Successfully merging a pull request may close this issue.

3 participants