mirror of
https://github.com/KevinMidboe/motdGOi.git
synced 2025-10-29 17:50:24 +00:00
various small changes
This commit is contained in:
23
char.go
23
char.go
@@ -3,11 +3,10 @@ package figlet4go
|
||||
import (
|
||||
"errors"
|
||||
"github.com/fatih/color"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Represents a single ascii character
|
||||
type AsciiChar struct {
|
||||
type asciiChar struct {
|
||||
// Slice with the lines of the Char
|
||||
Lines []string
|
||||
// Color of the char
|
||||
@@ -15,30 +14,20 @@ 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")
|
||||
}
|
||||
|
||||
height := font.height
|
||||
beginRow := (int(char) - 32) * height
|
||||
// Get the font's representation of the char
|
||||
lines := font.getCharSlice(char)
|
||||
|
||||
lines := make([]string, height)
|
||||
|
||||
// Get the char lines of the char
|
||||
for i := 0; i < height; i++ {
|
||||
row := font.fontSlice[beginRow+i]
|
||||
row = strings.Replace(row, "@", "", -1)
|
||||
row = strings.Replace(row, font.hardblank, " ", -1)
|
||||
lines[i] = row
|
||||
}
|
||||
|
||||
return &AsciiChar{Lines: lines}, nil
|
||||
return &asciiChar{Lines: lines}, nil
|
||||
}
|
||||
|
||||
// Return a line of the char as string with color if set
|
||||
func (char *AsciiChar) GetLine(index int) string {
|
||||
func (char *asciiChar) GetLine(index int) string {
|
||||
if char.Color != 0 {
|
||||
colorFunc := color.New(char.Color).SprintFunc()
|
||||
return colorFunc(char.Lines[index])
|
||||
|
||||
Reference in New Issue
Block a user