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:
parent
2c85cd905f
commit
291e9577ef
@ -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)!
|
||||
|
||||
/*
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user