-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchar.go
More file actions
45 lines (37 loc) · 1.1 KB
/
Copy pathchar.go
File metadata and controls
45 lines (37 loc) · 1.1 KB
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
35
36
37
38
39
40
41
42
43
44
45
package gofiglet
import (
"errors"
"image/color"
)
// asciiChar represents a single rendered ASCII-art character: the set of
// text lines that make up its glyph, plus an optional color applied when
// the line is emitted.
type asciiChar struct {
lines []string
color color.Color
}
// newASCIIChar builds an asciiChar for char using font's glyph data.
// It returns an error if char falls outside the printable ASCII range
// (0-127), since font only defines glyphs for ASCII characters.
func newASCIIChar(font *font, char rune) (*asciiChar, error) {
if char < 0 || char > 127 {
return nil, errors.New("not Ascii character")
}
lines, err := font.getCharSlice(char)
if err != nil {
return nil, err
}
return &asciiChar{lines: lines}, nil
}
// GetLine returns the line at index, wrapped in the character's color
// escape sequences if color is set, or unwrapped otherwise.
func (char *asciiChar) GetLine(index int) string {
prefix := ""
suffix := ""
line := char.lines[index]
if char.color != nil {
prefix = GetPrefix(char.color)
suffix = GetSuffix(char.color)
}
return prefix + line + suffix
}