func StringToColor(str string) tcell.Color {
	switch str {
	case "black":
		return tcell.ColorBlack
	case "red":
		return tcell.ColorMaroon
	case "green":
		return tcell.ColorGreen
	case "yellow":
		return tcell.ColorOlive
	case "blue":
		return tcell.ColorNavy
	case "magenta":
		return tcell.ColorPurple
	case "cyan":
		return tcell.ColorTeal
	case "white":
		return tcell.ColorSilver
	case "brightblack", "lightblack":
		return tcell.ColorGray
	case "brightred", "lightred":
		return tcell.ColorRed
	case "brightgreen", "lightgreen":
		return tcell.ColorLime
	case "brightyellow", "lightyellow":
		return tcell.ColorYellow
	case "brightblue", "lightblue":
		return tcell.ColorBlue
	case "brightmagenta", "lightmagenta":
		return tcell.ColorFuchsia
	case "brightcyan", "lightcyan":
		return tcell.ColorAqua
	case "brightwhite", "lightwhite":
		return tcell.ColorWhite
	case "default":
		return tcell.ColorDefault
	default:
		if num, err := strconv.Atoi(str); err == nil {
			return GetColor256(num)
		}
		return tcell.GetColor(str)
	}
}
StringToColor returns a tcell color from a string representation of a color
We accept either bright... or light... to mean the brighter version of a color
package editor
import (
	"log"
	"regexp"
	"strconv"
	"strings"
	"github.com/gdamore/tcell/v2"
)
type Colorscheme map[string]tcell.Style
var colorscheme Colorscheme
var defStyle tcell.Style
func GetColor(color string) tcell.Style {
	return colorscheme.GetColor(color)
}
func (colorscheme Colorscheme) GetColor(color string) tcell.Style {
	st := defStyle
	if color == "" {
		return st
	}
	groups := strings.Split(color, ".")
	if len(groups) > 1 {
		curGroup := ""
		for i, g := range groups {
			if i != 0 {
				curGroup += "."
			}
			curGroup += g
			if style, ok := colorscheme[curGroup]; ok {
				st = style
			}
		}
	} else if style, ok := colorscheme[color]; ok {
		st = style
	} else {
		st = StringToStyle(color)
	}
	return st
}
func init() {
	colorscheme = make(Colorscheme)
	defStyle = tcell.StyleDefault.
		Foreground(tcell.ColorDefault).
		Background(tcell.ColorDefault)
}
func SetDefaultColorscheme(scheme Colorscheme) {
	colorscheme = scheme
}
func ParseColorscheme(text string) Colorscheme {
	parser := regexp.MustCompile(`color-link\s+(\S*)\s+"(.*)"`)
	lines := strings.Split(text, "\n")
	c := make(Colorscheme)
	for _, line := range lines {
		if strings.TrimSpace(line) == "" ||
			strings.TrimSpace(line)[0] == '#' {
			continue
		}
		matches := parser.FindSubmatch([]byte(line))
		if len(matches) == 3 {
			link := string(matches[1])
			colors := string(matches[2])
			style := StringToStyle(colors)
			c[link] = style
			if link == "default" {
				defStyle = style
			}
		} else {
			log.Println("Color-link statement is not valid:", line)
		}
	}
	return c
}
func StringToStyle(str string) tcell.Style {
	var fg, bg string
	spaceSplit := strings.Split(str, " ")
	var split []string
	if len(spaceSplit) > 1 {
		split = strings.Split(spaceSplit[1], ",")
	} else {
		split = strings.Split(str, ",")
	}
	if len(split) > 1 {
		fg, bg = split[0], split[1]
	} else {
		fg = split[0]
	}
	fg = strings.TrimSpace(fg)
	bg = strings.TrimSpace(bg)
	var fgColor, bgColor tcell.Color
	if fg == "" {
		fgColor, _, _ = defStyle.Decompose()
	} else {
		fgColor = StringToColor(fg)
	}
	if bg == "" {
		_, bgColor, _ = defStyle.Decompose()
	} else {
		bgColor = StringToColor(bg)
	}
	style := defStyle.Foreground(fgColor).Background(bgColor)
	if strings.Contains(str, "bold") {
		style = style.Bold(true)
	}
	if strings.Contains(str, "reverse") {
		style = style.Reverse(true)
	}
	if strings.Contains(str, "underline") {
		style = style.Underline(true)
	}
	return style
}