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

moving to new FindStylePositions as first call

This commit is contained in:
Andrew Arrow 2022-11-08 08:59:48 -08:00
parent 2c85cd905f
commit 291e9577ef
2 changed files with 18 additions and 9 deletions

View File

@ -86,25 +86,32 @@ type StyleStringPosition struct {
}
func BreakByStyles(s string) []string {
return []string{}
}
func FindStylePositions(s string) []int {
fmt.Println(s)
index := strings.Index(s, "](")
if index == -1 {
return []string{s}
return []int{}
}
buff := []string{}
buff := []int{}
toProcess := s
offset := 0
for {
fmt.Println(index)
buff = append(buff, index+offset)
toProcess = toProcess[index+1:]
fmt.Println(toProcess)
offset += index + 1
index = strings.Index(toProcess, "](")
if index == -1 {
break
}
}
return buff
// test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!
/*

View File

@ -6,13 +6,15 @@ import (
"testing"
)
func TestFindStylePositions(t *testing.T) {
items := FindStylePositions("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!")
if len(items) != 3 {
t.Fatal("wrong length", len(items))
}
}
func TestBreakByStylesComplex(t *testing.T) {
items := BreakByStyles("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)!"
// 01234567890123456789012345678
// 0- 4 normal
// 5-28 style
// 29-
if len(items) != 10 {
t.Fatal("wrong length", len(items))
}