@oclif/multi-stage-output 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import { getLogger } from '@oclif/core/logger';
2
2
  import { capitalCase } from 'change-case';
3
3
  import { Box, Text, useStdout } from 'ink';
4
4
  import React from 'react';
5
+ import wrapAnsi from 'wrap-ansi';
5
6
  import { constructDesignParams } from '../design.js';
6
7
  import { Divider } from './divider.js';
7
8
  import { Icon } from './icon.js';
@@ -122,11 +123,9 @@ export function determineCompactionLevel({ design = constructDesignParams(), has
122
123
  // 10 characters + 1 character for the space between the stage and timer,
123
124
  // examples: 999ms (5), 59.99s (6), 59m 59.99s (10), 23h 59m (7)
124
125
  const estimatedTimeLength = 11;
125
- const calculateWrappedHeight = (length) => {
126
- if (length > columns) {
127
- return Math.ceil(length / columns);
128
- }
129
- return 1;
126
+ const calculateWrappedHeight = (text) => {
127
+ const wrapped = wrapAnsi(text, columns, { hard: true, trim: false, wordWrap: true });
128
+ return wrapped.split('\n').length;
130
129
  };
131
130
  const calculateHeightOfBlock = (block) => {
132
131
  if (!block)
@@ -137,7 +136,7 @@ export function determineCompactionLevel({ design = constructDesignParams(), has
137
136
  return acc;
138
137
  if (info.value.length > columns) {
139
138
  // if the message is longer than the terminal width, add the number of lines
140
- return acc + calculateWrappedHeight(info.value.length);
139
+ return acc + calculateWrappedHeight(info.value);
141
140
  }
142
141
  // if the message is multiline, add the number of lines
143
142
  return acc + info.value.split('\n').length;
@@ -149,7 +148,7 @@ export function determineCompactionLevel({ design = constructDesignParams(), has
149
148
  const totalLength = `${label}: ${value}`.length;
150
149
  if (totalLength > columns) {
151
150
  // if the value is longer than the terminal width, add the number of lines
152
- return acc + calculateWrappedHeight(totalLength);
151
+ return acc + calculateWrappedHeight(`${label}: ${value}`);
153
152
  }
154
153
  return acc + value.split('\n').length;
155
154
  }, 0);
@@ -158,13 +157,15 @@ export function determineCompactionLevel({ design = constructDesignParams(), has
158
157
  const status = stageTracker.get(stage) ?? 'pending';
159
158
  const skipped = status === 'skipped' ? ' - Skipped' : '';
160
159
  const stageTimeLength = hasStageTime ? estimatedTimeLength : 0;
161
- const totalLength = design.icons[status].paddingLeft +
162
- design.icons[status].figure.length +
163
- design.icons[status].paddingRight +
164
- stage.length +
165
- skipped.length +
166
- stageTimeLength;
167
- return calculateWrappedHeight(totalLength);
160
+ const parts = [
161
+ ' '.repeat(design.icons[status].paddingLeft),
162
+ design.icons[status].figure,
163
+ ' '.repeat(design.icons[status].paddingRight),
164
+ stage,
165
+ skipped,
166
+ '0'.repeat(stageTimeLength),
167
+ ];
168
+ return calculateWrappedHeight(parts.join(''));
168
169
  };
169
170
  const calculateWidthOfCompactStage = (stage) => {
170
171
  const status = stageTracker.get(stage) ?? 'current';
@@ -193,8 +194,10 @@ export function determineCompactionLevel({ design = constructDesignParams(), has
193
194
  const stageSpecificBlockHeight = calculateHeightOfBlock(stageSpecificBlock);
194
195
  // 3 at minimum because: 1 for marginTop on entire component, 1 for marginBottom on entire component, 1 for paddingBottom on StageEntries
195
196
  const paddings = 3 + (preStagesBlock ? 1 : 0) + (postStagesBlock ? 1 : 0) + (title ? 1 : 0);
196
- const elapsedTimeHeight = hasElapsedTime ? calculateWrappedHeight('Elapsed Time:'.length + estimatedTimeLength) : 0;
197
- const titleHeight = title ? calculateWrappedHeight(title.length) : 0;
197
+ const elapsedTimeHeight = hasElapsedTime
198
+ ? calculateWrappedHeight(`Elapsed Time:${'0'.repeat(estimatedTimeLength)}`)
199
+ : 0;
200
+ const titleHeight = title ? calculateWrappedHeight(title) : 0;
198
201
  const totalHeight = stagesHeight +
199
202
  preStagesBlockHeight +
200
203
  postStagesBlockHeight +
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/multi-stage-output",
3
3
  "description": "Terminal output for oclif commands with multiple stages",
4
- "version": "0.5.4",
4
+ "version": "0.5.5",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/multi-stage-output/issues",
7
7
  "dependencies": {
@@ -11,7 +11,8 @@
11
11
  "cli-spinners": "^2",
12
12
  "figures": "^6.1.0",
13
13
  "ink": "^5.0.1",
14
- "react": "^18.3.1"
14
+ "react": "^18.3.1",
15
+ "wrap-ansi": "^9.0.0"
15
16
  },
16
17
  "devDependencies": {
17
18
  "@commitlint/config-conventional": "^19",