Skip to content

Commit

Permalink
Merge pull request #2 from mattn/windows
Browse files Browse the repository at this point in the history
Windows Support
  • Loading branch information
dimiro1 committed Mar 28, 2016
2 parents 05561f2 + e563623 commit 58e944a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 69 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,26 @@ func main() {
isColorEnabled := true
banner.Init(os.Stdout, isEnabled, isColorEnabled, bytes.NewBufferString("My Custom Banner"))
}
```

If using windows, use go-colorable. This works in all-platforms.

```go
package main

import (
"bytes"
"os"

"github.com/dimiro1/banner"
"github.com/mattn/go-colorable"
)

func main() {
isEnabled := true
isColorEnabled := true
banner.Init(colorable.NewColorableStdout(), isEnabled, isColorEnabled, bytes.NewBufferString("My Custom Banner"))
}
```

# API
Expand Down
3 changes: 2 additions & 1 deletion autoload/autoload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"

"github.com/dimiro1/banner"
"github.com/mattn/go-colorable"
)

func init() {
Expand All @@ -36,5 +37,5 @@ func init() {
return
}

banner.Init(os.Stdout, isEnabled, isColorEnabled, in)
banner.Init(colorable.NewColorableStdout(), isEnabled, isColorEnabled, in)
}
14 changes: 11 additions & 3 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

package banner

import "runtime"
import (
"os"

"github.com/mattn/go-isatty"
)

const (
encodeStart = "\033["
Expand Down Expand Up @@ -156,15 +160,19 @@ func (a ansiColor) BrightWhite() string {
return outputANSI(a.isColorEnabled, "97")
}

func (a ansiBackground) Reset() string {
return outputANSI(a.isColorEnabled, encodeReset)
}

func outputANSI(isColorEnabled bool, code string) string {
if isColorEnabled && isANSIEnabled() {
return encodeStart + code + encodeEnd
}

return ""

}

func isANSIEnabled() bool {
// Windows is always disabled.
return isTerminal() && (runtime.GOOS != "windows")
return isatty.IsTerminal(os.Stdout.Fd())
}
2 changes: 1 addition & 1 deletion example/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Compiler: {{ .Compiler }}
ENV: {{ .Env "GOPATH" }}
Now: {{ .Now "Monday, 2 Jan 2006" }}
{{ .AnsiColor.BrightGreen }}This text will appear in Green
{{ .AnsiColor.BrightRed }}This text will appear in Red
{{ .AnsiColor.BrightRed }}This text will appear in Red{{ .AnsiColor.Default }}
24 changes: 0 additions & 24 deletions terminal.go

This file was deleted.

7 changes: 0 additions & 7 deletions terminal_bsd.go

This file was deleted.

12 changes: 0 additions & 12 deletions terminal_linux.go

This file was deleted.

21 changes: 0 additions & 21 deletions terminal_windows.go

This file was deleted.

0 comments on commit 58e944a

Please sign in to comment.