Rename style parsing functions
This commit is contained in:
parent
f8e30bacd3
commit
fd5a830d7a
@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## 2019/02/23
|
||||
|
||||
### Changed
|
||||
|
||||
- s/TextParse/ParseStyles
|
||||
- Removed AddColorMap in place of modifying StyleParserColorMap directly
|
||||
|
||||
## 2019/01/31
|
||||
|
||||
### Added
|
||||
|
@ -31,7 +31,8 @@ const (
|
||||
parserStateStyledText
|
||||
)
|
||||
|
||||
var colorMap = map[string]Color{
|
||||
// StyleParserColorMap can be modified to add custom color parsing to text
|
||||
var StyleParserColorMap = map[string]Color{
|
||||
"red": ColorRed,
|
||||
"blue": ColorBlue,
|
||||
"black": ColorBlack,
|
||||
@ -49,11 +50,6 @@ var modifierMap = map[string]Modifier{
|
||||
"reverse": ModifierReverse,
|
||||
}
|
||||
|
||||
// AddColorMap allows users to add/override the string to Color mapping
|
||||
func AddColorMap(str string, color Color) {
|
||||
colorMap[str] = color
|
||||
}
|
||||
|
||||
// readStyle translates an []rune like `fg:red,mod:bold,bg:white` to a style
|
||||
func readStyle(runes []rune, defaultStyle Style) Style {
|
||||
style := defaultStyle
|
||||
@ -63,9 +59,9 @@ func readStyle(runes []rune, defaultStyle Style) Style {
|
||||
if len(pair) == 2 {
|
||||
switch pair[0] {
|
||||
case tokenFg:
|
||||
style.Fg = colorMap[pair[1]]
|
||||
style.Fg = StyleParserColorMap[pair[1]]
|
||||
case tokenBg:
|
||||
style.Bg = colorMap[pair[1]]
|
||||
style.Bg = StyleParserColorMap[pair[1]]
|
||||
case tokenModifier:
|
||||
style.Modifier = modifierMap[pair[1]]
|
||||
}
|
||||
@ -74,11 +70,11 @@ func readStyle(runes []rune, defaultStyle Style) Style {
|
||||
return style
|
||||
}
|
||||
|
||||
// ParseText parses a string for embedded Styles and returns []Cell with the correct styling.
|
||||
// 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:<color>,mod:<attribute>,bg:<color>).
|
||||
// Ordering does not matter. All fields are optional.
|
||||
func ParseText(s string, defaultStyle Style) []Cell {
|
||||
func ParseStyles(s string, defaultStyle Style) []Cell {
|
||||
cells := []Cell{}
|
||||
runes := []rune(s)
|
||||
state := parserStateDefault
|
@ -42,7 +42,7 @@ func (self *List) Draw(buf *Buffer) {
|
||||
}
|
||||
|
||||
for row := self.topRow; row < uint(len(self.Rows)) && point.Y < self.Inner.Max.Y; row++ {
|
||||
cells := ParseText(self.Rows[row], self.TextStyle)
|
||||
cells := ParseStyles(self.Rows[row], self.TextStyle)
|
||||
if self.WrapText {
|
||||
cells = WrapCells(cells, uint(self.Inner.Dx()))
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func NewParagraph() *Paragraph {
|
||||
func (self *Paragraph) Draw(buf *Buffer) {
|
||||
self.Block.Draw(buf)
|
||||
|
||||
cells := ParseText(self.Text, self.TextStyle)
|
||||
cells := ParseStyles(self.Text, self.TextStyle)
|
||||
if self.WrapText {
|
||||
cells = WrapCells(cells, uint(self.Inner.Dx()))
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func (self *Table) Draw(buf *Buffer) {
|
||||
|
||||
// draw row cells
|
||||
for j := 0; j < len(row); j++ {
|
||||
col := ParseText(row[j], rowStyle)
|
||||
col := ParseStyles(row[j], rowStyle)
|
||||
// draw row cell
|
||||
if len(col) > columnWidths[j] || self.TextAlign == AlignLeft {
|
||||
for _, cx := range BuildCellWithXArray(col) {
|
||||
|
Loading…
Reference in New Issue
Block a user