From bf3699257d8d001273137227ec1a1da580a7dce6 Mon Sep 17 00:00:00 2001 From: surdeus Date: Wed, 5 Jun 2024 16:18:54 +0500 Subject: [PATCH] feat: started implementing AES. --- aes/colors.go | 57 ++++++++++++++++++++++++++++++++++++++++++++ aes/es.go | 27 +++++++++++++++++++++ aes/shortcut.go | 30 +++++++++++++++++++++++ cmd/termsize/main.go | 5 +++- 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 aes/colors.go create mode 100644 aes/es.go create mode 100644 aes/shortcut.go diff --git a/aes/colors.go b/aes/colors.go new file mode 100644 index 0000000..8577f40 --- /dev/null +++ b/aes/colors.go @@ -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 +) + + diff --git a/aes/es.go b/aes/es.go new file mode 100644 index 0000000..20838a2 --- /dev/null +++ b/aes/es.go @@ -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" +) + diff --git a/aes/shortcut.go b/aes/shortcut.go new file mode 100644 index 0000000..683589d --- /dev/null +++ b/aes/shortcut.go @@ -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) +} + diff --git a/cmd/termsize/main.go b/cmd/termsize/main.go index aac0c90..2a480eb 100644 --- a/cmd/termsize/main.go +++ b/cmd/termsize/main.go @@ -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", + ) } }