当前位置: 首页>>代码示例>>Golang>>正文


Golang ansicolor.NewAnsiColorWriter函数代码示例

本文整理汇总了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)
	}
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:8,代码来源:ansicolor_test.go

示例2: Replace

func Replace(newWriter io.Writer) (formerWriter io.Writer) {
	lock.Lock()
	formerWriter = logWriter
	logWriter = ansicolor.NewAnsiColorWriter(newWriter)
	lock.Unlock()
	return
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:7,代码来源:log.go

示例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()
}
开发者ID:samdec11,项目名称:snag,代码行数:30,代码来源:builder.go

示例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)
	}
}
开发者ID:j4ustin,项目名称:go-ethereum,代码行数:7,代码来源:ansicolor_test.go

示例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)
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:32,代码来源:unassigned_warning.go

示例6: main

func main() {
	w := ansicolor.NewAnsiColorWriter(os.Stdout)
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		fmt.Fprintln(w, scanner.Text())
	}
}
开发者ID:nocd5,项目名称:crz,代码行数:7,代码来源:main.go

示例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))
}
开发者ID:parkghost,项目名称:watchf,代码行数:26,代码来源:main.go

示例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)
}
开发者ID:kissthink,项目名称:nyagos,代码行数:9,代码来源:ls.go

示例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)
}
开发者ID:amnz,项目名称:nyagos,代码行数:9,代码来源:ls.go

示例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)
	}
}
开发者ID:rjeczalik,项目名称:images,代码行数:57,代码来源:images.go

示例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)
	}
}
开发者ID:sarifsystems,项目名称:sarif,代码行数:56,代码来源:cmd_interactive.go

示例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)
	}
}
开发者ID:ksarch-saas,项目名称:cc,代码行数:10,代码来源:ansicolor_windows_test.go

示例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()
}
开发者ID:dasnook,项目名称:godog,代码行数:42,代码来源:main.go

示例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")
}
开发者ID:Richardphp,项目名称:noms,代码行数:11,代码来源:example_test.go

示例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
}
开发者ID:ksarch-saas,项目名称:cc,代码行数:14,代码来源:ansicolor_windows_test.go


注:本文中的github.com/shiena/ansicolor.NewAnsiColorWriter函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。