This exists because Nim's terminal module is being fucky. Also because Ansi shit is easier to work with than oddly-lacking modules.
If you compile with DISABLE_TRUE_COLOR defined then all code pertaining to true color support will be omitted and the fallback color will be used for any colors you bind from nim's colors module. See mapColor for more information.
If you compile with DISABLE_ALL_COLOR then all color support will be disabled, effectively rendering this module pointless. You might be better off just implementing this on your end, but it is here nonetheless for the sake of quicker debugging in the end
Types
ConColor = object color: int isBg: bool isBold: bool isUnderlined: bool is24bit: bool color_24: Color
Consts
black = (color: 30, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
red = (color: 31, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
green = (color: 32, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
yellow = (color: 33, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
blue = (color: 34, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
magenta = (color: 35, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
cyan = (color: 36, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
white = (color: 37, isBg: false, isBold: false, isUnderlined: false, is24bit: false, color_24: 0)
reset = "\e[0m"
Procs
proc asBg(self: ConColor): ConColor {...}{.raises: [], tags: [].}
- Use the color as the background (This will automatically make it bold most of the time at least on posix shells idk)
proc asBold(self: ConColor): ConColor {...}{.raises: [], tags: [].}
- Set the color as bold. Does nothing if using a 24bit color.
proc asUnderlined(self: ConColor): ConColor {...}{.raises: [], tags: [].}
- Set the underline. Does nothing if using a 24bit color.
proc asDim(self: ConColor): ConColor {...}{.raises: [], tags: [].}
- Set the color as dim (or normal) mode. Does nothing if using a 24bit color.
proc asFg(self: ConColor): ConColor {...}{.raises: [], tags: [].}
- Set the color as foreground if it is already background
proc `$`(self: ConColor): string {...}{.raises: [ValueError], tags: [].}
- Get the ansi escape code for the given color
Templates
template mapColor(col: Color; background = false; fallback = white): ConColor
-
Use this to map colors from nim's colors module.
Please note: not every terminal supports 24bit colors, so fallback is provided to ensure that, should support for it be disabled, your colored text will still be some vague form of colored. This fallback is used when compiled with NO_TRUE_COLOR defined.