Skip to content

FilWisher/go-ansi-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ansi-diff

a literal translation of https://github.com/mafintosh/ansi-diff-stream to go

mafintosh wrote a module to generate ANSI control codes to update an ANSI compliant terminal. A bit like react. This is a literal translation into Go to make CLI applications simpler to write.

install

go get github.com/filwisher/go-ansi-diff

example

package main

import (
  diff "github.com/filwisher/go-ansi-diff"
  "time"
  "fmt"
)

func main() {

	d := diff.Differ{}

	ticker := time.NewTicker(1 * time.Second)
	quit := make(chan struct{})
	go func() {
		for {
			select {
			case <-ticker.C:
				fmt.Printf("%s", d.Diff([]byte(fmt.Sprintf("%s", time.Now().String()))))
			case <-quit:
				ticker.Stop()
				return
			}
		}
	}()

	<-quit
}

api

type Differ

A differ object. Use different Differ objects for unrelated pieces of text.

func (d *Differ) Diff(input []byte) []byte

Takes byte array to update the terminal with. Returns ANSI control codes as byte array with changes. To apply changes to terminal, simple write the codes to a terminal (e.g. fmt.Printf(...))

Releases

No releases published

Packages

No packages published

Languages