# stdout-update

> Updates the previous output in the terminal. Useful for correct rendering progress bars, animations, etc.

Latest version **4.0.1** (published 2024-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install stdout-update
pnpm add stdout-update
yarn add stdout-update
bun add stdout-update
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2024-02-14 |
| First published | 2019-06-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 4 |
| Unpacked size | 25 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 17 |
| Author | Daniil Ryazanov |
| Maintainers | keindev |
| Keywords | cli, console, indicator, log, logger, logging, output, overwrite, progress, refresh, shell, stdout, term, terminal, update |

## Links

- npm: https://www.npmjs.com/package/stdout-update
- Repository: https://github.com/keindev/stdout-update
- Homepage: https://github.com/keindev/stdout-update#readme
- Issues: https://github.com/keindev/stdout-update/issues
- npm.io page: https://npm.io/package/stdout-update

## Dependencies (4)

- [strip-ansi](https://npm.io/package/strip-ansi.md) ^7.1.0
- [ansi-styles](https://npm.io/package/ansi-styles.md) ^6.2.1
- [ansi-escapes](https://npm.io/package/ansi-escapes.md) ^6.2.0
- [string-width](https://npm.io/package/string-width.md) ^7.1.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 4.0.1 (latest) — 2024-02-14
- 4.0.0 — 2023-08-19
- 3.1.1 — 2022-11-26
- 3.1.0 — 2022-11-24
- 3.0.6 — 2022-04-20
- 3.0.5 — 2022-04-04
- 3.0.4 — 2022-03-17
- 3.0.3 — 2022-02-17
- 3.0.2 — 2022-01-16
- 3.0.1 — 2022-01-03
- 3.0.0 — 2022-01-01
- 2.0.4 — 2021-11-25
- 2.0.3 — 2021-08-26
- 2.0.1 — 2021-05-06
- 1.6.8 — 2021-05-06
- … 23 more at https://npm.io/package/stdout-update/versions

## README

<p align="center"><img src="https://cdn.jsdelivr.net/gh/tagproject/art/packages/stdout-update/banner.svg" alt="Package logo"></p>

<p align="center">
    <a href="https://github.com/keindev/stdout-update/actions"><img src="https://github.com/keindev/stdout-update/actions/workflows/build.yml/badge.svg" alt="Build Status"></a>
    <a href="https://codecov.io/gh/keindev/stdout-update"><img src="https://codecov.io/gh/keindev/stdout-update/branch/master/graph/badge.svg" /></a>
    <a href="https://www.npmjs.com/package/stdout-update"><img alt="npm" src="https://img.shields.io/npm/v/stdout-update.svg"></a>
    <a href="https://github.com/tagproject/ts-package-shared-config"><img src="https://img.shields.io/badge/standard--shared--config-nodejs%2Bts-green?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAfCAYAAACh+E5kAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJQSURBVHgB1VftUcMwDFU4/tMNyAZ0A7IBbBA2CExAmIBjApcJChO0TFA2SJkgMIGRyDNV3TSt26RN353OX/LHUyTZIdoB1tqMZcaS0imBDzxkeWaJWR51SX0HrJ6pdsJyifpdb4loq3v9A+1CaBuWMR0Q502DzuJRFD34Y9z3DXIRNy/QPWKZY27COlM6BtZZHWMJ3CkVa28KZMTJkDpCVLOhs/oL2gMuEhYpxeenPPah9EdczLkvpwZgnQHWnlNLiNQGYiWx5gu6Ehz4m+WNN/2i9Yd75CJmeRDXogbIFxECrqQ2wIvlLBOXaViuYbGQNSQLFSGZyOnulb2wadaGnyoSSeC8GBJkNDf5kloESAhy2gFIIPG2+ufUMtivn/gAEi+Gy4u6FLxh/qer8/xbLq7QlNh6X4mbtr+A3pylDI0Lb43YrmLmXP5v3a4I4ABDRSI4xjB/ghveoj4BCVm37JQADhGDgOA+YJ48TSaoOwKpt27aOQG1WRES3La65WPU3dysTjE8de0Aj8SsKS5sdS9lqCeYI08bU6d8EALYS5OoDW4c3qi2gf7f+4yODfj2DIcqdVzYKnMtEUO7RP2gT/W1AImxXSC3i7R7rfRuMT5G2xzSYzaCDzOyyzDeuNHZx1a3fOdJJwh28fRwwT1QY6Xzf7TvWG6ob/BIGPQ59ymUngRyRn2El6Fy5T7G0zl+JmoC3KRQXyT1xpfiJKIeAemzqBl6U3V5ocZNf4hHg61u223wn4nOqF8IzvF9IxCMkyfQ+i/lnnhlmW6h9+Mqv1SmQhehji4JAAAAAElFTkSuQmCC" alt="Standard Shared Config"></a>
</p>

Purely and accurately overwrites the previous output in the terminal, while maintaining the history of third-party logs.

<p align="center">
    <img src="media/demo.gif">
</p>

## Install

```
npm install stdout-update
```

## Usage

```typescript
import UpdateManager from 'stdout-update';

const TICKS = 60;
const TIMEOUT = 80;
const manager = UpdateManager.getInstance();
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
const messages = ['Swapping time and space...', 'Have a good day.', "Don't panic...", 'Updating Updater...', '42'];
let ticks = TICKS;
let i = 0;

manager.hook();

// eslint-disable-next-line no-console
console.log(' - log message');
// eslint-disable-next-line no-console
console.error(' - error message');
// eslint-disable-next-line no-console
console.warn(' - warn message');

const id = setInterval(() => {
  if (--ticks < 0) {
    clearInterval(id);
    manager.update(['✔ Success', '', 'Messages:', 'this line is be deleted!!!']);
    manager.erase(1);
    manager.unhook(false);
  } else {
    const frame = frames[(i = ++i % frames.length)];
    const index = Math.round(ticks / 10) % messages.length;
    const message = messages[index];

    if (message) manager.update([`${frame} Some process...`, message]);
  }
}, TIMEOUT);
```

## Examples

[tasktree-cli](https://github.com/keindev/tasktree) - simple terminal task tree, helps you keep track of your tasks in a tree structure.

## API

Read the [API documentation](docs/api/index.md) for more information.

---
_Source: https://npm.io/package/stdout-update · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
