mirror of
https://github.com/yamadapc/d-colorize
synced 2024-11-14 21:14:00 +01:00
Rename the colorize function to color.
This will fix the name conflicts we were having before. It's a major breaking change, but it should fix our problems which is nice. This closes #6 and bumps the version to v1.0.0.
This commit is contained in:
parent
7398ee11f1
commit
589c22e38f
27
README.md
27
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
|
||||
|
|
|
@ -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
|
||||
{
|
|
@ -6,5 +6,5 @@
|
|||
*/
|
||||
module colorize;
|
||||
|
||||
public import colorize.colorize;
|
||||
public import colorize.cwrite;
|
||||
public import colorize.colors;
|
||||
public import colorize.cwrite;
|
||||
|
|
Loading…
Reference in a new issue