├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── autoload └── autoload.go ├── banner-nyan.png ├── banner.go ├── banner_test.go ├── color.go ├── color_test.go ├── examples ├── file │ ├── banner.txt │ ├── main.go │ └── nyancat.txt └── title │ ├── banner.go │ └── main.go ├── go.mod ├── go.sum └── test-banner.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.11.x 5 | - 1.12.x 6 | - 1.13.x 7 | 8 | env: 9 | - GO111MODULE=on 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Claudemiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/dimiro1/banner.svg?branch=master)](https://travis-ci.org/dimiro1/banner) 2 | [![Go Report Card](https://goreportcard.com/badge/github.com/dimiro1/banner)](https://goreportcard.com/report/github.com/dimiro1/banner) 3 | [![GoDoc](https://godoc.org/github.com/dimiro1/banner?status.svg)](https://godoc.org/github.com/dimiro1/banner) 4 | 5 | Try browsing [the code on Sourcegraph](https://sourcegraph.com/github.com/dimiro1/banner)! 6 | 7 | # Banner 8 | 9 | Add beautiful banners into your Go applications 10 | 11 | **Table of Contents** 12 | 13 | - [Motivation](#motivation) 14 | - [Usage](#usage) 15 | - [API](#api) 16 | - [Command line flags](#command-line-flags) 17 | - [Template](#template) 18 | - [Log](#log) 19 | - [ASCII Banners](#ascii-banners) 20 | - [LICENSE](#license) 21 | 22 | # Motivation 23 | 24 | I Like to add these startup banners on all my applications, I think it give personality to the application. 25 | 26 | # Usage 27 | 28 | Import the package. Thats it. 29 | 30 | ```go 31 | package main 32 | 33 | import _ "github.com/dimiro1/banner/autoload" 34 | 35 | func main() {} 36 | ``` 37 | 38 | By default it look at the file **banner.txt** in the same directory. You can customize with the command line flags. 39 | 40 | If you do not want to use the autoload package you can always fallback to the banner API 41 | 42 | ```go 43 | package main 44 | 45 | import ( 46 | "bytes" 47 | "os" 48 | 49 | "github.com/dimiro1/banner" 50 | ) 51 | 52 | func main() { 53 | isEnabled := true 54 | isColorEnabled := true 55 | banner.Init(os.Stdout, isEnabled, isColorEnabled, bytes.NewBufferString("My Custom Banner")) 56 | } 57 | ``` 58 | 59 | If using windows, use go-colorable. This works in all-platforms. 60 | 61 | ```go 62 | package main 63 | 64 | import ( 65 | "bytes" 66 | "os" 67 | 68 | "github.com/dimiro1/banner" 69 | "github.com/mattn/go-colorable" 70 | ) 71 | 72 | func main() { 73 | isEnabled := true 74 | isColorEnabled := true 75 | banner.Init(colorable.NewColorableStdout(), isEnabled, isColorEnabled, bytes.NewBufferString("My Custom Banner")) 76 | } 77 | ``` 78 | 79 | # API 80 | 81 | I recommend you to vendor this dependency in your project, as it is a good practice. 82 | 83 | # Command line flags 84 | 85 | ```sh 86 | $ go run main.go -h 87 | ``` 88 | 89 | should output 90 | 91 | ``` 92 | Usage of main: 93 | -ansi 94 | ansi colors enabled? (default true) 95 | -banner string 96 | banner.txt file (default "banner.txt") 97 | -show-banner 98 | print the banner? (default true) 99 | ``` 100 | 101 | # Template 102 | 103 | You can use the following variables in the template. 104 | 105 | | Variable | Value | 106 | | -------------------------------------------- | ----------------------------------------- | 107 | | `{{ .Title "YourTitle" "fontname" indent }}` | `` | 108 | | `{{ .GoVersion }}` | `runtime.Version()` | 109 | | `{{ .GOOS }}` | `runtime.GOOS` | 110 | | `{{ .GOARCH }}` | `runtime.GOARCH` | 111 | | `{{ .NumCPU }}` | `runtime.NumCPU()` | 112 | | `{{ .GOPATH }}` | `os.Getenv("GOPATH")` | 113 | | `{{ .GOROOT }}` | `runtime.GOROOT()` | 114 | | `{{ .Compiler }}` | `runtime.Compiler` | 115 | | `{{ .Env "GOPATH" }}` | `os.Getenv("GOPATH")` | 116 | | `{{ .Now "Monday, 2 Jan 2006" }}` | `time.Now().Format("Monday, 2 Jan 2006")` | 117 | 118 | Please see the layout of the function **.Now** in https://github.com/golang/go/blob/f06795d9b742cf3292a0f254646c23603fc6419b/src/time/format.go#L9-L41 119 | 120 | ## Title 121 | 122 | Title generates ascii art for you using [go-figure](https://github.com/common-nighthawk/go-figure) 123 | Use it if you don't provide your own ascii title. 124 | 125 | See [examples/title](./examples/title) for an example 126 | 127 | **Note:** Must provide zero values if not using something i.e. 128 | 129 | ```go 130 | // .Title string string int 131 | // .Title title fontname indentation_spaces 132 | {{ .Title "Banner" "" 0 }} 133 | {{ .Title "Banner" "banner2" 0 }} 134 | {{ .Title "Banner" "" 4 }} 135 | ``` 136 | 137 | The fonts available can be seen here [go-figure#supported-fonts](https://github.com/common-nighthawk/go-figure#supported-fonts) 138 | 139 | ## Colors 140 | 141 | There are support for ANSI colors :) 142 | 143 | | Variable | 144 | | ------------------------------------- | 145 | | `{{ .AnsiColor.Default }}` | 146 | | `{{ .AnsiColor.Black }}` | 147 | | `{{ .AnsiColor.Red }}` | 148 | | `{{ .AnsiColor.Green }}` | 149 | | `{{ .AnsiColor.Yellow }}` | 150 | | `{{ .AnsiColor.Blue }}` | 151 | | `{{ .AnsiColor.Magenta }}` | 152 | | `{{ .AnsiColor.Cyan }}` | 153 | | `{{ .AnsiColor.White }}` | 154 | | `{{ .AnsiColor.BrightBlack }}` | 155 | | `{{ .AnsiColor.BrightRed }}` | 156 | | `{{ .AnsiColor.BrightGreen }}` | 157 | | `{{ .AnsiColor.BrightYellow }}` | 158 | | `{{ .AnsiColor.BrightBlue }}` | 159 | | `{{ .AnsiColor.BrightMagenta }}` | 160 | | `{{ .AnsiColor.BrightCyan }}` | 161 | | `{{ .AnsiColor.BrightWhite }}` | 162 | | `{{ .AnsiBackground.Default }}` | 163 | | `{{ .AnsiBackground.Black }}` | 164 | | `{{ .AnsiBackground.Red }}` | 165 | | `{{ .AnsiBackground.Green }}` | 166 | | `{{ .AnsiBackground.Yellow }}` | 167 | | `{{ .AnsiBackground.Blue }}` | 168 | | `{{ .AnsiBackground.Magenta }}` | 169 | | `{{ .AnsiBackground.Cyan }}` | 170 | | `{{ .AnsiBackground.White }}` | 171 | | `{{ .AnsiBackground.BrightBlack }}` | 172 | | `{{ .AnsiBackground.BrightRed }}` | 173 | | `{{ .AnsiBackground.BrightGreen }}` | 174 | | `{{ .AnsiBackground.BrightYellow }}` | 175 | | `{{ .AnsiBackground.BrightBlue }}` | 176 | | `{{ .AnsiBackground.BrightMagenta }}` | 177 | | `{{ .AnsiBackground.BrightCyan }}` | 178 | | `{{ .AnsiBackground.BrightWhite }}` | 179 | 180 | Want to see a nyancat? 181 | 182 | ```sh 183 | $ go run examples/file/main.go -banner examples/file/nyancat.txt 184 | ``` 185 | 186 | ![NyanCat Banner](banner-nyan.png?raw=true "NyanCat Banner") 187 | 188 | ## Example 189 | 190 | ``` 191 | ____ 192 | | _ \ 193 | | |_) | __ _ _ __ _ __ ___ _ __ 194 | | _ < / _` | '_ \| '_ \ / _ \ '__| 195 | | |_) | (_| | | | | | | | __/ | 196 | |____/ \__,_|_| |_|_| |_|\___|_| 197 | 198 | GoVersion: {{ .GoVersion }} 199 | GOOS: {{ .GOOS }} 200 | GOARCH: {{ .GOARCH }} 201 | NumCPU: {{ .NumCPU }} 202 | GOPATH: {{ .GOPATH }} 203 | GOROOT: {{ .GOROOT }} 204 | Compiler: {{ .Compiler }} 205 | ENV: {{ .Env "GOPATH" }} 206 | Now: {{ .Now "Monday, 2 Jan 2006" }} 207 | ``` 208 | 209 | will output something like this 210 | 211 | ``` 212 | ____ 213 | | _ \ 214 | | |_) | __ _ _ __ _ __ ___ _ __ 215 | | _ < / _` | '_ \| '_ \ / _ \ '__| 216 | | |_) | (_| | | | | | | | __/ | 217 | |____/ \__,_|_| |_|_| |_|\___|_| 218 | 219 | GoVersion: go1.6 220 | GOOS: darwin 221 | GOARCH: amd64 222 | NumCPU: 4 223 | GOPATH: /Users/claudemiro/go 224 | GOROOT: /usr/local/Cellar/go/1.6/libexec 225 | Compiler: gc 226 | ENV: /Users/claudemiro/go 227 | Now: Friday, 26 Mar 2016 228 | ``` 229 | 230 | # Log 231 | 232 | I am using the standard golang log, but there is a function SetLog that accepts a custom log, so you can customize the way you want. 233 | 234 | # ASCII Banners 235 | 236 | Access http://patorjk.com/software/taag/#p=display&f=Big&t=Banner to generate ASCII banners. 237 | 238 | Or use `{{ .Title }}` template 239 | 240 | # LICENSE 241 | 242 | The MIT License (MIT) 243 | 244 | Copyright (c) 2016 Claudemiro 245 | 246 | Permission is hereby granted, free of charge, to any person obtaining a copy 247 | of this software and associated documentation files (the "Software"), to deal 248 | in the Software without restriction, including without limitation the rights 249 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 250 | copies of the Software, and to permit persons to whom the Software is 251 | furnished to do so, subject to the following conditions: 252 | 253 | The above copyright notice and this permission notice shall be included in all 254 | copies or substantial portions of the Software. 255 | 256 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 257 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 258 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 259 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 260 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 261 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 262 | SOFTWARE. 263 | -------------------------------------------------------------------------------- /autoload/autoload.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package autoload configure the banner loader with defaults 6 | // Import the package. Thats it. 7 | package autoload 8 | 9 | import ( 10 | "flag" 11 | "os" 12 | 13 | "github.com/dimiro1/banner" 14 | "github.com/mattn/go-colorable" 15 | ) 16 | 17 | func init() { 18 | var ( 19 | filename string 20 | isEnabled bool 21 | isColorEnabled bool 22 | ) 23 | 24 | flag.StringVar(&filename, "banner", "banner.txt", "banner.txt file") 25 | flag.BoolVar(&isEnabled, "show-banner", true, "print the banner?") 26 | flag.BoolVar(&isColorEnabled, "ansi", true, "ansi colors enabled?") 27 | 28 | flag.Parse() 29 | 30 | in, err := os.Open(filename) 31 | 32 | if in != nil { 33 | defer in.Close() 34 | } 35 | 36 | if err != nil { 37 | return 38 | } 39 | 40 | banner.Init(colorable.NewColorableStdout(), isEnabled, isColorEnabled, in) 41 | } 42 | -------------------------------------------------------------------------------- /banner-nyan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dimiro1/banner/4f86e55de52dedeb9c329ce3aa142a6983f689e1/banner-nyan.png -------------------------------------------------------------------------------- /banner.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package banner 6 | 7 | import ( 8 | "bytes" 9 | "io" 10 | "io/ioutil" 11 | "log" 12 | "os" 13 | "runtime" 14 | "strings" 15 | "text/template" 16 | "time" 17 | 18 | "github.com/common-nighthawk/go-figure" 19 | ) 20 | 21 | var logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) 22 | 23 | // SetLog permits the user change the default logger instance 24 | func SetLog(l *log.Logger) { 25 | if l == nil { 26 | return 27 | } 28 | logger = l 29 | } 30 | 31 | type vars struct { 32 | GoVersion string 33 | GOOS string 34 | GOARCH string 35 | NumCPU int 36 | GOPATH string 37 | GOROOT string 38 | Compiler string 39 | AnsiColor ansiColor 40 | AnsiBackground ansiBackground 41 | } 42 | 43 | func (v vars) Env(env string) string { 44 | return os.Getenv(env) 45 | } 46 | 47 | // See https://github.com/golang/go/blob/f06795d9b742cf3292a0f254646c23603fc6419b/src/time/format.go#L9-L41 48 | func (v vars) Now(layout string) string { 49 | return time.Now().Format(layout) 50 | } 51 | 52 | // Create ASCII art from title 53 | func (v vars) Title(title, font string, indentW int) string { 54 | // TODO(phanirithvij) variadic args 55 | fig := figure.NewFigure(title, font, true) 56 | text := fig.String() 57 | // TODO(phanirithvij) Use ColorString as soon as PR 58 | // https://github.com/common-nighthawk/go-figure/pull/16 lands 59 | // if color != "" { 60 | // fig = figure.NewColorFigure(title, font, color, true) 61 | // } 62 | // text := fig.ColorString() 63 | // TODO(phanirithvij) figure out indetation https://stackoverflow.com/q/46066524/8608146 64 | return indent(indentW, text) 65 | } 66 | 67 | // See https://github.com/Masterminds/sprig/blob/4241ae82dd07e5d3391a83c25b79c04450eb22b0/strings.go#L109 68 | func indent(spaces int, v string) string { 69 | pad := strings.Repeat(" ", spaces) 70 | return pad + strings.Replace(v, "\n", "\n"+pad, -1) 71 | } 72 | 73 | // InitString load the banner from a string and prints it to output 74 | // All errors are ignored, the application will not print the banner in case of error. 75 | func InitString(out io.Writer, isEnabled, isColorEnabled bool, templ string) { 76 | Init(out, isEnabled, isColorEnabled, bytes.NewBufferString(templ)) 77 | } 78 | 79 | // Init load the banner and prints it to output 80 | // All errors are ignored, the application will not print the banner in case of error. 81 | func Init(out io.Writer, isEnabled, isColorEnabled bool, in io.Reader) { 82 | if !isEnabled { 83 | logger.Println("The banner is not enabled.") 84 | return 85 | } 86 | 87 | if in == nil { 88 | logger.Println("The input is nil") 89 | return 90 | } 91 | 92 | banner, err := ioutil.ReadAll(in) 93 | 94 | if err != nil { 95 | logger.Printf("Error trying to read the banner, err: %v", err) 96 | return 97 | } 98 | 99 | show(out, isColorEnabled, string(banner)) 100 | } 101 | 102 | func show(out io.Writer, isColorEnabled bool, content string) { 103 | t, err := template.New("banner").Parse(content) 104 | 105 | if err != nil { 106 | logger.Printf("Error trying to parse the banner file, err: %v", err) 107 | return 108 | } 109 | 110 | t.Execute(out, vars{ 111 | runtime.Version(), 112 | runtime.GOOS, 113 | runtime.GOARCH, 114 | runtime.NumCPU(), 115 | os.Getenv("GOPATH"), 116 | runtime.GOROOT(), 117 | runtime.Compiler, 118 | ansiColor{isColorEnabled}, 119 | ansiBackground{isColorEnabled}, 120 | }) 121 | } 122 | -------------------------------------------------------------------------------- /banner_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package banner 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "io/ioutil" 11 | "log" 12 | "os" 13 | "runtime" 14 | "testing" 15 | "time" 16 | 17 | "github.com/common-nighthawk/go-figure" 18 | ) 19 | 20 | func Test_printBanner(t *testing.T) { 21 | bannerContent := `Hello, {{ .GoVersion }}, {{ .GOOS }}, {{ .GOARCH }}, {{ .NumCPU }}, {{ .GOPATH }}, {{ .GOROOT }}, {{ .Compiler }}` 22 | var buffer bytes.Buffer 23 | 24 | version := runtime.Version() 25 | goos := runtime.GOOS 26 | goarch := runtime.GOARCH 27 | numCPU := runtime.NumCPU() 28 | gopath := os.Getenv("GOPATH") 29 | goroot := runtime.GOROOT() 30 | compiler := runtime.Compiler 31 | 32 | expected := fmt.Sprintf(`Hello, %s, %s, %s, %d, %s, %s, %s`, version, goos, goarch, numCPU, gopath, goroot, compiler) 33 | 34 | show(&buffer, true, bannerContent) 35 | 36 | result, err := ioutil.ReadAll(&buffer) 37 | 38 | if err != nil { 39 | t.Error(err) 40 | } 41 | 42 | if string(result) != expected { 43 | t.Errorf("result != expected, got %s", string(result)) 44 | } 45 | } 46 | 47 | func Test_printBanner_invalid(t *testing.T) { 48 | var buffer bytes.Buffer 49 | 50 | expected := "" 51 | 52 | show(&buffer, true, "{{}") 53 | 54 | result, err := ioutil.ReadAll(&buffer) 55 | 56 | if err != nil { 57 | t.Error(err) 58 | } 59 | 60 | if string(result) != expected { 61 | t.Errorf("result != expected, got %s", string(result)) 62 | } 63 | } 64 | 65 | func Test_printBanner_flags(t *testing.T) { 66 | var buffer bytes.Buffer 67 | 68 | Init(&buffer, true, true, bytes.NewBufferString("Test Banner")) 69 | 70 | expected := "Test Banner" 71 | 72 | result, err := ioutil.ReadAll(&buffer) 73 | 74 | if err != nil { 75 | t.Error(err) 76 | } 77 | 78 | if string(result) != expected { 79 | t.Errorf("result != expected, got %s", string(result)) 80 | } 81 | } 82 | 83 | func Test_printBanner_invalid_reader(t *testing.T) { 84 | var buffer bytes.Buffer 85 | 86 | Init(&buffer, true, true, nil) 87 | 88 | expected := "" 89 | 90 | result, err := ioutil.ReadAll(&buffer) 91 | 92 | if err != nil { 93 | t.Error(err) 94 | } 95 | 96 | if string(result) != expected { 97 | t.Errorf("result != expected, got %s", string(result)) 98 | } 99 | } 100 | 101 | func Test_printBanner_closed_reader(t *testing.T) { 102 | var buffer bytes.Buffer 103 | 104 | // Testing an error while reading a closed file. 105 | in, err := os.Open("test-banner.txt") 106 | 107 | if err != nil { 108 | t.Error(err) 109 | } 110 | 111 | in.Close() 112 | 113 | Init(&buffer, true, true, in) 114 | 115 | expected := "" 116 | 117 | result, err := ioutil.ReadAll(&buffer) 118 | 119 | if err != nil { 120 | t.Error(err) 121 | } 122 | 123 | if string(result) != expected { 124 | t.Errorf("result != expected, got %s", string(result)) 125 | } 126 | } 127 | 128 | func Test_printBanner_banner_disabled(t *testing.T) { 129 | var buffer bytes.Buffer 130 | 131 | Init(&buffer, false, true, bytes.NewBufferString("Test Banner")) 132 | 133 | expected := "" 134 | 135 | result, err := ioutil.ReadAll(&buffer) 136 | 137 | if err != nil { 138 | t.Error(err) 139 | } 140 | 141 | if string(result) != expected { 142 | t.Errorf("result != expected, got %s", string(result)) 143 | } 144 | } 145 | 146 | func Test_vars_Env(t *testing.T) { 147 | v := vars{} 148 | gopath := v.Env("GOPATH") 149 | 150 | expected := os.Getenv("GOPATH") 151 | 152 | if gopath != expected { 153 | t.Errorf("gopath != expected, got %s", gopath) 154 | } 155 | } 156 | 157 | func Test_vars_Title(t *testing.T) { 158 | v := vars{} 159 | ascii := v.Title("Banner", "", 0) 160 | 161 | fig := figure.NewFigure("Banner", "", true) 162 | expected := fig.String() 163 | 164 | if ascii != expected { 165 | t.Errorf("ascii != expected, got %s\n need\n %s\n", ascii, expected) 166 | } 167 | } 168 | 169 | func Test_vars_Now(t *testing.T) { 170 | v := vars{} 171 | gopath := v.Now("Monday, 2 Jan 2006") 172 | 173 | expected := time.Now().Format("Monday, 2 Jan 2006") 174 | 175 | if gopath != expected { 176 | t.Errorf("gopath != expected, got %s", gopath) 177 | } 178 | } 179 | 180 | func Test_SetLog(t *testing.T) { 181 | oldLogger := logger 182 | SetLog(log.New(os.Stderr, "", log.LstdFlags)) 183 | 184 | if oldLogger == logger { 185 | t.Errorf("logger was changed, must not be equal") 186 | } 187 | } 188 | 189 | func Test_SetLog_nil(t *testing.T) { 190 | oldLogger := logger 191 | SetLog(nil) 192 | 193 | if oldLogger != logger { 194 | t.Errorf("logger was not changed, must be equal") 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /color.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package banner 6 | 7 | import ( 8 | "os" 9 | 10 | "github.com/mattn/go-isatty" 11 | ) 12 | 13 | const ( 14 | encodeStart = "\033[" 15 | encodeEnd = "m" 16 | encodeReset = "0;39" 17 | ) 18 | 19 | type ansiBackground struct { 20 | isColorEnabled bool 21 | } 22 | 23 | func (a ansiBackground) Default() string { 24 | return outputANSI(a.isColorEnabled, "49") 25 | } 26 | 27 | func (a ansiBackground) Black() string { 28 | return outputANSI(a.isColorEnabled, "40") 29 | } 30 | 31 | func (a ansiBackground) Red() string { 32 | return outputANSI(a.isColorEnabled, "41") 33 | } 34 | 35 | func (a ansiBackground) Green() string { 36 | return outputANSI(a.isColorEnabled, "42") 37 | } 38 | 39 | func (a ansiBackground) Yellow() string { 40 | return outputANSI(a.isColorEnabled, "43") 41 | } 42 | 43 | func (a ansiBackground) Blue() string { 44 | return outputANSI(a.isColorEnabled, "44") 45 | } 46 | 47 | func (a ansiBackground) Magenta() string { 48 | return outputANSI(a.isColorEnabled, "45") 49 | } 50 | 51 | func (a ansiBackground) Cyan() string { 52 | return outputANSI(a.isColorEnabled, "46") 53 | } 54 | 55 | func (a ansiBackground) White() string { 56 | return outputANSI(a.isColorEnabled, "47") 57 | } 58 | 59 | func (a ansiBackground) BrightBlack() string { 60 | return outputANSI(a.isColorEnabled, "100") 61 | } 62 | 63 | func (a ansiBackground) BrightRed() string { 64 | return outputANSI(a.isColorEnabled, "101") 65 | } 66 | 67 | func (a ansiBackground) BrightGreen() string { 68 | return outputANSI(a.isColorEnabled, "102") 69 | } 70 | 71 | func (a ansiBackground) BrightYellow() string { 72 | return outputANSI(a.isColorEnabled, "103") 73 | } 74 | 75 | func (a ansiBackground) BrightBlue() string { 76 | return outputANSI(a.isColorEnabled, "104") 77 | } 78 | 79 | func (a ansiBackground) BrightMagenta() string { 80 | return outputANSI(a.isColorEnabled, "105") 81 | } 82 | 83 | func (a ansiBackground) BrightCyan() string { 84 | return outputANSI(a.isColorEnabled, "106") 85 | } 86 | 87 | func (a ansiBackground) BrightWhite() string { 88 | return outputANSI(a.isColorEnabled, "107") 89 | } 90 | 91 | type ansiColor struct { 92 | isColorEnabled bool 93 | } 94 | 95 | func (a ansiColor) Default() string { 96 | return outputANSI(a.isColorEnabled, "39") 97 | } 98 | 99 | func (a ansiColor) Black() string { 100 | return outputANSI(a.isColorEnabled, "30") 101 | } 102 | 103 | func (a ansiColor) Red() string { 104 | return outputANSI(a.isColorEnabled, "31") 105 | } 106 | 107 | func (a ansiColor) Green() string { 108 | return outputANSI(a.isColorEnabled, "32") 109 | } 110 | 111 | func (a ansiColor) Yellow() string { 112 | return outputANSI(a.isColorEnabled, "33") 113 | } 114 | 115 | func (a ansiColor) Blue() string { 116 | return outputANSI(a.isColorEnabled, "34") 117 | } 118 | 119 | func (a ansiColor) Magenta() string { 120 | return outputANSI(a.isColorEnabled, "35") 121 | } 122 | 123 | func (a ansiColor) Cyan() string { 124 | return outputANSI(a.isColorEnabled, "36") 125 | } 126 | 127 | func (a ansiColor) White() string { 128 | return outputANSI(a.isColorEnabled, "37") 129 | } 130 | 131 | func (a ansiColor) BrightBlack() string { 132 | return outputANSI(a.isColorEnabled, "90") 133 | } 134 | 135 | func (a ansiColor) BrightRed() string { 136 | return outputANSI(a.isColorEnabled, "91") 137 | } 138 | 139 | func (a ansiColor) BrightGreen() string { 140 | return outputANSI(a.isColorEnabled, "92") 141 | } 142 | 143 | func (a ansiColor) BrightYellow() string { 144 | return outputANSI(a.isColorEnabled, "93") 145 | } 146 | 147 | func (a ansiColor) BrightBlue() string { 148 | return outputANSI(a.isColorEnabled, "94") 149 | } 150 | 151 | func (a ansiColor) BrightMagenta() string { 152 | return outputANSI(a.isColorEnabled, "95") 153 | } 154 | 155 | func (a ansiColor) BrightCyan() string { 156 | return outputANSI(a.isColorEnabled, "96") 157 | } 158 | 159 | func (a ansiColor) BrightWhite() string { 160 | return outputANSI(a.isColorEnabled, "97") 161 | } 162 | 163 | func (a ansiBackground) Reset() string { 164 | return outputANSI(a.isColorEnabled, encodeReset) 165 | } 166 | 167 | func outputANSI(isColorEnabled bool, code string) string { 168 | if isColorEnabled && isANSIEnabled() { 169 | return encodeStart + code + encodeEnd 170 | } 171 | 172 | return "" 173 | 174 | } 175 | 176 | func isANSIEnabled() bool { 177 | return isatty.IsTerminal(os.Stdout.Fd()) 178 | } 179 | -------------------------------------------------------------------------------- /color_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package banner 6 | 7 | import "testing" 8 | 9 | func Test_ansiBackground_Default(t *testing.T) { 10 | ansi := ansiBackground{true} 11 | expected := outputANSI(true, "49") 12 | got := ansi.Default() 13 | 14 | if got != expected { 15 | t.Errorf("got != expected") 16 | } 17 | } 18 | 19 | func Test_ansiBackground_Black(t *testing.T) { 20 | ansi := ansiBackground{true} 21 | expected := outputANSI(true, "40") 22 | got := ansi.Black() 23 | 24 | if got != expected { 25 | t.Errorf("got != expected") 26 | } 27 | } 28 | 29 | func Test_ansiBackground_Red(t *testing.T) { 30 | ansi := ansiBackground{true} 31 | expected := outputANSI(true, "41") 32 | got := ansi.Red() 33 | 34 | if got != expected { 35 | t.Errorf("got != expected") 36 | } 37 | } 38 | 39 | func Test_ansiBackground_Green(t *testing.T) { 40 | ansi := ansiBackground{true} 41 | expected := outputANSI(true, "42") 42 | got := ansi.Green() 43 | 44 | if got != expected { 45 | t.Errorf("got != expected") 46 | } 47 | } 48 | 49 | func Test_ansiBackground_Yellow(t *testing.T) { 50 | ansi := ansiBackground{true} 51 | expected := outputANSI(true, "43") 52 | got := ansi.Yellow() 53 | 54 | if got != expected { 55 | t.Errorf("got != expected") 56 | } 57 | } 58 | 59 | func Test_ansiBackground_Blue(t *testing.T) { 60 | ansi := ansiBackground{true} 61 | expected := outputANSI(true, "44") 62 | got := ansi.Blue() 63 | 64 | if got != expected { 65 | t.Errorf("got != expected") 66 | } 67 | } 68 | 69 | func Test_ansiBackground_Magenta(t *testing.T) { 70 | ansi := ansiBackground{true} 71 | expected := outputANSI(true, "45") 72 | got := ansi.Magenta() 73 | 74 | if got != expected { 75 | t.Errorf("got != expected") 76 | } 77 | } 78 | 79 | func Test_ansiBackground_Cyan(t *testing.T) { 80 | ansi := ansiBackground{true} 81 | expected := outputANSI(true, "46") 82 | got := ansi.Cyan() 83 | 84 | if got != expected { 85 | t.Errorf("got != expected") 86 | } 87 | } 88 | 89 | func Test_ansiBackground_White(t *testing.T) { 90 | ansi := ansiBackground{true} 91 | expected := outputANSI(true, "47") 92 | got := ansi.White() 93 | 94 | if got != expected { 95 | t.Errorf("got != expected") 96 | } 97 | } 98 | 99 | func Test_ansiBackground_BrightBlack(t *testing.T) { 100 | ansi := ansiBackground{true} 101 | expected := outputANSI(true, "100") 102 | got := ansi.BrightBlack() 103 | 104 | if got != expected { 105 | t.Errorf("got != expected") 106 | } 107 | } 108 | 109 | func Test_ansiBackground_BrightRed(t *testing.T) { 110 | ansi := ansiBackground{true} 111 | expected := outputANSI(true, "101") 112 | got := ansi.BrightRed() 113 | 114 | if got != expected { 115 | t.Errorf("got != expected") 116 | } 117 | } 118 | 119 | func Test_ansiBackground_BrightGreen(t *testing.T) { 120 | ansi := ansiBackground{true} 121 | expected := outputANSI(true, "102") 122 | got := ansi.BrightGreen() 123 | 124 | if got != expected { 125 | t.Errorf("got != expected") 126 | } 127 | } 128 | 129 | func Test_ansiBackground_BrightYellow(t *testing.T) { 130 | ansi := ansiBackground{true} 131 | expected := outputANSI(true, "103") 132 | got := ansi.BrightYellow() 133 | 134 | if got != expected { 135 | t.Errorf("got != expected") 136 | } 137 | } 138 | 139 | func Test_ansiBackground_BrightBlue(t *testing.T) { 140 | ansi := ansiBackground{true} 141 | expected := outputANSI(true, "104") 142 | got := ansi.BrightBlue() 143 | 144 | if got != expected { 145 | t.Errorf("got != expected") 146 | } 147 | } 148 | 149 | func Test_ansiBackground_BrightMagenta(t *testing.T) { 150 | ansi := ansiBackground{true} 151 | expected := outputANSI(true, "105") 152 | got := ansi.BrightMagenta() 153 | 154 | if got != expected { 155 | t.Errorf("got != expected") 156 | } 157 | } 158 | 159 | func Test_ansiBackground_BrightCyan(t *testing.T) { 160 | ansi := ansiBackground{true} 161 | expected := outputANSI(true, "106") 162 | got := ansi.BrightCyan() 163 | 164 | if got != expected { 165 | t.Errorf("got != expected") 166 | } 167 | } 168 | 169 | func Test_ansiBackground_BrightWhite(t *testing.T) { 170 | ansi := ansiBackground{true} 171 | expected := outputANSI(true, "107") 172 | got := ansi.BrightWhite() 173 | 174 | if got != expected { 175 | t.Errorf("got != expected") 176 | } 177 | } 178 | 179 | func Test_ansiColor_Default(t *testing.T) { 180 | ansi := ansiColor{true} 181 | expected := outputANSI(true, "39") 182 | got := ansi.Default() 183 | 184 | if got != expected { 185 | t.Errorf("got != expected") 186 | } 187 | } 188 | 189 | func Test_ansiColor_Black(t *testing.T) { 190 | ansi := ansiColor{true} 191 | expected := outputANSI(true, "30") 192 | got := ansi.Black() 193 | 194 | if got != expected { 195 | t.Errorf("got != expected") 196 | } 197 | } 198 | 199 | func Test_ansiColor_Red(t *testing.T) { 200 | ansi := ansiColor{true} 201 | expected := outputANSI(true, "31") 202 | got := ansi.Red() 203 | 204 | if got != expected { 205 | t.Errorf("got != expected") 206 | } 207 | } 208 | 209 | func Test_ansiColor_Green(t *testing.T) { 210 | ansi := ansiColor{true} 211 | expected := outputANSI(true, "32") 212 | got := ansi.Green() 213 | 214 | if got != expected { 215 | t.Errorf("got != expected") 216 | } 217 | } 218 | 219 | func Test_ansiColor_Yellow(t *testing.T) { 220 | ansi := ansiColor{true} 221 | expected := outputANSI(true, "33") 222 | got := ansi.Yellow() 223 | 224 | if got != expected { 225 | t.Errorf("got != expected") 226 | } 227 | } 228 | 229 | func Test_ansiColor_Blue(t *testing.T) { 230 | ansi := ansiColor{true} 231 | expected := outputANSI(true, "34") 232 | got := ansi.Blue() 233 | 234 | if got != expected { 235 | t.Errorf("got != expected") 236 | } 237 | } 238 | 239 | func Test_ansiColor_Magenta(t *testing.T) { 240 | ansi := ansiColor{true} 241 | expected := outputANSI(true, "35") 242 | got := ansi.Magenta() 243 | 244 | if got != expected { 245 | t.Errorf("got != expected") 246 | } 247 | } 248 | 249 | func Test_ansiColor_Cyan(t *testing.T) { 250 | ansi := ansiColor{true} 251 | expected := outputANSI(true, "36") 252 | got := ansi.Cyan() 253 | 254 | if got != expected { 255 | t.Errorf("got != expected") 256 | } 257 | } 258 | 259 | func Test_ansiColor_White(t *testing.T) { 260 | ansi := ansiColor{true} 261 | expected := outputANSI(true, "37") 262 | got := ansi.White() 263 | 264 | if got != expected { 265 | t.Errorf("got != expected") 266 | } 267 | } 268 | 269 | func Test_ansiColor_BrightBlack(t *testing.T) { 270 | ansi := ansiColor{true} 271 | expected := outputANSI(true, "90") 272 | got := ansi.BrightBlack() 273 | 274 | if got != expected { 275 | t.Errorf("got != expected") 276 | } 277 | } 278 | 279 | func Test_ansiColor_BrightRed(t *testing.T) { 280 | ansi := ansiColor{true} 281 | expected := outputANSI(true, "91") 282 | got := ansi.BrightRed() 283 | 284 | if got != expected { 285 | t.Errorf("got != expected") 286 | } 287 | } 288 | 289 | func Test_ansiColor_BrightGreen(t *testing.T) { 290 | ansi := ansiColor{true} 291 | expected := outputANSI(true, "92") 292 | got := ansi.BrightGreen() 293 | 294 | if got != expected { 295 | t.Errorf("got != expected") 296 | } 297 | } 298 | 299 | func Test_ansiColor_BrightYellow(t *testing.T) { 300 | ansi := ansiColor{true} 301 | expected := outputANSI(true, "93") 302 | got := ansi.BrightYellow() 303 | 304 | if got != expected { 305 | t.Errorf("got != expected") 306 | } 307 | } 308 | 309 | func Test_ansiColor_BrightBlue(t *testing.T) { 310 | ansi := ansiColor{true} 311 | expected := outputANSI(true, "94") 312 | got := ansi.BrightBlue() 313 | 314 | if got != expected { 315 | t.Errorf("got != expected") 316 | } 317 | } 318 | 319 | func Test_ansiColor_BrightMagenta(t *testing.T) { 320 | ansi := ansiColor{true} 321 | expected := outputANSI(true, "95") 322 | got := ansi.BrightMagenta() 323 | 324 | if got != expected { 325 | t.Errorf("got != expected") 326 | } 327 | } 328 | 329 | func Test_ansiColor_BrightCyan(t *testing.T) { 330 | ansi := ansiColor{true} 331 | expected := outputANSI(true, "96") 332 | got := ansi.BrightCyan() 333 | 334 | if got != expected { 335 | t.Errorf("got != expected") 336 | } 337 | } 338 | 339 | func Test_ansiColor_BrightWhite(t *testing.T) { 340 | ansi := ansiColor{true} 341 | expected := outputANSI(true, "97") 342 | got := ansi.BrightWhite() 343 | 344 | if got != expected { 345 | t.Errorf("got != expected") 346 | } 347 | } 348 | -------------------------------------------------------------------------------- /examples/file/banner.txt: -------------------------------------------------------------------------------- 1 | ____ 2 | | _ \ 3 | | |_) | __ _ _ __ _ __ ___ _ __ 4 | | _ < / _` | '_ \| '_ \ / _ \ '__| 5 | | |_) | (_| | | | | | | | __/ | 6 | |____/ \__,_|_| |_|_| |_|\___|_| 7 | 8 | GoVersion: {{ .GoVersion }} 9 | GOOS: {{ .GOOS }} 10 | GOARCH: {{ .GOARCH }} 11 | NumCPU: {{ .NumCPU }} 12 | GOPATH: {{ .GOPATH }} 13 | GOROOT: {{ .GOROOT }} 14 | Compiler: {{ .Compiler }} 15 | ENV: {{ .Env "GOPATH" }} 16 | Now: {{ .Now "Monday, 2 Jan 2006" }} 17 | {{ .AnsiColor.BrightGreen }}This text will appear in Green 18 | {{ .AnsiColor.BrightRed }}This text will appear in Red{{ .AnsiColor.Default }} 19 | -------------------------------------------------------------------------------- /examples/file/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import _ "github.com/dimiro1/banner/autoload" 8 | 9 | func main() {} 10 | -------------------------------------------------------------------------------- /examples/file/nyancat.txt: -------------------------------------------------------------------------------- 1 | 2 | {{.AnsiColor.BrightBlue}}████████████████████████████████████████████████████████████████████████████████ 3 | {{.AnsiColor.BrightBlue}}████████████████████████████████████████████████████████████████████████████████ 4 | {{.AnsiColor.Red}}██████████████████{{.AnsiColor.BrightBlue}}████████████████{{.AnsiColor.Black}}██████████████████████████████{{.AnsiColor.BrightBlue}}████████████████ 5 | {{.AnsiColor.Red}}████████████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██████████████ 6 | {{.AnsiColor.BrightRed}}████{{.AnsiColor.Red}}██████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Magenta}}██████████████████████{{.AnsiColor.White}}██████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████████████ 7 | {{.AnsiColor.BrightRed}}██████████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.Magenta}}████████████████{{.AnsiColor.Black}}████{{.AnsiColor.Magenta}}██████{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██{{.AnsiColor.Black}}████{{.AnsiColor.BrightBlue}}██████ 8 | {{.AnsiColor.BrightRed}}██████████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.Magenta}}██████{{.AnsiColor.White}}██{{.AnsiColor.Black}}████{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████ 9 | {{.AnsiColor.BrightYellow}}██████████████████{{.AnsiColor.BrightRed}}████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Magenta}}██████{{.AnsiColor.White}}██{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████ 10 | {{.AnsiColor.BrightYellow}}██████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.BrightYellow}}██████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Black}}████████{{.AnsiColor.White}}████████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████ 11 | {{.AnsiColor.BrightYellow}}████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Black}}██{{.AnsiColor.BrightYellow}}████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████ 12 | {{.AnsiColor.BrightGreen}}██████████████████{{.AnsiColor.BrightYellow}}██{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Black}}████████{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}██████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██ 13 | {{.AnsiColor.BrightGreen}}██████████████████████{{.AnsiColor.White}}████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}██████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.BrightYellow}}██{{.AnsiColor.White}}██████████{{.AnsiColor.BrightYellow}}██{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██ 14 | {{.AnsiColor.BrightGreen}}██████████████████████{{.AnsiColor.Black}}████{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}██████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Black}}████{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██ 15 | {{.AnsiColor.Blue}}██████████████████{{.AnsiColor.BrightGreen}}████████{{.AnsiColor.Black}}██████{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}██████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Magenta}}████{{.AnsiColor.White}}████████████████{{.AnsiColor.Magenta}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██ 16 | {{.AnsiColor.Blue}}██████████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.Magenta}}██████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Black}}████████████{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████ 17 | {{.AnsiColor.BrightBlue}}██████████████████{{.AnsiColor.Blue}}████{{.AnsiColor.Blue}}██████{{.AnsiColor.Black}}████{{.AnsiColor.White}}██████{{.AnsiColor.Magenta}}██████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████████████████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██████ 18 | {{.AnsiColor.BrightBlue}}██████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██{{.AnsiColor.Black}}████{{.AnsiColor.White}}████████████████████{{.AnsiColor.Black}}██████████████████{{.AnsiColor.BrightBlue}}████████ 19 | {{.AnsiColor.BrightBlue}}████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}██████{{.AnsiColor.Black}}████████████████████████████████{{.AnsiColor.White}}██{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████████████ 20 | {{.AnsiColor.BrightBlue}}████████████████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}██{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.BrightBlue}}████████████{{.AnsiColor.Black}}██{{.AnsiColor.White}}████{{.AnsiColor.Black}}████{{.AnsiColor.White}}████{{.AnsiColor.Black}}██{{.AnsiColor.BrightBlue}}████████████ 21 | {{.AnsiColor.BrightBlue}}████████████████████████{{.AnsiColor.Black}}██████{{.AnsiColor.BrightBlue}}████{{.AnsiColor.Black}}██████{{.AnsiColor.BrightBlue}}████████████{{.AnsiColor.Black}}██████{{.AnsiColor.BrightBlue}}████{{.AnsiColor.Black}}██████{{.AnsiColor.BrightBlue}}████████████ 22 | ████████████████████████████████████████████████████████████████████████████████ 23 | {{ .AnsiColor.Default }} 24 | GoVersion: {{ .GoVersion }} 25 | GOOS: {{ .GOOS }} 26 | GOARCH: {{ .GOARCH }} 27 | NumCPU: {{ .NumCPU }} 28 | GOPATH: {{ .GOPATH }} 29 | GOROOT: {{ .GOROOT }} 30 | Compiler: {{ .Compiler }} 31 | ENV: {{ .Env "GOPATH" }} 32 | Now: {{ .Now "Monday, 2 Jan 2006" }} 33 | -------------------------------------------------------------------------------- /examples/title/banner.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "github.com/mattn/go-colorable" 9 | 10 | "github.com/dimiro1/banner" 11 | ) 12 | 13 | func init() { 14 | templ := `{{ .Title "Banner" "" 4 }} 15 | {{ .AnsiColor.BrightCyan }}The title will be ascii and indented 4 spaces{{ .AnsiColor.Default }} 16 | GoVersion: {{ .GoVersion }} 17 | GOOS: {{ .GOOS }} 18 | GOARCH: {{ .GOARCH }} 19 | NumCPU: {{ .NumCPU }} 20 | GOPATH: {{ .GOPATH }} 21 | GOROOT: {{ .GOROOT }} 22 | Compiler: {{ .Compiler }} 23 | ENV: {{ .Env "GOPATH" }} 24 | Now: {{ .Now "Monday, 2 Jan 2006" }} 25 | {{ .AnsiColor.BrightGreen }}This text will appear in Green 26 | {{ .AnsiColor.BrightRed }}This text will appear in Red{{ .AnsiColor.Default }}` 27 | 28 | banner.InitString(colorable.NewColorableStdout(), true, true, templ) 29 | } 30 | -------------------------------------------------------------------------------- /examples/title/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Claudemiro Alves Feitosa Neto. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // Banner init in banner.go 8 | 9 | func main() {} 10 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/dimiro1/banner 2 | 3 | go 1.11 4 | 5 | require ( 6 | github.com/common-nighthawk/go-figure v0.0.0-20200609044655-c4b36f998cf2 7 | github.com/mattn/go-colorable v0.1.4 8 | github.com/mattn/go-isatty v0.0.10 9 | ) 10 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/common-nighthawk/go-figure v0.0.0-20200609044655-c4b36f998cf2 h1:tjT4Jp4gxECvsJcYpAMtW2I3YqzBTPuB67OejxXs86s= 2 | github.com/common-nighthawk/go-figure v0.0.0-20200609044655-c4b36f998cf2/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w= 3 | github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= 4 | github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 5 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 6 | github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= 7 | github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= 8 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 9 | golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU= 10 | golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 11 | -------------------------------------------------------------------------------- /test-banner.txt: -------------------------------------------------------------------------------- 1 | Test Banner --------------------------------------------------------------------------------