• Stars
    star
    447
  • Rank 97,700 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An easy way to add useful startup banners into your Go applications

Build Status Go Report Card GoDoc

Try browsing the code on Sourcegraph!

Banner

Add beautiful banners into your Go applications

Table of Contents

Motivation

I Like to add these startup banners on all my applications, I think it give personality to the application.

Usage

Import the package. Thats it.

package main

import _ "github.com/dimiro1/banner/autoload"

func main() {}

By default it look at the file banner.txt in the same directory. You can customize with the command line flags.

If you do not want to use the autoload package you can always fallback to the banner API

package main

import (
	"bytes"
	"os"

	"github.com/dimiro1/banner"
)

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

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

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

I recommend you to vendor this dependency in your project, as it is a good practice.

Command line flags

$ go run main.go -h

should output

Usage of main:
  -ansi
    	ansi colors enabled? (default true)
  -banner string
    	banner.txt file (default "banner.txt")
  -show-banner
    	print the banner? (default true)

Template

You can use the following variables in the template.

Variable Value
{{ .Title "YourTitle" "fontname" indent }} <Generated ASCII art>
{{ .GoVersion }} runtime.Version()
{{ .GOOS }} runtime.GOOS
{{ .GOARCH }} runtime.GOARCH
{{ .NumCPU }} runtime.NumCPU()
{{ .GOPATH }} os.Getenv("GOPATH")
{{ .GOROOT }} runtime.GOROOT()
{{ .Compiler }} runtime.Compiler
{{ .Env "GOPATH" }} os.Getenv("GOPATH")
{{ .Now "Monday, 2 Jan 2006" }} time.Now().Format("Monday, 2 Jan 2006")

Please see the layout of the function .Now in https://github.com/golang/go/blob/f06795d9b742cf3292a0f254646c23603fc6419b/src/time/format.go#L9-L41

Title

Title generates ascii art for you using go-figure Use it if you don't provide your own ascii title.

See examples/title for an example

Note: Must provide zero values if not using something i.e.

// .Title string   string    int
// .Title title    fontname  indentation_spaces
{{ .Title "Banner" ""        0 }}
{{ .Title "Banner" "banner2" 0 }}
{{ .Title "Banner" ""        4 }}

The fonts available can be seen here go-figure#supported-fonts

Colors

There are support for ANSI colors :)

Variable
{{ .AnsiColor.Default }}
{{ .AnsiColor.Black }}
{{ .AnsiColor.Red }}
{{ .AnsiColor.Green }}
{{ .AnsiColor.Yellow }}
{{ .AnsiColor.Blue }}
{{ .AnsiColor.Magenta }}
{{ .AnsiColor.Cyan }}
{{ .AnsiColor.White }}
{{ .AnsiColor.BrightBlack }}
{{ .AnsiColor.BrightRed }}
{{ .AnsiColor.BrightGreen }}
{{ .AnsiColor.BrightYellow }}
{{ .AnsiColor.BrightBlue }}
{{ .AnsiColor.BrightMagenta }}
{{ .AnsiColor.BrightCyan }}
{{ .AnsiColor.BrightWhite }}
{{ .AnsiBackground.Default }}
{{ .AnsiBackground.Black }}
{{ .AnsiBackground.Red }}
{{ .AnsiBackground.Green }}
{{ .AnsiBackground.Yellow }}
{{ .AnsiBackground.Blue }}
{{ .AnsiBackground.Magenta }}
{{ .AnsiBackground.Cyan }}
{{ .AnsiBackground.White }}
{{ .AnsiBackground.BrightBlack }}
{{ .AnsiBackground.BrightRed }}
{{ .AnsiBackground.BrightGreen }}
{{ .AnsiBackground.BrightYellow }}
{{ .AnsiBackground.BrightBlue }}
{{ .AnsiBackground.BrightMagenta }}
{{ .AnsiBackground.BrightCyan }}
{{ .AnsiBackground.BrightWhite }}

Want to see a nyancat?

$ go run examples/file/main.go -banner examples/file/nyancat.txt

NyanCat Banner

