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

TestFindStyleBlocks is working

This commit is contained in:
Andrew Arrow 2022-11-08 13:32:59 -08:00
parent ea81b84555
commit 33fef6cb94

View File

@ -84,8 +84,36 @@ type StyleBlock struct {
End int
}
func findStartEndOfStyle(pos int, runes []rune) StyleBlock {
current := pos
sb := StyleBlock{0, 0}
for {
current--
if runes[current] == tokenBeginStyledText {
sb.Start = current
break
}
}
current = pos
for {
current++
if runes[current] == tokenEndStyle {
sb.End = current
break
}
}
return sb
}
func FindStyleBlocks(s string) []StyleBlock {
items := []StyleBlock{}
runes := []rune(s)
positions := FindStylePositions(s)
for _, pos := range positions {
sb := findStartEndOfStyle(pos, runes)
items = append(items, sb)
}
return items
}