func SliceColorized(str string, start, end int) string {
	if str == "" {
		return str
	}
	if start < 0 {
		start = 0
	}

	fgChanged, bgChanged := false, false
	curr := 0
	parser := NewColorParser(str, term.ColorBlack, term.ColorBlack)
	var out string
	for {
		if end != -1 && curr >= end {
			break
		}
		elem := parser.NextElement()
		if elem.Type == ElemEndOfText {
			break
		}

		switch elem.Type {
		case ElemTextColor:
			fgChanged = true
			if out != "" {
				out += "<t:" + ColorToString(elem.Fg) + ">"
			}
		case ElemBackColor:
			bgChanged = true
			if out != "" {
				out += "<b:" + ColorToString(elem.Bg) + ">"
			}
		case ElemPrintable:
			if curr == start {
				if fgChanged {
					out += "<t:" + ColorToString(elem.Fg) + ">"
				}
				if bgChanged {
					out += "<b:" + ColorToString(elem.Bg) + ">"
				}
			}
			if curr >= start {
				out += string(elem.Ch)
			}
			curr++
		}
	}

	return out
}
func SliceColorized(str string, start, end int) string {
	if str == "" {
		return str
	}
	if start < 0 {
		start = 0
	}

	fgChanged, bgChanged := false, false
	curr := 0
	parser := NewColorParser(str, term.ColorBlack, term.ColorBlack)
	var out string
	for {
		if end != -1 && curr >= end {
			break
		}
		elem := parser.NextElement()
		if elem.Type == ElemEndOfText {
			break
		}

		switch elem.Type {
		case ElemTextColor:
			fgChanged = true
			if out != "" {
				out += "<t:" + ColorToString(elem.Fg) + ">"
			}
		case ElemBackColor:
			bgChanged = true
			if out != "" {
				out += "<b:" + ColorToString(elem.Bg) + ">"
			}
		case ElemPrintable:
			if curr == start {
				if fgChanged {
					out += "<t:" + ColorToString(elem.Fg) + ">"
				}
				if bgChanged {
					out += "<b:" + ColorToString(elem.Bg) + ">"
				}
			}
			if curr >= start {
				out += string(elem.Ch)
			}
			curr++
		}
	}

	return out
}
// SliceColorized returns a slice of text with correct color
// tags. start and end are real printable rune indices