├── main.go ├── LICENSE ├── README.md └── pkg └── gostyle.go /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/EvilBytecode/GolangStyle/pkg" 5 | ) 6 | 7 | func main() { 8 | //console init, changing title clearing it and setting adjustement 9 | if err := gostyle.Init(); err != nil { 10 | gostyle.Write("Failed to init console:", gostyle.RED_TO_BLACK, false) 11 | return 12 | } 13 | // clears console (anything in there will be cleaned aka cls) 14 | gostyle.ClearConsole() 15 | // hides console cursor 16 | gostyle.HideCursor() 17 | // Shows Console Cursor 18 | gostyle.ShowCursor() 19 | // Writes an Ascii with gradient fade 20 | gostyle.Write(` 21 | _____ _____ _ _ 22 | / ____| / ____| | | | 23 | | | __ ___| (___ | |_ _ _| | ___ 24 | | | |_ |/ _ \\___ \| __| | | | |/ _ \ 25 | | |__| | (_) |___) | |_| |_| | | __/ 26 | \_____|\___/_____/ \__|\__, |_|\___| 27 | __/ | 28 | |___/ 29 | `, gostyle.PURPLE_TO_BLUE, true) 30 | 31 | gostyle.WriteColorized("Best Looking Color Library written in Go for Windows", "red", true) 32 | gostyle.Write("Coded by Evilbytecode & MMCopyMemory", gostyle.BLUE_TO_PURPLE, true) 33 | gostyle.Write(` 34 | Follow us on github: 35 | https://github.com/MmCopyMemory 36 | https://github.com/Evilbytecode 37 | `, gostyle.BLUE_TO_PURPLE, true) 38 | gostyle.Write("Without MMCopyMemory this wouldnt exist, follow him!", nil, true) 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 EvilBytecode 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to use the Software for educational and authorized cybersecurity research purposes only, subject to the following conditions: 7 | 8 | The above copyright notice, this permission notice, and the following disclaimer shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS (INCLUDING EvilBytecode) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 12 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE, COPYING, DOWNLOADING, OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | DISCLAIMER: I, EvilBytecode, release this project strictly for educational, academic, and authorized cybersecurity research purposes. 15 | By accessing, downloading, copying, using, or modifying this software, you agree to these terms. 16 | You must obtain explicit written permission from system owners before conducting any testing using this software. 17 | Unauthorized use, distribution, or deployment of this software against any third party, device, network, or system without prior consent is strictly forbidden and illegal. 18 | I, EvilBytecode, disclaim all responsibility, liability, or consequences arising from any misuse, illegal activities, damages, or losses resulting from this software. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoStyle (DONT USE NOT RELIABLE AT ALL + WIN ONLY) 2 | Best Looking Windows Color Library made for Go users! 3 | 4 | 5 | ![ConsoleLooks](https://github.com/EvilBytecode/GolangStyle/assets/151552809/d1bb0610-2c74-4049-b37e-797fb5c4d345) 6 | 7 | ## Install 8 | - ```go mod init bestcolorlib``` 9 | - ```go get github.com/EvilBytecode/GolangStyle/pkg``` 10 | - ```go run .``` 11 | 12 | ## GoStyle Functions 13 | 14 | - Sample README that provides documentation for the functions in the GoStyle package. 15 | ## `Init() error` 16 | 17 | - **Description:** Initializes the console, comes with simple error handle. 18 | - **Sample Usage:** 19 | ```go 20 | if err := gostyle.Init(); err != nil { 21 | gostyle.Write("Failed to init console:", gostyle.RED_TO_BLACK, false) 22 | return 23 | } 24 | ``` 25 | 26 | ## `ClearConsole()` 27 | 28 | - **Description:** Clears the console. Anything currently displayed will be removed. 29 | - **Sample Usage:** 30 | ```go 31 | gostyle.ClearConsole() 32 | ``` 33 | 34 | ## `HideCursor()` 35 | 36 | - **Description:** Hides the console cursor. 37 | - **Sample Usage:** 38 | ```go 39 | gostyle.HideCursor() 40 | ``` 41 | 42 | ## `ShowCursor()` 43 | 44 | - **Description:** Shows the console cursor. 45 | - **Sample Usage:** 46 | ```go 47 | gostyle.ShowCursor() 48 | ``` 49 | 50 | ## `Write(text string, gradient gostyle.Gradient, true/false)` 51 | 52 | - **Description:** Writes text to the console with an optional gradient and centers it based on your choice. 53 | - **Parameters:** 54 | - `text string`: Text to be written to the console. 55 | - `gradient gostyle.Gradient`: Optional gradient color for the text. 56 | - `true`: You Decide if it should be in center set true or false based on if you want the text to be centered or not. 57 | - **Sample Usage:** 58 | ```go 59 | gostyle.Write("Your text here", gostyle.PURPLE_TO_BLUE, true) 60 | ``` 61 | 62 | ## `WriteColorized(text string, color string, true/false)` 63 | 64 | - **Description:** Writes text to the console with a specified color and centers it based on your choice. 65 | - **Parameters:** 66 | - `text string`: Text to be written to the console. 67 | - `color string`: Color of the text (e.g., "red", "blue"). 68 | - `true`: You Decide if it should be in center set true or false based on if you want the text to be centered or not. 69 | - **Sample Usage:** 70 | ```go 71 | gostyle.WriteColorized("Your text here", "red", true) 72 | ``` 73 | 74 | ### MORE IN ```main.go``` 75 | 76 | Remember to import the `gostyle` package before using these functions. 77 | ### issues with some ascii styles will be fixed soon, i just need to find time for it. but most of them are supported 78 | ### Credits: 79 | - https://github.com/MmCopyMemory (Lots of help) 80 | - https://github.com/billythegoat356 (GoStyle Idea, From Python to Go) 81 | 82 | 83 | ## License 84 | This project is licensed under the MIT License. See the LICENSE file for details. -------------------------------------------------------------------------------- /pkg/gostyle.go: -------------------------------------------------------------------------------- 1 | package gostyle 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | "strings" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | // please don't skid or you're a noob lol 13 | var ( 14 | k32 = syscall.NewLazyDLL("kernel32.dll") 15 | procSetConsoleMode = k32.NewProc("SetConsoleMode") 16 | procGetConsoleMode = k32.NewProc("GetConsoleMode") 17 | pgsh = k32.NewProc("GetStdHandle") 18 | pgcci = k32.NewProc("GetConsoleCursorInfo") 19 | pscci = k32.NewProc("SetConsoleCursorInfo") 20 | // these are static colors, made for simple printing they are not assosicated with gradients colors at all. 21 | Reset = "\033[0m" 22 | Red = "\033[31m" 23 | Green = "\033[32m" 24 | Yellow = "\033[33m" 25 | Blue = "\033[34m" 26 | Magenta = "\033[35m" 27 | Cyan = "\033[36m" 28 | White = "\033[37m" 29 | // these are gradient colors, there arent assosicated with static ones, these are the colors that have transitions 30 | BLACK_TO_WHITE = []int{0, 0, 0, 255, 255, 255} 31 | BLACK_TO_RED = []int{0, 0, 0, 255, 0, 0} 32 | BLACK_TO_GREEN = []int{0, 0, 0, 0, 255, 0} 33 | BLACK_TO_BLUE = []int{0, 0, 0, 0, 0, 255} 34 | WHITE_TO_BLACK = []int{255, 255, 255, 0, 0, 0} 35 | WHITE_TO_RED = []int{255, 255, 255, 255, 0, 0} 36 | WHITE_TO_GREEN = []int{255, 255, 255, 0, 255, 0} 37 | WHITE_TO_BLUE = []int{255, 255, 255, 0, 0, 255} 38 | RED_TO_BLACK = []int{255, 0, 0, 0, 0, 0} 39 | RED_TO_WHITE = []int{255, 0, 0, 255, 255, 255} 40 | RED_TO_YELLOW = []int{255, 0, 0, 255, 255, 0} 41 | RED_TO_PURPLE = []int{255, 0, 0, 255, 0, 255} 42 | GREEN_TO_BLACK = []int{0, 255, 0, 0, 0, 0} 43 | GREEN_TO_WHITE = []int{0, 255, 0, 255, 255, 255} 44 | GREEN_TO_YELLOW = []int{0, 255, 0, 255, 255, 0} 45 | GREEN_TO_CYAN = []int{0, 255, 0, 0, 255, 255} 46 | BLUE_TO_BLACK = []int{0, 0, 255, 0, 0, 0} 47 | BLUE_TO_WHITE = []int{0, 0, 255, 255, 255, 255} 48 | BLUE_TO_CYAN = []int{0, 0, 255, 0, 255, 255} 49 | BLUE_TO_PURPLE = []int{0, 0, 255, 255, 0, 255} 50 | YELLOW_TO_RED = []int{255, 255, 0, 255, 0, 0} 51 | YELLOW_TO_GREEN = []int{255, 255, 0, 0, 255, 0} 52 | PURPLE_TO_RED = []int{255, 0, 255, 255, 0, 0} 53 | PURPLE_TO_BLUE = []int{255, 0, 255, 0, 0, 255} 54 | CYAN_TO_GREEN = []int{0, 255, 255, 0, 255, 0} 55 | CYAN_TO_BLUE = []int{0, 255, 255, 0, 0, 255} 56 | 57 | // this is init, this makes sure that colors print out successfully 58 | ENABLE_VIRTUAL_TERMINAL_PROCESSING uint32 = 0x0004 59 | ) 60 | 61 | /* 62 | GradientFade applies a gradient color effect to text. 63 | */ 64 | func GradientFade(text string, colors []int) string { 65 | var result string 66 | for i, char := range text { 67 | currentR := int(float64(colors[0]) + (float64(colors[3]-colors[0])/float64(len(text)-1))*float64(i)) 68 | currentG := int(float64(colors[1]) + (float64(colors[4]-colors[1])/float64(len(text)-1))*float64(i)) 69 | currentB := int(float64(colors[2]) + (float64(colors[5]-colors[2])/float64(len(text)-1))*float64(i)) 70 | 71 | result += fmt.Sprintf("\x1b[38;2;%d;%d;%dm%c", currentR, currentG, currentB, char) 72 | } 73 | result += Reset 74 | return result 75 | } 76 | 77 | /* 78 | Init initializes the console with ANSI color support. 79 | */ 80 | 81 | func Init() error { 82 | handle := syscall.Handle(os.Stdout.Fd()) 83 | 84 | var mode uint32 85 | ret, _, err := procGetConsoleMode.Call(uintptr(handle), uintptr(unsafe.Pointer(&mode))) 86 | if ret == 0 { 87 | return err 88 | } 89 | 90 | mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING 91 | 92 | ret, _, err = procSetConsoleMode.Call(uintptr(handle), uintptr(mode)) 93 | if ret == 0 { 94 | return err 95 | } 96 | 97 | return nil 98 | } 99 | 100 | const ( 101 | soh = uint32(-11 & 0xFFFFFFFF) 102 | ) 103 | 104 | type CONSOLE_CURSOR_INFO struct { 105 | Size uint32 106 | Visible int32 107 | } 108 | // gets console handle 109 | func getConsoleHandle() uintptr { 110 | handle, _, _ := pgsh.Call(uintptr(soh)) 111 | return handle 112 | } 113 | // hide console cursror 114 | func HideCursor() { 115 | handle := getConsoleHandle() 116 | var ci CONSOLE_CURSOR_INFO 117 | ci.Size = uint32(unsafe.Sizeof(ci)) 118 | pgcci.Call(handle, uintptr(unsafe.Pointer(&ci))) 119 | ci.Visible = 0 120 | pscci.Call(handle, uintptr(unsafe.Pointer(&ci))) 121 | } 122 | // show console cursor 123 | func ShowCursor() { 124 | handle := getConsoleHandle() 125 | var ci CONSOLE_CURSOR_INFO 126 | ci.Size = uint32(unsafe.Sizeof(ci)) 127 | pgcci.Call(handle, uintptr(unsafe.Pointer(&ci))) 128 | ci.Visible = 1 129 | pscci.Call(handle, uintptr(unsafe.Pointer(&ci))) 130 | } 131 | 132 | /* 133 | CenterText centers text within the console window. 134 | */ 135 | 136 | func CenterText(text string) string { 137 | width, _ := getConsoleWindowSize() 138 | lines := strings.Split(text, "\n") 139 | var centeredText string 140 | for _, line := range lines { 141 | // Calculate visible length after applying color codes 142 | visibleLength := len(line) - strings.Count(line, "\033[")*7 143 | 144 | centeredText += fmt.Sprintf("%*s%s\n", (width-visibleLength)/2, "", line) 145 | } 146 | return centeredText 147 | } 148 | 149 | 150 | 151 | /* 152 | WriteColorized writes colorized text to the console, optionally centering it. 153 | */ 154 | func WriteColorized(text, color string, center bool) { 155 | if center { 156 | text = CenterText(text) 157 | } 158 | formattedText := Colorize(text, color) 159 | fmt.Println(formattedText) 160 | } 161 | 162 | 163 | /* 164 | getConsoleWindowSize retrieves the console window size. 165 | */ 166 | func getConsoleWindowSize() (width, height int) { 167 | kernel32 := syscall.NewLazyDLL("kernel32.dll") 168 | proc := kernel32.NewProc("GetConsoleScreenBufferInfo") 169 | handle, _, _ := kernel32.NewProc("GetStdHandle").Call(uintptr(uint32(uintptr(0xfffffff5)))) 170 | 171 | var info struct{ SizeX, SizeY int16 } 172 | 173 | ret, _, _ := proc.Call(handle, uintptr(unsafe.Pointer(&info))) 174 | if ret == 0 { 175 | return -1, -1 176 | } 177 | // wow no wayyy.. 178 | return int(info.SizeX), int(info.SizeY) 179 | } 180 | 181 | 182 | /* 183 | Colorize applies color to text based on the provided color string. 184 | */ 185 | func Colorize(text, color string) string { 186 | color = strings.ToLower(color) 187 | switch color { 188 | case "red": 189 | return Red + text + Reset 190 | case "green": 191 | return Green + text + Reset 192 | case "yellow": 193 | return Yellow + text + Reset 194 | case "blue": 195 | return Blue + text + Reset 196 | case "magenta": 197 | return Magenta + text + Reset 198 | case "cyan": 199 | return Cyan + text + Reset 200 | case "white": 201 | return White + text + Reset 202 | default: 203 | return text 204 | } 205 | } 206 | /* 207 | Write writes text to the console, optionally applying colors and centering it. 208 | */ 209 | func Write(text string, colors []int, center bool) { 210 | if center { 211 | text = CenterText(text) 212 | } 213 | if len(colors) > 0 { 214 | text = GradientFade(text, colors) 215 | } 216 | lines := strings.Split(text, "\n") 217 | for _, line := range lines { 218 | fmt.Println(line) 219 | } 220 | } 221 | /* 222 | ClearConsole clears the console screen. 223 | */ 224 | 225 | func ClearConsole() { 226 | cmd := exec.Command("cmd", "/c", "cls") 227 | cmd.Stdout = os.Stdout 228 | cmd.Run() 229 | } 230 | --------------------------------------------------------------------------------