當前位置: 首頁>>代碼示例>>Golang>>正文


Golang colorstring.Color函數代碼示例

本文整理匯總了Golang中github.com/mitchellh/colorstring.Color函數的典型用法代碼示例。如果您正苦於以下問題:Golang Color函數的具體用法?Golang Color怎麽用?Golang Color使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Color函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Log

func (ConsolePlugin) Log(text string, skipChevron bool) {
	if skipChevron {
		fmt.Printf("%v", colorstring.Color("[light_gray]"+text))
		return
	}
	fmt.Printf("%v %v", colorstring.Color("[blue]>"), colorstring.Color("[light_gray]"+text))
}
開發者ID:tianhonglouis,項目名稱:cf-console,代碼行數:7,代碼來源:console.go

示例2: main

func main() {
	movie, err := movies.GetMovieByID(randomID())
	if err != nil {
		fmt.Println(colorstring.Color("[red]" + err.Error()))
	}

	textColor := getColorForRating(movie.ImdbRating)
	fmt.Println(colorstring.Color(textColor + movie.Title))
}
開發者ID:pj3677,項目名稱:gomovies,代碼行數:9,代碼來源:main.go

示例3: BuildSession

// BuildSession build a session based on Session structure
func BuildSession(s *Session, tmux string, args []string, attach bool) error {

	if s.Name == "" {
		s.Name = "tmass-session-" + strconv.Itoa(rand.Int())
	}
	// Wow this code is creepy :/
	if IsSessionExists(s.Name) {
		if !attach {
			return fmt.Errorf("session with name %s already exists, use the --attach switch to attach to it or use --target for overwrite name", s.Name)
		}
		s.Attach = true
	}

	for i := range s.Windows {
		if !s.Attach && i == 0 { // First window is created when new session is started, if its not an attach session
			cmd := Command{}
			if !s.Attach {
				cmd.Add("new-session", "-d", "-s")
			}
			cmd.Add(s.Name)
			cmd.Add("-n", s.Windows[i].Name, "-c", s.Windows[i].RealPane[0].Root)
			if _, err := cmd.Execute(tmux, args); err != nil {
				return err
			}
			// tmux -P switch for new window return data for window not the first pane
			//TODO: Default is zero, if default is changed by user?
			s.Windows[i].RealPane[0].identifier = s.Name + ":0.0"
		} else {
			c := Command{}
			c.Add("new-window", "-P", "-t", s.Name, "-n", s.Windows[i].Name, "-c", s.Windows[i].RealPane[0].Root)
			n, err := c.Execute(tmux, args)
			if err != nil {
				return err
			}
			s.Windows[i].RealPane[0].identifier = n
		}
		cf, err := BuildPane(&s.Windows[i], tmux, args, s)
		if err != nil {
			return err
		}
		// The problem is, layout may contain the focus. so for setting focus, we need to call it after setting layout
		c := Command{[]string{"select-layout", s.Windows[i].Layout}}
		if _, err := c.Execute(tmux, args); err != nil {
			log.Println(colorstring.Color("[yellow] Failed to apply layout. ignored"))
		}

		if cf != nil {
			if _, err := cf.Execute(tmux, args); err != nil {
				log.Println(colorstring.Color("[yellow] Failed to select pane. ignored"))
			}
		}
	}

	return nil
}
開發者ID:logic855,項目名稱:tmass,代碼行數:56,代碼來源:tmux.go

示例4: newWindowFallback

// A simple fallback, Sometime the split-window fails with `create pane failed: pane too small`
// In that case, print a warning and then try to use new-window
func newWindowFallback(w *Window, tmux string, args []string, s *Session, p *Pane) (string, error) {
	log.Println(colorstring.Color("[yellow] Failed to split window. try to create new window."))
	// First try to set layout for old window
	c := Command{[]string{"select-layout", w.Layout}}
	if _, err := c.Execute(tmux, args); err != nil {
		log.Println(colorstring.Color("[yellow] Failed to apply layout. ignored"))
	}
	c.Clear()
	c.Add("new-window", "-P", "-t", s.Name, "-n", w.Name, "-c", p.Root)
	return c.Execute(tmux, args)
}
開發者ID:logic855,項目名稱:tmass,代碼行數:13,代碼來源:tmux.go

示例5: printCurrentWeather

