mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 13:22:52 +02:00
Edit colors and add more control codes
This commit is contained in:
parent
dcf32b2a13
commit
464773daa8
@ -2,12 +2,16 @@ module birchwood.formatting
|
||||
|
||||
import std.string;
|
||||
|
||||
// Reset character; resets all formatting
|
||||
enum reset = '\x0F';
|
||||
|
||||
// Toggle characters
|
||||
enum bold = '\x02';
|
||||
enum italic = '\x1D';
|
||||
enum underline = '\x1F';
|
||||
enum strikethrough = '\x1E';
|
||||
enum monospace = '\x11';
|
||||
enum reverse_colors = '\x16'; // NOT UNIVERSALLY SUPPORTED
|
||||
|
||||
// Color characters
|
||||
enum ascii_color_code = '\x03';
|
||||
@ -34,15 +38,23 @@ enum simple_colors: string {
|
||||
DEFAULT = "99" // NOT UNIVERSALLY SUPPORTED
|
||||
}
|
||||
|
||||
// Generates a string that changes the foreground color
|
||||
string set_foreground(string color) {
|
||||
char[1] control_char;
|
||||
// Return the hex control character if color is a hexadecimal color code, the ASCII control character if color is two ASCII digits, and throw an exception if it's neither
|
||||
char generate_color_control_char(string color) {
|
||||
if (color.length == 6) {
|
||||
control_char[0] = hex_color_code;
|
||||
return hex_color_code;
|
||||
} else if (color.length == 2) {
|
||||
control_char[0] = ascii_color_code;
|
||||
return ascii_color_code;
|
||||
} else {
|
||||
throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
||||
}
|
||||
return control_char.idup ~ color;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a string that sets the foreground color
|
||||
string set_fg(string color) {return [generate_color_control_char(color)].idup ~ color;}
|
||||
|
||||
// Generate a string that sets the foreground and background color
|
||||
string set_fg_bg(string color) {return [generate_color_control_char(color)].idup ~ color ~ "," ~ color;}
|
||||
|
||||
// Generate a string that resets the foreground and background colors
|
||||
pragma(inline)
|
||||
string reset_fg_bg() {return "\x03";}
|
@ -2,4 +2,5 @@ module birchwood;
|
||||
|
||||
public import birchwood.client;
|
||||
public import birchwood.config;
|
||||
public import birchwood.protocol;
|
||||
public import birchwood.protocol;
|
||||
public import birchwood.formatting
|
Loading…
Reference in New Issue
Block a user