@ms-cloudpack/task-reporter
Advanced tools
Comparing version 0.14.0 to 0.14.1
@@ -31,2 +31,6 @@ export declare const ansiEscape = "\u001B["; | ||
export declare function bold(text?: string | number): string; | ||
/** | ||
* Removes ANSI escape codes from the input string. | ||
*/ | ||
export declare function removeANSIEscapeCodes(input: string): string; | ||
//# sourceMappingURL=ansiHelpers.d.ts.map |
/** | ||
* Set a function to call instead of `process.stdout.write`. | ||
*/ | ||
export declare function setStdoutWriteOverride(override: ((message: string) => void) | undefined): void; | ||
export declare function setStdoutOverride(stdoutOverride?: { | ||
write: (message: string) => void; | ||
columns: number; | ||
}): void; | ||
export declare function write(message: string): void; | ||
export declare function getColumnsCount(): number; | ||
//# sourceMappingURL=write.d.ts.map |
import { Sticky } from './Sticky.js'; | ||
export declare class Writer { | ||
private _stickies; | ||
private _lastStickyCount; | ||
private _lastStickies; | ||
get stickies(): Sticky[]; | ||
@@ -6,0 +6,0 @@ set stickies(newStickies: (Sticky | string | undefined)[]); |
@@ -31,2 +31,6 @@ export declare const ansiEscape = "\u001B["; | ||
export declare function bold(text?: string | number): string; | ||
/** | ||
* Removes ANSI escape codes from the input string. | ||
*/ | ||
export declare function removeANSIEscapeCodes(input: string): string; | ||
//# sourceMappingURL=ansiHelpers.d.ts.map |
@@ -138,2 +138,24 @@ import { write } from './write.js'; | ||
} | ||
/** | ||
* Removes ANSI escape codes from the input string. | ||
*/ | ||
export function removeANSIEscapeCodes(input) { | ||
let result = ''; | ||
let escapeCode = false; | ||
for (let i = 0; i < input.length; i++) { | ||
const char = input.charAt(i); | ||
if (char === '\x1b') { | ||
escapeCode = true; | ||
continue; | ||
} | ||
if (escapeCode && char === 'm') { | ||
escapeCode = false; | ||
continue; | ||
} | ||
if (!escapeCode) { | ||
result += char; | ||
} | ||
} | ||
return result; | ||
} | ||
//# sourceMappingURL=ansiHelpers.js.map |
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.39.4" | ||
"packageVersion": "7.43.2" | ||
} | ||
] | ||
} |
/** | ||
* Set a function to call instead of `process.stdout.write`. | ||
*/ | ||
export declare function setStdoutWriteOverride(override: ((message: string) => void) | undefined): void; | ||
export declare function setStdoutOverride(stdoutOverride?: { | ||
write: (message: string) => void; | ||
columns: number; | ||
}): void; | ||
export declare function write(message: string): void; | ||
export declare function getColumnsCount(): number; | ||
//# sourceMappingURL=write.d.ts.map |
let stdoutWriteOverride; | ||
let stdoutColumnsOverride; | ||
/** | ||
* Set a function to call instead of `process.stdout.write`. | ||
*/ | ||
export function setStdoutWriteOverride(override) { | ||
stdoutWriteOverride = override; | ||
export function setStdoutOverride(stdoutOverride) { | ||
stdoutWriteOverride = stdoutOverride?.write; | ||
stdoutColumnsOverride = stdoutOverride?.columns ?? 0; | ||
} | ||
@@ -16,2 +18,5 @@ export function write(message) { | ||
} | ||
export function getColumnsCount() { | ||
return stdoutColumnsOverride ?? process.stdout.columns; | ||
} | ||
//# sourceMappingURL=write.js.map |
import { Sticky } from './Sticky.js'; | ||
export declare class Writer { | ||
private _stickies; | ||
private _lastStickyCount; | ||
private _lastStickies; | ||
get stickies(): Sticky[]; | ||
@@ -6,0 +6,0 @@ set stickies(newStickies: (Sticky | string | undefined)[]); |
@@ -1,3 +0,3 @@ | ||
import { write } from './write.js'; | ||
import { moveDownLines, moveUpLines, clearLine } from './ansiHelpers.js'; | ||
import { write, getColumnsCount } from './write.js'; | ||
import { moveDownLines, moveUpLines, clearLine, removeANSIEscapeCodes } from './ansiHelpers.js'; | ||
import { Sticky } from './Sticky.js'; | ||
@@ -7,3 +7,3 @@ export class Writer { | ||
this._stickies = []; | ||
this._lastStickyCount = 0; | ||
this._lastStickies = []; | ||
} | ||
@@ -38,20 +38,31 @@ get stickies() { | ||
_printStickies() { | ||
this._lastStickyCount = 0; | ||
this._lastStickies = []; | ||
if (this._stickies.length > 0) { | ||
for (const sticky of this._stickies) { | ||
write(`${sticky.text}\n`); | ||
this._lastStickies.push(sticky.text); | ||
} | ||
} | ||
this._lastStickyCount = this._stickies.length; | ||
} | ||
_clearPreviousStickies() { | ||
// Clear previous stickies first. | ||
if (this._lastStickyCount > 0) { | ||
moveUpLines(this._lastStickyCount); | ||
for (let i = 0; i < this._lastStickyCount; i++) { | ||
if (this._lastStickies.length > 0) { | ||
const columns = getColumnsCount(); | ||
// total number of lines that the last stickies took. | ||
let totalNumberOfLines = 0; | ||
for (const item of this._lastStickies) { | ||
// Remove the ANSI escape codes from the string and get the length | ||
const charCount = removeANSIEscapeCodes(item).length; | ||
// If the charCount is 0, it means that the string was empty. In that case, we still need to consider it as 1 line. | ||
// Otherwise, we need to calculate the number of lines that the string took by dividing the charCount by the number of columns. | ||
const lines = charCount === 0 ? 1 : Math.ceil(charCount / columns); | ||
totalNumberOfLines += lines; | ||
} | ||
moveUpLines(totalNumberOfLines); | ||
for (let i = 0; i < totalNumberOfLines; i++) { | ||
clearLine(); | ||
moveDownLines(1); | ||
} | ||
moveUpLines(this._lastStickyCount); | ||
this._lastStickyCount = 0; | ||
moveUpLines(totalNumberOfLines); | ||
this._lastStickies = []; | ||
} | ||
@@ -58,0 +69,0 @@ } |
{ | ||
"name": "@ms-cloudpack/task-reporter", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"description": "Helpers for logging tasks to the console.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
289516
2706