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

master
dev 1 year ago
parent aef026a192
commit a6a44febba

@ -52,12 +52,18 @@ package main
import (
"base/ansi"
"fmt"
"os"
"strings"
)
func ansiStylesMain() {
fmt.Printf("-%#v-\n",strings.ToLower(os.Getenv("TERM")))
s4 := ansi.NewBasicStyleBuilder(ansi.BColorRed,0, ansi.TextStyleItalic|ansi.TextStyleBold).Build()
s4.Apply("A")
fmt.Printf("Esto es %s\n",s4.Apply("TXTXTXTXTXT"))
s4.Stylize("A")
fmt.Printf("Esto es %s\n",s4.Stylize("TXTXTXTXTXT"))
}

@ -52,5 +52,7 @@ package main
func main() {
ansiStylesMain()
}

@ -95,7 +95,9 @@ var (
{ []byte("3"), []byte("italic") }, // TextStyleItalic (bit 2)
{ []byte("4"), []byte("underline") }, // TextStyleUnderline (bit 3)
{ []byte("5"), []byte("blink") }, // TextStyleBlink (bit 4)
{ []byte("7"), []byte("reverse") }, // TextStyleReverse (bit 5)
{ []byte("7"), []byte("inverse") }, // TextStyleInverse (bit 5)
{ []byte("8"), []byte("hidden") }, // TextStyleInverse (bit 6)
{ []byte("9"), []byte("strikethrough") }, // TextStyleInverse (bit 7)
}
@ -119,7 +121,7 @@ var (
Error,
Warning,
Info,
Success ANSIStyle
Success Style
}{
Red : NewBasicStyleBuilder(BColorRed , BColorNone, TextStyleNone).Build(),
@ -136,7 +138,7 @@ var (
Italic : NewBasicStyleBuilder(BColorNone , BColorNone, TextStyleItalic).Build(),
Underline : NewBasicStyleBuilder(BColorNone , BColorNone, TextStyleUnderline).Build(),
Blink : NewBasicStyleBuilder(BColorNone , BColorNone, TextStyleBlink).Build(),
Reverse : NewBasicStyleBuilder(BColorNone , BColorNone, TextStyleReverse).Build(),
Reverse : NewBasicStyleBuilder(BColorNone , BColorNone, TextStyleInverse).Build(),
// Common combinations
Error : NewBasicStyleBuilder(BColorRed , BColorNone, TextStyleBold).Build(),

@ -53,13 +53,13 @@ package ansi
type (
ANSIStyle string
Style string
)
func (s ANSIStyle) Apply (text string) string {
func (s Style) Stylize(text string) string {
if s == "" {
return text
}
@ -73,14 +73,14 @@ func (s ANSIStyle) Apply (text string) string {
}
func (s ANSIStyle) Begin () string {
func (s Style) CodeBegin() string {
if len(s) == 0 {
return ""
}
return string(s)
}
func (s ANSIStyle) End() string {
func (s Style) CodeEnd() string {
if len(s) == 0 {
return ""
}

@ -65,7 +65,7 @@ func NewBasicStyleBuilder(fgcolor, bgcolor BasicColor, txStyle TextStyle) *Basic
s := &BasicStyleBuilder{
fgColor : fgcolor.sanitize(),
bgColor : bgcolor.sanitize(),
txStyle : txStyle.sanitize(),
txStyle : txStyle,
}
return s
}
@ -75,7 +75,7 @@ func (s *BasicStyleBuilder) FgColor () BasicColor { return s.fgColor }
func (s *BasicStyleBuilder) BgColor () BasicColor { return s.bgColor }
func (s *BasicStyleBuilder) TxStyle () TextStyle { return s.txStyle }
func (s *BasicStyleBuilder) TextStyle () TextStyle { return s.txStyle }
@ -90,12 +90,17 @@ func (s *BasicStyleBuilder) SetBgColor (color BasicColor) *BasicStyleBuilder {
}
func (s *BasicStyleBuilder) SetTextStyle (txtStyle TextStyle) *BasicStyleBuilder {
s.txStyle = txtStyle.sanitize()
s.txStyle = txtStyle
return s
}
func (s *BasicStyleBuilder) Build () ANSIStyle {
func (s *BasicStyleBuilder) AddStyle (txtStyle TextStyle) { s.txStyle = s.txStyle.Add(txtStyle) }
func (s *BasicStyleBuilder) DelStyle (txtStyle TextStyle) { s.txStyle = s.txStyle.Del(txtStyle) }
func (s *BasicStyleBuilder) Build () Style {
bf := make([]byte, 0,defaultAnsiBufferSize)
bf = append(bf,ansiCodeBegin...)
hc := false
@ -116,7 +121,7 @@ func (s *BasicStyleBuilder) Build () ANSIStyle {
if s.txStyle != 0 {
bf = s.txStyle.appendStyles(bf, hc)
}
return ANSIStyle(bf)
return Style(bf)
}

@ -0,0 +1,79 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero capabilities.go
Package ansi
Autor Juan V. Navarro juanvnl@activething.com
Creado 19/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
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.
CapStyleDim
CapStyleItalic // Soporte para texto en cursiva.
CapStyleUnderline // Soporte para texto subrayado.
CapStyleBlink
CapStyleInverse
CapStyleHidden
CapStyleStrike
CapNone Capabilities = 0 // El terminal no soporta nada.
)
type (
Capabilities uint16
)

@ -1,10 +1,10 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero style_builder.go
Package ansi3
Fichero capabilities_detect.go
Package ansi
Autor Juan V. Navarro juanvnl@activething.com
Creado 17/08/2025
Creado 19/08/2025
—————————————————————————————————————————————————————————————————————————————
LICENSES AND TERMS OF USE
@ -46,74 +46,55 @@
—————————————————————————————————————————————————————————————————————————————
Copyright (c) 2025 Active Thing
————————————————————————————————————————————————————————————————————————————— */
package ansi
//go:build !windows
package ansi
type (
styleBuilder struct {
fgColor []byte
bgColor []byte
tStyle []byte
}
import (
"os"
"strings"
)
func (s *styleBuilder) FGColorCode () string { return string(s.fgColor) }
func (s *styleBuilder) BGColorCode () string { return string(s.bgColor) }
// DetectTerminalCapabilities detecta capacidades de terminal sin ejecutar nada externo.
func DetectTerminalCapabilities() Capabilities {
if _, ok := os.LookupEnv("NO_COLOR"); ok {
return CapNone
}
func (s *styleBuilder) TextStyle () string { return string(s.tStyle ) }
term := os.Getenv("TERM")
if term == "dumb" {
return CapNone
}
var caps Capabilities
func (s *styleBuilder) SetTextStyle (txtStyle TextStyle) {
s.tStyle = s.tStyle[0:]
if txtStyle &= textStyleMask; txtStyle == 0 {
return
// --- Estilos: heurística ---
// La mayoría de terminales modernos soportan bold, underline e italic.
switch {
case strings.Contains(term, "xterm"), strings.Contains(term, "screen"),
strings.Contains(term, "tmux"), strings.Contains(term, "rxvt"),
strings.Contains(term, "kitty"), strings.Contains(term, "wezterm"):
caps |= CapStyleBold | CapStyleItalic | CapStyleUnderline | CapStyleBlink | CapStyleInverse
// Strike y Hidden menos comunes, se asume false
}
hasCode := false
for i,info := range textStylesInfos {
if txtStyle&(1<<i) != 0 {
if hasCode {
s.tStyle = append(s.tStyle, ansiCodeSep)
}
s.tStyle = append(s.tStyle, info.cd...)
hasCode = true
}
// --- Colores ---
colorTerm := os.Getenv("COLORTERM")
if strings.Contains(colorTerm, "truecolor") || strings.Contains(colorTerm, "24bit") {
caps |= CapTrueColor | Cap256Color | CapBasicColor
} else if strings.Contains(term, "256color") {
caps |= Cap256Color | CapBasicColor
} else if strings.Contains(term, "color") {
caps |= CapBasicColor
}
return caps
}
func (s *styleBuilder) Build() ANSIStyle {
lp := len(s.fgColor)+len(s.bgColor)+len(s.tStyle)
if lp == 0 {
return ""
}
hs := false
bf := make([]byte,0,defaultAnsiBufferSize)
bf = append(bf,ansiCodeBegin...)
if len(s.fgColor) > 0 {
bf = append(bf, s.fgColor...)
hs = true
}
if len(s.bgColor) > 0 {
if hs {
bf = append(bf, ansiCodeSep)
} else {
hs = true
}
bf = append(bf, s.bgColor...)
}
if len(s.tStyle) > 0 {
if hs {
bf = append(bf, ansiCodeSep)
}
bf = append(bf, s.tStyle...)
}
return ANSIStyle(append(bf,ansiCodeEndStyle))
}

@ -0,0 +1,78 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero capabilities_detect_windows.go
Package ansi
Autor Juan V. Navarro juanvnl@activething.com
Creado 19/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
————————————————————————————————————————————————————————————————————————————— */
//go:build windows
package ansi
import (
"os"
"strings"
)
func DetectTerminalCapabilities() Capabilities {
// Respeta NO_COLOR y FORCE_COLOR
if _, ok := os.LookupEnv("NO_COLOR"); ok {
return CapNone
}
if _, ok := os.LookupEnv("FORCE_COLOR"); ok {
return CapTrueColor | Cap256Color | CapBasicColor |
CapStyleBold | CapStyleItalic | CapStyleUnderline
}
// Terminales modernos en Windows (Windows Terminal, VSCode)
if os.Getenv("WT_SESSION") != "" ||
strings.Contains(strings.ToLower(os.Getenv("TERM_PROGRAM")), "vscode") {
return CapTrueColor | Cap256Color | CapBasicColor |
CapStyleBold | CapStyleItalic | CapStyleUnderline
}
// Consola clásica (cmd.exe, PowerShell sin soporte ANSI completo)
return CapBasicColor
}

@ -72,7 +72,7 @@ func NewIndexStyleBuilder(fgcolor, bgcolor IndexColor, txtStyle TextStyle) *Inde
return &IndexStyleBuilder{
fgColor: fgcolor.sanitize(),
bgColor: bgcolor.sanitize(),
txStyle: txtStyle.sanitize(),
txStyle: txtStyle,
}
}
@ -88,20 +88,25 @@ func (s *IndexStyleBuilder) SetBgColor (color IndexColor) *IndexStyleBuilder {
}
func (s *IndexStyleBuilder) SetTextStyle (txtStyle TextStyle) *IndexStyleBuilder {
s.txStyle = txtStyle.sanitize()
s.txStyle = txtStyle
return s
}
func (s *IndexStyleBuilder) AddStyle (txtStyle TextStyle) { s.txStyle = s.txStyle.Add(txtStyle) }
func (s *IndexStyleBuilder) DelStyle (txtStyle TextStyle) { s.txStyle = s.txStyle.Del(txtStyle) }
func (s *IndexStyleBuilder) FgColor () IndexColor { return s.fgColor }
func (s *IndexStyleBuilder) BgColor () IndexColor { return s.bgColor }
func (s *IndexStyleBuilder) TxStyle () TextStyle { return s.txStyle }
func (s *IndexStyleBuilder) TextStyle () TextStyle { return s.txStyle }
func (s *IndexStyleBuilder) Build () ANSIStyle {
func (s *IndexStyleBuilder) Build () Style {
bf := make([]byte, 0,defaultAnsiBufferSize)
bf = append(bf,ansiCodeBegin...)
hc := false
@ -124,5 +129,5 @@ func (s *IndexStyleBuilder) Build () ANSIStyle {
if s.txStyle != 0 {
bf = s.txStyle.appendStyles(bf, hc)
}
return ANSIStyle(bf)
return Style(bf)
}

@ -51,7 +51,7 @@ package ansi
const (
maxBitsTextStyle = 6
maxBitsTextStyle = 8
textStyleMask = (1 << maxBitsTextStyle)-1
)
@ -64,8 +64,9 @@ const (
TextStyleItalic
TextStyleUnderline
TextStyleBlink
TextStyleReverse
TextStyleInverse
TextStyleHidden
TextStyleStrike
)
@ -79,22 +80,30 @@ type (
func (s TextStyle) HasBold () bool { return s&TextStyleBold != 0 }
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) HasItalic() bool { return s&TextStyleItalic != 0 }
func (s TextStyle) HasInverse () bool { return s&TextStyleInverse != 0 }
func (s TextStyle) HasUnderline() bool { return s&TextStyleUnderline != 0 }
func (s TextStyle) HasHidden () bool { return s&TextStyleHidden != 0 }
func (s TextStyle) HasBlink() bool { return s&TextStyleBlink != 0 }
func (s TextStyle) HasStrikethrogh () bool { return s&TextStyleStrike != 0 }
func (s TextStyle) HasReverse() bool { return s&TextStyleReverse != 0 }
func (s TextStyle) HasDim () bool { return s&TextStyleDim != 0 }
func (s TextStyle) Add (txtStyle TextStyle) TextStyle { return s|txtStyle }
func (s TextStyle) Del (txtStyle TextStyle) TextStyle { return s &^ txtStyle }
func (s TextStyle) sanitize() TextStyle { return TextStyle(s & textStyleMask) }
//func (s TextStyle) sanitize() TextStyle { return s & textStyleMask }

@ -0,0 +1,64 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero theme.go
Package ansi
Autor Juan V. Navarro juanvnl@activething.com
Creado 19/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 (
Theme struct {
Name string
Default Style
Styles []string
Dark []string
}
)

@ -1,7 +1,7 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero rgb_color.go
Fichero true_color.go
Package ansi3
Autor Juan V. Navarro juanvnl@activething.com
Creado 17/08/2025
@ -52,17 +52,17 @@ package ansi
type (
RGBColor struct {
TrueColor struct {
R,G,B uint8
}
)
func MakeRGBColor(r, g, b uint8) RGBColor { return RGBColor{r, g, b} }
func MakeTrueColor(r, g, b uint8) TrueColor { return TrueColor{r, g, b} }
func (c RGBColor) Has() bool { return c.R|c.G|c.B != 0 }
func (c TrueColor) Has() bool { return c.R|c.G|c.B != 0 }

@ -1,7 +1,7 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero rgb_style_builder.go
Fichero true_style_builder.go
Package ansi3
Autor Juan V. Navarro juanvnl@activething.com
Creado 17/08/2025
@ -54,8 +54,8 @@ import (
)
const(
rgbAnsiForeg = "38;2;"
rgbAnsiBackg = "48;2;"
trueAnsiForeg = "38;2;"
trueAnsiBackg = "48;2;"
)
const(
@ -66,55 +66,60 @@ const(
type (
RGBStyleBuilder struct {
fgColor RGBColor
bgColor RGBColor
TrueStyleBuilder struct {
fgColor TrueColor
bgColor TrueColor
txStyle TextStyle
}
)
func NewRGBStyleBuilder(fgcolor, bgcolor RGBColor, txtStyle TextStyle) *RGBStyleBuilder {
return &RGBStyleBuilder{
func NewTrueStyleBuilder(fgcolor, bgcolor TrueColor, txtStyle TextStyle) *TrueStyleBuilder {
return &TrueStyleBuilder{
fgColor: fgcolor,
bgColor: bgcolor,
txStyle: txtStyle.sanitize(),
txStyle: txtStyle,
}
}
func (s *RGBStyleBuilder) SetFgColor (color RGBColor) *RGBStyleBuilder {
func (s *TrueStyleBuilder) SetFgColor (color TrueColor) *TrueStyleBuilder {
s.fgColor = color
return s
}
func (s *RGBStyleBuilder) SetBgColor (color RGBColor) *RGBStyleBuilder {
func (s *TrueStyleBuilder) SetBgColor (color TrueColor) *TrueStyleBuilder {
s.bgColor = color
return s
}
func (s *RGBStyleBuilder) SetTextStyle (txtStyle TextStyle) *RGBStyleBuilder {
s.txStyle = txtStyle.sanitize()
func (s *TrueStyleBuilder) SetTextStyle (txtStyle TextStyle) *TrueStyleBuilder {
s.txStyle = txtStyle
return s
}
func (s *TrueStyleBuilder) AddStyle (txtStyle TextStyle) { s.txStyle = s.txStyle.Add(txtStyle) }
func (s *RGBStyleBuilder) FgColor () RGBColor { return s.fgColor }
func (s *TrueStyleBuilder) DelStyle (txtStyle TextStyle) { s.txStyle = s.txStyle.Del(txtStyle) }
func (s *RGBStyleBuilder) BgColor () RGBColor { return s.bgColor }
func (s *RGBStyleBuilder) TxStyle () TextStyle{ return s.txStyle }
func (s *TrueStyleBuilder) FgColor () TrueColor { return s.fgColor }
func (s *TrueStyleBuilder) BgColor () TrueColor { return s.bgColor }
func (s *RGBStyleBuilder) Build () ANSIStyle {
func (s *TrueStyleBuilder) TextStyle () TextStyle { return s.txStyle }
func (s *TrueStyleBuilder) Build () Style {
bf := make([]byte, 0,defaultAnsiBufferSize)
bf = append(bf,ansiCodeBegin...)
hc := false
if s.fgColor.Has() {
bf = append(bf,rgbAnsiForeg...)
bf = append(bf, trueAnsiForeg...)
bf = strconv.AppendUint(bf,uint64(s.fgColor.R), 10); bf = append(bf,ansiCodeSep)
bf = strconv.AppendUint(bf,uint64(s.fgColor.G), 10); bf = append(bf,ansiCodeSep)
bf = strconv.AppendUint(bf,uint64(s.fgColor.B), 10)
@ -126,7 +131,7 @@ func (s *RGBStyleBuilder) Build () ANSIStyle {
} else {
hc = true
}
bf = append(bf,rgbAnsiBackg...)
bf = append(bf, trueAnsiBackg...)
bf = strconv.AppendUint(bf,uint64(s.bgColor.R), 10); bf = append(bf,ansiCodeSep)
bf = strconv.AppendUint(bf,uint64(s.bgColor.G), 10); bf = append(bf,ansiCodeSep)
bf = strconv.AppendUint(bf,uint64(s.bgColor.B), 10)
@ -138,6 +143,6 @@ func (s *RGBStyleBuilder) Build () ANSIStyle {
}
return ANSIStyle(bf)
return Style(bf)
}

@ -0,0 +1,70 @@
/* ——————————————————————————————————————————————————————————————————————————
Proyecto WIAWAIW
—————————————————————————————————————————————————————————————————————————————
Fichero g_option.go
Package opts
Autor Juan V. Navarro juanvnl@activething.com
Creado 19/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 opts
type (
GOptionFnc [T any] func(*T)
)
func Apply [T any](target *T, opts...GOptionFnc[T]){
for _,o := range opts {
o(target)
}
}
func ApplyFluent [T any](target *T, opts...GOptionFnc[T]) *T {
for _,o := range opts {
o(target)
}
return target
}
Loading…
Cancel
Save

Powered by TurnKey Linux.