You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This release adds:
- 256 Color and True Color support and enabler for Windows Console
- `White` and `HiWhite` as inbuilt colors
- Terminal detection for Unix and Windows System and also for rounding off True Color into 4 bit or 8 bit as max supported by the terminal.
- Deprecates `box.Output` for Windows
- Major Code Cleanup
- More comments for better understanding of the CodeBase
- Doc improvements
It has color support from [fatih/color](https://github.com/fatih/color) module from which this module uses `FgColor` and `FgHiColor`. `Color` is a key for the following maps:
164
+
It has color support from [gookit/color](github.com/gookit/color) module from which this module uses `FgColor` and `FgHiColor`. `Color` is a key for the following maps:
166
165
167
166
```go
168
-
varfgColors = map[string]color.Attribute{
169
-
"Black": color.FgBlack,
170
-
"Blue": color.FgBlue,
171
-
"Red": color.FgRed,
172
-
"Green": color.FgGreen,
173
-
"Yellow": color.FgYellow,
174
-
"Cyan": color.FgCyan,
175
-
"Magenta": color.FgMagenta,
167
+
fgColors map[string]color.Color = {
168
+
"Black": color.FgBlack,
169
+
"Blue": color.FgBlue,
170
+
"Red": color.FgRed,
171
+
"Green": color.FgGreen,
172
+
"Yellow": color.FgYellow,
173
+
"Cyan": color.FgCyan,
174
+
"Magenta": color.FgMagenta,
175
+
"White": color.FgWhite,
176
176
}
177
177
178
-
varfgHiColors = map[string]color.Attribute{
179
-
"HiBlack": color.FgHiBlack,
180
-
"HiBlue": color.FgHiBlue,
181
-
"HiRed": color.FgHiRed,
182
-
"HiGreen": color.FgHiGreen,
183
-
"HiYellow": color.FgHiYellow,
184
-
"HiCyan": color.FgHiCyan,
185
-
"HiMagenta": color.FgHiMagenta,
178
+
fgHiColors map[string]color.Color = {
179
+
"HiBlack": color.FgDarkGray,
180
+
"HiBlue": color.FgLightBlue,
181
+
"HiRed": color.FgLightRed,
182
+
"HiGreen": color.FgLightGreen,
183
+
"HiYellow": color.FgLightYellow,
184
+
"HiCyan": color.FgLightCyan,
185
+
"HiMagenta": color.FgLightMagenta,
186
+
"HiWhite": color.FgLightWhite,
186
187
}
187
188
```
188
189
189
-
If you want High Intensity Colors then the Color name should start with `Hi`. If Color option is empty or invalid then Box with default Color is formed.
190
+
If you want High Intensity Colors then the Color name must start with `Hi`. If Color option is empty or invalid then Box with default Color is formed.
191
+
192
+
True Color is possible though you need to provide it as `uint` or `[3]uint` and make sure that the terminals which will be targetted must have it supported.
190
193
191
-
You can also have more 16 Colors but the terminals must be 24 bit and the `Color` field must be provided either as `[3]uint` or `uint` though the elements of the array must be in a range of `[0x0, 0xFF]` and `uint`must be in a range of `[0x000000, 0xFFFFFF]`.
194
+
`[3]uint`'s element all must be in a range of `[0, 0xFF]` and `uint`in range of `[0x000000, 0xFFFFFF]`.
192
195
193
-
If you want to use the string representation of the `Box` and print them for [`Windows Console`](https://en.wikipedia.org/wiki/Windows_Console) then you would have to use `box.Output` as the passing stream to the respective functions.
196
+
As convenience, if the terminal's doesn't support True Color then it will round off according to the terminal's max supported colors which makes it easier for the users not to worry about other terminal for most of the cases.
194
197
195
-
`Windows Console` is 4 bit (16 colors) so Custom Colors will not work for them but the `Box` will be printed correctly without the Color effect.
198
+
Here's a list of 24 bit [supported terminals](https://gist.github.com/XVilka/8346728) and 8 bit [supported terminals](https://fedoraproject.org/wiki/Features/256_Color_Terminals).
199
+
200
+
This module also enables **True Color** and **256 Colors** support on Windows Console through [Virtual Terminal Processing](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) but you need have at least [Windows 10 Version 1511](https://en.wikipedia.org/wiki/Windows_10_version_history_(version_1511)) for 256 colors or [Windows 10 Version 1607](https://en.wikipedia.org/wiki/Windows_10_version_history_(version_1607)) for True Color Support.
201
+
202
+
4 bit Color are now supported by every terminal now so there is no list for them unlike the above ones.
196
203
197
204
### Note
198
205
@@ -204,11 +211,25 @@ As different terminals have different font by default so the right vertical alig
204
211
205
212
It uses [mattn/go-runewidth](https://github.com/mattn/go-runewidth) for Unicode and Emoji support though there are some limitations:
206
213
207
-
-`Windows Terminal` and `Windows SubSystem Linux` are the only know terminals which can render Unicode and Emojis properly on Windows.
208
-
-Marathi Text only works on very few Terminals as less support it.
209
-
- It is recommended not to use Online Playgrounds like [`Go Playground`](https://play.golang.org/) and [`Repl.it`](https://repl.it) because they use a font that only has ASCII support and other Character Set is used which becomes problematic for finding the length as the font changes during runtime.
214
+
-`Windows Terminal` and `Mintty` are the only know terminal emulators which can render Unicode and Emojis properly on Windows.
215
+
-Indic Text only works on very few Terminals as less support it.
216
+
- It is recommended not to use this for Online Playgrounds like [`Go Playground`](https://play.golang.org/) and [`Repl.it`](https://repl.it), `CI/CDs` etc. because they use a font that only has ASCII support and other Character Set is used which becomes problematic for finding the length as the font changes during runtime.
210
217
- Change your font which supports Unicode and Emojis else the right vertical alignment will break.
211
218
219
+
#### Terminal Color Detection
220
+
221
+
It is possible to round off true color provided to 8 bit or 16 bit according to your terminal's maximum capacity.
222
+
223
+
There is no **standardized way** of detecting the terminal's maximum color capacity so the way of detecting your terminal might not work for you. If this can be fixed for you then you can always make a PR.
224
+
225
+
If you think that the module can't detect True Color of the terminal then you must set your environment variable `COLORTERM` to `truecolor` or `24bit` for True Color support.
226
+
227
+
If you are targetting 8 bit color based terminals and if the module couln't detect it then set your environment variable `TERM` to name of the terminal emulator with `256color` as suffix like `xterm-256color`.
228
+
229
+
There might be no color effect for very old terminals like [`Windows Console (Legacy Mode)`](https://docs.microsoft.com/en-us/windows/console/legacymode) or environment variable `TERM` give `DUMB` so it will output some garbage value or a warning if used.
230
+
231
+
In `Online Playgrounds`, `CI/CDs`, `Browsers` etc, it is recommended **not** to use this module with color effect as few may have it but this is hard to detect in general. If you think that it's possible then open an issue and address the solution!
232
+
212
233
### Acknowledgements
213
234
214
235
I thank the following people and their packages whom I have studied and was able to port to Go accordingly.
0 commit comments