package lipgloss
import (
)
type Border struct {
Top string
Bottom string
Left string
Right string
TopLeft string
TopRight string
BottomLeft string
BottomRight string
MiddleLeft string
MiddleRight string
Middle string
MiddleTop string
MiddleBottom string
}
func ( Border) () int {
return getBorderEdgeWidth(.TopLeft, .Top, .TopRight)
}
func ( Border) () int {
return getBorderEdgeWidth(.TopRight, .Right, .BottomRight)
}
func ( Border) () int {
return getBorderEdgeWidth(.BottomLeft, .Bottom, .BottomRight)
}
func ( Border) () int {
return getBorderEdgeWidth(.TopLeft, .Left, .BottomLeft)
}
func ( ...string) ( int) {
for , := range {
= max(, maxRuneWidth())
}
return
}
var (
noBorder = Border{}
normalBorder = Border{
Top: "─",
Bottom: "─",
Left: "│",
Right: "│",
TopLeft: "┌",
TopRight: "┐",
BottomLeft: "└",
BottomRight: "┘",
MiddleLeft: "├",
MiddleRight: "┤",
Middle: "┼",
MiddleTop: "┬",
MiddleBottom: "┴",
}
roundedBorder = Border{
Top: "─",
Bottom: "─",
Left: "│",
Right: "│",
TopLeft: "╭",
TopRight: "╮",
BottomLeft: "╰",
BottomRight: "╯",
MiddleLeft: "├",
MiddleRight: "┤",
Middle: "┼",
MiddleTop: "┬",
MiddleBottom: "┴",
}
blockBorder = Border{
Top: "█",
Bottom: "█",
Left: "█",
Right: "█",
TopLeft: "█",
TopRight: "█",
BottomLeft: "█",
BottomRight: "█",
MiddleLeft: "█",
MiddleRight: "█",
Middle: "█",
MiddleTop: "█",
MiddleBottom: "█",
}
outerHalfBlockBorder = Border{
Top: "▀",
Bottom: "▄",
Left: "▌",
Right: "▐",
TopLeft: "▛",
TopRight: "▜",
BottomLeft: "▙",
BottomRight: "▟",
}
innerHalfBlockBorder = Border{
Top: "▄",
Bottom: "▀",
Left: "▐",
Right: "▌",
TopLeft: "▗",
TopRight: "▖",
BottomLeft: "▝",
BottomRight: "▘",
}
thickBorder = Border{
Top: "━",
Bottom: "━",
Left: "┃",
Right: "┃",
TopLeft: "┏",
TopRight: "┓",
BottomLeft: "┗",
BottomRight: "┛",
MiddleLeft: "┣",
MiddleRight: "┫",
Middle: "╋",
MiddleTop: "┳",
MiddleBottom: "┻",
}
doubleBorder = Border{
Top: "═",
Bottom: "═",
Left: "║",
Right: "║",
TopLeft: "╔",
TopRight: "╗",
BottomLeft: "╚",
BottomRight: "╝",
MiddleLeft: "╠",
MiddleRight: "╣",
Middle: "╬",
MiddleTop: "╦",
MiddleBottom: "╩",
}
hiddenBorder = Border{
Top: " ",
Bottom: " ",
Left: " ",
Right: " ",
TopLeft: " ",
TopRight: " ",
BottomLeft: " ",
BottomRight: " ",
MiddleLeft: " ",
MiddleRight: " ",
Middle: " ",
MiddleTop: " ",
MiddleBottom: " ",
}
markdownBorder = Border{
Top: "-",
Bottom: "-",
Left: "|",
Right: "|",
TopLeft: "|",
TopRight: "|",
BottomLeft: "|",
BottomRight: "|",
MiddleLeft: "|",
MiddleRight: "|",
Middle: "|",
MiddleTop: "|",
MiddleBottom: "|",
}
asciiBorder = Border{
Top: "-",
Bottom: "-",
Left: "|",
Right: "|",
TopLeft: "+",
TopRight: "+",
BottomLeft: "+",
BottomRight: "+",
MiddleLeft: "+",
MiddleRight: "+",
Middle: "+",
MiddleTop: "+",
MiddleBottom: "+",
}
)
func () Border {
return normalBorder
}
func () Border {
return roundedBorder
}
func () Border {
return blockBorder
}
func () Border {
return outerHalfBlockBorder
}
func () Border {
return innerHalfBlockBorder
}
func () Border {
return thickBorder
}
func () Border {
return doubleBorder
}
func () Border {
return hiddenBorder
}
func () Border {
return markdownBorder
}
func () Border {
return asciiBorder
}
type borderBlend struct {
topGradient []color.Color
rightGradient []color.Color
bottomGradient []color.Color
leftGradient []color.Color
}
func ( Style) (, int, ...color.Color) *borderBlend {
:= Blend1D(
(++2)*2,
...,
)
if := -.getAsInt(borderForegroundBlendOffsetKey); != 0 {
:= len()
%=
if < 0 {
+=
}
slices.Reverse([:])
slices.Reverse([:])
slices.Reverse()
}
:= 0
:= func( int) ( []color.Color) {
= [ : +]
+=
return
}
:= &borderBlend{
topGradient: ( + 2),
rightGradient: (),
bottomGradient: ( + 2),
leftGradient: (),
}
slices.Reverse(.bottomGradient)
slices.Reverse(.leftGradient)
return
}
func ( Style) ( string) string {
var (
= .getBorderStyle()
= .getAsBool(borderTopKey, false)
= .getAsBool(borderRightKey, false)
= .getAsBool(borderBottomKey, false)
= .getAsBool(borderLeftKey, false)
)
if .isBorderStyleSetWithoutSides() {
= true
= true
= true
= true
}
if == noBorder || (! && ! && ! && !) {
return
}
, := getLines()
if {
if .Left == "" {
.Left = " "
}
+= maxRuneWidth(.Left)
}
if {
if .Right == "" {
.Right = " "
}
+= maxRuneWidth(.Right)
}
if && && .TopLeft == "" {
.TopLeft = " "
}
if && && .TopRight == "" {
.TopRight = " "
}
if && && .BottomLeft == "" {
.BottomLeft = " "
}
if && && .BottomRight == "" {
.BottomRight = " "
}
if {
switch {
case ! && !:
.TopLeft = ""
.TopRight = ""
case !:
.TopLeft = ""
case !:
.TopRight = ""
}
}
if {
switch {
case ! && !:
.BottomLeft = ""
.BottomRight = ""
case !:
.BottomLeft = ""
case !:
.BottomRight = ""
}
}
.TopLeft = getFirstRuneAsString(.TopLeft)
.TopRight = getFirstRuneAsString(.TopRight)
.BottomRight = getFirstRuneAsString(.BottomRight)
.BottomLeft = getFirstRuneAsString(.BottomLeft)
var , , , color.Color
var (
= .getAsColors(borderForegroundBlendKey)
= .getAsColor(borderTopBackgroundKey)
= .getAsColor(borderRightBackgroundKey)
= .getAsColor(borderBottomBackgroundKey)
= .getAsColor(borderLeftBackgroundKey)
)
var *borderBlend
if len() > 0 {
= .borderBlend(, len(), ...)
} else {
= .getAsColor(borderTopForegroundKey)
= .getAsColor(borderRightForegroundKey)
= .getAsColor(borderBottomForegroundKey)
= .getAsColor(borderLeftForegroundKey)
}
var strings.Builder
if {
:= renderHorizontalEdge(.TopLeft, .Top, .TopRight, )
if != nil {
.WriteString(.styleBorderBlend(, .topGradient, ))
} else {
.WriteString(.styleBorder(, , ))
}
.WriteRune('\n')
}
:= []rune(.Left)
:= 0
:= []rune(.Right)
:= 0
var string
for , := range {
if {
= string([])
++
if >= len() {
= 0
}
if != nil {
.WriteString(.styleBorder(, .leftGradient[], ))
} else {
.WriteString(.styleBorder(, , ))
}
}
.WriteString()
if {
= string([])
++
if >= len() {
= 0
}
if != nil {
.WriteString(.styleBorder(, .rightGradient[], ))
} else {
.WriteString(.styleBorder(, , ))
}
}
if < len()-1 {
.WriteRune('\n')
}
}
if {
:= renderHorizontalEdge(.BottomLeft, .Bottom, .BottomRight, )
.WriteRune('\n')
if != nil {
.WriteString(.styleBorderBlend(, .bottomGradient, ))
} else {
.WriteString(.styleBorder(, , ))
}
}
return .String()
}
func (, , string, int) string {
if == "" {
= " "
}
:= ansi.StringWidth()
:= ansi.StringWidth()
:= []rune()
:= 0
:= strings.Builder{}
.WriteString()
for := 0; < --; {
:= []
.WriteRune()
:= ansi.StringWidth(string())
if < 1 {
= 1
}
+=
++
if >= len() {
= 0
}
}
.WriteString()
return .String()
}
func ( Style) ( string, , color.Color) string {
if == noColor && == noColor {
return
}
var ansi.Style
if != noColor {
= .ForegroundColor()
}
if != noColor {
= .BackgroundColor()
}
return .Styled()
}
func ( Style) ( string, []color.Color, color.Color) string {
var strings.Builder
var ansi.Style
var int
:= uniseg.NewGraphemes()
for .Next() {
= [:0]
if [] != noColor {
= .ForegroundColor([])
}
if != noColor {
= .BackgroundColor()
}
_, _ = .WriteString(.String())
_, _ = .Write(.Bytes())
++
}
_, _ = .WriteString(ansi.ResetStyle)
return .String()
}
func ( string) int {
switch len() {
case 0:
return 0
case 1:
return displaywidth.String()
}
var int
:= displaywidth.StringGraphemes()
for .Next() {
= max(, .Width())
}
return
}
func ( string) string {
if == "" {
return
}
, := utf8.DecodeRuneInString()
return [:]
}