diff --git a/style_parser.go b/style_parser.go index ce537da..8f77efd 100644 --- a/style_parser.go +++ b/style_parser.go @@ -70,11 +70,30 @@ func readStyle(runes []rune, defaultStyle Style) Style { return style } +func processToken(token string) { +} + // ParseStyles parses a string for embedded Styles and returns []Cell with the correct styling. // Uses defaultStyle for any text without an embedded style. // Syntax is of the form [text](fg:,mod:,bg:). // Ordering does not matter. All fields are optional. func ParseStyles(s string, defaultStyle Style) []Cell { + //test [blue](fg:blue,bg:white,mod:bold) + cells := []Cell{} + + tokens := strings.Split(s, "](") + if len(tokens) == 1 { + // easy case, not styled string + return cells + } + for i := len(tokens) - 1; i > 0; i-- { + processToken(tokens[i]) + } + + return cells +} + +func ParseStyles2(s string, defaultStyle Style) []Cell { cells := []Cell{} runes := []rune(s) state := parserStateDefault diff --git a/style_parser_test.go b/style_parser_test.go index 9f0ec4b..0c8b5b2 100644 --- a/style_parser_test.go +++ b/style_parser_test.go @@ -6,8 +6,9 @@ import ( ) func TestParseStyles(t *testing.T) { - cells := ParseStyles("test [blue](fg:blue,bg:white,mod:bold)", NewStyle(ColorWhite)) - if len(cells) != 9 { + cells := ParseStyles("test nothing", NewStyle(ColorWhite)) + cells = ParseStyles("test [blue](fg:blue,bg:white,mod:bold) and [red](fg:red)", NewStyle(ColorWhite)) + if len(cells) != 17 { t.Fatal("wrong length", len(cells)) } for i := 0; i < 5; i++ { @@ -21,7 +22,7 @@ func TestParseStyles(t *testing.T) { t.Fatal("wrong mod", cells[i]) } } - for i := 5; i < len(cells); i++ { + for i := 5; i < 9; i++ { if cells[i].Style.Fg != ColorBlue { t.Fatal("wrong fg color", cells[i]) } @@ -34,7 +35,7 @@ func TestParseStyles(t *testing.T) { } text := textFromCells(cells) - if text != "test blue" { + if text != "test blue and red" { t.Fatal("wrong text", text) }