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.
go get github.com/filwisher/go-ansi-diff
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
}
A differ object. Use different Differ objects for unrelated pieces of text.
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(...))