├── examples ├── README.md └── readme-image.odin ├── .github ├── FUNDING.yml ├── PULL_REQUEST_TEMPLATE │ ├── bug_resolution.md │ └── feature_impl_request.md └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── mod.pkg ├── ols.json ├── .gitignore ├── LICENSE ├── DOCS.md ├── README.md └── color.odin /examples/README.md: -------------------------------------------------------------------------------- 1 | # odin-color - Examples -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: hrszpuk 4 | -------------------------------------------------------------------------------- /mod.pkg: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.1-beta", 3 | "description": "A simple color pacakge for Odin.", 4 | "url": "https://github.com/hrszpuk/odin-color", 5 | "readme": "README.md", 6 | "license": "MIT", 7 | "keywords": ["color", "console", "terminal", "remy"] 8 | } -------------------------------------------------------------------------------- /ols.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json", 3 | "collections": [ 4 | { 5 | "name": "core", 6 | "path": "/usr/lib/odin/core" 7 | } 8 | ], 9 | "enable_document_symbols": true, 10 | "enable_semantic_tokens": false, 11 | "enable_hover": true, 12 | "enable_snippets": true 13 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | *.bin 34 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/bug_resolution.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug resolution 3 | about: A solution or correction to an pre-existing bug issue 4 | title: '' 5 | labels: bug 6 | assignees: hrszpuk 7 | 8 | --- 9 | 10 | **Link to issue** 11 | Quick link to issue with details about the bug. 12 | 13 | **Changes** 14 | Please create a brief bullet point list of the changes made to fix the bug: 15 | 16 | **Desktop (please complete the following information):** [Remove if you're the issue author] 17 | - OS: [e.g. Windows, MacOS, Linux] 18 | - Version [e.g. 10, Snow Big Sur, Arch] 19 | 20 | **Additional context** 21 | Add any other context about the problem/solution here. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: hrszpuk 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/feature_impl_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature implementation request 3 | about: Suggest an implementation of an existing feature request 4 | title: '' 5 | labels: enhancement 6 | assignees: hrszpuk 7 | 8 | --- 9 | 10 | **Link to issue** 11 | Quick link to issue with details about the feature request. 12 | 13 | **Changes** 14 | Please create a brief bullet point list of the changes or additions made to implement the feature: 15 | 16 | **Desktop (please complete the following information):** [Remove if you're the issue author] 17 | - OS: [e.g. Windows, MacOS, Linux] 18 | - Version [e.g. 10, Snow Big Sur, Arch] 19 | 20 | **Additional context** 21 | Add any other context about the problem/solution here. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report about something that isn't quite right... 4 | title: '' 5 | labels: bug 6 | assignees: hrszpuk 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Desktop (please complete the following information):** 23 | - OS: [e.g. Windows, MacOS, Linux] 24 | - Version [e.g. 10, Snow Big Sur, Arch] 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /examples/readme-image.odin: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import color ".." 4 | import "core:fmt" 5 | 6 | main :: proc() { 7 | using color 8 | fg_colors := [?]proc(string)->string{ 9 | black, red, green, yellow, blue, magenta, cyan, white, 10 | bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white, 11 | } 12 | bg_colors := [?]proc(string)->string{ 13 | on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white, 14 | on_bright_black, on_bright_red, on_bright_green, on_bright_yellow, on_bright_blue, on_bright_magenta, on_bright_cyan, on_bright_white, 15 | } 16 | for bg in bg_colors { 17 | for fg in fg_colors { 18 | fmt.printf("%s ", bg(fg("odin"))) 19 | } 20 | fmt.println() 21 | } 22 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Remy 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 deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /DOCS.md: -------------------------------------------------------------------------------- 1 | # odin-color - Documentation 2 | 3 | ## Functions 4 | 5 | ```odin 6 | // Below are all the available color functions. 7 | // Each wrap a string in ANSI color codes: COLOR + s + RESET 8 | black(string) -> string 9 | red(string) -> string 10 | green(string) -> string 11 | yellow(string) -> string 12 | blue(string) -> string 13 | magenta(string) -> string 14 | cyan(string) -> string 15 | ``` 16 | For background color, simply add `on_` prefix to the start of each function (`on_red()` for example). 17 | FOr bright colors add `bright_` prefix to the start of each function (`bright_red()`). 18 | For bright background colors add `on_bright_` prefix to the start of each function (`on_bright_red()`). 19 | 20 | ## Constants 21 | You can also use the color constants. 22 | 23 | ```odin 24 | // Usage: 25 | fmt.println(RED + "Hello, " + BRIGHT_BLUE + "World!" + RESET) 26 | 27 | // Foreground colors + reset 28 | RESET 29 | BLACK 30 | RED 31 | GREEN 32 | YELLOW 33 | BLUE 34 | MAGENTA 35 | CYAN 36 | WHITE 37 | 38 | // Background colors 39 | ON_BLACK 40 | ON_RED 41 | ON_GREEN 42 | ON_YELLOW 43 | ON_BLUE 44 | ON_MAGENTA 45 | ON_CYAN 46 | ON_WHITE 47 | 48 | // Foreground, bright colors 49 | BRIGHT_BLACK 50 | BRIGHT_RED 51 | BRIGHT_GREEN 52 | BRIGHT_YELLOW 53 | BRIGHT_BLUE 54 | BRIGHT_MAGENTA 55 | BRIGHT_CYAN 56 | BRIGHT_WHITE 57 | 58 | // Background, bright colors 59 | ON_BRIGHT_BLACK 60 | ON_BRIGHT_RED 61 | ON_BRIGHT_GREEN 62 | ON_BRIGHT_YELLOW 63 | ON_BRIGHT_BLUE 64 | ON_BRIGHT_MAGENTA 65 | ON_BRIGHT_CYAN 66 | ON_BRIGHT_WHITE 67 | ``` 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Odin color 2 | A simple ANSI color package similar to Rust's colored crate. 3 | 4 | [![hrszpuk - odin-color](https://img.shields.io/static/v1?label=hrszpuk&message=odin-color&color=blue&logo=github)](https://github.com/hrszpuk/odin-color "Go to GitHub repo") 5 | [![stars - odin-color](https://img.shields.io/github/stars/hrszpuk/odin-color?style=social)](https://github.com/hrszpuk/odin-color) 6 | [![forks - odin-color](https://img.shields.io/github/forks/hrszpuk/odin-color?style=social)](https://github.com/hrszpuk/odin-color) 7 | [![GitHub release](https://img.shields.io/github/release/hrszpuk/odin-color?include_prereleases=&sort=semver&color=blue)](https://github.com/hrszpuk/odin-color/releases/) 8 | [![License](https://img.shields.io/badge/License-MIT-blue)](#license) 9 | [![issues - odin-color](https://img.shields.io/github/issues/hrszpuk/odin-color)](https://github.com/hrszpuk/odin-color/issues) 10 | 11 | ![image](https://github.com/hrszpuk/odin-color/assets/107559570/3946ebe3-470c-4913-bc3d-ce262e16989b) 12 | 13 | [Read more in our documentation](https://github.com/hrszpuk/odin-color/blob/main/DOCS.md) 14 | or [check out some examples](https://github.com/hrszpuk/odin-color/blob/main/examples/readme-image.odin) 15 | 16 | ## Installation 17 | 18 | ### Submodule 19 | Create an external folder in your project's root directory. 20 | Add the project as a submodule like in the example below: 21 | ``` 22 | git submodule add https://github.com/hrszpuk/odin-color.git external/odin-color 23 | ``` 24 | Import the package using a relative path: `import color "./external/odin-color`. 25 | 26 | ### Shared collection 27 | Download the repository code using git and place the folder in your shared/external collection directory. 28 | Import the package using `import color "collection-name:odin-color"` and build/run with the flag `--collection:collection-name=/path/to/collection`. 29 | 30 | 31 | -------------------------------------------------------------------------------- /color.odin: -------------------------------------------------------------------------------- 1 | package color 2 | 3 | import "core:fmt" 4 | 5 | @(private = "package") 6 | ESC :: "\033[" 7 | 8 | RESET :: ESC + "0m" 9 | BLACK :: ESC + "30m" 10 | RED :: ESC + "31m" 11 | GREEN :: ESC + "32m" 12 | YELLOW :: ESC + "33m" 13 | BLUE :: ESC + "34m" 14 | MAGENTA :: ESC + "35m" 15 | CYAN :: ESC + "36m" 16 | WHITE :: ESC + "37m" 17 | 18 | ON_BLACK :: ESC + "40m" 19 | ON_RED :: ESC + "41m" 20 | ON_GREEN :: ESC + "42m" 21 | ON_YELLOW :: ESC + "43m" 22 | ON_BLUE :: ESC + "44m" 23 | ON_MAGENTA :: ESC + "45m" 24 | ON_CYAN :: ESC + "46m" 25 | ON_WHITE :: ESC + "47m" 26 | 27 | BRIGHT_BLACK :: ESC + "90m" 28 | BRIGHT_RED :: ESC + "91m" 29 | BRIGHT_GREEN :: ESC + "92m" 30 | BRIGHT_YELLOW :: ESC + "93m" 31 | BRIGHT_BLUE :: ESC + "94m" 32 | BRIGHT_MAGENTA :: ESC + "95m" 33 | BRIGHT_CYAN :: ESC + "96m" 34 | BRIGHT_WHITE :: ESC + "97m" 35 | 36 | ON_BRIGHT_BLACK :: ESC + "100m" 37 | ON_BRIGHT_RED :: ESC + "101m" 38 | ON_BRIGHT_GREEN :: ESC + "102m" 39 | ON_BRIGHT_YELLOW :: ESC + "103m" 40 | ON_BRIGHT_BLUE :: ESC + "104m" 41 | ON_BRIGHT_MAGENTA :: ESC + "105m" 42 | ON_BRIGHT_CYAN :: ESC + "106m" 43 | ON_BRIGHT_WHITE :: ESC + "107m" 44 | 45 | // taken from hrszpuk/odin-color:dev: 46 | // Styles 47 | 48 | BOLD :: ESC + "1m" 49 | DIM :: ESC + "2m" 50 | ITALIC :: ESC + "3m" 51 | UNDERLINE :: ESC + "4m" 52 | BLINKING :: ESC + "5m" 53 | INVERSE :: ESC + "7m" 54 | HIDDEN :: ESC + "8m" 55 | STRIKETHROUGH :: ESC + "9m" 56 | 57 | // Style resets 58 | 59 | BOLD_RESET :: ESC + "22m" 60 | DIM_RESET :: ESC + "22m" 61 | ITALIC_RESET :: ESC + "23m" 62 | UNDERLINE_RESET :: ESC + "24m" 63 | BLINKING_RESET :: ESC + "25m" 64 | INVERSE_RESET :: ESC + "27m" 65 | HIDDEN_RESET :: ESC + "28m" 66 | STRIKETHROUGH_RESET :: ESC + "29m" 67 | 68 | 69 | @(private = "package") 70 | color :: proc(color, input: string, allocator := context.allocator) -> string { 71 | return fmt.aprintf("%s%s%s", color, input, RESET, allocator = allocator) 72 | } 73 | 74 | black :: proc(input: string, allocator := context.allocator) -> string { 75 | return color(BLACK, input, allocator = allocator) 76 | } 77 | 78 | red :: proc(input: string, allocator := context.allocator) -> string { 79 | return color(RED, input, allocator = allocator) 80 | } 81 | 82 | green :: proc(input: string, allocator := context.allocator) -> string { 83 | return color(GREEN, input, allocator = allocator) 84 | } 85 | 86 | yellow :: proc(input: string, allocator := context.allocator) -> string { 87 | return color(YELLOW, input, allocator = allocator) 88 | } 89 | 90 | blue :: proc(input: string, allocator := context.allocator) -> string { 91 | return color(BLUE, input, allocator = allocator) 92 | } 93 | 94 | magenta :: proc(input: string, allocator := context.allocator) -> string { 95 | return color(MAGENTA, input, allocator = allocator) 96 | } 97 | 98 | cyan :: proc(input: string, allocator := context.allocator) -> string { 99 | return color(CYAN, input, allocator = allocator) 100 | } 101 | 102 | white :: proc(input: string, allocator := context.allocator) -> string { 103 | return color(WHITE, input, allocator = allocator) 104 | } 105 | 106 | on_white :: proc(input: string, allocator := context.allocator) -> string { 107 | return color(ON_WHITE, input, allocator = allocator) 108 | } 109 | 110 | on_black :: proc(input: string, allocator := context.allocator) -> string { 111 | return color(ON_BLACK, input, allocator = allocator) 112 | } 113 | 114 | on_red :: proc(input: string, allocator := context.allocator) -> string { 115 | return color(ON_RED, input, allocator = allocator) 116 | } 117 | 118 | on_green :: proc(input: string, allocator := context.allocator) -> string { 119 | return color(ON_GREEN, input, allocator = allocator) 120 | } 121 | 122 | on_yellow :: proc(input: string, allocator := context.allocator) -> string { 123 | return color(ON_YELLOW, input, allocator = allocator) 124 | } 125 | 126 | on_blue :: proc(input: string, allocator := context.allocator) -> string { 127 | return color(ON_BLUE, input, allocator = allocator) 128 | } 129 | 130 | on_magenta :: proc(input: string, allocator := context.allocator) -> string { 131 | return color(ON_MAGENTA, input, allocator = allocator) 132 | } 133 | 134 | on_cyan :: proc(input: string, allocator := context.allocator) -> string { 135 | return color(ON_CYAN, input, allocator = allocator) 136 | } 137 | 138 | bright_white :: proc(input: string, allocator := context.allocator) -> string { 139 | return color(BRIGHT_WHITE, input, allocator = allocator) 140 | } 141 | 142 | bright_black :: proc(input: string, allocator := context.allocator) -> string { 143 | return color(BRIGHT_BLACK, input, allocator = allocator) 144 | } 145 | 146 | bright_red :: proc(input: string, allocator := context.allocator) -> string { 147 | return color(BRIGHT_RED, input, allocator = allocator) 148 | } 149 | 150 | bright_green :: proc(input: string, allocator := context.allocator) -> string { 151 | return color(BRIGHT_GREEN, input, allocator = allocator) 152 | } 153 | 154 | bright_yellow :: proc(input: string, allocator := context.allocator) -> string { 155 | return color(BRIGHT_YELLOW, input, allocator = allocator) 156 | } 157 | 158 | bright_blue :: proc(input: string, allocator := context.allocator) -> string { 159 | return color(BRIGHT_BLUE, input, allocator = allocator) 160 | } 161 | 162 | bright_magenta :: proc(input: string, allocator := context.allocator) -> string { 163 | return color(BRIGHT_MAGENTA, input, allocator = allocator) 164 | } 165 | 166 | bright_cyan :: proc(input: string, allocator := context.allocator) -> string { 167 | return color(BRIGHT_CYAN, input, allocator = allocator) 168 | } 169 | 170 | on_bright_black :: proc(input: string, allocator := context.allocator) -> string { 171 | return color(ON_BRIGHT_BLACK, input, allocator = allocator) 172 | } 173 | 174 | on_bright_red :: proc(input: string, allocator := context.allocator) -> string { 175 | return color(ON_BRIGHT_RED, input, allocator = allocator) 176 | } 177 | 178 | on_bright_green :: proc(input: string, allocator := context.allocator) -> string { 179 | return color(ON_BRIGHT_GREEN, input, allocator = allocator) 180 | } 181 | 182 | on_bright_yellow :: proc(input: string, allocator := context.allocator) -> string { 183 | return color(ON_BRIGHT_YELLOW, input, allocator = allocator) 184 | } 185 | 186 | on_bright_blue :: proc(input: string, allocator := context.allocator) -> string { 187 | return color(ON_BRIGHT_BLUE, input, allocator = allocator) 188 | } 189 | 190 | on_bright_magenta :: proc(input: string, allocator := context.allocator) -> string { 191 | return color(ON_BRIGHT_MAGENTA, input, allocator = allocator) 192 | } 193 | 194 | on_bright_cyan :: proc(input: string, allocator := context.allocator) -> string { 195 | return color(ON_BRIGHT_CYAN, input, allocator = allocator) 196 | } 197 | 198 | on_bright_white :: proc(input: string, allocator := context.allocator) -> string { 199 | return color(ON_BRIGHT_WHITE, input, allocator = allocator) 200 | } 201 | --------------------------------------------------------------------------------