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

adding containsStyle func

This commit is contained in:
Andrew Arrow 2022-11-09 05:46:13 -08:00
parent 29db86d4f2
commit 238057237b
2 changed files with 9 additions and 2 deletions

View File

@ -167,6 +167,12 @@ func findStylePositions(s string) []int {
} }
func containsStyle(s string) bool { func containsStyle(s string) bool {
if strings.HasPrefix(s, string(tokenBeginStyledText)) &&
strings.HasSuffix(s, string(tokenEndStyle)) &&
strings.Contains(s, string(tokenEndStyledText)) &&
strings.Contains(s, string(tokenBeginStyle)) {
return true
}
return false return false
} }

View File

@ -1,14 +1,15 @@
package termui package termui
import ( import (
"fmt"
"strings" "strings"
"testing" "testing"
) )
func TestBreakBlocksIntoStrings(t *testing.T) { func TestBreakBlocksIntoStrings(t *testing.T) {
items := breakBlocksIntoStrings("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!") items := breakBlocksIntoStrings("test [blue](fg:blue,mod:bold) and [red](fg:red) and maybe even [foo](bg:red)!")
fmt.Println(strings.Join(items, "")) if len(items) != 7 {
t.Fatal("wrong length", len(items))
}
} }
func TestFindStylePositions(t *testing.T) { func TestFindStylePositions(t *testing.T) {