本文整理汇总了Golang中github.com/shiena/ansicolor.NewAnsiColorWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAnsiColorWriter函数的具体用法?Golang NewAnsiColorWriter怎么用?Golang NewAnsiColorWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewAnsiColorWriter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNewAnsiColor2
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)
}
}
示例2: Replace
func Replace(newWriter io.Writer) (formerWriter io.Writer) {
lock.Lock()
formerWriter = logWriter
logWriter = ansicolor.NewAnsiColorWriter(newWriter)
lock.Unlock()
return
}
示例3: execute
func (b *Bob) execute() {
b.stopCurVow()
clearBuffer()
b.mtx.Lock()
if len(b.depWarning) > 0 {
fmt.Printf("Deprecation Warnings!\n%s", b.depWarning)
}
// setup the first command
firstCmd := b.buildCmds[0]
b.curVow = vow.To(firstCmd[0], firstCmd[1:]...)
// setup the remaining commands
for i := 1; i < len(b.buildCmds); i++ {
cmd := b.buildCmds[i]
b.curVow = b.curVow.Then(cmd[0], cmd[1:]...)
}
// setup all parallel commands
for i := 0; i < len(b.runCmds); i++ {
cmd := b.runCmds[i]
b.curVow = b.curVow.ThenAsync(cmd[0], cmd[1:]...)
}
b.curVow.Verbose = b.verbose
go b.curVow.Exec(ansicolor.NewAnsiColorWriter(os.Stdout))
b.mtx.Unlock()
}
示例4: TestNewAnsiColor1
func TestNewAnsiColor1(t *testing.T) {
inner := bytes.NewBufferString("")
w := ansicolor.NewAnsiColorWriter(inner)
if w == inner {
t.Errorf("Get %#v, want %#v", w, inner)
}
}
示例5: PrintUnassignedWarning
func PrintUnassignedWarning(writer io.Writer, commits []*git.Commit) (n int64, err error) {
var output bytes.Buffer
// Let's be colorful!
redBold := color.New(color.FgRed).Add(color.Bold).SprintFunc()
fmt.Fprint(&output,
redBold("Warning: There are some commits missing the Story-Id tag.\n"))
red := color.New(color.FgRed).SprintFunc()
fmt.Fprint(&output,
red("Make sure that this is alright before proceeding further.\n\n"))
hashRe := regexp.MustCompile("^[0-9a-f]{40}$")
yellow := color.New(color.FgYellow).SprintFunc()
for _, commit := range commits {
var (
sha = commit.SHA
source = commit.Source
title = prompt.ShortenCommitTitle(commit.MessageTitle)
)
if hashRe.MatchString(commit.Source) {
source = "unknown commit source branch"
}
fmt.Fprintf(&output, " %v | %v | %v\n", yellow(sha), yellow(source), title)
}
// Write the output to the writer.
return io.Copy(ansicolor.NewAnsiColorWriter(writer), &output)
}
示例6: main
func main() {
w := ansicolor.NewAnsiColorWriter(os.Stdout)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fmt.Fprintln(w, scanner.Text())
}
}
示例7: init
func init() {
flag.BoolVar(&verbose, "V", false, "Show debugging messages")
flag.StringVar(&configFile, "f", "."+Program+".conf", "Specifies a configuration file")
flag.BoolVar(&writeConfig, "w", false, "Write command-line arguments to configuration file (write and exit)")
flag.Usage = func() {
fmt.Println("Usage:\n " + os.Args[0] + " [options]\n")
fmt.Println("Options:")
flag.PrintDefaults()
fmt.Println(`
Events:
all Create/Write/Remove/Rename/Chmod
create File/directory created in watched directory
write File written in watched directory
remove File/directory deleted from watched directory
rename File moved out of watched directory
chmod File Metadata changed
Variables:
%f The filename of changed file
%t The event type of file changes`)
printExample()
}
log.SetOutput(ansicolor.NewAnsiColorWriter(os.Stderr))
}
示例8: cmd_ls
func cmd_ls(cmd *interpreter.Interpreter) (interpreter.NextT, error) {
var out io.Writer
if cmd.Stdout == os.Stdout {
out = ansicolor.NewAnsiColorWriter(cmd.Stdout)
} else {
out = cmd.Stdout
}
return interpreter.CONTINUE, ls.Main(cmd.Args[1:], out)
}
示例9: cmd_ls
func cmd_ls(cmd *interpreter.Interpreter) (interpreter.ErrorLevel, error) {
var out io.Writer
if cmd.Stdout == os.Stdout {
out = ansicolor.NewAnsiColorWriter(cmd.Stdout)
} else {
out = cmd.Stdout
}
return interpreter.NOERROR, ls.Main(cmd.Args[1:], out)
}
示例10: Print
// Print prints the images to standard output.
func (i Images) Print(mode utils.OutputMode) error {
if len(i) == 0 {
return errors.New("no images found")
}
switch mode {
case utils.JSON:
out, err := i.outputJSON()
if err != nil {
return err
}
fmt.Println(out)
return nil
case utils.Simplified:
green := color.New(color.FgGreen).SprintfFunc()
output := ansicolor.NewAnsiColorWriter(os.Stdout)
w := utils.NewImagesTabWriter(output)
defer w.Flush()
for region, images := range i {
if len(images) == 0 {
continue
}
fmt.Fprintln(w, green("AWS Region: %s (%d images):", region, len(images)))
fmt.Fprintln(w, " Name\tID\tState\tTags")
for ix, image := range images {
tags := make([]string, len(image.Tags))
for i, tag := range image.Tags {
tags[i] = *tag.Key + ":" + *tag.Value
}
name := ""
if image.Name != nil {
name = *image.Name
}
state := *image.State
if *image.State == "failed" {
state += " (" + *image.StateReason.Message + ")"
}
fmt.Fprintf(w, "[%d] %s\t%s\t%s\t%+v\n",
ix+1, name, *image.ImageId, state, tags)
}
fmt.Fprintln(w, "")
}
return nil
default:
return fmt.Errorf("output mode '%s' is not valid", mode)
}
}
示例11: Interactive
func (app *App) Interactive() {
rl, err := readline.NewEx(&readline.Config{
Prompt: color.BlueString("say » "),
HistoryFile: app.Config.HistoryFile,
})
if err != nil {
log.Fatal(err)
}
defer rl.Close()
app.Log.SetOutput(rl.Stderr())
log.SetOutput(rl.Stderr())
color.Output = ansicolor.NewAnsiColorWriter(rl.Stderr())
pings := make(map[string]time.Time)
// Subscribe to all replies and print them to stdout
app.Client.Subscribe("", "self", func(msg sarif.Message) {
text := msg.Text
if text == "" {
text = msg.Action + " from " + msg.Source
}
if msg.IsAction("err") {
text = color.RedString(text)
}
if sent, ok := pings[msg.CorrId]; ok {
text += color.YellowString("[%.1fms]", time.Since(sent).Seconds()*1e3)
}
log.Println(color.GreenString(" « ") + strings.Replace(text, "\n", "\n ", -1))
})
// Interactive mode sends all lines from stdin.
for {
line, err := rl.Readline()
if err != nil {
if err == io.EOF {
return
}
log.Fatal(err)
}
if len(line) == 0 {
continue
}
// Publish natural message
msg := sarif.Message{
Id: sarif.GenerateId(),
Action: "natural/handle",
Text: line,
}
if *profile {
pings[msg.Id] = time.Now()
}
app.Client.Publish(msg)
}
}
示例12: TestWritePlanText
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)
}
}
示例13: buildAndRun
func buildAndRun() (status int, err error) {
// will support Ansi colors for windows
stdout := ansicolor.NewAnsiColorWriter(os.Stdout)
buffer := bytes.NewBuffer([]byte(""))
stderr := ansicolor.NewAnsiColorWriter(buffer)
builtFile := fmt.Sprintf("%s/%dgodog.go", os.TempDir(), time.Now().UnixNano())
buf, err := godog.Build()
if err != nil {
return
}
w, err := os.Create(builtFile)
if err != nil {
return
}
defer os.Remove(builtFile)
if _, err = w.Write(buf); err != nil {
w.Close()
return
}
w.Close()
cmd := exec.Command("go", append([]string{"run", builtFile}, os.Args[1:]...)...)
cmd.Stdout = stdout
cmd.Stderr = stderr
defer func() {
s := strings.TrimSpace(buffer.String())
if s == "" {
status = 0
} else if m := statusMatch.FindStringSubmatch(s); len(m) > 1 {
status, _ = strconv.Atoi(m[1])
} else {
io.Copy(stdout, buffer)
}
}()
return status, cmd.Run()
}
示例14: ExampleNewAnsiColorWriter
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")
}
示例15: writeAnsiColor
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
}