Example

  ____
 |  _ \
 | |_) | __ _ _ __  _ __   ___ _ __
 |  _ < / _` | '_ \| '_ \ / _ \ '__|
 | |_) | (_| | | | | | | |  __/ |
 |____/ \__,_|_| |_|_| |_|\___|_|

GoVersion: {{ .GoVersion }}
GOOS: {{ .GOOS }}
GOARCH: {{ .GOARCH }}
NumCPU: {{ .NumCPU }}
GOPATH: {{ .GOPATH }}
GOROOT: {{ .GOROOT }}
Compiler: {{ .Compiler }}
ENV: {{ .Env "GOPATH" }}
Now: {{ .Now "Monday, 2 Jan 2006" }}

will output something like this

  ____
 |  _ \
 | |_) | __ _ _ __  _ __   ___ _ __
 |  _ < / _` | '_ \| '_ \ / _ \ '__|
 | |_) | (_| | | | | | | |  __/ |
 |____/ \__,_|_| |_|_| |_|\___|_|

GoVersion: go1.6
GOOS: darwin
GOARCH: amd64
NumCPU: 4
GOPATH: /Users/claudemiro/go
GOROOT: /usr/local/Cellar/go/1.6/libexec
Compiler: gc
ENV: /Users/claudemiro/go
Now: Friday, 26 Mar 2016

Log

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.

ASCII Banners

Access http://patorjk.com/software/taag/#p=display&f=Big&t=Banner to generate ASCII banners.

Or use {{ .Title }} template

LICENSE

The MIT License (MIT)

Copyright (c) 2016 Claudemiro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

health

An easy to use, extensible health check library for Go applications.
Go
452
star
2

ipe

An open source Pusher server implementation compatible with Pusher client libraries written in GO
Go
366
star
3

gopong

HTML5 Pong implementation in GO
Go
36
star
4

lambda-wkhtmltopdf

Convert HTML to PDF using wkhtmltopdf on AWS Lambda
JavaScript
18
star
5

Z80-js

A Z80 emulator implemented in Typescript/Javascript
JavaScript
17
star
6

aws-serverlerss-go

How to use standard HTTP library with the new Golang official AWS lambda runtime.
Go
8
star
7

faker

A package that generates fake data for GO
Go
7
star
8

experiments

Collection of programming experiments
Go
7
star
9

reply

Library to trim replies from plain text email. (Golang port of https://github.com/discourse/email_reply_trimmer)
Go
5
star
10

GameBoyCPP

A GameBoy Emulator written in C++
C++
4
star
11

x-example

Example for https://github.com/dimiro1/x
Go
3
star
12

mixpanel-aws-lambda

JavaScript
2
star
13

vimfiles

my vim configuration
Vim Script
2
star
14

x

X is a set of modules that make creating HTTP servers fun again
Go
2
star
15

thrift-clojure-example

Implementation of the Thrift Servlet with Clojure Ring/compojure.
Clojure
2
star
16

z80-cpu

Automatically exported from code.google.com/p/z80-cpu
Java
2
star
17

hackvm

nand2tetris HackVM implemented in Go
Go
2
star
18

sense

Extract meaning from HTML pages
Kotlin
2
star
19

go-lambda

Golang Hello World Lambda With API Gateway and Serverless
Go
2
star
20

.emacs.d

My Emacs config
Emacs Lisp
1
star
21

jschip8

Javascript Chip8 Emulator
JavaScript
1
star
22

mynes

A Work in Progress NES Emulator
Java
1
star
23

ramaze-rubinius

Ruby
1
star
24

GraficoAFN

Trabalho de computação gráfica e Linguagens Formais
C++
1
star
25

example

Go
1
star
26

cookbook

Golang Cookbook
1
star
27

gochip8

A chip8 emulator in GO
Go
1
star
28

sameForm

Your form with the same nice look in all browsers.
JavaScript
1
star
29

graphql-api

GraphQL API implementation Golang
Go
1
star
30

bogus

Fake HTTP Server
Go
1
star
31

avaz-sample-backend-frontend-auth

Very simple application that shows how to deal with user authentication with React.
JavaScript
1
star
32

gettitle

Amazon AWS Lambda compatible page get title service.
Java
1
star
33

toggle

A Go feature switch library
Go
1
star
34

todos-sample

Sample Application using gorm and database/sql
Go
1
star
35

healthz

Straightforward health package
Go
1
star
36

guia_mais_js

JavaScript
1
star