V1.1.0 - RGB Tupples in ColorRGB, Extended UTIL #2
Chaosyr
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
NUGET Package Link: https://www.nuget.org/packages/Cecil.ANSI_Utils/
THIS VERSIONS README;
Cecil ANSI Utilities
Copyright 2025 Cecil Libraries Organization and the Founder(s) Chaosyr
FAQ's/Project Intro
What is Cecil Libraries?
Cecil Libraries are a group of libraries in which extend functionality to many API and provide utilities as a Pseudo-API for several necessity's.
Who is Cecil?
Both a Member of the Vessel Chaosyr, and the Mascot of our Libraries. Mascot wise she is as originally described by Chaosyr "10ft tall, raven, succubus, whom is Bi, Poly, and a Femboy". That's as far as we are with her at the moment, if more details arrive it will be on the Organizations main page, figured we'd fill in for the case anyone's wondering what the logo stems from.
What is this Library for?
This library is primarily for enabling the ability to utilize ANSI Color Codes on a much greater scope within the Console associated with most Console Apps. It also contains some functions for converting HSV/HSL, Gray and Hex Code into RGB. Note HSL/HSV rounding is slightly off somewhere by a point or two in present so it might not be perfect.
Library Documentation (Ansi Utils)
This will probably be easier to navigate through in the GitHub's Wiki, however this will just be as in depth as the Wiki will be, so everything you need will be within this very file, the Code is also fully commented if you wish to jump straight into coding. If any explanations are weaker than other let us know so we can fix it up!
The Color List's
These list's stem I believe all the way back to Chaosyr's AP Computer Science Principles Project when they were making a Book Displayer Console App of sorts.
First off the Most Useful tool for seeing how these work would be calling
Displayer.DisplayListBased(), this will iterate through every Color List we have in this project in a really nice to look and understand at way. If you're too lazy to call it here's a few Screenshots.Regular
Taken In Microsoft's Command Prompt
Taken In Microsoft's Command Prompt
Taken In Microsoft's Command Prompt
High Intensity
Taken In Microsoft's Command Prompt
Taken In Microsoft's Command Prompt
Taken In Microsoft's Command Prompt
Calls
Calling the Lists are pretty straightforward. But essentially call
ANSICodeListsthan apply a.WhateverListThisIsto the end of it, and to choose an Entry append a[X]to the end of it, theXbeing the Entry Number shown in the above screenshots. For exampleANSICodeLists.ColorList[4]would be Blue on the Regular list, apologies for any weird namings, these Lists are Old, the names will likely be standardized in the future, though it's highly recommended to use the Color Objects instead as it's much easier to work with.GetColorFromType
These Functions Stem from a Mod Chaosyr made to enable ANSI in the BepInEx Console. They are also marked as Obsolete now as the Color Objects are much better to work with. So how do I use them? Well first you will need the context of the below tables for Inputs, there's a reminder of them in the functions Code Comments. Also for reference this utilizes the List's within ANSICodeLists to simplify the process [still overly complex though].
Type List;
Colors
Calls
Now how would you call this functionality? Well as follows;
GetColorFromType.GetColorFromString(Color, Type)orGetColorFromInt.GetColorFromInt(Color, Type). Again these are marked as Obsolete, and it is recommended that you instead use the Color Objects this library provides.Reset Codes
These are pretty straight forward, there are 3 hard coded constants provided for Resets, one for Everything, one for Foreground affects and one for Background affects e.g. Colors, the resets for the Text Types are in the Objects or bundled in the Everything Reset.
Calls
ANSICodeLists.ResetColorthis resets all effects done to the foreground, background, and all Text Types to default.ANSICodeLists.ResetForegroundthis resets all effects done to the foreground.ANSICodeLists.ResetBackgroundthis resets all effects done to the background.Color Object
This is a more refined system for doing basic stuff with ANSI Color Codes, it was made for the purpose of being in this Project. Beware this will be a long section because it's a powerful Object. So first off let's go over the getters and setters of the Object.
Getters and Setters
Now let's move onto the Constructors, these are pretty much the same but there is a few differences.
Construction
Since the Types and Colors can be both String and Int we need to define both luckily we already defined it in the GetColorFromType so let's take that and modify it to match the new setup.
Type List;
Colors
Okay now back to the Constructor, there are 3 optional bool's all defaulting to false, here's how they work;
Some takeaways about these 3 items;
.GetReset().Format()on both to do the same effect, we may add a Function that gets a "Full" reset of sorts in the future.reset: truein the constructor, this way the order isn't relevant, and you don't need to dofalseon all properties irrelevant, as they all default false.Now let's get into the Object's Functions.
GetReset()
This function pretty much just says, hey this is our current object, lets just pass back the same object EXCEPT, reset is marked as True. This works because you need to do
.Format()in order to get the code anyhow, and both the constructor and the.Format()handle reset Objects already.GetTypeString()
This function pretty much just says oh, we have this Type, and we had a String switch already to make it an integer, lets reverse the integers last digit back to the original string and send that back. This has little to no use case off the top of my head and is mainly utilized for the Displayer associated with the Color object.
Format()
This function is vital to displaying the Code onto the screen so it takes affect. What this does well, in laymen's terms it formats the Variables in the Object into a Proper ANSI Escape Code for Colors. Though it's a bit more complex, and I'd recommend checking out the code to see the full of what it does! Same for the Constructors if you have not!
GetTypeVariant(string/int type) 1.1.0+
This function essentially says, so this is our current object, lets take that and give it the type your after.
GetColorVariant(string/int color) 1.1.0+
This function does similar to GetTypeVariant() however, it affects the set color instead.
ToggleBackground() 1.1.0+
This function just switches the State of the Foreground to Background and vice versa for the Object given.
ToggleHighIntensity() 1.1.0+
This function just switches the State of the HighIntensity to LowIntensity and vice versa for the Object given.
Displayer
There is a Displayer associated with this Object to show all possibilities, you can call it via
Displayer.DisplayColor(), this one I'd run yourself sense almost every console displays it differently for some reason The first screenshot is taken with JetBrains Rider, and the latter is taken with Microsoft's built-in Windows 11 Terminal. I show both rather than just Rider because Microsoft's Terminal actually handles the Underlight correctly (claps), however at the same time for some reason when Dulled Italic and Underlined are next to each other it decides to underline all 3 of them?!?! In fact double underline applied for Dulled and Italic, each mode is reset after usage for record so that shouldn't even be possible. But that's asides the point XDTaken in JetBrains Rider
Taken In Microsoft's Command Prompt
Calls
So you may be wondering, well how do I utilize this Object within my own code? Here's an Example taken from the Tester used in Development of how you can use it, in fact two examples.
Example 1
Taken In Microsoft's Command Prompt
So what is this doing? Well it's pretty straightforward, we are creating in this case 4 Color Objects [GetReset() did not exist yet], after creating these objects which are essentially Set Red with Highlight, Unset Highlight, Set Red, Unset Red, we test them by printing a line note how each Object in the printed line is followed by
.Format()this is a required component so the ANSI Code actually prints and causes the format to change, note Legacy consoles will display the exact code instead, you can change this by enabling VirtualMachineProcessing at least on Windows.Example 2
Taken In Microsoft's Command Prompt
You may have noticed this is nearly identical to Test 2, and that's intentional, in this case we are enabling highIntensity and the background booleans so we change the background color versus the foreground one, and so that the colors appear brighter. Again notice that
.Format()is required to display the color change properly.Example 3
Lastly let me show you the Displayer Code so you can see how to utilize
.Reset()You already saw what this outputs in the Displayer section, so allow me to explain how the code works. In this case we start by looping through the 8 shades available in the Object. Within this Loop, we create a Color Object of the current iterated color, and set up the start of the printed line, being the
$"{baseColor.Format()}Entry {i}: "what this does is set the color to the current iterated color, and set up the Entry with its associated number. What's next? We loop through all possible types for the current color. In this nested loop we do the following, create a typedColor e.g. a color which is set to the iterators color, and to the current type in iteration. After we do that we append the printed line with the following;$"{typedColor.Format()}{typedColor.GetTypeString()}{typedColor.GetReset().Format()}"it looks really complex but, it's not. What this is doing in a nutshell is this; Setting the Color and the current Mode to print, since we don't know the Types Name we callGetTypeString()to fetch it, and then after this we Reset the mode back to just the iterators color via.GetReset().Format(), this is essentially formatting the code of the outputted reset fromGetReset(). Think of it as this; Set Mode, Say Something, Unset Mode. Once we clear the type loop, we print the line and append$"{baseColor.GetReset().Format()}"this says Reset Color, this way we ensure that the next line has the correct colors applied. Afterward we do a check by mod of 15 [not applicable here but applicable in 256] to pause the loop so that the person running the display can actually see the options they have. After we iterated through all colors, then we send the standard press enter to proceed.Color256
This is a more refined system for doing basic stuff with ANSI Color Codes, it was made for the purpose of being in this Project. Beware this will be a long section because it's a powerful Object. So first off let's go over the getters and setters of the Object.
Getters and Setters
Now let's move onto the Constructors, these are pretty much the same but there's a few differences.
Construction
Since the Types can be both String and Int we need to define both luckily we already defined it in the GetColorFromType so let's take that and modify it to match the new setup.
Type List;
Okay now back to the Constructor, the shade parameter is a value of 0-255, there are also 2 optional bool's all defaulting to false, here's how they work;
Some takeaways about these 2 items;
.GetReset().Format()on both to do the same effect, we may add a Function that gets a "Full" reset of sorts in the future.reset: truein the constructor, this way the order isn't relevant, and you don't need to dofalseon all properties irrelevant, as they all default false.Now let's get into the Object's Functions.
GetReset()
This function pretty much just says, hey this is our current object, lets just pass back the same object EXCEPT, reset is marked as True. This works because you need to do
.Format()in order to get the code anyhow, and both the constructor and the.Format()handle reset Objects already.GetTypeString()
This function pretty much just says oh, we have this Type, and we had a String switch already to make it an integer, lets reverse the integers last digit back to the original string and send that back. This has little to no use case off the top of my head and is mainly utilized for the Displayer associated with the Color object.
Format()
This function is vital to displaying the Code onto the screen so it takes affect. What this does well, in laymen's terms it formats the Variables in the Object into a Proper ANSI Escape Code for Colors. Though it's a bit more complex, and I'd recommend checking out the code to see the full of what it does! Same for the Constructors if you have not!
GetTypeVariant(string/int type) 1.1.0+
This function essentially says, so this is our current object, lets take that and give it the type your after.
GetColorVariant(int color) 1.1.0+
This function does similar to GetTypeVariant() however, it affects the set color instead.
ToggleBackground() 1.1.0+
This function just switches the State of the Foreground to Background and vice versa for the Object given.
Displayer
There is a Displayer associated with this Object to show all possibilities, you can call it via
Displayer.DisplayColor256(), it'll look similar to the one outlined in the Color Object, also because there's a ton of them, there won't be screenshots so, I encourage you run it yourself!!! And yeah it has the same display issues that were mentioned on the Color Object (would be really cool if they were fixed if your listening Microsoft, and if you brought back Blinking)Calls
So you may be wondering, well how do I utilize this Object within my own code? Here's an Example taken from the Tester used in Development of how you can use it.
Example 1
Taken in Microsoft Command Prompt
How this works? It creates four Color256 Objects, two Setters, two Unsetters. Then prints a line that does the following; Sets the Color, says something, sets a highlight, says something, unsets the highlight, says something, unsets the color, says something.
Example 2
Taken In JetBrains Rider
This was explained better in the Color Object, but here's what this does, iterates over every possible color the object can use, creates a Color256 for the BaseColor, creates a line in which sets that color and states the current Entry Number, iterates over all possible types, creates a Color256 for the Type, appends it to the printed line in the form of a Set, Say, Unset, once it's done iterating the types it prints the line, and appends an unset for the iterated color, every 15 goes it pauses to let the user read the entries and see what each are. Then, follows suit with the normal Press Enter To Proceed so that the app doesn't just close out once all entries are gone through.
ColorRGB
This Object is similar to the Color and Color256 Objects, however here's the kicker, ColorRGB supports all RGB Colors!!! Plus we have some extensions to convert Gray, HSL/HSV, and Hex codes into RGB, which will be covered in the next section.
Getters and Setters
Let's start by covering the Getters and Setters of the Object
With that out of the way lets delve into the Constructors in which are provided.
Constructors
The below table is associated with the first variable of the constructor; the Types e.g. the Text Processing Modes in which are provided for ANSI.
Type List;
Okay now back to the Constructor, After the Type you chose, there are 3 parameters that follow these correlate with; Red, Green, Blue, each are a 0-255 integer, there are also 2 optional bool's all defaulting to false, here's how they work;
Some takeaways about these 2 items;
.GetReset().Format()on both to do the same effect, we may add a Function that gets a "Full" reset of sorts in the future.reset: truein the constructor, this way the order isn't relevant, and you don't need to dofalseon all properties irrelevant, as they all default false.GetReset()
This function pretty much just says, hey this is our current object, lets just pass back the same object EXCEPT, reset is marked as True. This works because you need to do
.Format()in order to get the code anyhow, and both the constructor and the.Format()handle reset Objects already.GetTypeString()
This function pretty much just says oh, we have this Type, and we had a String switch already to make it an integer, lets reverse the integers last digit back to the original string and send that back. This has little to no use case off the top of my head and is mainly utilized for the Displayer associated with the Color object.
Format()
This function is vital to displaying the Code onto the screen so it takes affect. What this does well, in laymen's terms it formats the Variables in the Object into a Proper ANSI Escape Code for Colors. Though it's a bit more complex, and I'd recommend checking out the code to see the full of what it does! Same for the Constructors if you have not!
GetTypeVariant(string/int type) 1.1.0+
This function essentially says, so this is our current object, lets take that and give it the type your after.
GetColorVariant(int red, int green, int blue/Tupple(int red, int green, int blue)) 1.1.0+
This function does similar to GetTypeVariant() however, it affects the set color instead.
ToggleBackground() 1.1.0+
This function just switches the State of the Foreground to Background and vice versa for the Object given.
Displayer
So while we do have a Displayer with
Displayer.DisplayColorRGB(), it will take an hour or so to complete so, I would advise instead opening an Art Program or similar and using the Color Picker to choose a color. Plus it also doesn't have a functional [had a pause but, it only worked in one iteration of green so removed it] pausing system.That said if anyone makes a video slowed down of the Displayer running I can link it here, because it is really satisfying to watch and pretty useful for seeing what works against the console or not, just would not recommend the current system for it!!!
Calls
These examples are pretty much the same as Color and Color256's so these won't be too wordy as its already explained twice!
Example 1
Taken in JetBrains Rider
Within this example, again we make 4 Color Objects this time ColorRGB, 2 sets, 2 unsets, all associated with
RGB(64, 56, 56). After we set these up we print a testing message in the vein of; Turn color on for the background, Turn Highlight on, turn Highlight off, turn color off for the background. Note once more that the.Format()is required for it to print properly.Example 2
This one's more complex but as an Example here is our current RGB Displayer setup.
Taken in Microsoft Command Prompt
So what this does is essentially starts a loop through all 256 shads of red, followed by all 256 shades of green, followed by all 256 shades of blue. Once we are in the Blue loop we set up the iterator color, filling in a
0for Normal color, and the r, g, and b iteration values. Afterwards we start the print line of Color On, Entry R G B. Than we loop through all possible types, and create a typed color in that loop. With that typed color we add to the printing line essentially Turn Type On, Print Type, Turn Type Off and Space, this repeats until we reach the end of the code block for the loop. Once we exit the type loop we add Color Off and print the line. This one doesn't have a pause, frankly because I couldn't get it working, which is why I do not recommend it. However, it's beautiful to watch.RGB Conversions
Now let's dig into the RGB Convertors and how to use them. As of 1.1.0 you can now pass the output tupples directly into the ColorRGB Object.
FromHex(string Code)
For this one you simply need to pass in either something like "#ffffff" or "ffffff", because hex is base 16 it must be a string. How it works internally is trimming the start of the code of
#'s, than converting each split of 2 characters in the code from base 16 into base 10, than returns the RGB values that were outputted.Now here's an example from the Tester of how you can use it.
Example 1
Taken in JetBrains Rider
So here's what this piece of code is doing, First it gets the RGB pair from the Hex Conversion of "#aa55cb". Then it takes that color and makes two ColorRGB's from it, setting the mode to Regular (e.g. normal color), followed by the returned R G B from the hex conversion, one a reset one a set. Lastly it prints a line attempting to see if the color converted properly with a
Format()for turning the Hex on and off, and feeds back the results it got from the math it did. And that's pretty much all there is to it!!FromGrayscale(int Gray)
So code wise this is the simplest one by far, essentially what it does is take the passed in gray and set that gray to each R G B value and returns it.
Here's an Example from the Tester on how to use it!!
Example 1
Taken in JetBrains Rider
Code wise this does the same thing as the HEX conversion, however it is a grayscale instead, and yes the Resultants should be the same number ats the input three times.
FromHueShadeValue(int hue, int shade, int value)
This one's probably one of the trickier ones to explain on a coding frontier plus its off slightly in rounding but here's what it does;
BackToRGB()for the associated combination.BackToRGB()it takes the floats passed in and does the following to the RGB values.Now here's an example of how you can use it without needing to know all of that Math!
Example 1
Taken in JetBrains Rider
Again similar to the last two code wise except this time it converts from an HSV pair to an RGB. Also, the R and B value are off by 2 digits from the math not sure as to where it stems but yeah ^^
FromHueSaturationLightness(int hue, int saturation, int lightness)
This one is also one of the trickier ones code wise but here's what it does broken down.
BackToRGB()for the associated combination.BackToRGB()it takes the floats passed in and does the following to the RGB values.Alright now let's get into the example from the Tester
Example 1
Taken in JetBrains Rider
Again pretty much identical to the prior examples just this time it utilizes HSL instead, this one is off by 1 in the R and B and 2 in the G, again not sure where the rounding errors stem from.
Credits;
Attribution to Guides we looked at;
License(s);
Cecil Libraries License (1.0.0)
Copyright 2025 Cecil Libraries Organization and the Founder(s) Chaosyr
In the case where it so falls that a Sub-License and this License conflicts, this License dictates.
Also, any Licenses applied to this Product outside of this License are deemed as Sub-Licenses unless otherwise stated.
Key Terms
This section likely self-explanatory goes over any Key Terms that may be unfamiliar to those looking at this License and seeing if their Project breaks it.
Founder Clause
This clause goes over all right's in which the Founder has over the Product this License affects.
Contributor's Clause
This will both go over any right's Contributors have over their code included in the Product, and any requirements for their contribution's to this Product.
Right's of the Contributor
This sections goes over all right's in which the Contributor has over the usage of their Code within the Product this License affects.
Responsibilities of the Contributor
This section goes over all responsibilities Contributors must follow when working with this Product's Code Base.
[Obsolete]in the code base and may not be deleted.Developer's Clauses
This section will go over 3 clauses related to Developers along with a generalized set of rights among all Developers.
Mod Makers Clause
This section will go over usage of this Product by Mod Makers.
Game Developer's Clause
This section will go over usage of this Product by Game Developers.
Software Developer's Clause
This section will go over usage of this product by Software Developers.
Developer's Clause
This section will go over usage of this product by all Developers, this clause also applies to the aforementioned Developer's as well.
End User's Clause
This section will go over the rights of the End User, i.e. the Consumer who has this Product installed from another Project that uses the Product.
SaxbyMod's License (Branched off of the MIT License)
Copyright 2025 SaxbyMod
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Additionally, any software that is published, or derived from this project must credit the author(s) of this project.
If this is to be published code may not match in a 1:1, there must be some alteration.
Alterations not allowed would be for example changing of comments, stripping of comments, adding of comments, changing variable names, changing variable types, or adding or removing variables that make no change to the code.
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 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Full Changelog: v1.0.1...v1.1.0
Support Discord;
Beta Was this translation helpful? Give feedback.
All reactions