Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/log-update
Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.
https://github.com/sindresorhus/log-update
Last synced: 2 days ago
JSON representation
Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.
- Host: GitHub
- URL: https://github.com/sindresorhus/log-update
- Owner: sindresorhus
- License: mit
- Created: 2015-08-16T08:27:28.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T14:04:35.000Z (5 months ago)
- Last Synced: 2024-12-07T19:34:58.358Z (5 days ago)
- Language: JavaScript
- Size: 90.8 KB
- Stars: 1,098
- Watchers: 11
- Forks: 40
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-nodejs-cn - log-update - 在终端里以覆盖前一个输出的方式打印日志,用于制作进度条或者动画等 (包 / 命令行工具)
- awesome-web-cn - log-update - 用当前的 log 输出覆盖先前的终端中的输出。用于渲染进度条、动画等 (Uncategorized / Uncategorized)
- awesome-nodejs-cn - log-update - **star:1097** 通过覆盖终端中的前一个输出来记录日志用于绘制进度条、动画等 (包 / 命令行实用工具)
- awesome-github-star - log-update
- awesome-nodejs - log-update - Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc. (Packages / Command-line utilities)
- awesome-nodejs - log-update - Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc. - ★ 523 (Command-line utilities)
- awesome-node - log-update - Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc. (Packages / Command-line utilities)
- awesome-nodejs-cn - log-update - 通过覆盖终端中的上一个输出来记录。用于渲染进度条、动画等. (目录 / 命令行工具)
- awesome-nodejs - log-update - 在 Terminal 渲染进度条或动画 (Uncategorized / Uncategorized)
README
# log-update
> Log by overwriting the previous output in the terminal.\
> Useful for rendering progress bars, animations, etc.![](screenshot.gif)
## Install
```sh
npm install log-update
```## Usage
```js
import logUpdate from 'log-update';const frames = ['-', '\\', '|', '/'];
let index = 0;setInterval(() => {
const frame = frames[index = ++index % frames.length];logUpdate(
`
♥♥
${frame} unicorns ${frame}
♥♥
`
);
}, 80);
```## API
### logUpdate(text…)
Log to stdout.
### logUpdate.clear()
Clear the logged output.
### logUpdate.done()
Persist the logged output.
Useful if you want to start a new log session below the current one.
### logUpdateStderr(text…)
Log to stderr.
### logUpdateStderr.clear()
### logUpdateStderr.done()### createLogUpdate(stream, options?)
Get a `logUpdate` method that logs to the specified stream.
#### options
Type: `object`
##### showCursor
Type: `boolean`\
Default: `false`Show the cursor. This can be useful when a CLI accepts input from a user.
```js
import {createLogUpdate} from 'log-update';// Write output but don't hide the cursor
const log = createLogUpdate(process.stdout, {
showCursor: true
});
```## Examples
- [listr](https://github.com/SamVerschueren/listr) - Uses this module to render an interactive task list
- [ora](https://github.com/sindresorhus/ora) - Uses this module to render awesome spinners
- [speed-test](https://github.com/sindresorhus/speed-test) - Uses this module to render a [spinner](https://github.com/sindresorhus/elegant-spinner)