1
0
mirror of https://github.com/gizak/termui.git synced 2025-04-26 13:48:54 +08:00

StyleStringPosition struct helping

This commit is contained in:
Andrew Arrow 2022-11-08 06:19:35 -08:00
parent 3be455ecc5
commit 4901307000

View File

@ -79,6 +79,12 @@ func lookRightForEndStyle(s string) int {
return strings.Index(s, ")") return strings.Index(s, ")")
} }
type StyleStringPosition struct {
Start int
End int
IsStyle bool
}
func BreakByStyles(s string) []string { func BreakByStyles(s string) []string {
fmt.Println(s) fmt.Println(s)
tokens := strings.Split(s, "](") tokens := strings.Split(s, "](")
@ -86,19 +92,31 @@ func BreakByStyles(s string) []string {
return tokens return tokens
} }
ssps := []StyleStringPosition{}
buff := []string{} buff := []string{}
// test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)! // test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!
offset := 0
for i, token := range tokens { for i, token := range tokens {
if i%2 == 0 { if i%2 == 0 {
index := lookLeftForBracket(token) index := lookLeftForBracket(token)
ssp := StyleStringPosition{offset, offset + index, false}
ssps = append(ssps, ssp)
ssp = StyleStringPosition{offset + index, offset + len(token), true}
ssps = append(ssps, ssp)
fmt.Println(i, "even", len(token), index) fmt.Println(i, "even", len(token), index)
} else { } else {
index := lookRightForEndStyle(token) index := lookRightForEndStyle(token)
ssp := StyleStringPosition{offset, offset + index, true}
ssps = append(ssps, ssp)
ssp = StyleStringPosition{offset + index, offset + len(token), false}
ssps = append(ssps, ssp)
fmt.Println(i, "odd", len(token), index) fmt.Println(i, "odd", len(token), index)
} }
offset += len(token) + 2
buff = append(buff, token) buff = append(buff, token)
} }
fmt.Println(ssps)
/* /*
styleString := "" styleString := ""