go-ethereum/vendor/github.com/morikuni/aec/ansi.go
Rafael Matias 388d8ccd9f
PoC: Network simulation framework (#1555)
* simv2: wip

* simulation: exec adapter start/stop

* simulation: add node status to exec adapter

* simulation: initial simulation code

* simulation: exec adapter, configure path to executable

* simulation: initial docker adapter

* simulation: wip kubernetes adapter

* simulation: kubernetes adapter proxy

* simulation: implement GetAll/StartAll/StopAll

* simulation: kuberentes adapter - set env vars and resource limits

* simulation: discovery test

* simulation: remove port definitions within docker adapter

* simulation: simplify wait for healthy loop

* simulation: get nat ip addr from interface

* simulation: pull docker images automatically

* simulation: NodeStatus -> NodeInfo

* simulation: move discovery test to example dir

* simulation: example snapshot usage

* simulation: add goclient specific simulation

* simulation: add peer connections to snapshot

* simulation: close rpc client

* simulation: don't export kubernetes proxy server

* simulation: merge simulation code

* simulation: don't export nodemap

* simulation: rename SimulationSnapshot -> Snapshot

* simulation: linting fixes

* simulation: add k8s available helper func

* simulation: vendor

* simulation: fix 'no non-test Go files' when building

* simulation: remove errors from interface methods where non were returned

* simulation: run getHealthInfo check in parallel
2019-07-24 17:00:13 +02:00

59 lines
978 B
Go

package aec
import (
"fmt"
"strings"
)
const esc = "\x1b["
// Reset resets SGR effect.
const Reset string = "\x1b[0m"
var empty = newAnsi("")
// ANSI represents ANSI escape code.
type ANSI interface {
fmt.Stringer
// With adapts given ANSIs.
With(...ANSI) ANSI
// Apply wraps given string in ANSI.
Apply(string) string
}
type ansiImpl string
func newAnsi(s string) *ansiImpl {
r := ansiImpl(s)
return &r
}
func (a *ansiImpl) With(ansi ...ANSI) ANSI {
return concat(append([]ANSI{a}, ansi...))
}
func (a *ansiImpl) Apply(s string) string {
return a.String() + s + Reset
}
func (a *ansiImpl) String() string {
return string(*a)
}
// Apply wraps given string in ANSIs.
func Apply(s string, ansi ...ANSI) string {
if len(ansi) == 0 {
return s
}
return concat(ansi).Apply(s)
}
func concat(ansi []ANSI) ANSI {
strs := make([]string, 0, len(ansi))
for _, p := range ansi {
strs = append(strs, p.String())
}
return newAnsi(strings.Join(strs, ""))
}