2021-03-16 23:35:28 +03:00
|
|
|
package lipgloss
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/muesli/reflow/ansi"
|
|
|
|
)
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetBold returns the style's bold value. If no value is set false is returned.
|
2021-04-21 01:07:51 +03:00
|
|
|
func (s Style) GetBold() bool {
|
|
|
|
return s.getAsBool(boldKey, false)
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetItalic returns the style's italic value. If no value is set false is
|
2021-04-21 01:07:51 +03:00
|
|
|
// returned.
|
|
|
|
func (s Style) GetItalic() bool {
|
|
|
|
return s.getAsBool(italicKey, false)
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetUnderline returns the style's underline value. If no value is set false is
|
2021-04-21 01:07:51 +03:00
|
|
|
// returned.
|
|
|
|
func (s Style) GetUnderline() bool {
|
|
|
|
return s.getAsBool(underlineKey, false)
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetStrikethrough returns the style's strikethrough value. If no value is set false
|
2021-04-21 01:07:51 +03:00
|
|
|
// is returned.
|
|
|
|
func (s Style) GetStrikethrough() bool {
|
|
|
|
return s.getAsBool(strikethroughKey, false)
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetReverse returns the style's reverse value. If no value is set false is
|
2021-04-21 01:07:51 +03:00
|
|
|
// returned.
|
|
|
|
func (s Style) GetReverse() bool {
|
|
|
|
return s.getAsBool(reverseKey, false)
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetBlink returns the style's blink value. If no value is set false is
|
2021-04-21 01:07:51 +03:00
|
|
|
// returned.
|
|
|
|
func (s Style) GetBlink() bool {
|
|
|
|
return s.getAsBool(blinkKey, false)
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:37:38 +03:00
|
|
|
// GetFaint returns the style's faint value. If no value is set false is
|
2021-04-21 01:07:51 +03:00
|
|
|
// returned.
|
|
|
|
func (s Style) GetFaint() bool {
|
|
|
|
return s.getAsBool(faintKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetForeground returns the style's foreground color. If no value is set
|
|
|
|
// NoColor{} is returned.
|
|
|
|
func (s Style) GetForeground() TerminalColor {
|
|
|
|
return s.getAsColor(foregroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBackground returns the style's back color. If no value is set
|
|
|
|
// NoColor{} is returned.
|
|
|
|
func (s Style) GetBackground() TerminalColor {
|
|
|
|
return s.getAsColor(backgroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWidth returns the style's width setting. If no width is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetWidth() int {
|
|
|
|
return s.getAsInt(widthKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetHeight returns the style's height setting. If no height is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetHeight() int {
|
|
|
|
return s.getAsInt(heightKey)
|
|
|
|
}
|
|
|
|
|
2022-08-30 23:59:06 +03:00
|
|
|
// GetAlign returns the style's implicit horizontal alignment setting.
|
2022-10-15 22:37:38 +03:00
|
|
|
// If no alignment is set Position.Left is returned.
|
2021-04-21 01:07:51 +03:00
|
|
|
func (s Style) GetAlign() Position {
|
2022-08-30 23:59:06 +03:00
|
|
|
v := s.getAsPosition(alignHorizontalKey)
|
2021-04-21 01:07:51 +03:00
|
|
|
if v == Position(0) {
|
|
|
|
return Left
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2022-08-30 23:59:06 +03:00
|
|
|
// GetAlignHorizontal returns the style's implicit horizontal alignment setting.
|
2022-10-15 22:37:38 +03:00
|
|
|
// If no alignment is set Position.Left is returned.
|
2022-08-30 23:59:06 +03:00
|
|
|
func (s Style) GetAlignHorizontal() Position {
|
|
|
|
v := s.getAsPosition(alignHorizontalKey)
|
|
|
|
if v == Position(0) {
|
|
|
|
return Left
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetAlignVertical returns the style's implicit vertical alignment setting.
|
2022-10-15 22:37:38 +03:00
|
|
|
// If no alignment is set Position.Top is returned.
|
2022-08-30 23:59:06 +03:00
|
|
|
func (s Style) GetAlignVertical() Position {
|
|
|
|
v := s.getAsPosition(alignVerticalKey)
|
|
|
|
if v == Position(0) {
|
|
|
|
return Top
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2021-04-21 01:07:51 +03:00
|
|
|
// GetPadding returns the style's top, right, bottom, and left padding values,
|
|
|
|
// in that order. 0 is returned for unset values.
|
|
|
|
func (s Style) GetPadding() (top, right, bottom, left int) {
|
|
|
|
return s.getAsInt(paddingTopKey),
|
|
|
|
s.getAsInt(paddingRightKey),
|
|
|
|
s.getAsInt(paddingBottomKey),
|
|
|
|
s.getAsInt(paddingLeftKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPaddingTop returns the style's top padding. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetPaddingTop() int {
|
|
|
|
return s.getAsInt(paddingTopKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPaddingRight returns the style's right padding. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetPaddingRight() int {
|
|
|
|
return s.getAsInt(paddingRightKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPaddingBottom returns the style's bottom padding. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetPaddingBottom() int {
|
|
|
|
return s.getAsInt(paddingBottomKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPaddingLeft returns the style's left padding. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetPaddingLeft() int {
|
|
|
|
return s.getAsInt(paddingLeftKey)
|
|
|
|
}
|
|
|
|
|
2021-08-19 05:01:01 +03:00
|
|
|
// GetHorizontalPadding returns the style's left and right padding. Unset
|
|
|
|
// values are measured as 0.
|
|
|
|
func (s Style) GetHorizontalPadding() int {
|
|
|
|
return s.getAsInt(paddingLeftKey) + s.getAsInt(paddingRightKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetVerticalPadding returns the style's top and bottom padding. Unset values
|
|
|
|
// are measured as 0.
|
|
|
|
func (s Style) GetVerticalPadding() int {
|
2021-08-19 19:59:21 +03:00
|
|
|
return s.getAsInt(paddingTopKey) + s.getAsInt(paddingBottomKey)
|
2021-08-19 05:01:01 +03:00
|
|
|
}
|
|
|
|
|
2021-04-21 01:07:51 +03:00
|
|
|
// GetColorWhitespace returns the style's whitespace coloring setting. If no
|
|
|
|
// value is set false is returned.
|
|
|
|
func (s Style) GetColorWhitespace() bool {
|
|
|
|
return s.getAsBool(colorWhitespaceKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMargin returns the style's top, right, bottom, and left margins, in that
|
|
|
|
// order. 0 is returned for unset values.
|
|
|
|
func (s Style) GetMargin() (top, right, bottom, left int) {
|
|
|
|
return s.getAsInt(marginTopKey),
|
|
|
|
s.getAsInt(marginRightKey),
|
|
|
|
s.getAsInt(marginBottomKey),
|
|
|
|
s.getAsInt(marginLeftKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMarginTop returns the style's top margin. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetMarginTop() int {
|
|
|
|
return s.getAsInt(marginTopKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMarginRight returns the style's right margin. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetMarginRight() int {
|
|
|
|
return s.getAsInt(marginRightKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMarginBottom returns the style's bottom margin. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetMarginBottom() int {
|
|
|
|
return s.getAsInt(marginBottomKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMarginLeft returns the style's left margin. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetMarginLeft() int {
|
|
|
|
return s.getAsInt(marginLeftKey)
|
|
|
|
}
|
|
|
|
|
2021-08-19 05:01:01 +03:00
|
|
|
// GetHorizontalMargins returns the style's left and right margins. Unset
|
|
|
|
// values are measured as 0.
|
|
|
|
func (s Style) GetHorizontalMargins() int {
|
|
|
|
return s.getAsInt(marginLeftKey) + s.getAsInt(marginRightKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetVerticalMargins returns the style's top and bottom padding. Unset values
|
|
|
|
// are measured as 0.
|
|
|
|
func (s Style) GetVerticalMargins() int {
|
|
|
|
return s.getAsInt(marginTopKey) + s.getAsInt(marginBottomKey)
|
|
|
|
}
|
|
|
|
|
2021-04-21 01:07:51 +03:00
|
|
|
// GetBorder returns the style's border style (type Border) and value for the
|
|
|
|
// top, right, bottom, and left in that order. If no value is set for the
|
|
|
|
// border style, Border{} is returned. For all other unset values false is
|
|
|
|
// returend.
|
|
|
|
func (s Style) GetBorder() (b Border, top, right, bottom, left bool) {
|
2021-08-19 17:08:00 +03:00
|
|
|
return s.getBorderStyle(),
|
2021-04-21 01:07:51 +03:00
|
|
|
s.getAsBool(borderTopKey, false),
|
|
|
|
s.getAsBool(borderRightKey, false),
|
|
|
|
s.getAsBool(borderBottomKey, false),
|
|
|
|
s.getAsBool(borderLeftKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderStyle returns the style's border style (type Border). If no value
|
|
|
|
// is set Border{} is returned.
|
|
|
|
func (s Style) GetBorderStyle() Border {
|
2021-08-19 17:08:00 +03:00
|
|
|
return s.getBorderStyle()
|
2021-04-21 01:07:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderTop returns the style's top border setting. If no value is set
|
|
|
|
// false is returned.
|
|
|
|
func (s Style) GetBorderTop() bool {
|
|
|
|
return s.getAsBool(borderTopKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderRight returns the style's right border setting. If no value is set
|
|
|
|
// false is returned.
|
|
|
|
func (s Style) GetBorderRight() bool {
|
|
|
|
return s.getAsBool(borderRightKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderBottom returns the style's bottom border setting. If no value is
|
|
|
|
// set false is returned.
|
|
|
|
func (s Style) GetBorderBottom() bool {
|
|
|
|
return s.getAsBool(borderBottomKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderLeft returns the style's left border setting. If no value is
|
|
|
|
// set false is returned.
|
|
|
|
func (s Style) GetBorderLeft() bool {
|
|
|
|
return s.getAsBool(borderLeftKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderTopForeground returns the style's border top foreground color. If
|
|
|
|
// no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderTopForeground() TerminalColor {
|
|
|
|
return s.getAsColor(borderTopForegroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderRightForeground returns the style's border right foreground color.
|
|
|
|
// If no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderRightForeground() TerminalColor {
|
|
|
|
return s.getAsColor(borderRightForegroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderBottomForeground returns the style's border bottom foreground
|
|
|
|
// color. If no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderBottomForeground() TerminalColor {
|
|
|
|
return s.getAsColor(borderBottomForegroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderLeftForeground returns the style's border bottom foreground
|
|
|
|
// color. If no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderLeftForeground() TerminalColor {
|
|
|
|
return s.getAsColor(borderLeftForegroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderTopBackground returns the style's border top background color. If
|
|
|
|
// no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderTopBackground() TerminalColor {
|
|
|
|
return s.getAsColor(borderTopBackgroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderRightBackground returns the style's border right background color.
|
|
|
|
// If no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderRightBackground() TerminalColor {
|
|
|
|
return s.getAsColor(borderRightBackgroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderBottomBackground returns the style's border bottom background
|
|
|
|
// color. If no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderBottomBackground() TerminalColor {
|
|
|
|
return s.getAsColor(borderBottomBackgroundKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBorderLeftBackground returns the style's border bottom background
|
|
|
|
// color. If no value is set NoColor{} is returned.
|
|
|
|
func (s Style) GetBorderLeftBackground() TerminalColor {
|
|
|
|
return s.getAsColor(borderLeftBackgroundKey)
|
|
|
|
}
|
|
|
|
|
2021-08-19 04:54:20 +03:00
|
|
|
// GetBorderTopWidth returns the width of the top border. If borders contain
|
|
|
|
// runes of varying widths, the widest rune is returned. If no border exists on
|
|
|
|
// the top edge, 0 is returned.
|
|
|
|
func (s Style) GetBorderTopWidth() int {
|
2021-08-19 17:11:25 +03:00
|
|
|
if !s.getAsBool(borderTopKey, false) {
|
|
|
|
return 0
|
|
|
|
}
|
2021-08-19 19:59:21 +03:00
|
|
|
return s.getBorderStyle().GetTopSize()
|
2021-08-19 04:54:20 +03:00
|
|
|
}
|
|
|
|
|
2021-08-19 19:59:21 +03:00
|
|
|
// GetBorderLeftSize returns the width of the left border. If borders contain
|
2021-08-19 04:54:20 +03:00
|
|
|
// runes of varying widths, the widest rune is returned. If no border exists on
|
|
|
|
// the left edge, 0 is returned.
|
2021-08-19 19:59:21 +03:00
|
|
|
func (s Style) GetBorderLeftSize() int {
|
2021-08-19 17:11:25 +03:00
|
|
|
if !s.getAsBool(borderLeftKey, false) {
|
|
|
|
return 0
|
|
|
|
}
|
2021-08-19 19:59:21 +03:00
|
|
|
return s.getBorderStyle().GetLeftSize()
|
2021-08-19 04:54:20 +03:00
|
|
|
}
|
|
|
|
|
2022-02-14 19:39:57 +03:00
|
|
|
// GetBorderBottomSize returns the width of the bottom border. If borders
|
2021-08-19 04:54:20 +03:00
|
|
|
// contain runes of varying widths, the widest rune is returned. If no border
|
|
|
|
// exists on the left edge, 0 is returned.
|
2021-08-19 19:59:21 +03:00
|
|
|
func (s Style) GetBorderBottomSize() int {
|
2021-08-19 17:11:25 +03:00
|
|
|
if !s.getAsBool(borderBottomKey, false) {
|
|
|
|
return 0
|
|
|
|
}
|
2021-08-19 19:59:21 +03:00
|
|
|
return s.getBorderStyle().GetBottomSize()
|
2021-08-19 04:54:20 +03:00
|
|
|
}
|
|
|
|
|
2021-08-19 19:59:21 +03:00
|
|
|
// GetBorderRightSize returns the width of the right border. If borders
|
2021-08-19 04:54:20 +03:00
|
|
|
// contain runes of varying widths, the widest rune is returned. If no border
|
|
|
|
// exists on the right edge, 0 is returned.
|
2021-08-19 19:59:21 +03:00
|
|
|
func (s Style) GetBorderRightSize() int {
|
2021-08-19 17:11:25 +03:00
|
|
|
if !s.getAsBool(borderRightKey, false) {
|
|
|
|
return 0
|
|
|
|
}
|
2021-08-19 19:59:21 +03:00
|
|
|
return s.getBorderStyle().GetBottomSize()
|
2021-08-19 04:54:20 +03:00
|
|
|
}
|
|
|
|
|
2021-08-19 19:59:21 +03:00
|
|
|
// GetHorizontalBorderSize returns the width of the horizontal borders. If
|
2021-08-19 04:54:20 +03:00
|
|
|
// borders contain runes of varying widths, the widest rune is returned. If no
|
|
|
|
// border exists on the horizontal edges, 0 is returned.
|
2021-08-19 19:59:21 +03:00
|
|
|
func (s Style) GetHorizontalBorderSize() int {
|
2021-08-19 17:08:00 +03:00
|
|
|
b := s.getBorderStyle()
|
2021-08-19 19:59:21 +03:00
|
|
|
return b.GetLeftSize() + b.GetRightSize()
|
2021-08-19 04:54:20 +03:00
|
|
|
}
|
|
|
|
|
2021-08-19 19:59:21 +03:00
|
|
|
// GetVerticalBorderSize returns the width of the horizontal borders. If
|
2021-08-19 04:54:20 +03:00
|
|
|
// borders contain runes of varying widths, the widest rune is returned. If no
|
|
|
|
// border exists on the horizontal edges, 0 is returned.
|
2021-08-19 19:59:21 +03:00
|
|
|
func (s Style) GetVerticalBorderSize() int {
|
2021-08-19 17:08:00 +03:00
|
|
|
b := s.getBorderStyle()
|
2021-08-19 19:59:21 +03:00
|
|
|
return b.GetTopSize() + b.GetBottomSize()
|
2021-08-19 04:54:20 +03:00
|
|
|
}
|
|
|
|
|
2021-04-21 01:07:51 +03:00
|
|
|
// GetInline returns the style's inline setting. If no value is set false is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetInline() bool {
|
|
|
|
return s.getAsBool(inlineKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMaxWidth returns the style's max width setting. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetMaxWidth() int {
|
|
|
|
return s.getAsInt(maxWidthKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetMaxHeight returns the style's max width setting. If no value is set 0 is
|
|
|
|
// returned.
|
|
|
|
func (s Style) GetMaxHeight() int {
|
|
|
|
return s.getAsInt(maxHeightKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetUnderlineSpaces returns whether or not the style is set to underline
|
|
|
|
// spaces. If not value is set false is returned.
|
|
|
|
func (s Style) GetUnderlineSpaces() bool {
|
|
|
|
return s.getAsBool(underlineSpacesKey, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetStrikethroughSpaces returns whether or not the style is set to underline
|
|
|
|
// spaces. If not value is set false is returned.
|
|
|
|
func (s Style) GetStrikethroughSpaces() bool {
|
|
|
|
return s.getAsBool(strikethroughSpacesKey, false)
|
|
|
|
}
|
|
|
|
|
2021-08-19 19:59:21 +03:00
|
|
|
// GetHorizontalFrameSize returns the sum of the style's horizontal margins, padding
|
2021-08-19 05:01:01 +03:00
|
|
|
// and border widths.
|
2021-08-19 19:59:21 +03:00
|
|
|
//
|
|
|
|
// Provisional: this method may be renamed.
|
|
|
|
func (s Style) GetHorizontalFrameSize() int {
|
|
|
|
return s.GetHorizontalMargins() + s.GetHorizontalPadding() + s.GetHorizontalBorderSize()
|
2021-08-19 05:01:01 +03:00
|
|
|
}
|
|
|
|
|
2021-08-19 19:59:21 +03:00
|
|
|
// GetVerticalFrameSize returns the sum of the style's horizontal margins, padding
|
2021-08-19 05:01:01 +03:00
|
|
|
// and border widths.
|
2021-08-19 19:59:21 +03:00
|
|
|
//
|
|
|
|
// Provisional: this method may be renamed.
|
|
|
|
func (s Style) GetVerticalFrameSize() int {
|
|
|
|
return s.GetVerticalMargins() + s.GetVerticalPadding() + s.GetVerticalBorderSize()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetFrameSize returns the sum of the margins, padding and border width for
|
|
|
|
// both the horizontal and vertical margins.
|
|
|
|
func (s Style) GetFrameSize() (x, y int) {
|
|
|
|
return s.GetHorizontalFrameSize(), s.GetVerticalFrameSize()
|
2021-08-19 05:01:01 +03:00
|
|
|
}
|
|
|
|
|
2021-03-26 03:43:40 +03:00
|
|
|
// Returns whether or not the given property is set.
|
|
|
|
func (s Style) isSet(k propKey) bool {
|
|
|
|
_, exists := s.rules[k]
|
|
|
|
return exists
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:35:28 +03:00
|
|
|
func (s Style) getAsBool(k propKey, defaultVal bool) bool {
|
|
|
|
v, ok := s.rules[k]
|
|
|
|
if !ok {
|
|
|
|
return defaultVal
|
|
|
|
}
|
|
|
|
if b, ok := v.(bool); ok {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
return defaultVal
|
|
|
|
}
|
|
|
|
|
2021-03-31 05:19:38 +03:00
|
|
|
func (s Style) getAsColor(k propKey) TerminalColor {
|
2021-03-16 23:35:28 +03:00
|
|
|
v, ok := s.rules[k]
|
|
|
|
if !ok {
|
2021-03-18 21:34:39 +03:00
|
|
|
return NoColor{}
|
2021-03-16 23:35:28 +03:00
|
|
|
}
|
2021-03-31 05:19:38 +03:00
|
|
|
if c, ok := v.(TerminalColor); ok {
|
2021-03-16 23:35:28 +03:00
|
|
|
return c
|
|
|
|
}
|
2021-03-18 21:34:39 +03:00
|
|
|
return NoColor{}
|
2021-03-16 23:35:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s Style) getAsInt(k propKey) int {
|
|
|
|
v, ok := s.rules[k]
|
|
|
|
if !ok {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if i, ok := v.(int); ok {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:35:48 +03:00
|
|
|
func (s Style) getAsPosition(k propKey) Position {
|
2021-03-16 23:35:28 +03:00
|
|
|
v, ok := s.rules[k]
|
|
|
|
if !ok {
|
2021-03-26 20:35:48 +03:00
|
|
|
return Position(0)
|
2021-03-16 23:35:28 +03:00
|
|
|
}
|
2021-03-26 20:35:48 +03:00
|
|
|
if p, ok := v.(Position); ok {
|
|
|
|
return p
|
2021-03-16 23:35:28 +03:00
|
|
|
}
|
2021-03-26 20:35:48 +03:00
|
|
|
return Position(0)
|
2021-03-16 23:35:28 +03:00
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:00 +03:00
|
|
|
func (s Style) getBorderStyle() Border {
|
|
|
|
v, ok := s.rules[borderStyleKey]
|
2021-03-26 03:43:40 +03:00
|
|
|
if !ok {
|
|
|
|
return noBorder
|
|
|
|
}
|
|
|
|
if b, ok := v.(Border); ok {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
return noBorder
|
|
|
|
}
|
|
|
|
|
2021-03-16 23:35:28 +03:00
|
|
|
// Split a string into lines, additionally returning the size of the widest
|
|
|
|
// line.
|
|
|
|
func getLines(s string) (lines []string, widest int) {
|
|
|
|
lines = strings.Split(s, "\n")
|
|
|
|
|
|
|
|
for _, l := range lines {
|
|
|
|
w := ansi.PrintableRuneWidth(l)
|
|
|
|
if widest < w {
|
|
|
|
widest = w
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lines, widest
|
|
|
|
}
|