From 342da0b563b4c92453da0fb6930f6f57ef0e9fe1 Mon Sep 17 00:00:00 2001 From: yamadapc Date: Sat, 12 Jul 2014 20:02:27 -0300 Subject: [PATCH] Use a generic function for the `colorHelper`. Instead of using a template. This is cleaner; I don't know why it didn't come to my mind. I'm not sure if it's possible to make it work while using the private specifier. --- source/colorize.d | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/source/colorize.d b/source/colorize.d index 215bfb7..23daa03 100644 --- a/source/colorize.d +++ b/source/colorize.d @@ -96,17 +96,15 @@ unittest assert(ret == "\033[5;31;44mThis is red on blue blinking\033[0m"); } -private template colorHelper(T) +string colorHelper(T)(const string str, const T t=T.init) +if(is(T : fg) || is(T : bg) || is(T : mode)) { - string fn(const string str, const T t=T.init) - { - return format("\033[%dm%s\033[0m", t, str); - } + return format("\033[%dm%s\033[0m", t, str); } -alias colorHelper!bg.fn background; -alias colorHelper!fg.fn foreground; -alias colorHelper!mode.fn style; +alias colorHelper!bg background; +alias colorHelper!fg foreground; +alias colorHelper!mode style; unittest {