log-update
Advanced tools
Comparing version 6.0.0 to 6.1.0
48
index.js
@@ -10,25 +10,9 @@ import process from 'node:process'; | ||
const getWidth = stream => { | ||
const {columns} = stream; | ||
const getWidth = ({columns = 80}) => columns; | ||
if (!columns) { | ||
return 80; | ||
} | ||
return columns; | ||
}; | ||
const fitToTerminalHeight = (stream, text) => { | ||
const terminalHeight = stream.rows ?? defaultTerminalHeight; | ||
const lines = text.split('\n'); | ||
const toRemove = lines.length - terminalHeight; | ||
if (toRemove <= 0) { | ||
return text; | ||
} | ||
return sliceAnsi( | ||
text, | ||
stripAnsi(lines.slice(0, toRemove).join('\n')).length + 1, | ||
); | ||
const toRemove = Math.max(0, lines.length - terminalHeight); | ||
return toRemove ? sliceAnsi(text, stripAnsi(lines.slice(0, toRemove).join('\n')).length + 1) : text; | ||
}; | ||
@@ -41,2 +25,8 @@ | ||
const reset = () => { | ||
previousOutput = ''; | ||
previousWidth = getWidth(stream); | ||
previousLineCount = 0; | ||
}; | ||
const render = (...arguments_) => { | ||
@@ -47,5 +37,5 @@ if (!showCursor) { | ||
let output = arguments_.join(' ') + '\n'; | ||
output = fitToTerminalHeight(stream, output); | ||
let output = fitToTerminalHeight(stream, arguments_.join(' ') + '\n'); | ||
const width = getWidth(stream); | ||
if (output === previousOutput && previousWidth === width) { | ||
@@ -57,7 +47,4 @@ return; | ||
previousWidth = width; | ||
output = wrapAnsi(output, width, { | ||
trim: false, | ||
hard: true, | ||
wordWrap: false, | ||
}); | ||
output = wrapAnsi(output, width, {trim: false, hard: true, wordWrap: false}); | ||
stream.write(ansiEscapes.eraseLines(previousLineCount) + output); | ||
@@ -69,12 +56,7 @@ previousLineCount = output.split('\n').length; | ||
stream.write(ansiEscapes.eraseLines(previousLineCount)); | ||
previousOutput = ''; | ||
previousWidth = getWidth(stream); | ||
previousLineCount = 0; | ||
reset(); | ||
}; | ||
render.done = () => { | ||
previousOutput = ''; | ||
previousWidth = getWidth(stream); | ||
previousLineCount = 0; | ||
reset(); | ||
if (!showCursor) { | ||
@@ -81,0 +63,0 @@ cliCursor.show(); |
{ | ||
"name": "log-update", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.", | ||
@@ -18,2 +18,3 @@ "license": "MIT", | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
@@ -48,5 +49,5 @@ "node": ">=18" | ||
"dependencies": { | ||
"ansi-escapes": "^6.2.0", | ||
"cli-cursor": "^4.0.0", | ||
"slice-ansi": "^7.0.0", | ||
"ansi-escapes": "^7.0.0", | ||
"cli-cursor": "^5.0.0", | ||
"slice-ansi": "^7.1.0", | ||
"strip-ansi": "^7.1.0", | ||
@@ -56,8 +57,8 @@ "wrap-ansi": "^9.0.0" | ||
"devDependencies": { | ||
"@types/node": "^20.8.9", | ||
"ava": "^5.3.1", | ||
"@types/node": "^20.14.12", | ||
"ava": "^6.1.3", | ||
"terminal.js": "^1.0.11", | ||
"tsd": "^0.29.0", | ||
"tsd": "^0.31.1", | ||
"wcwidth": "^1.0.1", | ||
"xo": "^0.56.0" | ||
"xo": "^0.59.2" | ||
}, | ||
@@ -64,0 +65,0 @@ "xo": { |
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
7576
135
+ Addedansi-escapes@7.0.0(transitive)
+ Addedcli-cursor@5.0.0(transitive)
+ Addedenvironment@1.1.0(transitive)
+ Addedmimic-function@5.0.1(transitive)
+ Addedonetime@7.0.0(transitive)
+ Addedrestore-cursor@5.1.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
- Removedansi-escapes@6.2.1(transitive)
- Removedcli-cursor@4.0.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removedonetime@5.1.2(transitive)
- Removedrestore-cursor@4.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
Updatedansi-escapes@^7.0.0
Updatedcli-cursor@^5.0.0
Updatedslice-ansi@^7.1.0