You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
6.6 KiB
164 lines
6.6 KiB
/* ——————————————————————————————————————————————————————————————————————————
|
|
Proyecto WIAWAIW
|
|
—————————————————————————————————————————————————————————————————————————————
|
|
Fichero capabilities.go
|
|
Package ansi2
|
|
Autor Juan V. Navarro juanvnl@activething.com
|
|
Creado 28/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 ansi2
|
|
|
|
|
|
import "strings"
|
|
|
|
const (
|
|
maxCapabilities = 15
|
|
)
|
|
|
|
const (
|
|
|
|
|
|
|
|
CanFormatBold Capabilities = 1 << iota // 1 (negrita)
|
|
CanFormatFaint // 2 (atenuado)
|
|
CanFormatItalic // 3 (cursiva)
|
|
CanFormatUnderline // 4 (subrayado)
|
|
CanFormatSlowBlink // 5 (parpadeo lento)
|
|
CanFormatRapidBlink // 6 (parpadeo rápido)
|
|
CanFormatReverse // 7 (inverso)
|
|
CanFormatConceal // 8 (oculto)
|
|
CanFormatCrossedOut // 9 (tachado)
|
|
CanFormatFramed // 51 (enmarcado)
|
|
CanFormatEncircled // 52 (encerrado en círculo)
|
|
CanFormatOverlined
|
|
|
|
|
|
|
|
CanBasicColor //Capabilities = 1 << 12
|
|
Can256Color //Capabilities = 1 << 13
|
|
CanTrueColor //Capabilities = 1 << 14
|
|
|
|
CanNone Capabilities = 0 // El terminal no soporta nada.
|
|
|
|
|
|
|
|
CanAllColor = CanBasicColor | Can256Color | CanTrueColor
|
|
|
|
CanAllStyle = CanFormatBold | CanFormatFaint | CanFormatItalic |
|
|
CanFormatUnderline | CanFormatSlowBlink| CanFormatRapidBlink | CanFormatReverse
|
|
|
|
CanAllExtended = CanAllStyle | CanFormatConceal | CanFormatCrossedOut|
|
|
CanFormatFramed | CanFormatOverlined| CanFormatEncircled
|
|
|
|
CanAll = CanAllColor | CanAllStyle | CanAllExtended
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
Capabilities uint16
|
|
)
|
|
|
|
|
|
|
|
// Métodos para verificar capacidades de color
|
|
|
|
func (c Capabilities) CanColorType (ct ColorType) bool {
|
|
switch ct {
|
|
case ColorTypeNone : return true
|
|
case ColorTypeBasic : return c&CanBasicColor != 0
|
|
case ColorTypeIndex : return c&Can256Color != 0
|
|
case ColorTypeTrue : return c&CanTrueColor != 0
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func (c Capabilities) CanBasicColor () bool { return c&CanBasicColor != 0 }
|
|
func (c Capabilities) Can256Color () bool { return c&Can256Color != 0 }
|
|
func (c Capabilities) CanTrueColor () bool { return c&CanTrueColor != 0 }
|
|
func (c Capabilities) CanAnyColor () bool { return c&CanAllColor != 0 }
|
|
|
|
// Métodos para verificar capacidades de estilo
|
|
|
|
func (c Capabilities) CanFormatBold () bool { return c&CanFormatBold != 0 }
|
|
func (c Capabilities) CanFormatFaint () bool { return c&CanFormatFaint != 0 }
|
|
func (c Capabilities) CanFormatItalic () bool { return c&CanFormatItalic != 0 }
|
|
func (c Capabilities) CanFormatUnderline () bool { return c&CanFormatUnderline != 0 }
|
|
func (c Capabilities) CanFormatSlowBlink () bool { return c&CanFormatSlowBlink != 0 }
|
|
func (c Capabilities) CanFormatRapidBlink () bool { return c&CanFormatRapidBlink != 0 }
|
|
func (c Capabilities) CanFormatReverse () bool { return c&CanFormatReverse != 0 }
|
|
func (c Capabilities) CanFormatConceal () bool { return c&CanFormatConceal != 0 }
|
|
|
|
// Métodos para capacidades extendidas
|
|
|
|
func (c Capabilities) CanFormatCrossedOut () bool { return c&CanFormatCrossedOut != 0 }
|
|
func (c Capabilities) CanFormatFramed () bool { return c&CanFormatFramed != 0 }
|
|
func (c Capabilities) CanFormatEncircled () bool { return c&CanFormatEncircled != 0 }
|
|
func (c Capabilities) CanFormatOverlined () bool { return c&CanFormatOverlined != 0 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c Capabilities) String () string {
|
|
if c == 0 {
|
|
return ""
|
|
}
|
|
cs := make([]string, 0, maxCapabilities)
|
|
for i := 0; i < maxCapabilities; i++ {
|
|
if c&1<<i != 0 {
|
|
cs = append(cs, capNames[i])
|
|
}
|
|
}
|
|
return strings.Join(cs, "|")
|
|
}
|
|
|
|
|