From a6d9470b73815463ec72e8a069d2f633042b1ac3 Mon Sep 17 00:00:00 2001 From: probandula Date: Thu, 3 Nov 2016 10:25:51 +0100 Subject: [PATCH] filewriting enabled, gofmt --- README.md | 2 +- cmd/figlet4go/figlet4go.go | 19 +++++++++++++++++++ cmd/figlet4go/test | 1 + color.go | 20 ++++++++++---------- parser.go | 14 +++++++------- 5 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 cmd/figlet4go/test diff --git a/README.md b/README.md index f7ce3de..8cbdf21 100644 --- a/README.md +++ b/README.md @@ -139,5 +139,5 @@ Other fonts can mainly be found on [figlet](http://www.figlet.org). You have to - [x] More parsers (HTML) - [x] Better parsers (maybe stored in a map) - [ ] Pointer-Value standarization -- [ ] Writer choosing for writing to file +- [x] Writer choosing for writing to file - [ ] Tests diff --git a/cmd/figlet4go/figlet4go.go b/cmd/figlet4go/figlet4go.go index 69914e0..5629de6 100644 --- a/cmd/figlet4go/figlet4go.go +++ b/cmd/figlet4go/figlet4go.go @@ -15,6 +15,7 @@ var ( fontpath *string = flag.String("fontpath", "", "Font path to load fonts from") colors *string = flag.String("colors", "", "Character colors separated by ';'\n\tPossible colors: black, red, green, yellow, blue, magenta, cyan, white, or any hexcode (f.e. '885DBA')") parser *string = flag.String("parser", "terminal", "Parser to use\tPossible parsers: terminal (default), html") + file *string = flag.String("file", "", "File to write to") ) func main() { @@ -54,6 +55,24 @@ func main() { log.Fatal(err) } + // Write to file if given + if *file != "" { + // Create file + f, err := os.Create(*file) + defer f.Close() + if err != nil { + log.Fatal(err) + } + // Write to file + b, err := f.WriteString(renderStr) + if err != nil { + log.Fatal(err) + } + fmt.Printf("Wrote %d bytes to %s\n", b, *file) + return + } + + // Default is printing fmt.Print(renderStr) } diff --git a/cmd/figlet4go/test b/cmd/figlet4go/test new file mode 100644 index 0000000..87ffeee --- /dev/null +++ b/cmd/figlet4go/test @@ -0,0 +1 @@ +  _   _          _   _         
 | | | |   ___  | | | |   ___  
 | |_| |  / _ \ | | | |  / _ \ 
 |  _  | |  __/ | | | | | (_) |
 |_| |_|  \___| |_| |_|  \___/ 
                               
\ No newline at end of file diff --git a/color.go b/color.go index e209c5d..524918e 100644 --- a/color.go +++ b/color.go @@ -25,17 +25,17 @@ var ( // Colors based on http://clrs.cc/ // "TrueColorForAnsiColor" var tcfac map[AnsiColor]TrueColor = map[AnsiColor]TrueColor{ - ColorBlack: TrueColor{0, 0, 0}, - ColorRed: TrueColor{255, 65, 54}, - ColorGreen: TrueColor{149, 189, 64}, - ColorYellow: TrueColor{255, 220, 0}, - ColorBlue: TrueColor{0, 116, 217}, - ColorMagenta: TrueColor{177, 13, 201}, - ColorCyan: TrueColor{105, 206, 245}, - ColorWhite: TrueColor{255, 255, 255}, + ColorBlack: {0, 0, 0}, + ColorRed: {255, 65, 54}, + ColorGreen: {149, 189, 64}, + ColorYellow: {255, 220, 0}, + ColorBlue: {0, 116, 217}, + ColorMagenta: {177, 13, 201}, + ColorCyan: {105, 206, 245}, + ColorWhite: {255, 255, 255}, } -// Every color has a pre- and a suffix +// Color has a pre- and a suffix type Color interface { getPrefix(p Parser) string getSuffix(p Parser) string @@ -109,7 +109,7 @@ func (ac AnsiColor) getPrefix(p Parser) string { } return "" - + } // Suffix for ansi color diff --git a/parser.go b/parser.go index 8a7d75d..90f4f06 100644 --- a/parser.go +++ b/parser.go @@ -5,23 +5,23 @@ import "errors" // Parser stores some output specific stuff type Parser struct { // Name used for switching in colors.go - Name string + Name string // Parser prefix - Prefix string + Prefix string // Parser suffix - Suffix string + Suffix string // Newline representation - NewLine string + NewLine string // Things to be replaced (f.e. \n to
) Replaces map[string]string } -var parsers map[string]Parser = map[string]Parser { +var parsers map[string]Parser = map[string]Parser{ // Default terminal parser - "terminal": Parser{"terminal", "", "", "\n", nil}, + "terminal": {"terminal", "", "", "\n", nil}, // Parser for HTML code - "html": Parser{"html", "", "", "
", map[string]string{" ": " "}}, + "html": {"html", "", "", "
", map[string]string{" ": " "}}, } // GetParser returns a parser by its key