# ansi-diff

> A module that diffs an input buffer with the previous one provided to it and outputs the diff as ANSI

Latest version **1.2.0** (published 2024-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install ansi-diff
pnpm add ansi-diff
yarn add ansi-diff
bun add ansi-diff
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-08-29 |
| First published | 2017-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Mathias Buus |
| Maintainers | mafintosh |

## Links

- npm: https://www.npmjs.com/package/ansi-diff
- Repository: https://github.com/mafintosh/ansi-diff
- Issues: https://github.com/mafintosh/ansi-diff/issues
- npm.io page: https://npm.io/package/ansi-diff

## Dependencies (2)

- [wcwidth](https://npm.io/package/wcwidth.md) ^1.0.1
- [ansi-split](https://npm.io/package/ansi-split.md) ^1.0.1

## Recent versions

- 1.2.0 (latest) — 2024-08-29
- 1.1.1 — 2018-06-16
- 1.1.0 — 2018-03-29
- 1.0.10 — 2017-12-29
- 1.0.9 — 2017-12-28
- 1.0.8 — 2017-12-28
- 1.0.7 — 2017-12-28
- 1.0.6 — 2017-12-28
- 1.0.5 — 2017-12-28
- 1.0.4 — 2017-12-27
- 1.0.3 — 2017-12-27
- 1.0.2 — 2017-12-27
- 1.0.1 — 2017-12-27
- 1.0.0 — 2017-12-27
- 0.0.0 — 2017-10-11

## README

# ansi-diff

A module that diffs an input buffer with the previous one provided to it and outputs the diff as ANSI.
If you write out the diff to the terminal it will update the previous output with minimal changes

```
npm install ansi-diff
```

[![Build Status](https://travis-ci.org/mafintosh/ansi-diff.svg?branch=master)](https://travis-ci.org/mafintosh/ansi-diff)

## Usage

``` js
var diff = require('ansi-diff')({
  // if you want to support word wrapping, provide the terminal width
  width: process.stdout.columns
})

// render now
render()

// render every 1s
setInterval(render, 1000)

function render () {
  // will update the terminal with minimal changes
  process.stdout.write(diff.update('hello world...\n' + new Date()))
}
```

It also has terminal resize support

``` js
process.stdout.on('resize', function () {
  diff.resize({width: process.stdout.columns})
  render()
})
```

## API

#### `var diff = ansiDiff([options])`

Create a new differ. Options include:

``` js
{
  width: terminalWidth,
  height: terminalHeight
}
```

If you provide the terminal width ansi-diff will be able to support word wrapping
done by the terminal. That means that if you print out a line that is too long to fit in the terminal
the diff will still work.

#### `var changes = diff.update(buffer, opts)`

Update the buffer and return the diff between this and the previous one.
The diff is returned in ANSI as a buffer so you can write it out to the terminal.

* `opts.moveTo` - array of `[column,row]` to move the cursor after diffing the
  screen (in absolute coordinates)

#### `diff.resize([options])`

Update the terminal width / height. If you are writing to stdout
you should update the width when `process.stdout.on('resize')` is fired.

Options should look like this:

``` js
{
  width: terminalWidth,
  height: terminalHeight
}
```

#### `diff.toString()`

Returns the last diffed string.

#### `diff.width`

Property containing the last set terminal width.

#### `diff.height`

Property containing the last set terminal height.

## License

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