mirror of
https://github.com/KevinMidboe/motdGO.git
synced 2025-10-29 09:40:23 +00:00
filewriting enabled, gofmt
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
1
cmd/figlet4go/test
Normal file
1
cmd/figlet4go/test
Normal file
@@ -0,0 +1 @@
|
||||
<code><span style='color: rgb(255,153,0);'> _ _ </span><span style='color: rgb(187,86,84);'> </span><span style='color: rgb(149,189,64);'> _ </span><span style='color: rgb(255,153,0);'> _ </span><span style='color: rgb(187,86,84);'> </span><br><span style='color: rgb(255,153,0);'> | | | |</span><span style='color: rgb(187,86,84);'> ___ </span><span style='color: rgb(149,189,64);'> | |</span><span style='color: rgb(255,153,0);'> | |</span><span style='color: rgb(187,86,84);'> ___ </span><br><span style='color: rgb(255,153,0);'> | |_| |</span><span style='color: rgb(187,86,84);'> / _ \</span><span style='color: rgb(149,189,64);'> | |</span><span style='color: rgb(255,153,0);'> | |</span><span style='color: rgb(187,86,84);'> / _ \ </span><br><span style='color: rgb(255,153,0);'> | _ |</span><span style='color: rgb(187,86,84);'> | __/</span><span style='color: rgb(149,189,64);'> | |</span><span style='color: rgb(255,153,0);'> | |</span><span style='color: rgb(187,86,84);'> | (_) |</span><br><span style='color: rgb(255,153,0);'> |_| |_|</span><span style='color: rgb(187,86,84);'> \___|</span><span style='color: rgb(149,189,64);'> |_|</span><span style='color: rgb(255,153,0);'> |_|</span><span style='color: rgb(187,86,84);'> \___/ </span><br><span style='color: rgb(255,153,0);'> </span><span style='color: rgb(187,86,84);'> </span><span style='color: rgb(149,189,64);'> </span><span style='color: rgb(255,153,0);'> </span><span style='color: rgb(187,86,84);'> </span><br></code>
|
||||
18
color.go
18
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
|
||||
|
||||
@@ -19,9 +19,9 @@ type Parser struct {
|
||||
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", "<code>", "</code>", "<br>", map[string]string{" ": " "}},
|
||||
"html": {"html", "<code>", "</code>", "<br>", map[string]string{" ": " "}},
|
||||
}
|
||||
|
||||
// GetParser returns a parser by its key
|
||||
|
||||
Reference in New Issue
Block a user