prim/source/style/package.d

23 lines
490 B
D
Raw Normal View History

2023-08-09 20:01:15 +00:00
module style;
import std.conv;
2023-08-10 15:50:57 +00:00
import core.stdc.stdlib : getenv;
2023-08-09 20:01:15 +00:00
import style.color;
string set(string s, int code) {
2023-08-10 15:50:57 +00:00
if (getenv("NO_COLOR"))
return s;
2023-08-10 15:13:22 +00:00
return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ (
"%{\x1b[" ~ to!string((Color.reset + 0)) ~ "m%}");
}
string set(string s, int code, bool close) {
2023-08-10 15:50:57 +00:00
if (getenv("NO_COLOR"))
return s;
2023-08-10 15:13:22 +00:00
return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ (close ? (
"%{\x1b[" ~ to!string((Color.reset + 0)) ~ "m%}") : "");
2023-08-09 20:01:15 +00:00
}