Crates.io | easy-sgr-macros |
lib.rs | easy-sgr-macros |
version | 0.1.0 |
source | src |
created_at | 2023-08-08 22:31:57.846831 |
updated_at | 2023-08-08 22:31:57.846831 |
description | The implementation of macros used within easy-sgr |
homepage | https://github.com/4lineclear/easy-sgr/tree/main |
repository | https://github.com/4lineclear/easy-sgr/tree/main |
max_upload_size | |
id | 939582 |
size | 41,853 |
The proc-macro implementation for the easy-sgr crate
The syntax of this crate is a near mirror copy to that of the fmt module, with one addition: SGR keywords.
These keywords get translated to SGR codes at compile time,
using them is similar to formatting variables into string literals
within the fmt crate, as you use block brackets
within curly brackets: {[...]}
to specify them.
Each keyword within is to be separated by spaces.
use easy_sgr::println;
println!("{[bold green on-red]}This is colorful");
println!("{[!bold default on-default]}This is not");
See the rust docs for more
There are a set of 'simple' keywords, which are made up of a word:
reset | bold | dim | italic | underline | blink | inverse | hide | strike
!bold | !dim | !italic | !underline | !blink | !inverse | !hide | !strike
black | red | green | yellow | blue | magenta | cyan | white | default
on-black | on-red | on-green | on-yellow | on-blue | on-magenta | on-cyan | on-white | on-default
{[]}
reset
is a little different than the others in that it is empty.
The more complex syntax is entirely reserved for color codes.
Colors are expected to be one of the following,
optionally prefixed by 'on-
' to indicate being a background color:
u8
-> (38|48);5;u8
u8,u8,u8
-> (38|48);2;u8;u8;u8
And, prefixed with #
to indicate hex,
but without any commas:
#u8
-> (38|48);5;u8
#u8u8u8
-> (38|48);2;u8;u8;u8
so some example colors could be
on-15
-> 48;5;15
15,115,215
-> 38;2;15;115;215
#0f
-> 38;5;15
on-#0f73d7
-> 48;2;15;115;215