diff --git a/README.md b/README.md index 9e42d97..60dc19a 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,11 @@ This package is registered in the dub registry as ## Usage ```d import std.stdio; -import colorize : fg; -import colorize.colorize : colorize; +import colorize : fg, color; void main() { - writeln("This is blue".colorize(fg.blue)); + writeln("This is blue".color(fg.blue)); } ``` @@ -29,7 +28,7 @@ void main() ## Setting background, foreground and text modes: ```d -string colorize( +string color( const string str, const fg c, const bg b=bg.init, @@ -48,14 +47,14 @@ Wraps a string around color escape sequences. ### Example ```d -colorize("This is red over green blinking", fg.blue, bg.green, mode.blink) +color("This is red over green blinking", fg.blue, bg.green, mode.blink) ``` - - - ## Setting background colors: ```d -string colorize(const string str, const bg b) pure; // alias to background +string color(const string str, const bg b) pure; // alias to background ``` Wraps a string around a background color escape sequence. @@ -66,7 +65,7 @@ Wraps a string around a background color escape sequence. ## Example ```d -colorize("This has a blue background", bg.blue); +color("This has a blue background", bg.blue); background("This has a red background", bg.red); ``` @@ -74,7 +73,7 @@ background("This has a red background", bg.red); ## Setting text modes: ```d -string colorize(const string str, const mode m) pure; // alias to `style` +string color(const string str, const mode m) pure; // alias to `style` ``` Wraps a string around a text mode. @@ -85,13 +84,13 @@ Wraps a string around a text mode. ### Example ```d -colorize("This text is bold", mode.bold); +color("This text is bold", mode.bold); style("This text is blinking", mode.blink); ``` ## Coloring with strings: ```d -string colorize(const string str, const string name) pure; +string color(const string str, const string name) pure; ``` Wraps a string around the foreground color, background color or text style @@ -102,11 +101,11 @@ prefixed with either `"bg_"` or `"mode_"` (thus, `"bg_black"` will be `40`, ### Example ```d -colorize("This text is blue", "blue"); +color("This text is blue", "blue"); "This is red over blue, blinking" - .colorize("red") - .colorize("bg_blue") - .colorize("mode_blue"); + .color("red") + .color("bg_blue") + .color("mode_blue"); ``` ### Params diff --git a/source/colorize/colorize.d b/source/colorize/colors.d similarity index 86% rename from source/colorize/colorize.d rename to source/colorize/colors.d index 49628d8..7a4e8c2 100644 --- a/source/colorize/colorize.d +++ b/source/colorize/colors.d @@ -4,11 +4,11 @@ * License: Licensed under the MIT license. See LICENSE for more information * Version: 0.1.0 */ -module colorize.colorize; +module colorize.colors; import std.string : format; -private template color(int offset) +private template color_type(int offset) { static enum type : int { @@ -34,8 +34,8 @@ private template color(int offset) } } -alias color!0 .type fg; -alias color!10 .type bg; +alias color_type!0 .type fg; +alias color_type!10 .type bg; // Text modes static enum mode : int @@ -58,14 +58,14 @@ static enum mode : int * m = The text mode (see the mode enum type) * Example: * --- - * writeln("This is blue".colorize(fg.blue)); + * writeln("This is blue".color(fg.blue)); * writeln( - * colorize("This is red over green blinking", fg.blue, bg.green, mode.blink) + * color("This is red over green blinking", fg.blue, bg.green, mode.blink) * ); * --- */ -string colorize( +string color( const string str, const fg c=fg.init, const bg b=bg.init, @@ -80,23 +80,23 @@ unittest import std.stdio; string ret; - ret = "This is yellow".colorize(fg.yellow); + ret = "This is yellow".color(fg.yellow); writeln(ret); assert(ret == "\033[33mThis is yellow\033[0m"); - ret = "This is light green".colorize(fg.light_green); + ret = "This is light green".color(fg.light_green); writeln(ret); assert(ret == "\033[92mThis is light green\033[0m"); - ret = "This is light blue with red background".colorize(fg.light_blue, bg.red); + ret = "This is light blue with red background".color(fg.light_blue, bg.red); writeln(ret); assert(ret == "\033[0;94;41mThis is light blue with red background\033[0m"); - ret = "This is red on blue blinking".colorize(fg.red, bg.blue, mode.blink); + ret = "This is red on blue blinking".color(fg.red, bg.blue, mode.blink); writeln(ret); assert(ret == "\033[5;31;44mThis is red on blue blinking\033[0m"); - ret = colorize("This is magenta", "magenta"); + ret = color("This is magenta", "magenta"); writeln(ret); assert(ret == "\033[35mThis is magenta\033[0m"); } @@ -173,10 +173,10 @@ alias colorHelper!bg background; alias colorHelper!fg foreground; alias colorHelper!mode style; -alias background colorize; -alias foreground colorize; -alias style colorize; -alias colorHelper colorize; +alias background color; +alias foreground color; +alias style color; +alias colorHelper color; unittest { diff --git a/source/colorize/package.d b/source/colorize/package.d index c4c07f5..d8a86f6 100644 --- a/source/colorize/package.d +++ b/source/colorize/package.d @@ -6,5 +6,5 @@ */ module colorize; -public import colorize.colorize; -public import colorize.cwrite; \ No newline at end of file +public import colorize.colors; +public import colorize.cwrite;