log-update
Advanced tools
Comparing version 4.0.0 to 5.0.0
152
index.d.ts
@@ -1,80 +0,104 @@ | ||
/// <reference types="node"/> | ||
export interface Options { | ||
/** | ||
Show the cursor. This can be useful when a CLI accepts input from a user. | ||
declare namespace logUpdate { | ||
interface LogUpdate { | ||
/** | ||
Log to `stdout` by overwriting the previous output in the terminal. | ||
@example | ||
``` | ||
import {createLogUpdate} from 'log-update'; | ||
@param text - The text to log to `stdout`. | ||
// Write output but don't hide the cursor | ||
const log = createLogUpdate(process.stdout, { | ||
showCursor: true | ||
}); | ||
``` | ||
*/ | ||
readonly showCursor?: boolean; | ||
} | ||
@example | ||
``` | ||
import logUpdate = require('log-update'); | ||
type LogUpdateMethods = { | ||
/** | ||
Clear the logged output. | ||
*/ | ||
clear(): void; | ||
const frames = ['-', '\\', '|', '/']; | ||
let i = 0; | ||
/** | ||
Persist the logged output. Useful if you want to start a new log session below the current one. | ||
*/ | ||
done(): void; | ||
}; | ||
setInterval(() => { | ||
const frame = frames[i = ++i % frames.length]; | ||
/** | ||
Log to `stdout` by overwriting the previous output in the terminal. | ||
logUpdate( | ||
` | ||
♥♥ | ||
${frame} unicorns ${frame} | ||
♥♥ | ||
` | ||
); | ||
}, 80); | ||
``` | ||
*/ | ||
(...text: string[]): void; | ||
@param text - The text to log to `stdout`. | ||
/** | ||
Clear the logged output. | ||
*/ | ||
clear(): void; | ||
@example | ||
``` | ||
import logUpdate from 'log-update'; | ||
/** | ||
Persist the logged output. Useful if you want to start a new log session below the current one. | ||
*/ | ||
done(): void; | ||
} | ||
const frames = ['-', '\\', '|', '/']; | ||
let index = 0; | ||
interface Options { | ||
/** | ||
Show the cursor. This can be useful when a CLI accepts input from a user. | ||
setInterval(() => { | ||
const frame = frames[index = ++index % frames.length]; | ||
@example | ||
``` | ||
import logUpdate = require('log-update'); | ||
logUpdate( | ||
` | ||
♥♥ | ||
${frame} unicorns ${frame} | ||
♥♥ | ||
` | ||
); | ||
}, 80); | ||
``` | ||
*/ | ||
declare const logUpdate: ((...text: string[]) => void) & LogUpdateMethods; | ||
// Write output but don't hide the cursor | ||
const log = logUpdate.create(process.stdout, { | ||
showCursor: true | ||
}); | ||
``` | ||
*/ | ||
readonly showCursor?: boolean; | ||
} | ||
} | ||
export default logUpdate; | ||
declare const logUpdate: logUpdate.LogUpdate & { | ||
/** | ||
Log to `stderr` by overwriting the previous output in the terminal. | ||
/** | ||
Log to `stderr` by overwriting the previous output in the terminal. | ||
@param text - The text to log to `stderr`. | ||
*/ | ||
readonly stderr: logUpdate.LogUpdate; | ||
@param text - The text to log to `stderr`. | ||
/** | ||
Get a `logUpdate` method that logs to the specified stream. | ||
@example | ||
``` | ||
import {logUpdateStderr} from 'log-update'; | ||
@param stream - The stream to log to. | ||
*/ | ||
readonly create: ( | ||
stream: NodeJS.WritableStream, | ||
options?: logUpdate.Options | ||
) => logUpdate.LogUpdate; | ||
}; | ||
const frames = ['-', '\\', '|', '/']; | ||
let index = 0; | ||
export = logUpdate; | ||
setInterval(() => { | ||
const frame = frames[index = ++index % frames.length]; | ||
logUpdateStderr( | ||
` | ||
♥♥ | ||
${frame} unicorns ${frame} | ||
♥♥ | ||
` | ||
); | ||
}, 80); | ||
``` | ||
*/ | ||
declare const logUpdateStderr: ((...text: string[]) => void) & LogUpdateMethods; | ||
export {logUpdateStderr}; | ||
/** | ||
Get a `logUpdate` method that logs to the specified stream. | ||
@param stream - The stream to log to. | ||
@example | ||
``` | ||
import {createLogUpdate} from 'log-update'; | ||
// Write output but don't hide the cursor | ||
const log = createLogUpdate(process.stdout); | ||
``` | ||
*/ | ||
export function createLogUpdate( | ||
stream: NodeJS.WritableStream, | ||
options?: Options | ||
): typeof logUpdate; |
27
index.js
@@ -1,6 +0,6 @@ | ||
'use strict'; | ||
const ansiEscapes = require('ansi-escapes'); | ||
const cliCursor = require('cli-cursor'); | ||
const wrapAnsi = require('wrap-ansi'); | ||
const sliceAnsi = require('slice-ansi'); | ||
import process from 'node:process'; | ||
import ansiEscapes from 'ansi-escapes'; | ||
import cliCursor from 'cli-cursor'; | ||
import wrapAnsi from 'wrap-ansi'; | ||
import sliceAnsi from 'slice-ansi'; | ||
@@ -34,3 +34,3 @@ const defaultTerminalHeight = 24; | ||
const main = (stream, {showCursor = false} = {}) => { | ||
export function createLogUpdate(stream, {showCursor = false} = {}) { | ||
let previousLineCount = 0; | ||
@@ -40,3 +40,3 @@ let previousWidth = getWidth(stream); | ||
const render = (...args) => { | ||
const render = (...arguments_) => { | ||
if (!showCursor) { | ||
@@ -46,3 +46,3 @@ cliCursor.hide(); | ||
let output = args.join(' ') + '\n'; | ||
let output = arguments_.join(' ') + '\n'; | ||
output = fitToTerminalHeight(stream, output); | ||
@@ -59,3 +59,3 @@ const width = getWidth(stream); | ||
hard: true, | ||
wordWrap: false | ||
wordWrap: false, | ||
}); | ||
@@ -84,6 +84,7 @@ stream.write(ansiEscapes.eraseLines(previousLineCount) + output); | ||
return render; | ||
}; | ||
} | ||
module.exports = main(process.stdout); | ||
module.exports.stderr = main(process.stderr); | ||
module.exports.create = main; | ||
const logUpdate = createLogUpdate(process.stdout); | ||
export default logUpdate; | ||
export const logUpdateStderr = createLogUpdate(process.stderr); |
{ | ||
"name": "log-update", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.", | ||
@@ -11,6 +11,8 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -43,14 +45,14 @@ "scripts": { | ||
"dependencies": { | ||
"ansi-escapes": "^4.3.0", | ||
"cli-cursor": "^3.1.0", | ||
"slice-ansi": "^4.0.0", | ||
"wrap-ansi": "^6.2.0" | ||
"ansi-escapes": "^5.0.0", | ||
"cli-cursor": "^4.0.0", | ||
"slice-ansi": "^5.0.0", | ||
"wrap-ansi": "^8.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^13.7.4", | ||
"ava": "^3.3.0", | ||
"terminal.js": "^1.0.10", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.26.1" | ||
"@types/node": "^16.11.1", | ||
"ava": "^3.15.0", | ||
"terminal.js": "^1.0.11", | ||
"tsd": "^0.18.0", | ||
"xo": "^0.45.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# log-update [![Build Status](https://travis-ci.org/sindresorhus/log-update.svg?branch=master)](https://travis-ci.org/sindresorhus/log-update) | ||
# log-update | ||
> Log by overwriting the previous output in the terminal.<br> | ||
> Log by overwriting the previous output in the terminal.\ | ||
> Useful for rendering progress bars, animations, etc. | ||
@@ -10,5 +10,5 @@ | ||
```sh | ||
npm install log-update | ||
``` | ||
$ npm install log-update | ||
``` | ||
@@ -18,9 +18,9 @@ ## Usage | ||
```js | ||
const logUpdate = require('log-update'); | ||
import logUpdate from 'log-update'; | ||
const frames = ['-', '\\', '|', '/']; | ||
let i = 0; | ||
let index = 0; | ||
setInterval(() => { | ||
const frame = frames[i = ++i % frames.length]; | ||
const frame = frames[index = ++index % frames.length]; | ||
@@ -49,13 +49,14 @@ logUpdate( | ||
Persist the logged output.<br> | ||
Persist the logged output. | ||
Useful if you want to start a new log session below the current one. | ||
### logUpdate.stderr(text…) | ||
### logUpdateStderr(text…) | ||
Log to stderr. | ||
### logUpdate.stderr.clear() | ||
### logUpdate.stderr.done() | ||
### logUpdateStderr.clear() | ||
### logUpdateStderr.done() | ||
### logUpdate.create(stream, options?) | ||
### createLogUpdate(stream, options?) | ||
@@ -76,3 +77,3 @@ Get a `logUpdate` method that logs to the specified stream. | ||
```js | ||
const logUpdate = require('log-update'); | ||
import logUpdate from 'log-update'; | ||
@@ -79,0 +80,0 @@ // Write output but don't hide the cursor |
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
7955
150
99
Yes
+ Addedansi-escapes@5.0.0(transitive)
+ Addedansi-regex@6.1.0(transitive)
+ Addedansi-styles@6.2.1(transitive)
+ Addedcli-cursor@4.0.0(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@9.2.2(transitive)
+ Addedis-fullwidth-code-point@4.0.0(transitive)
+ Addedrestore-cursor@4.0.0(transitive)
+ Addedslice-ansi@5.0.0(transitive)
+ Addedstring-width@5.1.2(transitive)
+ Addedstrip-ansi@7.1.0(transitive)
+ Addedtype-fest@1.4.0(transitive)
+ Addedwrap-ansi@8.1.0(transitive)
- Removedansi-escapes@4.3.2(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedastral-regex@2.0.0(transitive)
- Removedcli-cursor@3.1.0(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedrestore-cursor@3.1.0(transitive)
- Removedslice-ansi@4.0.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedtype-fest@0.21.3(transitive)
- Removedwrap-ansi@6.2.0(transitive)
Updatedansi-escapes@^5.0.0
Updatedcli-cursor@^4.0.0
Updatedslice-ansi@^5.0.0
Updatedwrap-ansi@^8.0.1