fin de ANSI3 como mejor opcion de implementacion de los escapes de estilo ANSI

master
dev 1 year ago
parent a6a44febba
commit d14aed8d7b

@ -61,11 +61,11 @@ type (
)
func NewBasicStyleBuilder(fgcolor, bgcolor BasicColor, txStyle TextStyle) *BasicStyleBuilder {
func NewBasicStyleBuilder(fgcolor, bgcolor BasicColor, txtStyle TextStyle) *BasicStyleBuilder {
s := &BasicStyleBuilder{
fgColor : fgcolor.sanitize(),
bgColor : bgcolor.sanitize(),
txStyle : txStyle,
txStyle : txtStyle.sanitize(),
}
return s
}
@ -90,7 +90,7 @@ func (s *BasicStyleBuilder) SetBgColor (color BasicColor) *BasicStyleBuilder {
}
func (s *BasicStyleBuilder) SetTextStyle (txtStyle TextStyle) *BasicStyleBuilder {
s.txStyle = txtStyle
s.txStyle = txtStyle.sanitize()
return s
}

@ -49,14 +49,10 @@
package ansi
const (
CapBasicColor = 1 // Soporte para 16 colores (ANSI).
Cap256Color = 2 // Soporte para 256 colores.
CapTrueColor = 4 // Soporte para 24-bit "True Color".
)
const (
CapStyleBold = 1 << (8 + iota) // Soporte para texto en negrita.
CapStyleBold Capabilities = 1 << iota // Soporte para texto en negrita.
CapStyleDim
CapStyleItalic // Soporte para texto en cursiva.
CapStyleUnderline // Soporte para texto subrayado.
@ -65,15 +61,62 @@ const (
CapStyleHidden
CapStyleStrike
CapDoubleUnderline
CapOverline
CapFraktur
CapProportional
CapBasicColor Capabilities = 1 << 13
Cap256Color Capabilities = 1 << 14
CapTrueColor Capabilities = 1 << 15
CapNone Capabilities = 0 // El terminal no soporta nada.
CapAllColor = CapBasicColor | Cap256Color | CapTrueColor
CapNone Capabilities = 0 // El terminal no soporta nada.
CapAllStyle = CapStyleBold | CapStyleDim | CapStyleItalic |
CapStyleUnderline | CapStyleBlink | CapStyleInverse
CapAllExtended = CapStyleHidden | CapStyleStrike| CapDoubleUnderline|
CapOverline | CapFraktur | CapProportional
CapAll = CapAllColor | CapAllStyle | CapAllExtended
)
type (
Capabilities uint16
)
// Métodos para verificar capacidades de color
func (c Capabilities) HasBasicColor() bool { return c&CapBasicColor != 0 }
func (c Capabilities) Has256Color () bool { return c&Cap256Color != 0 }
func (c Capabilities) HasTrueColor () bool { return c&CapTrueColor != 0 }
func (c Capabilities) HasAnyColor () bool { return c&CapAllColor != 0 }
// Métodos para verificar capacidades de estilo
func (c Capabilities) HasBold() bool { return c&CapStyleBold != 0 }
func (c Capabilities) HasDim() bool { return c&CapStyleDim != 0 }
func (c Capabilities) HasItalic() bool { return c&CapStyleItalic != 0 }
func (c Capabilities) HasUnderline() bool { return c&CapStyleUnderline != 0 }
func (c Capabilities) HasBlink() bool { return c&CapStyleBlink != 0 }
func (c Capabilities) HasInverse() bool { return c&CapStyleInverse != 0 }
func (c Capabilities) HasHidden() bool { return c&CapStyleHidden != 0 }
func (c Capabilities) HasStrike() bool { return c&CapStyleStrike != 0 }
// Métodos para capacidades extendidas
func (c Capabilities) HasDoubleUnderline() bool { return c&CapDoubleUnderline != 0 }
func (c Capabilities) HasOverline() bool { return c&CapOverline != 0 }
func (c Capabilities) HasFraktur() bool { return c&CapFraktur != 0 }
func (c Capabilities) HasProportional() bool { return c&CapProportional != 0 }

@ -72,7 +72,7 @@ func NewIndexStyleBuilder(fgcolor, bgcolor IndexColor, txtStyle TextStyle) *Inde
return &IndexStyleBuilder{
fgColor: fgcolor.sanitize(),
bgColor: bgcolor.sanitize(),
txStyle: txtStyle,
txStyle: txtStyle.sanitize(),
}
}
@ -88,7 +88,7 @@ func (s *IndexStyleBuilder) SetBgColor (color IndexColor) *IndexStyleBuilder {
}
func (s *IndexStyleBuilder) SetTextStyle (txtStyle TextStyle) *IndexStyleBuilder {
s.txStyle = txtStyle
s.txStyle = txtStyle.sanitize()
return s
}

@ -0,0 +1,92 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero mono_style_builder.go
Package ansi
Autor Juan V. Navarro juanvnl@activething.com
Creado 20/08/2025
—————————————————————————————————————————————————————————————————————————————
LICENSES AND TERMS OF USE
-------------------------
This software is licensed under the Elastic License v2.0 (the "License").
For full terms and additional information regarding permitted and prohibited
uses, please visit:
https://activething.com/wiawiaw/licenses
You may use, copy, modify, and redistribute this software internally within
your organization for any purpose, including research, development, and
testing, subject to the terms of this License.
You may NOT, however, use, provide, distribute, or make this software
available to any third party as part of a hosted service, SaaS offering, or
commercial product without first obtaining a commercial license from
Active Thing.
You may combine this software with other code, provided that such
combination does not circumvent the restrictions of this License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. In no event shall
the authors or copyright holders be liable for any claim, damages, or other
liability arising from the use of this software.
—————————————————————————————————————————————————————————————————————————————
Web : activething.com | wiawiaw.com
git : g.activething.com | github.com/activething
Correo : dev@activething.com
—————————————————————————————————————————————————————————————————————————————
No deseo caminar sobre el agua", dijo Siddhartha.
Que los antiguos chamanes se contenten con tales habilidades.
—— Hermann Hesse, Siddhartha
—————————————————————————————————————————————————————————————————————————————
Copyright (c) 2025 Active Thing
————————————————————————————————————————————————————————————————————————————— */
package ansi
type (
MonoStyleBuilder struct {
txtStyle TextStyle
}
)
func NewMonoStyleBuilder(txtStyle TextStyle) *MonoStyleBuilder {
return &MonoStyleBuilder{txtStyle: txtStyle.sanitize()}
}
func (s *MonoStyleBuilder) TextStyle () TextStyle { return s.txtStyle }
func (s *MonoStyleBuilder) SetTextStyle (txtStyle TextStyle) *MonoStyleBuilder {
s.txtStyle = txtStyle.sanitize()
return s
}
func (s *MonoStyleBuilder) AddStyle (txtStyle TextStyle) { s.txtStyle = s.txtStyle.Add(txtStyle) }
func (s *MonoStyleBuilder) DelStyle (txtStyle TextStyle) { s.txtStyle = s.txtStyle.Del(txtStyle) }
func (s *MonoStyleBuilder) Build () Style {
if s.txtStyle == 0 {
return ""
}
bf := make([]byte, 0,defaultAnsiBufferSize)
bf = append(bf,ansiCodeBegin...)
if s.txtStyle != 0 {
bf = s.txtStyle.appendStyles(bf, false)
}
return Style(bf)
}

@ -51,14 +51,14 @@ package ansi
const (
maxBitsTextStyle = 8
maxBitsTextStyle = 12
textStyleMask = (1 << maxBitsTextStyle)-1
)
const (
TextStyleNone TextStyle = 0
TextStyleBold TextStyle = 1 << iota
TextStyleDim
TextStyleItalic
@ -68,42 +68,50 @@ const (
TextStyleHidden
TextStyleStrike
// Extended styles
TextStyleDoubleUnderline
TextStyleOverline
TextStyleFraktur
TextStyleProportional
TextStyleNone TextStyle = 0
)
type (
TextStyle uint8
TextStyle uint16
)
// Basic Styles
func (s TextStyle) HasBold () bool { return s&TextStyleBold != 0 }
func (s TextStyle) HasDim () bool { return s&TextStyleDim != 0 }
func (s TextStyle) HasItalic () bool { return s&TextStyleItalic != 0 }
func (s TextStyle) HasUnderline () bool { return s&TextStyleUnderline != 0 }
func (s TextStyle) HasBlink () bool { return s&TextStyleBlink != 0 }
func (s TextStyle) HasInverse () bool { return s&TextStyleInverse != 0 }
func (s TextStyle) HasHidden () bool { return s&TextStyleHidden != 0 }
func (s TextStyle) HasStrikethrogh () bool { return s&TextStyleStrike != 0 }
func (s TextStyle) Add (txtStyle TextStyle) TextStyle { return s|txtStyle }
// Extended Syles
func (s TextStyle) HasDoubleUnderline() bool{ return s&TextStyleDoubleUnderline != 0}
func (s TextStyle) HasOverline () bool{ return s&TextStyleOverline != 0}
func (s TextStyle) HasFraktur () bool{ return s&TextStyleFraktur != 0}
func (s TextStyle) HasProportional () bool{ return s&TextStyleProportional != 0}
func (s TextStyle) Add (txtStyle TextStyle) TextStyle { return s|(textStyleMask&txtStyle) }
func (s TextStyle) Del (txtStyle TextStyle) TextStyle { return s &^ txtStyle }
func (s TextStyle) Del (txtStyle TextStyle) TextStyle { return s &^ (textStyleMask&txtStyle) }
//func (s TextStyle) sanitize() TextStyle { return s & textStyleMask }
func (s TextStyle) sanitize() TextStyle { return s & textStyleMask }

@ -51,12 +51,52 @@ package ansi
type (
Theme struct {
Name string
Default Style
Styles []string
Dark []string
Theme struct {
// Logging levels
Debug Style
Info Style
Warning Style
Error Style
Fatal Style
Trace Style
// UI Elements
Title Style
Subtitle Style
Header Style
Text Style
Muted Style
// Data presentation
Field Style // Para nombres de campos (key en key=value)
Value Style // Para valores de campos
Number Style // Para números
String Style // Para strings/texto citado
Boolean Style // Para valores booleanos
Null Style // Para valores null/nil
// Status and feedback
Success Style
Failure Style
Pending Style
// Interactive elements
Highlight Style // Para resaltado/selección
Focus Style // Para elemento enfocado
Disabled Style // Para elementos deshabilitados
// Structural
Border Style // Para bordes y marcos
Separator Style // Para separadores y líneas
Indent Style // Para indentación
// Code/Technical
Code Style // Para código fuente
Comment Style // Para comentarios
Keyword Style // Para palabras clave
Function Style // Para nombres de función
Variable Style // Para nombres de variable
Type Style // Para nombres de tipo
}
)

@ -0,0 +1,58 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero theme_manager.go
Package ansi
Autor Juan V. Navarro juanvnl@activething.com
Creado 20/08/2025
—————————————————————————————————————————————————————————————————————————————
LICENSES AND TERMS OF USE
-------------------------
This software is licensed under the Elastic License v2.0 (the "License").
For full terms and additional information regarding permitted and prohibited
uses, please visit:
https://activething.com/wiawiaw/licenses
You may use, copy, modify, and redistribute this software internally within
your organization for any purpose, including research, development, and
testing, subject to the terms of this License.
You may NOT, however, use, provide, distribute, or make this software
available to any third party as part of a hosted service, SaaS offering, or
commercial product without first obtaining a commercial license from
Active Thing.
You may combine this software with other code, provided that such
combination does not circumvent the restrictions of this License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. In no event shall
the authors or copyright holders be liable for any claim, damages, or other
liability arising from the use of this software.
—————————————————————————————————————————————————————————————————————————————
Web : activething.com | wiawiaw.com
git : g.activething.com | github.com/activething
Correo : dev@activething.com
—————————————————————————————————————————————————————————————————————————————
No deseo caminar sobre el agua", dijo Siddhartha.
Que los antiguos chamanes se contenten con tales habilidades.
—— Hermann Hesse, Siddhartha
—————————————————————————————————————————————————————————————————————————————
Copyright (c) 2025 Active Thing
————————————————————————————————————————————————————————————————————————————— */
package ansi
import "sync"
type ThemeManager struct {
mu sync.RWMutex
currentTheme *Theme
capabilities Capabilities
}

@ -79,7 +79,7 @@ func NewTrueStyleBuilder(fgcolor, bgcolor TrueColor, txtStyle TextStyle) *TrueSt
return &TrueStyleBuilder{
fgColor: fgcolor,
bgColor: bgcolor,
txStyle: txtStyle,
txStyle: txtStyle.sanitize(),
}
}
@ -95,7 +95,7 @@ func (s *TrueStyleBuilder) SetBgColor (color TrueColor) *TrueStyleBuilder {
}
func (s *TrueStyleBuilder) SetTextStyle (txtStyle TextStyle) *TrueStyleBuilder {
s.txStyle = txtStyle
s.txStyle = txtStyle.sanitize()
return s
}

Loading…
Cancel
Save

Powered by TurnKey Linux.