Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mafintosh/ansi-diff-stream
A transform stream that diffs input buffers and outputs the diff as ANSI. If you pipe this to a terminal it will update the output with minimal changes
https://github.com/mafintosh/ansi-diff-stream
Last synced: 6 days ago
JSON representation
A transform stream that diffs input buffers and outputs the diff as ANSI. If you pipe this to a terminal it will update the output with minimal changes
- Host: GitHub
- URL: https://github.com/mafintosh/ansi-diff-stream
- Owner: mafintosh
- License: mit
- Created: 2016-07-14T17:52:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T02:32:28.000Z (almost 7 years ago)
- Last Synced: 2024-04-23T19:38:17.322Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 108
- Watchers: 7
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cli - ansi-diff-stream - A diff friendly cli input module. (Input)
README
# ansi-diff-stream
A transform stream that diffs input buffers and outputs the diff as ANSI.
If you pipe this to a terminal it will update the output with minimal changes.```
npm install ansi-diff-stream
```[![build status](http://img.shields.io/travis/mafintosh/ansi-diff-stream.svg?style=flat)](http://travis-ci.org/mafintosh/ansi-diff-stream)
## Usage
``` js
var differ = require('ansi-diff-stream')
var diff = differ()setInterval(function () {
diff.write(
'This is a demo\n' +
'The time is: ' + new Date() + '\n' +
'That is all'
)
}, 500)diff.pipe(process.stdout)
```Running the above example will produce an output that looks like this:
```
This is a demo
The time is: Thu Jul 14 2016 19:46:56 GMT+0200 (CEST)
That is all
```Every half second the time will update.
The diff produced by running the above means that the terminal will move the cursor to the beginning of the time stamp only update that part.For a more advanced example see `example.js`.
## API
#### `var stream = differ()`
Create a new diff stream. You should pipe it to a ansi capable stream.
#### `stream.reset()`
Will reset the diff. Useful you print something manually inbetween updates.
#### `stream.clear()`
Clear the last printed output from the screen. Similar to doing `stream.write('')`.
## CLI
There is a command line tools available as
```
npm install -g ansi-diff-stream
nc -l 10000 | ansi-diff-stream
```In another terminal
```
nc localhost 10000
hello
world
```## License
MIT