feat: started implementing AES.

This commit is contained in:
Andrey Parhomenko 2024-06-05 16:18:54 +05:00
parent 95c9037391
commit bf3699257d
4 changed files with 118 additions and 1 deletions

57
aes/colors.go Normal file
View file

@ -0,0 +1,57 @@
package aes
import "strings"
import "strconv"
//import "fmt"
type Effect int
type Effects []Effect
func (effects Effects) Format() string {
intStrs := make([]string, len(effects))
for i, e := range effects {
intStrs[i] = strconv.Itoa(int(e))
}
return strings.Join(intStrs, ";")
}
const (
EffectReset Effect = iota
EffectBold
EffectDim
EffectItalic
EffectUnderline
EffectBlinking
)
const (
EffectInverse Effect = 7 + iota
EffectHidden
// Effect strikethrough.
EffectStirke
)
const (
EffectBlackFG = 30 + iota
EffectRedFG
EffectGreenFG
EffectYellowFG
EffectBlueFG
EffectMagentaFG
EffectCyanFG
EffectWhiteFG
EffectDefaultFG
)
const (
EffectBlackBG Effect = 40 + iota
EffectRedBG
EffectGreenBG
EffectYellowBG
EffectBlueBG
EffectMagentaBG
EffectCyanBG
EffectWhiteBG
EffectDefaultBG
)

27
aes/es.go Normal file
View file

@ -0,0 +1,27 @@
package aes
const (
// Start.
ESC = "\x1B"
// Control sequence introducer.
CSI = ESC+"["
// Device control string.
DCS = ESC+"P"
// Operating system command.
OSC = ESC+"]"
)
const (
BEL = "\a"
BS = "\b"
HT = "\t"
LF = "\n"
VT = "\v"
FF = "\f"
CR = "\r"
DEL = "\x7F"
)

30
aes/shortcut.go Normal file
View file

@ -0,0 +1,30 @@
package aes
import "fmt"
type EffectText struct {
Effects Effects
Text string
}
func (et EffectText) String() string {
return fmt.Sprintf(
CSI+"%sm%s"+CSI+"0m",
et.Effects.Format(), et.Text,
)
}
func ETF(format string, v ...any) EffectText {
ret := EffectText{}
ret.Text = fmt.Sprintf(format, v...)
return ret
}
func (et EffectText) With(effects ...Effect) EffectText {
et.Effects = append(et.Effects, effects...)
return et
}
func (et EffectText) Bold() EffectText {
return et.With(EffectBold)
}

View file

@ -4,6 +4,7 @@ import "surdeus.su/core/cli/tx"
import "log"
import "os"
import "io"
import "surdeus.su/core/cli/aes"
//import "fmt"
func main() {
@ -32,7 +33,9 @@ func main() {
if key == tx.KeyControlC {
break
}
term.Printf("shit: %q\r\n", key)
term.Print(
"shit:", aes.ETF("%q", key).Bold().With(aes.EffectRedFG), "\r\n",
)
}
}