package uv
import (
)
var EmptyCell = Cell{Content: " ", Width: 1}
type Cell struct {
Content string
Style Style
Link Link
Width int
}
func ( WidthMethod, string) *Cell {
if len() == 0 {
return &Cell{}
}
if == " " {
return EmptyCell.Clone()
}
return &Cell{
Content: ,
Width: .StringWidth(),
}
}
func ( *Cell) () string {
return .Content
}
func ( *Cell) ( *Cell) bool {
return != nil &&
.Width == .Width &&
.Content == .Content &&
.Style.Equal(&.Style) &&
.Link.Equal(&.Link)
}
func ( *Cell) () bool {
return * == Cell{}
}
func ( *Cell) () bool {
return != nil && .Width == 0
}
func ( *Cell) () ( *Cell) {
= new(Cell)
* = *
return
}
func ( *Cell) () {
.Content = " "
.Width = 1
}
func ( string, ...string) Link {
return Link{
URL: ,
Params: strings.Join(, ":"),
}
}
type Link struct {
URL string
Params string
}
func ( *Link) () string {
return .URL
}
func ( *Link) ( *Link) bool {
return != nil && * == *
}
func ( *Link) () bool {
return * == Link{}
}
const (
AttrBold = 1 << iota
AttrFaint
AttrItalic
AttrBlink
AttrRapidBlink
AttrReverse
AttrConceal
AttrStrikethrough
AttrReset = 0
)
const (
AttrSlowBlink = AttrBlink
)
type Underline = ansi.Underline
type UnderlineStyle = ansi.Underline
const (
UnderlineNone = ansi.UnderlineNone
UnderlineSingle = ansi.UnderlineSingle
UnderlineDouble = ansi.UnderlineDouble
UnderlineCurly = ansi.UnderlineCurly
UnderlineDotted = ansi.UnderlineDotted
UnderlineDashed = ansi.UnderlineDashed
)
const (
UnderlineStyleNone = ansi.UnderlineNone
UnderlineStyleSingle = ansi.UnderlineSingle
UnderlineStyleDouble = ansi.UnderlineDouble
UnderlineStyleCurly = ansi.UnderlineCurly
UnderlineStyleDotted = ansi.UnderlineDotted
UnderlineStyleDashed = ansi.UnderlineDashed
)
type Style struct {
Fg color.Color
Bg color.Color
UnderlineColor color.Color
Underline Underline
Attrs uint8
}
func ( *Style) ( *Style) bool {
return .Attrs == .Attrs &&
.Underline == .Underline &&
colorEqual(.Fg, .Fg) &&
colorEqual(.Bg, .Bg) &&
colorEqual(.UnderlineColor, .UnderlineColor)
}
func ( *Style) ( string) string {
if .IsZero() {
return
}
return .String() + + ansi.ResetStyle
}
func ( *Style) () string {
if .IsZero() {
return ansi.ResetStyle
}
var ansi.Style
if .Attrs != 0 {
if .Attrs&AttrBold != 0 {
= .Bold()
}
if .Attrs&AttrFaint != 0 {
= .Faint()
}
if .Attrs&AttrItalic != 0 {
= .Italic(true)
}
if .Attrs&AttrBlink != 0 {
= .Blink(true)
}
if .Attrs&AttrRapidBlink != 0 {
= .RapidBlink(true)
}
if .Attrs&AttrReverse != 0 {
= .Reverse(true)
}
if .Attrs&AttrConceal != 0 {
= .Conceal(true)
}
if .Attrs&AttrStrikethrough != 0 {
= .Strikethrough(true)
}
}
if .Underline != UnderlineStyleNone {
switch .Underline {
case UnderlineStyleSingle:
= .Underline(true)
case UnderlineStyleDouble:
= .UnderlineStyle(UnderlineStyleDouble)
case UnderlineStyleCurly:
= .UnderlineStyle(UnderlineStyleCurly)
case UnderlineStyleDotted:
= .UnderlineStyle(UnderlineStyleDotted)
case UnderlineStyleDashed:
= .UnderlineStyle(UnderlineStyleDashed)
}
}
if .Fg != nil {
= .ForegroundColor(.Fg)
}
if .Bg != nil {
= .BackgroundColor(.Bg)
}
if .UnderlineColor != nil {
= .UnderlineColor(.UnderlineColor)
}
return .String()
}
func ( *Style) ( *Style) string {
return StyleDiff(, )
}
func (, *Style) string {
if == nil && == nil {
return ""
}
if != nil && != nil && .Equal() {
return ""
}
if == nil {
return .String()
}
if == nil || .IsZero() {
return ansi.ResetStyle
}
var ansi.Style
if !colorEqual(.Fg, .Fg) {
= .ForegroundColor(.Fg)
}
if !colorEqual(.Bg, .Bg) {
= .BackgroundColor(.Bg)
}
if !colorEqual(.UnderlineColor, .UnderlineColor) {
= .UnderlineColor(.UnderlineColor)
}
:= .Attrs&AttrBold != 0
:= .Attrs&AttrFaint != 0
:= .Attrs&AttrItalic != 0
:= .Underline != UnderlineStyleNone
:= .Attrs&AttrBlink != 0
:= .Attrs&AttrRapidBlink != 0
:= .Attrs&AttrReverse != 0
:= .Attrs&AttrConceal != 0
:= .Attrs&AttrStrikethrough != 0
:= .Attrs&AttrBold != 0
:= .Attrs&AttrFaint != 0
:= .Attrs&AttrItalic != 0
:= .Underline != UnderlineStyleNone
:= .Attrs&AttrBlink != 0
:= .Attrs&AttrRapidBlink != 0
:= .Attrs&AttrReverse != 0
:= .Attrs&AttrConceal != 0
:= .Attrs&AttrStrikethrough != 0
:= !=
:= !=
if || {
if && ! || && ! {
= .Normal()
= true
= true
}
}
:= !=
if && ! {
= .Italic(false)
}
:= != || .Underline != .Underline
if && ! {
= .Underline(false)
}
:= !=
:= !=
if || {
if && ! || && ! {
= .Blink(false)
= true
= true
}
}
:= !=
if && ! {
= .Reverse(false)
}
:= !=
if && ! {
= .Conceal(false)
}
:= !=
if && ! {
= .Strikethrough(false)
}
if && {
= .Bold()
}
if && {
= .Faint()
}
if && {
= .Italic(true)
}
if && && .Underline == UnderlineStyleSingle {
= .Underline(true)
}
if && {
= .Blink(true)
}
if && {
= .RapidBlink(true)
}
if && {
= .Reverse(true)
}
if && {
= .Conceal(true)
}
if && {
= .Strikethrough(true)
}
if && && .Underline > UnderlineStyleSingle {
= .UnderlineStyle(.Underline)
}
return .String()
}
func (, color.Color) bool {
if == nil && == nil {
return true
}
if == nil || == nil {
return false
}
, , , := .RGBA()
, , , := .RGBA()
return == && == && == && ==
}
func ( *Style) () bool {
return * == Style{}
}
func ( Style, colorprofile.Profile) Style {
switch {
case colorprofile.TrueColor:
return
case colorprofile.ANSI, colorprofile.ANSI256:
case colorprofile.Ascii:
.Fg = nil
.Bg = nil
.UnderlineColor = nil
case colorprofile.NoTTY:
return Style{}
}
if .Fg != nil {
.Fg = .Convert(.Fg)
}
if .Bg != nil {
.Bg = .Convert(.Bg)
}
if .UnderlineColor != nil {
.UnderlineColor = .Convert(.UnderlineColor)
}
return
}
func ( Link, colorprofile.Profile) Link {
if == colorprofile.NoTTY {
return Link{}
}
return
}