func printCurrentWeather(forecast Forecast, geolocation GeoLocation, ignoreAlerts bool) {
	unitsFormat := UnitFormats[forecast.Flags.Units]

	icon, err := getIcon(forecast.Currently.Icon)
	if err != nil {
		printError(err)
	} else {
		fmt.Println(icon)
	}

	location := colorstring.Color(fmt.Sprintf("[green]%s in %s", geolocation.City, geolocation.Region))
	fmt.Printf("\nCurrent weather is %s in %s for %s\n", colorstring.Color("[cyan]"+forecast.Currently.Summary), location, colorstring.Color("[cyan]"+epochFormat(forecast.Currently.Time)))

	temp := colorstring.Color(fmt.Sprintf("[magenta]%v%s", forecast.Currently.Temperature, unitsFormat.Degrees))
	feelslike := colorstring.Color(fmt.Sprintf("[magenta]%v%s", forecast.Currently.ApparentTemperature, unitsFormat.Degrees))
	fmt.Printf("The temperature is %s, but it feels like %s\n\n", temp, feelslike)

	if !ignoreAlerts {
		for _, alert := range forecast.Alerts {
			if alert.Title != "" {
				fmt.Println(colorstring.Color("[red]" + alert.Title))
			}
			if alert.Description != "" {
				fmt.Print(colorstring.Color("[red]" + alert.Description))
			}
			fmt.Println("\t\t\t" + colorstring.Color("[red]Created: "+epochFormat(alert.Time)))
			fmt.Println("\t\t\t" + colorstring.Color("[red]Expires: "+epochFormat(alert.Expires)) + "\n")
		}
	}

	printWeather(forecast.Currently, unitsFormat)
}
開發者ID:RavenB,項目名稱:weather,代碼行數:32,代碼來源:output.go

示例6: LoadSessionFromTmux

// LoadSessionFromTmux fill session structure from a running instance of tmux
func LoadSessionFromTmux(tmux string, args []string, session string) (*Session, error) {
	sess := Session{Name: session}
	sess.Windows = make([]Window, 0)
	cmd := Command{}
	cmd.Add("list-window", "-t", session, "-F", "#S:#I|#{window_name}|#{window_layout}")
	out, err := cmd.Execute(tmux, args)
	if err != nil {
		return nil, err
	}
	for _, s := range strings.Split(out, "\n") {
		parts := strings.Split(s, "|")
		if len(parts) != 3 {
			log.Println(colorstring.Color("[red][_yellow_]Invalid count! ignoring this window!"))
			continue
		}
		w, err := LoadWindowFromTmux(tmux, args, parts[0], parts[1], parts[2])
		if err != nil {
			return nil, err
		}
		sess.Windows = append(sess.Windows, *w)
	}

	return &sess, nil

}
開發者ID:logic855,項目名稱:tmass,代碼行數:26,代碼來源:tmux.go

示例7: renderSummary

func renderSummary() {
	printHR()
	printCentered(fmt.Sprintf(c.Color("[white]lsp \"[red]%s[white]\""), presentPath(mode.targetPath)) + fmt.Sprintf(c.Color(", [red]%v[white] files, [red]%v[white] directories"), len(FileList), len(Trie.Ch["dirs"].Fls)))
	for _, cm := range mode.comments {
		printCentered(cm)
	}
}
開發者ID:TarunParimi,項目名稱:lsp,代碼行數:7,代碼來源:render.go

示例8: main

func main() {
	var filepath string
	var isVersion bool
	flag.StringVar(&filepath, "f", "", "keepalived.conf file path")
	flag.BoolVar(&isVersion, "v", false, "print the version")
	flag.Parse()

	if isVersion {
		log.Infof("gokc version %s", Version)
		os.Exit(0)
	}

	if filepath == "" {
		log.Error("filepath required")
	}

	file, err := os.Open(filepath)
	if err != nil {
		log.Error(err)
	}
	defer file.Close()

	if err := parser.Parse(file, filepath); err != nil {
		if e, ok := err.(*parser.Error); ok {
			msg := colorstring.Color(fmt.Sprintf("[white]%s:%d:%d: [red]%s[reset]", e.Filename, e.Line, e.Column, e.Message))
			log.Error(msg)
		} else {
			log.Error(err)
		}
	}

	log.Infof("gokc: the configuration file %s syntax is ok", filepath)
}
開發者ID:rrreeeyyy,項目名稱:gokc,代碼行數:33,代碼來源:gokc.go

