本文整理匯總了Golang中github.com/mgutz/ansi.ColorCode函數的典型用法代碼示例。如果您正苦於以下問題:Golang ColorCode函數的具體用法?Golang ColorCode怎麽用?Golang ColorCode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ColorCode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ServeHTTP
func (h *HTTPLogger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
//Colors to be used on the logger
red := ansi.ColorCode("red+bh")
white := ansi.ColorCode("white+bh")
greenUnderline := ansi.ColorCode("green+buh")
blackOnWhite := ansi.ColorCode("black+b:white+h")
//Reset the color
reset := ansi.ColorCode("reset")
//Log data
fmt.Println(red,
time.Now(),
reset,
":",
white,
r.RemoteAddr,
reset, "requested page",
greenUnderline,
r.URL.String(),
reset,
"with method",
blackOnWhite,
r.Method,
reset)
}
示例2: Convert
// thanks to IonicaBizau/image-to-ascii for algorithm
func Convert(img image.Image) (str string) {
var buffer bytes.Buffer
size := img.Bounds().Max
pixels := ".,:;[email protected]"
precision := (255 * 4) / (len(pixels) - 1)
// ansi color end constant
reset := ansi.ColorCode("reset")
for y := 0; y < size.Y; y += 1 {
for x := 0; x < size.X; x += 1 {
r, g, b, a := img.At(x, y).RGBA()
sum := r>>8 + g>>8 + b>>8 + a>>8
pixel := pixels[int(sum)/precision]
// find the closest ansi color code
code := x256.ClosestCode(uint8(r>>8), uint8(g>>8), uint8(b>>8))
/// get the ansi color code
color := ansi.ColorCode(strconv.Itoa(code))
// write the pixel
buffer.WriteString(color)
buffer.WriteString(string(pixel))
buffer.WriteString(reset)
}
buffer.WriteString("\n")
}
return buffer.String()
}
示例3: showBlockedList
func showBlockedList(successBlock []anaconda.User, failedBlock []User) (err error) {
red := ansi.ColorCode("red")
blue := ansi.ColorCode("blue")
reset := ansi.ColorCode("reset")
if len(successBlock) > 0 {
fmt.Println(red, "Blocked", reset)
for idx, user := range successBlock {
fmt.Println(idx+1, ":", user.Name, "(@", user.ScreenName, ")")
}
}
if len(failedBlock) > 0 {
fmt.Println(blue, "Failed Block", reset)
for idx, user := range failedBlock {
if user.id == 0 {
fmt.Println(idx+1, ":", user.screenName)
} else {
fmt.Println(idx+1, ":", user.id)
}
}
}
return
}
示例4: DisplayResult
func (g *githubPackage) DisplayResult() {
localTime, lerr := g.LocalLastCommitDate()
githubTime, gerr := g.GithubLastCommitDate()
fmt.Println("Package:", g.ImportName)
if lerr != nil {
fmt.Println("Local: Error")
} else {
fmt.Println("Local: ", localTime)
}
if gerr != nil {
fmt.Println("Github: Error")
} else {
fmt.Println("Github: ", githubTime)
}
if lerr == nil && gerr == nil {
delta := localTime.Sub(githubTime)
if delta.Minutes() == 0 {
green := ansi.ColorCode("green")
reset := ansi.ColorCode("reset")
fmt.Println("Status:", green, "OK", reset)
} else {
green := ansi.ColorCode("red")
reset := ansi.ColorCode("reset")
fmt.Println("Status:", green, "Outdated", reset)
}
}
fmt.Println(strings.Repeat("-", len(g.ImportName)))
}
示例5: AssertJSONBody
func AssertJSONBody(tb testing.TB, exp, act interface{}) {
red := ansi.ColorCode("red+h:black")
green := ansi.ColorCode("green+h:black")
yellow := ansi.ColorFunc("yellow+h")
reset := ansi.ColorCode("reset")
var actBuf bytes.Buffer
err := json.Indent(&actBuf, []byte(act.(string)), "", " ")
if err != nil {
fmt.Println(red, "Invalid json: ", act, reset)
}
act = string(actBuf.Bytes())
var expBuf bytes.Buffer
err = json.Indent(&expBuf, []byte(exp.(string)), "", " ")
if err != nil {
fmt.Println(red, "Invalid json: ", exp, reset)
}
exp = string(expBuf.Bytes())
if !reflect.DeepEqual(exp, act) {
_, file, line, _ := runtime.Caller(1)
fmt.Println(yellow(fmt.Sprintf("%s:%d", filepath.Base(file), line)))
fmt.Println(green, "Expected: ", exp, reset)
fmt.Println(red, " Got: ", act, reset)
tb.FailNow()
}
}
示例6: Config
func Config(c *cli.Context) {
_, err := ioutil.ReadFile(utils.Home() + "/.asana.yml")
if err != nil || config.Load().Api_key == "" {
println("visit: http://app.asana.com/-/account_api")
print("paste your api_key: ")
var s string
fmt.Scanf("%s", &s)
f, _ := os.Create(utils.Home() + "/.asana.yml")
defer f.Close()
f.WriteString("api_key: " + s + "\n")
}
ws := api.Me().Workspaces
index := 0
cyan := ansi.ColorCode("cyan")
reset := ansi.ColorCode("reset")
if len(ws) > 1 {
fmt.Println("\n" + strconv.Itoa(len(ws)) + " workspaces found.")
for i, w := range ws {
fmt.Printf("%s[%d]%s %s\n", cyan, i, reset, w.Name)
}
index = utils.EndlessSelect(len(ws)-1, index)
}
apiKey := config.Load().Api_key
f, _ := os.Create(utils.Home() + "/.asana.yml")
f.WriteString("api_key: " + apiKey + "\n")
f.WriteString("workspace: " + strconv.Itoa(ws[index].Id) + "\n")
}
示例7: colorizeMessage
func colorizeMessage(color, prefix, message string, args ...interface{}) string {
prefResult := ""
if prefix != "" {
prefResult = ansi.Color(prefix, color+"+b") + " " + ansi.ColorCode("reset")
}
return prefResult + ansi.Color(fmt.Sprintf(message, args...), color) + ansi.ColorCode("reset")
}
示例8: Print
func (r *Row) Print(c bool) {
if c {
color := ansi.ColorCode(r.Color)
reset := ansi.ColorCode("reset")
fmt.Println(color, r.Message, reset)
return
}
fmt.Println(r.Message)
}
示例9: main
func main() {
flag.Parse()
u, err := url.Parse(flag.Arg(0))
if err != nil {
panic(err)
}
h := http.Header{"Origin": {"http://" + u.Host}}
conn, _, err := websocket.DefaultDialer.Dial(u.String(), h)
if err != nil {
panic(err)
}
go func() {
for {
t, buf, err := conn.ReadMessage()
if *flagDebug {
log.Println("type:", t, len(buf), err)
continue
}
if *flagPretty {
color := ansi.ColorCode("green")
reset := ansi.ColorCode("reset")
fmt.Fprintf(os.Stdout, "%s%s%s\n", color, strings.Repeat("<", 10), reset)
var v interface{}
if err := json.Unmarshal(buf, &v); err != nil {
os.Stdout.Write(buf)
} else {
buf, err = json.MarshalIndent(v, "", " ")
if err != nil {
panic(err)
}
os.Stdout.Write(buf)
fmt.Fprintln(os.Stdout)
}
} else {
os.Stdout.Write(buf)
}
}
}()
b := bufio.NewReader(os.Stdin)
for {
line, err := b.ReadString('\n')
if err != nil {
log.Println(err)
break
}
if err := conn.WriteMessage(websocket.TextMessage, []byte(line)); err != nil {
break
}
}
conn.Close()
}
示例10: MaintenanceString
func (f *fullDBInfo) MaintenanceString() string {
valstr, _ := f.DBInfo.Info.GetString("Maintenance")
if valstr != "" && valstr != "not required" {
return " " + ansi.Color("!!", "red+b") + ansi.ColorCode("reset")
}
return ""
}
示例11: SetColor
func SetColor(colors bool) {
config.Colors = colors
logger.SetPrefix("")
if config.Colors {
logger.SetPrefix(ansi.ColorCode("white"))
}
}
示例12: main
func main() {
reset := ansi.ColorCode("reset")
msg := ansi.Color("red+b", "red+b:white")
fmt.Println(msg, reset)
msg = ansi.Color("green", "green")
fmt.Println(msg, reset)
msg = ansi.Color("background white", "black:white")
fmt.Println(msg, reset)
warn := ansi.ColorFunc("yellow:black")
fmt.Println(warn("this is warning!"), reset)
lime := ansi.ColorCode("green+h:black")
fmt.Println(lime, "Lime message.", reset)
}
示例13: toExecCmd
func (gcmd *command) toExecCmd() (cmd *exec.Cmd, err error) {
cmd = exec.Command(gcmd.executable, gcmd.argv...)
if gcmd.wd != "" {
cmd.Dir = gcmd.wd
}
cmd.Env = effectiveEnv(gcmd.env)
cmd.Stdin = os.Stdin
if gcmd.captureOutput {
outWrapper := newFileWrapper(os.Stdout, &gcmd.recorder, "")
errWrapper := newFileWrapper(os.Stderr, &gcmd.recorder, ansi.ColorCode("red+b"))
cmd.Stdout = outWrapper
cmd.Stderr = errWrapper
} else {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
if verbose {
if Env != "" {
util.Debug("#", "Env: %s\n", Env)
}
util.Debug("#", "%s\n", gcmd.commandstr)
}
return cmd, nil
}
示例14: AssertEqual
func AssertEqual(tb testing.TB, exp, act interface{}) {
if !reflect.DeepEqual(exp, act) {
yellow := ansi.ColorFunc("yellow+h")
green := ansi.ColorCode("green+h:black")
red := ansi.ColorCode("red+h:black")
reset := ansi.ColorCode("reset")
_, file, line, _ := runtime.Caller(1)
fmt.Println(yellow(fmt.Sprintf("%s:%d", filepath.Base(file), line)))
fmt.Println(green, "Expected: ", exp, reset)
fmt.Println(red, " Got: ", act, reset)
tb.FailNow()
}
}
示例15: Writeln
func (c *colorizer) Writeln(p string) (n int, err error) {
if c.filter.MatchString(p) {
submatches := c.filter.FindStringSubmatch(p)
return fmt.Fprintln(c.writer, ansi.Color(submatches[1], c.resolve(submatches[2]))+ansi.ColorCode("reset")+submatches[3])
}
return fmt.Fprintln(c.writer, p)
}