feat(config/StyleWrapper): Add underline support (#763)
This commit is contained in:
parent
424243a96f
commit
745706b5d5
2 changed files with 43 additions and 42 deletions
|
|
@ -169,7 +169,7 @@ down = "ctrl+n"
|
|||
top = "home"
|
||||
bottom = "end"
|
||||
|
||||
# style = { foreground = "", background = "", attributes = "" or [""] }
|
||||
# style = { foreground = "", background = "", attributes = "" or ["",""], underline = "", underline_color = "" }
|
||||
[theme.title]
|
||||
alignment = "left" # `"left"`, `"center"`, or `"right"`.
|
||||
normal_style = { attributes = "dim" }
|
||||
|
|
@ -208,7 +208,7 @@ thumb_style = {}
|
|||
reply_indicator = ">"
|
||||
forwarded_indicator = "<"
|
||||
|
||||
mention_style = { foreground = "blue" }
|
||||
mention_style = { foreground = "blue", attributes = "bold" }
|
||||
emoji_style = { foreground = "green" }
|
||||
url_style = { foreground = "blue" }
|
||||
attachment_style = { foreground = "yellow" }
|
||||
|
|
|
|||
|
|
@ -44,45 +44,65 @@ func (sw *StyleWrapper) UnmarshalTOML(v any) error {
|
|||
for key, val := range m {
|
||||
switch key {
|
||||
case "foreground":
|
||||
s, ok := val.(string)
|
||||
if !ok {
|
||||
continue
|
||||
if s, ok := val.(string); ok {
|
||||
sw.Style = sw.Foreground(tcell.GetColor(s))
|
||||
}
|
||||
|
||||
color := tcell.GetColor(s)
|
||||
sw.Style = sw.Foreground(color)
|
||||
case "background":
|
||||
s, ok := val.(string)
|
||||
if !ok {
|
||||
continue
|
||||
if s, ok := val.(string); ok {
|
||||
sw.Style = sw.Background(tcell.GetColor(s))
|
||||
}
|
||||
|
||||
color := tcell.GetColor(s)
|
||||
sw.Style = sw.Background(color)
|
||||
case "attributes":
|
||||
var attrs tcell.AttrMask
|
||||
switch val := val.(type) {
|
||||
case string:
|
||||
attrs |= stringToAttrMask(val)
|
||||
sw.parseAttr(val)
|
||||
case []any:
|
||||
for _, attr := range val {
|
||||
s, ok := attr.(string)
|
||||
if !ok {
|
||||
continue
|
||||
if s, ok := attr.(string); ok {
|
||||
sw.parseAttr(s)
|
||||
}
|
||||
|
||||
attrs |= stringToAttrMask(s)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sw.Style = sw.Attributes(attrs)
|
||||
case "underline":
|
||||
if s, ok := val.(string); ok {
|
||||
switch s {
|
||||
case "": sw.Style = sw.Underline(tcell.UnderlineStyleNone)
|
||||
case "solid": sw.Style = sw.Underline(tcell.UnderlineStyleSolid)
|
||||
case "double": sw.Style = sw.Underline(tcell.UnderlineStyleDouble)
|
||||
case "curly": sw.Style = sw.Underline(tcell.UnderlineStyleCurly)
|
||||
case "dotted": sw.Style = sw.Underline(tcell.UnderlineStyleDotted)
|
||||
case "dashed": sw.Style = sw.Underline(tcell.UnderlineStyleDashed)
|
||||
}
|
||||
}
|
||||
case "underline_color":
|
||||
if s, ok := val.(string); ok {
|
||||
sw.Style = sw.Underline(tcell.GetColor(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sw *StyleWrapper) parseAttr(s string) {
|
||||
switch s {
|
||||
case "underline":
|
||||
sw.Style = sw.Underline(true)
|
||||
case "bold":
|
||||
sw.Style = sw.Bold(true)
|
||||
case "blink":
|
||||
sw.Style = sw.Blink(true)
|
||||
case "reverse":
|
||||
sw.Style = sw.Reverse(true)
|
||||
case "dim":
|
||||
sw.Style = sw.Dim(true)
|
||||
case "italic":
|
||||
sw.Style = sw.Italic(true)
|
||||
case "strikethrough":
|
||||
sw.Style = sw.StrikeThrough(true)
|
||||
}
|
||||
}
|
||||
|
||||
type BorderSetWrapper struct{ tview.BorderSet }
|
||||
|
||||
func (bw *BorderSetWrapper) UnmarshalTOML(val any) error {
|
||||
|
|
@ -227,22 +247,3 @@ type (
|
|||
Help HelpTheme `toml:"help"`
|
||||
}
|
||||
)
|
||||
|
||||
func stringToAttrMask(s string) tcell.AttrMask {
|
||||
switch s {
|
||||
case "bold":
|
||||
return tcell.AttrBold
|
||||
case "blink":
|
||||
return tcell.AttrBlink
|
||||
case "reverse":
|
||||
return tcell.AttrReverse
|
||||
case "dim":
|
||||
return tcell.AttrDim
|
||||
case "italic":
|
||||
return tcell.AttrItalic
|
||||
case "strikethrough":
|
||||
return tcell.AttrStrikeThrough
|
||||
default:
|
||||
return tcell.AttrNone
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue