mirror of
https://github.com/yamadapc/d-colorize
synced 2024-11-14 21:14:00 +01:00
Fix the proposed helper functions.
I think this can be simplified with templates. I'm wondering if the colorize function could be made compile-time when that's possible.
This commit is contained in:
parent
5f944fad66
commit
fc2a2dd537
|
@ -115,17 +115,31 @@ unittest
|
|||
assert(ret == "\033[5;31;44mThis is red on blue blinking\033[0m");
|
||||
}
|
||||
|
||||
string background(string str, bg b=bg.init)
|
||||
string background(const string str, const bg b=bg.init)
|
||||
{
|
||||
return colorize(str, fg.init, b, mode.init);
|
||||
return format("\033[%dm%s\033[0m", b, str);
|
||||
}
|
||||
|
||||
string foreground(string str, fg c=fg.init)
|
||||
string foreground(const string str, const fg c=fg.init)
|
||||
{
|
||||
return colorize(str, c, bg.init, mode.init);
|
||||
return format("\033[%dm%s\033[0m", c, str);
|
||||
}
|
||||
|
||||
string style(string str, mode m=mode.init)
|
||||
string style(const string str, const mode m=mode.init)
|
||||
{
|
||||
return colorize(str, fg.init, bg.init, m);
|
||||
return format("\033[%dm%s\033[0m", m, str);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
import std.stdio;
|
||||
string ret;
|
||||
|
||||
ret = "This is red on blue blinking"
|
||||
.foreground(fg.red)
|
||||
.background(bg.blue)
|
||||
.style(mode.blink);
|
||||
|
||||
writeln(ret);
|
||||
assert(ret == "\033[5m\033[44m\033[31mThis is red on blue blinking\033[0m\033[0m\033[0m");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue