Skip to content

Commit

Permalink
Merge pull request #1 from mattn/windows-color
Browse files Browse the repository at this point in the history
fix Windows color
  • Loading branch information
shenwei356 authored Apr 26, 2017
2 parents 6a8a979 + 142fa4e commit 35199f9
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions brename.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package main

import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
Expand All @@ -31,6 +32,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/mattn/go-colorable"
"github.com/op/go-logging"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -131,7 +133,11 @@ func getOptions(cmd *cobra.Command) *Options {

func init() {
logFormat := logging.MustStringFormatter(`%{color}[%{level:.4s}]%{color:reset} %{message}`)
backend := logging.NewLogBackend(os.Stderr, "", 0)
var stderr io.Writer = os.Stderr
if isWindows {
stderr = colorable.NewColorableStderr()
}
backend := logging.NewLogBackend(stderr, "", 0)
backendFormatter := logging.NewBackendFormatter(backend, logFormat)
logging.SetBackend(backendFormatter)
log = logging.MustGetLogger(app)
Expand Down Expand Up @@ -394,19 +400,6 @@ var green = color.New(color.FgGreen).SprintFunc()
var isWindows = runtime.GOOS == "windows"

func (c code) String() string {
if isWindows {
switch c {
case codeOK:
return "ok"
case codeUnchanged:
return "unchanged"
case codeExisted:
return "new path existed"
case codeMissingTarget:
return "missing target"
}
}

switch c {
case codeOK:
return green("ok")
Expand Down

0 comments on commit 35199f9

Please sign in to comment.