func TestNewAnsiColor2(t *testing.T) { inner := bytes.NewBufferString("") w1 := ansicolor.NewAnsiColorWriter(inner) w2 := ansicolor.NewAnsiColorWriter(w1) if w1 != w2 { t.Errorf("Get %#v, want %#v", w1, w2) } }
func TestNewAnsiColor1(t *testing.T) { inner := bytes.NewBufferString("") w := ansicolor.NewAnsiColorWriter(inner) if w == inner { t.Errorf("Get %#v, want %#v", w, inner) } }
func TestWritePlanText(t *testing.T) { inner := bytes.NewBufferString("") w := ansicolor.NewAnsiColorWriter(inner) expected := "plain text" fmt.Fprintf(w, expected) actual := inner.String() if actual != expected { t.Errorf("Get %s, want %s", actual, expected) } }
func ExampleNewAnsiColorWriter() { w := ansicolor.NewAnsiColorWriter(os.Stdout) text := "%sforeground %sbold%s %sbackground%s\n" fmt.Fprintf(w, text, "\x1b[31m", "\x1b[1m", "\x1b[21m", "\x1b[41;32m", "\x1b[0m") fmt.Fprintf(w, text, "\x1b[32m", "\x1b[1m", "\x1b[21m", "\x1b[42;31m", "\x1b[0m") fmt.Fprintf(w, text, "\x1b[33m", "\x1b[1m", "\x1b[21m", "\x1b[43;34m", "\x1b[0m") fmt.Fprintf(w, text, "\x1b[34m", "\x1b[1m", "\x1b[21m", "\x1b[44;33m", "\x1b[0m") fmt.Fprintf(w, text, "\x1b[35m", "\x1b[1m", "\x1b[21m", "\x1b[45;36m", "\x1b[0m") fmt.Fprintf(w, text, "\x1b[36m", "\x1b[1m", "\x1b[21m", "\x1b[46;35m", "\x1b[0m") fmt.Fprintf(w, text, "\x1b[37m", "\x1b[1m", "\x1b[21m", "\x1b[47;30m", "\x1b[0m") }
func writeAnsiColor(expectedText, colorCode string) (actualText string, actualAttributes uint16, err error) { inner := bytes.NewBufferString("") w := ansicolor.NewAnsiColorWriter(inner) fmt.Fprintf(w, "\x1b[%sm%s", colorCode, expectedText) actualText = inner.String() screenInfo := GetConsoleScreenBufferInfo(uintptr(syscall.Stdout)) if screenInfo != nil { actualAttributes = screenInfo.WAttributes } else { err = &screenNotFoundError{} } return }
func TestWriteParseText(t *testing.T) { inner := bytes.NewBufferString("") w := ansicolor.NewAnsiColorWriter(inner) inputTail := "\x1b[0mtail text" expectedTail := "tail text" fmt.Fprintf(w, inputTail) actualTail := inner.String() inner.Reset() if actualTail != expectedTail { t.Errorf("Get %s, want %s", actualTail, expectedTail) } inputHead := "head text\x1b[0m" expectedHead := "head text" fmt.Fprintf(w, inputHead) actualHead := inner.String() inner.Reset() if actualHead != expectedHead { t.Errorf("Get %s, want %s", actualHead, expectedHead) } inputBothEnds := "both ends \x1b[0m text" expectedBothEnds := "both ends text" fmt.Fprintf(w, inputBothEnds) actualBothEnds := inner.String() inner.Reset() if actualBothEnds != expectedBothEnds { t.Errorf("Get %s, want %s", actualBothEnds, expectedBothEnds) } inputManyEsc := "\x1b\x1b\x1b\x1b[0m many esc" expectedManyEsc := "\x1b\x1b\x1b many esc" fmt.Fprintf(w, inputManyEsc) actualManyEsc := inner.String() inner.Reset() if actualManyEsc != expectedManyEsc { t.Errorf("Get %s, want %s", actualManyEsc, expectedManyEsc) } expectedSplit := "split text" for _, ch := range "split \x1b[0m text" { fmt.Fprintf(w, string(ch)) } actualSplit := inner.String() inner.Reset() if actualSplit != expectedSplit { t.Errorf("Get %s, want %s", actualSplit, expectedSplit) } }
"regexp" "runtime" "strings" "sync" "time" "github.com/Perlence/go-wikigenre/Godeps/_workspace/src/github.com/PuerkitoBio/goquery" "github.com/Perlence/go-wikigenre/Godeps/_workspace/src/github.com/franela/goreq" "github.com/Perlence/go-wikigenre/Godeps/_workspace/src/github.com/shiena/ansicolor" "github.com/Perlence/go-wikigenre/Godeps/_workspace/src/github.com/ttacon/chalk" ) // ErrNoGenres is returned if scraping yields no genres. var ErrNoGenres = fmt.Errorf("couldn't find any genres") var colorStderr = ansicolor.NewAnsiColorWriter(os.Stderr) var logger = log.New(colorStderr, "", log.LstdFlags) // Log requests to Wikipedia. var Verbose = false const verboseUsage = "print URIs of HTTP requests" func init() { flag.BoolVar(&Verbose, "v", false, verboseUsage) goreq.SetConnectTimeout(10 * time.Second) } func usage() { fmt.Fprintln(os.Stderr, `usage: go-wikigenre [-h] [-v] "[ARTIST - ]ALBUM"( "[ARTIST - ]ALBUM")*`)
func main() { w := ansicolor.NewAnsiColorWriter(os.Stdout) io.Copy(w, os.Stdin) }