mirror of
https://github.com/gizak/termui.git
synced 2025-04-24 13:48:50 +08:00
all tests passing
This commit is contained in:
parent
238057237b
commit
ecf49517b1
@ -5,6 +5,7 @@
|
||||
package termui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -176,12 +177,16 @@ func containsStyle(s string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// [text](style) will return text
|
||||
func extractTextFromBlock(item string) string {
|
||||
return "hi"
|
||||
index := strings.Index(item, string(tokenEndStyledText))
|
||||
return item[1:index]
|
||||
}
|
||||
|
||||
// [text](style) will return style
|
||||
func extractStyleFromBlock(item string) string {
|
||||
return "fg:red"
|
||||
index := strings.Index(item, string(tokenBeginStyle))
|
||||
return item[index+1 : len(item)-1]
|
||||
}
|
||||
|
||||
// ParseStyles parses a string for embedded Styles and returns []Cell with the correct styling.
|
||||
@ -200,10 +205,11 @@ func ParseStyles(s string, defaultStyle Style) []Cell {
|
||||
if containsStyle(item) {
|
||||
text := extractTextFromBlock(item)
|
||||
styleText := extractStyleFromBlock(item)
|
||||
fmt.Println("|" + text + "|" + styleText + "|")
|
||||
style := readStyle([]rune(styleText), defaultStyle)
|
||||
cells = append(RunesToStyledCells([]rune(text), style), cells...)
|
||||
cells = append(cells, RunesToStyledCells([]rune(text), style)...)
|
||||
} else {
|
||||
cells = append(RunesToStyledCells([]rune(item), defaultStyle), cells...)
|
||||
cells = append(cells, RunesToStyledCells([]rune(item), defaultStyle)...)
|
||||
}
|
||||
}
|
||||
return cells
|
||||
|
@ -1,6 +1,7 @@
|
||||
package termui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@ -50,9 +51,12 @@ func TestParseStyles(t *testing.T) {
|
||||
if len(cells) != 17 {
|
||||
t.Fatal("wrong length", len(cells))
|
||||
}
|
||||
text := textFromCells(cells)
|
||||
fmt.Println(text)
|
||||
fmt.Println(cells)
|
||||
for i := 0; i < 5; i++ {
|
||||
if cells[i].Style.Fg != ColorWhite {
|
||||
t.Fatal("wrong fg color", cells[i])
|
||||
t.Fatal("wrong fg color", cells[i], i)
|
||||
}
|
||||
if cells[i].Style.Bg != ColorClear {
|
||||
t.Fatal("wrong bg color", cells[i])
|
||||
@ -73,7 +77,7 @@ func TestParseStyles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
text := textFromCells(cells)
|
||||
text = textFromCells(cells)
|
||||
if text != "test blue and red" {
|
||||
t.Fatal("wrong text", text)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user