mirror of
https://github.com/KevinMidboe/motdGO.git
synced 2025-10-29 01:30:25 +00:00
fixed goreportcard stuff
This commit is contained in:
2
char.go
2
char.go
@@ -14,7 +14,7 @@ type asciiChar struct {
|
||||
}
|
||||
|
||||
// Creates a new ascii character
|
||||
func NewAsciiChar(font *font, char rune) (*asciiChar, error) {
|
||||
func newAsciiChar(font *font, char rune) (*asciiChar, error) {
|
||||
// If not ascii, throw an error
|
||||
if char < 0 || char > 127 {
|
||||
return nil, errors.New("Not Ascii")
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"github.com/probandula/figlet4go"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -22,10 +22,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
// Validate and log the error
|
||||
err := validate()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
validate()
|
||||
|
||||
// Create objects
|
||||
ascii := figlet4go.NewAsciiRender()
|
||||
@@ -87,9 +84,9 @@ func getColorSlice(colorStr string) []color.Attribute {
|
||||
|
||||
// Validate if all required options are given
|
||||
// flag.Parse() must be called before this
|
||||
func validate() error {
|
||||
func validate() {
|
||||
if *str == "" {
|
||||
return errors.New("No string given")
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
1
font.go
1
font.go
@@ -1,4 +1,5 @@
|
||||
package figlet4go
|
||||
|
||||
// Explanation of the .flf file header
|
||||
// THE HEADER LINE
|
||||
//
|
||||
|
||||
@@ -66,7 +66,7 @@ func (fm *fontManager) getFont(fontName string) *font {
|
||||
func (fm *fontManager) loadFontList(fontPath string) error {
|
||||
// Walk through the path
|
||||
return filepath.Walk(fontPath, func(path string, info os.FileInfo, err error) error {
|
||||
// Return an error if occured
|
||||
// Return an error if occurred
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
12
render.go
12
render.go
@@ -13,7 +13,7 @@ type RenderOptions struct {
|
||||
FontColor []color.Attribute
|
||||
}
|
||||
|
||||
// Create new RenderOptions
|
||||
// NewRenderOptions creates new RenderOptions
|
||||
// Sets the default font name
|
||||
func NewRenderOptions() *RenderOptions {
|
||||
return &RenderOptions{
|
||||
@@ -27,25 +27,25 @@ type AsciiRender struct {
|
||||
fontMgr *fontManager
|
||||
}
|
||||
|
||||
// Create a new AsciiRender
|
||||
// NewAsciiRender creates a new AsciiRender
|
||||
func NewAsciiRender() *AsciiRender {
|
||||
return &AsciiRender{
|
||||
fontMgr: newFontManager(),
|
||||
}
|
||||
}
|
||||
|
||||
// Loading all *.flf font files recursively in a path
|
||||
// LoadFont loads all *.flf font files recursively in a path
|
||||
func (ar *AsciiRender) LoadFont(fontPath string) error {
|
||||
return ar.fontMgr.loadFontList(fontPath)
|
||||
}
|
||||
|
||||
// Render a string with the default options
|
||||
// Render renders a string with the default options
|
||||
// Calls the RenderOpts method with a new RenderOptions object
|
||||
func (ar *AsciiRender) Render(str string) (string, error) {
|
||||
return ar.RenderOpts(str, NewRenderOptions())
|
||||
}
|
||||
|
||||
// Render a string with special RenderOptions
|
||||
// RenderOpts renders a string with special RenderOptions
|
||||
// Can be called from the user (if options wished) or the above Render method
|
||||
// Contains the whole rendering logic
|
||||
func (ar *AsciiRender) RenderOpts(str string, opt *RenderOptions) (string, error) {
|
||||
@@ -64,7 +64,7 @@ func (ar *AsciiRender) RenderOpts(str string, opt *RenderOptions) (string, error
|
||||
// Foreach char create the ascii char
|
||||
for _, char := range str {
|
||||
// AsciiChar
|
||||
asciiChar, err := NewAsciiChar(font, char)
|
||||
asciiChar, err := newAsciiChar(font, char)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user