示例9: LoadWindowFromTmux

// LoadWindowFromTmux loads window from a tmux session
func LoadWindowFromTmux(tmux string, args []string, window, name, layout string) (*Window, error) {
	// The real pane is not used here. ignore it
	w := Window{Name: name, Layout: layout, Panes: make([]interface{}, 0)}
	cmd := Command{}
	cmd.Add("list-pane", "-t", window, "-F", "#{pane_current_path}|#{pane_current_command}|#{pane_active}")
	out, err := cmd.Execute(tmux, args)
	if err != nil {
		return nil, err
	}
	for _, s := range strings.Split(out, "\n") {
		parts := strings.Split(s, "|")
		if len(parts) != 3 {
			log.Println(colorstring.Color("[red][_yellow_]Invalid count! ignoring this pane!"))
			continue
		}
		for _, v := range IgnoredCmd {
			if v == parts[1] {
				parts[1] = DefaultCmd
				break
			}
		}
		p := Pane{Commands: []string{parts[1]}, Root: parts[0], Focus: parts[2] == "1"}
		w.Panes = append(w.Panes, p)
	}

	return &w, nil
}
開發者ID:logic855,項目名稱:tmass,代碼行數:28,代碼來源:tmux.go

示例10: Colorize

// Colorize color msg.
func Colorize(msg string, color string) (out string) {
	// If color is blank return plain text
	if color == "" {
		return msg
	}

	return colorstring.Color(fmt.Sprintf("[%s]%s[reset]", color, msg))
}
開發者ID:wallyqs,項目名稱:ghr,代碼行數:9,代碼來源:ui.go

示例11: printHeader

func printHeader(o string) {
	length := utf8.RuneCountInString(o)
	sideburns := (6+2*columnSize-length)/2 - dashesNumber
	if sideburns < 0 {
		sideburns = 0
	}
	fmt.Printf(strings.Repeat(" ", sideburns))
	fmt.Printf(c.Color("[yellow]" + strings.Repeat("-", dashesNumber) + o + strings.Repeat("-", dashesNumber) + "[white]\n"))
}
開發者ID:TarunParimi,項目名稱:lsp,代碼行數:9,代碼來源:fmt.go

示例12: printCentered

func printCentered(o string) {
	length := utf8.RuneCountInString(o)
	sideburns := (6 + 2*columnSize - length) / 2
	if sideburns < 0 {
		sideburns = 0
	}
	fmt.Printf(strings.Repeat(" ", sideburns))
	fmt.Printf(c.Color("[yellow]" + o + "[white]\n"))
}
開發者ID:TarunParimi,項目名稱:lsp,代碼行數:9,代碼來源:fmt.go

示例13: Print

func (t *IssueDetailTemplate) Print() error {
	var buf bytes.Buffer
	if err := t.Execute(&buf, t); err != nil {
		return err
	}
	fmt.Println(color.Color(buf.String()))

	return nil
}
開發者ID:kyokomi,項目名稱:gitlab-cli,代碼行數:9,代碼來源:gitlab.go

示例14: printTotals

func printTotals(totals map[string]string) {
	if len(totals) > 0 {
		header := []string{"Totals"}
		row := []string{"-"}

		fmt.Println("")
		w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
		for k, v := range totals {
			header = append(header, stripColon(k))
			row = append(row, v)
		}

		fmt.Fprintln(w, colorstring.Color("[cyan]"+strings.Join(header, "\t")))
		fmt.Fprintln(w, colorstring.Color("[blue]"+strings.Join(row, "\t")))

		w.Flush()
	}
	return
}
開發者ID:golang-alex-alex2006hw,項目名稱:ga,代碼行數:19,代碼來源:utilities.go

示例15: catchUserInterruption

func catchUserInterruption(start time.Time) {
	c := make(chan os.Signal, 2)
	signal.Notify(c, os.Interrupt)
	go func() {
		for sig := range c {
			fmt.Printf(colorstring.Color("Awww, your total pomodoro time was: %v, [red]%v\n"), elapsedTime(start), sig)
			os.Exit(2)
		}
	}()
}
開發者ID:DrGo,項目名稱:gomodoro,代碼行數:10,代碼來源:gomodoro.go


注:本文中的github.com/mitchellh/colorstring.Color函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。