forked from mbndr/figlet4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.go
34 lines (29 loc) · 780 Bytes
/
parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package figletgo
import "errors"
// Parser stores some output specific stuff
type Parser struct {
// Name used for switching in colors.go
Name string
// Parser prefix
Prefix string
// Parser suffix
Suffix string
// Newline representation
NewLine string
// Things to be replaced (f.e. \n to <br>)
Replaces map[string]string
}
var parsers map[string]Parser = map[string]Parser{
// Default terminal parser
"terminal": {"terminal", "", "", "\n", nil},
// Parser for HTML code
"html": {"html", "<code>", "</code>", "<br>", map[string]string{" ": " "}},
}
// GetParser returns a parser by its key
func GetParser(key string) (*Parser, error) {
parser, ok := parsers[key]
if !ok {
return nil, errors.New("Invalid parser key: " + key)
}
return &parser, nil
}