@rushstack/terminal 0.3.84 → 0.3.86
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.
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrintUtilities.d.ts","sourceRoot":"","sources":["../src/PrintUtilities.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAW,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,cAAc;IACzB;;OAEG;WACW,eAAe,IAAI,MAAM,GAAG,SAAS;IAOnD;;;OAGG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"PrintUtilities.d.ts","sourceRoot":"","sources":["../src/PrintUtilities.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAW,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,cAAc;IACzB;;OAEG;WACW,eAAe,IAAI,MAAM,GAAG,SAAS;IAOnD;;;OAGG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IA0BtF;;;;OAIG;WACW,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;CAsB/F"}
|
package/lib/PrintUtilities.js
CHANGED
|
@@ -39,8 +39,19 @@ class PrintUtilities {
|
|
|
39
39
|
if (!maxLineLength) {
|
|
40
40
|
maxLineLength = PrintUtilities.getConsoleWidth() || exports.DEFAULT_CONSOLE_WIDTH;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
// Apply word wrapping and the provided indent, while also respecting existing newlines
|
|
43
|
+
// and prefix spaces that may exist in the text string already.
|
|
44
|
+
const lines = text.split(/\r?\n/);
|
|
45
|
+
const wrappedLines = lines.map((line) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const startingSpace = line.match(/^ +/);
|
|
48
|
+
const addlIndent = ((_a = startingSpace === null || startingSpace === void 0 ? void 0 : startingSpace[0]) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
49
|
+
if (addlIndent > 0) {
|
|
50
|
+
line = line.replace(/^ +/, '');
|
|
51
|
+
}
|
|
52
|
+
return (0, wordwrap_1.default)(indent + addlIndent, maxLineLength - indent - addlIndent, { mode: 'soft' })(line);
|
|
53
|
+
});
|
|
54
|
+
return wrappedLines.join('\n');
|
|
44
55
|
}
|
|
45
56
|
/**
|
|
46
57
|
* Displays a message in the console wrapped in a box UI.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrintUtilities.js","sourceRoot":"","sources":["../src/PrintUtilities.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAG3D,wDAAgC;AAGhC;;;;GAIG;AACU,QAAA,qBAAqB,GAAW,EAAE,CAAC;AAEhD;;;;GAIG;AACH,MAAa,cAAc;IACzB;;OAEG;IACI,MAAM,CAAC,eAAe;QAC3B,MAAM,MAAM,GAAoB,OAAO,CAAC,MAAyB,CAAC;QAClE,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;YAC5B,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;IACH,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,SAAS,CAAC,IAAY,EAAE,aAAsB,EAAE,MAAe;QAC3E,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,GAAG,CAAC,CAAC;SACZ;QAED,IAAI,CAAC,aAAa,EAAE;YACl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YAAY,CAAC,IAAI,CAAC,CAAC;SAC/F;QACD,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC;CACF;AApED,wCAoEC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as tty from 'tty';\nimport wordwrap from 'wordwrap';\nimport { ITerminal } from '@rushstack/node-core-library';\n\n/**\n * A sensible fallback column width for consoles.\n *\n * @public\n */\nexport const DEFAULT_CONSOLE_WIDTH: number = 80;\n\n/**\n * A collection of utilities for printing messages to the console.\n *\n * @public\n */\nexport class PrintUtilities {\n /**\n * Returns the width of the console, measured in columns\n */\n public static getConsoleWidth(): number | undefined {\n const stdout: tty.WriteStream = process.stdout as tty.WriteStream;\n if (stdout && stdout.columns) {\n return stdout.columns;\n }\n }\n\n /**\n * Applies word wrapping. If maxLineLength is unspecified, then it defaults to the\n * console width.\n */\n public static wrapWords(text: string, maxLineLength?: number, indent?: number): string {\n if (!indent) {\n indent = 0;\n }\n\n if (!maxLineLength) {\n maxLineLength = PrintUtilities.getConsoleWidth() || DEFAULT_CONSOLE_WIDTH;\n }\n\n // Apply word wrapping and the provided indent, while also respecting existing newlines\n // and prefix spaces that may exist in the text string already.\n const lines: string[] = text.split(/\\r?\\n/);\n const wrappedLines: string[] = lines.map((line) => {\n const startingSpace: RegExpMatchArray | null = line.match(/^ +/);\n const addlIndent: number = startingSpace?.[0]?.length || 0;\n\n if (addlIndent > 0) {\n line = line.replace(/^ +/, '');\n }\n\n return wordwrap(indent! + addlIndent, maxLineLength! - indent! - addlIndent, { mode: 'soft' })(line);\n });\n\n return wrappedLines.join('\\n');\n }\n\n /**\n * Displays a message in the console wrapped in a box UI.\n *\n * @param boxWidth - The width of the box, defaults to half of the console width.\n */\n public static printMessageInBox(message: string, terminal: ITerminal, boxWidth?: number): void {\n if (!boxWidth) {\n const consoleWidth: number = PrintUtilities.getConsoleWidth() || DEFAULT_CONSOLE_WIDTH;\n boxWidth = Math.floor(consoleWidth / 2);\n }\n const maxLineLength: number = boxWidth - 10;\n const wrappedMessage: string = PrintUtilities.wrapWords(message, maxLineLength);\n const wrappedMessageLines: string[] = wrappedMessage.split('\\n');\n\n // ╔═══════════╗\n // ║ Message ║\n // ╚═══════════╝\n terminal.writeLine(` ╔${'═'.repeat(boxWidth - 2)}╗ `);\n for (const line of wrappedMessageLines) {\n const trimmedLine: string = line.trim();\n const padding: number = boxWidth - trimmedLine.length - 2;\n const leftPadding: number = Math.floor(padding / 2);\n const rightPadding: number = padding - leftPadding;\n terminal.writeLine(` ║${' '.repeat(leftPadding)}${trimmedLine}${' '.repeat(rightPadding)}║ `);\n }\n terminal.writeLine(` ╚${'═'.repeat(boxWidth - 2)}╝ `);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/terminal",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.86",
|
|
4
4
|
"description": "User interface primitives for console applications",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/terminal.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@rushstack/eslint-config": "3.1.1",
|
|
20
20
|
"@rushstack/heft": "0.48.8",
|
|
21
|
-
"@rushstack/heft-node-rig": "1.11.
|
|
21
|
+
"@rushstack/heft-node-rig": "1.11.9",
|
|
22
22
|
"@types/heft-jest": "1.0.1",
|
|
23
23
|
"@types/wordwrap": "~1.0.0",
|
|
24
24
|
"colors": "~1.2.1"
|