MCPcopy Create free account
hub / github.com/gokcehan/lf / parseColor

Function parseColor

colors.go:91–125  ·  view source on GitHub ↗
(toks []string)

Source from the content-addressed store, hash-verified

89}
90
91func parseColor(toks []string) (tcell.Color, int, error) {
92 if len(toks) == 0 {
93 return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
94 }
95
96 if toks[0] == "5" && len(toks) >= 2 {
97 n, err := strconv.ParseUint(toks[1], 10, 8)
98 if err != nil {
99 return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
100 }
101
102 return tcell.PaletteColor(int(n)), 2, nil
103 }
104
105 if toks[0] == "2" && len(toks) >= 4 {
106 r, err := strconv.ParseUint(toks[1], 10, 8)
107 if err != nil {
108 return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
109 }
110
111 g, err := strconv.ParseUint(toks[2], 10, 8)
112 if err != nil {
113 return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
114 }
115
116 b, err := strconv.ParseUint(toks[3], 10, 8)
117 if err != nil {
118 return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
119 }
120
121 return tcell.NewRGBColor(int32(r), int32(g), int32(b)), 4, nil
122 }
123
124 return tcell.ColorDefault, 0, fmt.Errorf("invalid args: %v", toks)
125}
126
127func (sm styleMap) parseFile(path string) {
128 log.Printf("reading file: %s", path)

Callers 2

applySGRFunction · 0.85
TestParseColorFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseColorFunction · 0.68