• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ansicolor.NewAnsiColorWriter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/shiena/ansicolor.NewAnsiColorWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewAnsiColorWriter函数的具体用法?Golang NewAnsiColorWriter怎么用?Golang NewAnsiColorWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewAnsiColorWriter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TestWriteParseText

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


示例17: Print

// Print prints the stored images to standard output.
func (i Images) Print(mode utils.OutputMode) error {
	if len(i.Items) == 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()

		imageDesc := "image"
		if len(i.Items) > 1 {
			imageDesc = "images"
		}

		fmt.Fprintln(w, green("GCE (%d %s):", len(i.Items), imageDesc))
		fmt.Fprintln(w, "    Name\tID\tStatus\tType\tDeprecated\tCreation Timestamp")

		for ix, image := range i.Items {
			deprecatedState := ""
			if image.Deprecated != nil {
				deprecatedState = image.Deprecated.State
			}

			fmt.Fprintf(w, "[%d] %s (%s)\t%d\t%s\t%s (%d)\t%s\t%s\n",
				ix+1, image.Name, image.Description, image.Id,
				image.Status, image.SourceType, image.DiskSizeGb,
				deprecatedState, image.CreationTimestamp,
			)
		}

		return nil
	default:
		return fmt.Errorf("output mode '%s' is not valid", mode)
	}
}
开发者ID:hanscj1,项目名称:images,代码行数:47,代码来源:images.go


示例18: cmdWriteSub

func cmdWriteSub(L lua.Lua, out io.Writer) int {
	switch out.(type) {
	case *os.File:
		out = ansicolor.NewAnsiColorWriter(out)
	}
	n := L.GetTop()
	for i := 1; i <= n; i++ {
		str, err := L.ToString(i)
		if err != nil {
			return L.Push(nil, err)
		}
		if i > 1 {
			fmt.Fprint(out, "\t")
		}
		fmt.Fprint(out, str)
	}
	return L.Push(true)
}
开发者ID:tyochiai,项目名称:nyagos,代码行数:18,代码来源:lua_cmd.go


示例19: newWriter

func newWriter(option *Option) io.Writer {
	encoder := func() io.Writer {
		switch option.OutputEncode {
		case "sjis":
			return transform.NewWriter(os.Stdout, japanese.ShiftJIS.NewEncoder())
		case "euc":
			return transform.NewWriter(os.Stdout, japanese.EUCJP.NewEncoder())
		case "jis":
			return transform.NewWriter(os.Stdout, japanese.ISO2022JP.NewEncoder())
		default:
			return os.Stdout
		}
	}()
	if option.EnableColor {
		return ansicolor.NewAnsiColorWriter(encoder)
	}
	return encoder
}
开发者ID:LK4D4,项目名称:the_platinum_searcher,代码行数:18,代码来源:print.go


示例20: init

// Initialization of supported colors
func init() {
	colors = make(map[string]string)
	colors["black"] = "30m"
	colors["red"] = "31m"
	colors["green"] = "32m"
	colors["yellow"] = "33m"
	colors["blue"] = "34m"
	colors["magenta"] = "35m"
	colors["cyan"] = "36m"
	colors["white"] = "37m"
	colors["default"] = "39m"

	if runtime.GOOS == "windows" {
		Out = ansicolor.NewAnsiColorWriter(os.Stdout)
	} else {
		Out = os.Stdout
	}
}
开发者ID:jiangshengwu,项目名称:dockerf,代码行数:19,代码来源:clicolor.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang utils.Fatalf函数代码示例发布时间:2022-05-28
下一篇:
Golang nanovgo.Context类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap