@travetto/terminal 3.1.0-rc.0 → 3.1.0-rc.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/operation.ts +12 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/terminal",
3
- "version": "3.1.0-rc.0",
3
+ "version": "3.1.0-rc.1",
4
4
  "description": "General terminal support",
5
5
  "keywords": [
6
6
  "terminal",
package/src/operation.ts CHANGED
@@ -5,8 +5,18 @@ import { ColorOutputUtil, TermStyleInput } from './color-output';
5
5
 
6
6
  const STD_WAIT_STATES = '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'.split('');
7
7
 
8
+ /**
9
+ * Standard Terminal Operations
10
+ */
8
11
  export class TerminalOperation {
9
12
 
13
+ static truncateIfNeeded(term: TermState, text: string, suffix = '...'): string {
14
+ if (text.length > term.width) {
15
+ return `${text.substring(0, term.width - suffix.length)}${suffix}`;
16
+ }
17
+ return text;
18
+ }
19
+
10
20
  /**
11
21
  * Allows for writing at top, bottom, or current position while new text is added
12
22
  */
@@ -104,7 +114,7 @@ export class TerminalOperation {
104
114
  .replace(/%idx/, idxStr)
105
115
  .replace(/%total/, totalStr)
106
116
  .replace(/%pct/, `${Math.trunc(pct * 100)}`);
107
- const full = ` ${line}`.padEnd(term.width);
117
+ const full = this.truncateIfNeeded(term, ` ${line}`.padEnd(term.width));
108
118
  const mid = Math.trunc(pct * term.width);
109
119
  const [l, r] = [full.substring(0, mid), full.substring(mid)];
110
120
  return `${color(l)}${r}`;
@@ -139,7 +149,7 @@ export class TerminalOperation {
139
149
  if (msg !== undefined) {
140
150
  msg = msg.replace(/\n$/, '');
141
151
  pos = await term.getCursorPosition();
142
- writer = this.streamWaiting(term, msg, { ...cfg, at: pos, clearOnFinish: false });
152
+ writer = this.streamWaiting(term, this.truncateIfNeeded(term, msg), { ...cfg, at: pos, clearOnFinish: false });
143
153
  line = msg;
144
154
  }
145
155
  }