Giter VIP home page Giter VIP logo

ansi-diff's Introduction

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

Usage

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

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

API

var diff = ansiDiff([options])

Create a new differ. Options include:

{
  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:

{
  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

ansi-diff's People

Contributors

mafintosh avatar zkochan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.