Skip to content

Commit

Permalink
Fix line breaks when custom prefix is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcarpanelli committed Jun 18, 2019
1 parent 5f5eee8 commit 6033b14
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.2] - 2019-06-18
### Fixed
- Fix line breaks when a custom succeedPrefix/failPrefix is provided

## [0.4.1] - 2019-06-18
### Fixed
- Properly add line breaks in spinner texts when it has '\n' characters
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,17 @@ class Spinnies {
text = breakText(text, prefixLength);
line = `${chalk[spinnerColor](frame)} ${color ? chalk[color](text) : text}`;
} else {
if (hasActiveSpinners) text = breakText(text, prefixLength);
if (status === 'succeed') {
prefixLength = succeedPrefix.length + 1;
if (hasActiveSpinners) text = breakText(text, prefixLength);
line = `${chalk.green(succeedPrefix)} ${chalk[succeedColor](text)}`;
} else if (status === 'fail') {
prefixLength = failPrefix.length + 1;
if (hasActiveSpinners) text = breakText(text, prefixLength);
line = `${chalk.red(failPrefix)} ${chalk[failColor](text)}`;
} else {
prefixLength = 0;
if (hasActiveSpinners) text = breakText(text, prefixLength);
line = color ? chalk[color](text) : text;
}
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spinnies",
"version": "0.4.1",
"version": "0.4.2",
"description": "Create and manage multiple spinners in command-line interface programs",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ function breakText(text, prefixLength) {
.join('\n');
}

function breakLine(text, prefixLength) {
function breakLine(line, prefixLength) {
const columns = process.stderr.columns || 95;
return text.length >= columns - prefixLength
? `${text.substring(0, columns - prefixLength - 1)}\n${
breakText(text.substring(columns - prefixLength - 1, text.length), 0)
return line.length >= columns - prefixLength
? `${line.substring(0, columns - prefixLength - 1)}\n${
breakLine(line.substring(columns - prefixLength - 1, line.length), 0)
}`
: text;
: line;
}

function getLinesLength(text, prefixLength) {
Expand Down

0 comments on commit 6033b14

Please sign in to comment.