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] More parsers (HTML)
|
||||||
- [x] Better parsers (maybe stored in a map)
|
- [x] Better parsers (maybe stored in a map)
|
||||||
- [ ] Pointer-Value standarization
|
- [ ] Pointer-Value standarization
|
||||||
- [ ] Writer choosing for writing to file
|
- [x] Writer choosing for writing to file
|
||||||
- [ ] Tests
|
- [ ] Tests
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ var (
|
|||||||
fontpath *string = flag.String("fontpath", "", "Font path to load fonts from")
|
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')")
|
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")
|
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() {
|
func main() {
|
||||||
@@ -54,6 +55,24 @@ func main() {
|
|||||||
log.Fatal(err)
|
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)
|
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>
|
||||||
20
color.go
20
color.go
@@ -25,17 +25,17 @@ var (
|
|||||||
// Colors based on http://clrs.cc/
|
// Colors based on http://clrs.cc/
|
||||||
// "TrueColorForAnsiColor"
|
// "TrueColorForAnsiColor"
|
||||||
var tcfac map[AnsiColor]TrueColor = map[AnsiColor]TrueColor{
|
var tcfac map[AnsiColor]TrueColor = map[AnsiColor]TrueColor{
|
||||||
ColorBlack: TrueColor{0, 0, 0},
|
ColorBlack: {0, 0, 0},
|
||||||
ColorRed: TrueColor{255, 65, 54},
|
ColorRed: {255, 65, 54},
|
||||||
ColorGreen: TrueColor{149, 189, 64},
|
ColorGreen: {149, 189, 64},
|
||||||
ColorYellow: TrueColor{255, 220, 0},
|
ColorYellow: {255, 220, 0},
|
||||||
ColorBlue: TrueColor{0, 116, 217},
|
ColorBlue: {0, 116, 217},
|
||||||
ColorMagenta: TrueColor{177, 13, 201},
|
ColorMagenta: {177, 13, 201},
|
||||||
ColorCyan: TrueColor{105, 206, 245},
|
ColorCyan: {105, 206, 245},
|
||||||
ColorWhite: TrueColor{255, 255, 255},
|
ColorWhite: {255, 255, 255},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every color has a pre- and a suffix
|
// Color has a pre- and a suffix
|
||||||
type Color interface {
|
type Color interface {
|
||||||
getPrefix(p Parser) string
|
getPrefix(p Parser) string
|
||||||
getSuffix(p Parser) string
|
getSuffix(p Parser) string
|
||||||
@@ -109,7 +109,7 @@ func (ac AnsiColor) getPrefix(p Parser) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suffix for ansi color
|
// Suffix for ansi color
|
||||||
|
|||||||
14
parser.go
14
parser.go
@@ -5,23 +5,23 @@ import "errors"
|
|||||||
// Parser stores some output specific stuff
|
// Parser stores some output specific stuff
|
||||||
type Parser struct {
|
type Parser struct {
|
||||||
// Name used for switching in colors.go
|
// Name used for switching in colors.go
|
||||||
Name string
|
Name string
|
||||||
// Parser prefix
|
// Parser prefix
|
||||||
Prefix string
|
Prefix string
|
||||||
// Parser suffix
|
// Parser suffix
|
||||||
Suffix string
|
Suffix string
|
||||||
// Newline representation
|
// Newline representation
|
||||||
NewLine string
|
NewLine string
|
||||||
// Things to be replaced (f.e. \n to <br>)
|
// Things to be replaced (f.e. \n to <br>)
|
||||||
Replaces map[string]string
|
Replaces map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsers map[string]Parser = map[string]Parser {
|
var parsers map[string]Parser = map[string]Parser{
|
||||||
|
|
||||||
// Default terminal parser
|
// Default terminal parser
|
||||||
"terminal": Parser{"terminal", "", "", "\n", nil},
|
"terminal": {"terminal", "", "", "\n", nil},
|
||||||
// Parser for HTML code
|
// 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
|
// GetParser returns a parser by its key
|
||||||
|
|||||||
Reference in New Issue
Block a user