Added italics and strikethrough to style attributes. Resolves #457

This commit is contained in:
Oliver 2021-10-01 12:26:26 +02:00
parent ee97a7ab39
commit 5508f4b002
4 changed files with 15 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
) )
const colorsText = `You can use color tags almost everywhere to partially change the color of a string. Simply put a color name or hex string in square brackets to change the following characters' color. H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. The [black:red]tags [black:green]look [black:yellow]like [::u]this: [blue:yellow:u[] [#00ff00[]` const colorsText = `You can use color tags almost everywhere to partially change the color of a string. Simply put a color name or hex string in square brackets to change [::s]all[::-]the following characters' color. H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. [::i]The [black:red]tags [black:green]look [black:yellow]like [::u]this: [blue:yellow:u[] [#00ff00[]`
// Colors demonstrates how to use colors. // Colors demonstrates how to use colors.
func Colors(nextSlide func()) (title string, content tview.Primitive) { func Colors(nextSlide func()) (title string, content tview.Primitive) {

2
doc.go
View File

@ -96,9 +96,11 @@ terminal):
l: blink l: blink
b: bold b: bold
i: italic
d: dim d: dim
r: reverse (switch foreground and background color) r: reverse (switch foreground and background color)
u: underline u: underline
s: strike-through
Examples: Examples:

View File

@ -637,7 +637,7 @@ func (t *Table) GetOffset() (row, column int) {
// are evaluated. When true, all rows in the table are evaluated. // are evaluated. When true, all rows in the table are evaluated.
// //
// Set this flag to true to avoid shifting column widths when the table is // Set this flag to true to avoid shifting column widths when the table is
// scrolled. (May be slower for large tables.) // scrolled. (May come with a performance penalty for large tables.)
// //
// Use with caution on very large tables, especially those not backed by the // Use with caution on very large tables, especially those not backed by the
// default TableContent data structure. // default TableContent data structure.

17
util.go
View File

@ -20,7 +20,7 @@ const (
// Common regular expressions. // Common regular expressions.
var ( var (
colorPattern = regexp.MustCompile(`\[([a-zA-Z]+|#[0-9a-zA-Z]{6}|\-)?(:([a-zA-Z]+|#[0-9a-zA-Z]{6}|\-)?(:([lbdru]+|\-)?)?)?\]`) colorPattern = regexp.MustCompile(`\[([a-zA-Z]+|#[0-9a-zA-Z]{6}|\-)?(:([a-zA-Z]+|#[0-9a-zA-Z]{6}|\-)?(:([lbidrus]+|\-)?)?)?\]`)
regionPattern = regexp.MustCompile(`\["([a-zA-Z0-9_,;: \-\.]*)"\]`) regionPattern = regexp.MustCompile(`\["([a-zA-Z0-9_,;: \-\.]*)"\]`)
escapePattern = regexp.MustCompile(`\[([a-zA-Z0-9_,;: \-\."#]+)\[(\[*)\]`) escapePattern = regexp.MustCompile(`\[([a-zA-Z0-9_,;: \-\."#]+)\[(\[*)\]`)
nonEscapePattern = regexp.MustCompile(`(\[[a-zA-Z0-9_,;: \-\."#]+\[*)\]`) nonEscapePattern = regexp.MustCompile(`(\[[a-zA-Z0-9_,;: \-\."#]+\[*)\]`)
@ -124,11 +124,12 @@ func overlayStyle(style tcell.Style, fgColor, bgColor, attributes string) tcell.
} }
if attributes == "-" { if attributes == "-" {
style = style.Bold(defAttr&tcell.AttrBold > 0) style = style.Bold(defAttr&tcell.AttrBold > 0).
style = style.Blink(defAttr&tcell.AttrBlink > 0) Italic(defAttr&tcell.AttrItalic > 0).
style = style.Reverse(defAttr&tcell.AttrReverse > 0) Blink(defAttr&tcell.AttrBlink > 0).
style = style.Underline(defAttr&tcell.AttrUnderline > 0) Reverse(defAttr&tcell.AttrReverse > 0).
style = style.Dim(defAttr&tcell.AttrDim > 0) Underline(defAttr&tcell.AttrUnderline > 0).
Dim(defAttr&tcell.AttrDim > 0)
} else if attributes != "" { } else if attributes != "" {
style = style.Normal() style = style.Normal()
for _, flag := range attributes { for _, flag := range attributes {
@ -137,12 +138,16 @@ func overlayStyle(style tcell.Style, fgColor, bgColor, attributes string) tcell.
style = style.Blink(true) style = style.Blink(true)
case 'b': case 'b':
style = style.Bold(true) style = style.Bold(true)
case 'i':
style = style.Italic(true)
case 'd': case 'd':
style = style.Dim(true) style = style.Dim(true)
case 'r': case 'r':
style = style.Reverse(true) style = style.Reverse(true)
case 'u': case 'u':
style = style.Underline(true) style = style.Underline(true)
case 's':
style = style.StrikeThrough(true)
} }
} }
} }