| Index: lib/src/log.dart
|
| diff --git a/lib/src/log.dart b/lib/src/log.dart
|
| index 3f31a39d212d328de629256d83f980f134ca6d08..057f9c9fbfdd38d49944226994c5de619537acd0 100644
|
| --- a/lib/src/log.dart
|
| +++ b/lib/src/log.dart
|
| @@ -29,6 +29,9 @@ Verbosity verbosity = Verbosity.NORMAL;
|
| /// Whether or not to log entries with prejudice.
|
| bool withPrejudice = false;
|
|
|
| +/// Whether or not to log entries sparklily.
|
| +bool sparkle = false;
|
| +
|
| /// In cases where there's a ton of log spew, make sure we don't eat infinite
|
| /// memory.
|
| ///
|
| @@ -53,11 +56,15 @@ final _green = getSpecial('\u001b[32m');
|
| final _magenta = getSpecial('\u001b[35m');
|
| final _red = getSpecial('\u001b[31m');
|
| final _yellow = getSpecial('\u001b[33m');
|
| +final _blue = getSpecial('\u001b[34m');
|
| final _gray = getSpecial('\u001b[1;30m');
|
| final _none = getSpecial('\u001b[0m');
|
| final _noColor = getSpecial('\u001b[39m');
|
| final _bold = getSpecial('\u001b[1m');
|
|
|
| +/// All color codees.
|
| +var _allColors = [_cyan, _green, _magenta, _red, _yellow, _blue, ''];
|
| +
|
| /// An enum type for defining the different logging levels a given message can
|
| /// be associated with.
|
| ///
|
| @@ -241,17 +248,29 @@ void write(Level level, message) {
|
|
|
| final _capitalizedAnsiEscape = new RegExp(r'\u001b\[\d+(;\d+)?M');
|
|
|
| +final _character = new RegExp(r'(\u001b\[\d+(?:;\d+)?m)|.');
|
| +
|
| /// Returns [string] formatted as it would be if it were logged.
|
| String format(String string) {
|
| - if (!withPrejudice) return string;
|
| + if (sparkle) {
|
| + string = string.replaceAllMapped(_character, (match) {
|
| + if (match[1] != null) return match[0];
|
| + var char = "${choose(_allColors)}${match[0]}$_noColor";
|
| + return (withPrejudice || random.nextBool()) ? char : "$_bold$char$_none";
|
| + });
|
| + }
|
|
|
| - // [toUpperCase] can corrupt terminal colorings, so fix them up using
|
| - // [replaceAllMapped].
|
| - string = string.toUpperCase().replaceAllMapped(_capitalizedAnsiEscape,
|
| - (match) => match[0].toLowerCase());
|
| + if (withPrejudice) {
|
| + // [toUpperCase] can corrupt terminal colorings, so fix them up using
|
| + // [replaceAllMapped].
|
| + string = string.toUpperCase().replaceAllMapped(_capitalizedAnsiEscape,
|
| + (match) => match[0].toLowerCase());
|
|
|
| - // Don't use [bold] because it's disabled under [withPrejudice].
|
| - return "$_bold$string$_none";
|
| + // Don't use [bold] because it's disabled under [withPrejudice].
|
| + string = "$_bold$string$_none";
|
| + }
|
| +
|
| + return string;
|
| }
|
|
|
| /// Logs an asynchronous IO operation.
|
| @@ -454,7 +473,7 @@ void collapsible(String message, String template) {
|
| ///
|
| /// This is disabled under [withPrejudice] since all text is bold with
|
| /// prejudice.
|
| -String bold(text) => withPrejudice ? text : "$_bold$text$_none";
|
| +String bold(text) => (withPrejudice || sparkle) ? text : "$_bold$text$_none";
|
|
|
| /// Wraps [text] in the ANSI escape codes to make it gray when on a platform
|
| /// that supports that.
|
| @@ -463,40 +482,43 @@ String bold(text) => withPrejudice ? text : "$_bold$text$_none";
|
| ///
|
| /// The gray marker also enables bold, so it needs to be handled specially with
|
| /// [withPrejudice] to avoid disabling bolding entirely.
|
| -String gray(text) =>
|
| - withPrejudice ? "$_gray$text$_noColor" : "$_gray$text$_none";
|
| +String gray(text) {
|
| + if (sparkle) return text;
|
| + if (withPrejudice) return "$_gray$text$_noColor";
|
| + return "$_gray$text$_none";
|
| +}
|
|
|
| /// Wraps [text] in the ANSI escape codes to color it cyan when on a platform
|
| /// that supports that.
|
| ///
|
| /// Use this to highlight something interesting but neither good nor bad.
|
| -String cyan(text) => "$_cyan$text$_noColor";
|
| +String cyan(text) => sparkle ? text : "$_cyan$text$_noColor";
|
|
|
| /// Wraps [text] in the ANSI escape codes to color it green when on a platform
|
| /// that supports that.
|
| ///
|
| /// Use this to highlight something successful or otherwise positive.
|
| -String green(text) => "$_green$text$_noColor";
|
| +String green(text) => sparkle ? text : "$_green$text$_noColor";
|
|
|
| /// Wraps [text] in the ANSI escape codes to color it magenta when on a
|
| /// platform that supports that.
|
| ///
|
| /// Use this to highlight something risky that the user should be aware of but
|
| /// may intend to do.
|
| -String magenta(text) => "$_magenta$text$_noColor";
|
| +String magenta(text) => sparkle ? text : "$_magenta$text$_noColor";
|
|
|
| /// Wraps [text] in the ANSI escape codes to color it red when on a platform
|
| /// that supports that.
|
| ///
|
| /// Use this to highlight unequivocal errors, problems, or failures.
|
| -String red(text) => "$_red$text$_noColor";
|
| +String red(text) => sparkle ? text : "$_red$text$_noColor";
|
|
|
| /// Wraps [text] in the ANSI escape codes to color it yellow when on a platform
|
| /// that supports that.
|
| ///
|
| /// Use this to highlight warnings, cautions or other things that are bad but
|
| /// do not prevent the user's goal from being reached.
|
| -String yellow(text) => "$_yellow$text$_noColor";
|
| +String yellow(text) => sparkle ? text : "$_yellow$text$_noColor";
|
|
|
| /// Log function that prints the message to stdout.
|
| void _logToStdout(Entry entry) {
|
|
|