package ui

import (
	
	
)

const sgrPrefix = "\033["

var sgrStyling = map[int]Styling{
	0: Reset,
	1: Bold,
	2: Dim,
	4: Underlined,
	5: Blink,
	7: Inverse,
}

// StyleFromSGR builds a Style from an SGR sequence.
func ( string) Style {
	var  Style
	StylingFromSGR().transform(&)
	return 
}

// StylingFromSGR builds a Style from an SGR sequence.
func ( string) Styling {
	 := jointStyling{}
	 := getSGRCodes()
	if len() == 0 {
		return Reset
	}
	for len() > 0 {
		 := [0]
		 := 1
		var  Styling

		switch {
		case sgrStyling[] != nil:
			 = sgrStyling[]
		case 30 <=  &&  <= 37:
			 = Fg(ansiColor( - 30))
		case 40 <=  &&  <= 47:
			 = Bg(ansiColor( - 40))
		case 90 <=  &&  <= 97:
			 = Fg(ansiBrightColor( - 90))
		case 100 <=  &&  <= 107:
			 = Bg(ansiBrightColor( - 100))
		case  == 38 && len() >= 3 && [1] == 5:
			 = Fg(xterm256Color([2]))
			 = 3
		case  == 48 && len() >= 3 && [1] == 5:
			 = Bg(xterm256Color([2]))
			 = 3
		case  == 38 && len() >= 5 && [1] == 2:
			 = Fg(trueColor{
				uint8([2]), uint8([3]), uint8([4])})
			 = 5
		case  == 48 && len() >= 5 && [1] == 2:
			 = Bg(trueColor{
				uint8([2]), uint8([3]), uint8([4])})
			 = 5
		default:
			// Do nothing; skip this code
		}
		 = [:]
		if  != nil {
			 = append(, )
		}
	}
	return 
}

func getSGRCodes( string) []int {
	var  []int
	for ,  := range strings.Split(, ";") {
		if  == "" {
			 = append(, 0)
		} else {
			,  := strconv.Atoi()
			if  == nil {
				 = append(, )
			}
		}
	}
	return 
}