diff --git a/source/dub/generators/build.d b/source/dub/generators/build.d index 85e141a..80b6781 100644 --- a/source/dub/generators/build.d +++ b/source/dub/generators/build.d @@ -155,8 +155,8 @@ if (any_cached) { logInfo("Finished", Color.green, - "To force a rebuild of up-to-date targets, run again with --force" - ); + "To force a rebuild of up-to-date targets, run again with --force" + ); } } } diff --git a/source/dub/internal/colorize/colors.d b/source/dub/internal/colorize/colors.d index f125ac3..f62ab26 100644 --- a/source/dub/internal/colorize/colors.d +++ b/source/dub/internal/colorize/colors.d @@ -10,28 +10,28 @@ private template color_type(int offset) { - static enum type : int - { - init = 39 + offset, + static enum type : int + { + init = 39 + offset, - black = 30 + offset, - red = 31 + offset, - green = 32 + offset, - yellow = 33 + offset, - blue = 34 + offset, - magenta = 35 + offset, - cyan = 36 + offset, - white = 37 + offset, + black = 30 + offset, + red = 31 + offset, + green = 32 + offset, + yellow = 33 + offset, + blue = 34 + offset, + magenta = 35 + offset, + cyan = 36 + offset, + white = 37 + offset, - light_black = 90 + offset, - light_red = 91 + offset, - light_green = 92 + offset, - light_yellow = 93 + offset, - light_blue = 94 + offset, - light_magenta = 95 + offset, - light_cyan = 96 + offset, - light_white = 97 + offset - } + light_black = 90 + offset, + light_red = 91 + offset, + light_green = 92 + offset, + light_yellow = 93 + offset, + light_blue = 94 + offset, + light_magenta = 95 + offset, + light_cyan = 96 + offset, + light_white = 97 + offset + } } alias color_type!0 .type fg; @@ -40,12 +40,12 @@ // Text modes static enum mode : int { - init = 0, - bold = 1, - underline = 4, - blink = 5, - swap = 7, - hide = 8 + init = 0, + bold = 1, + underline = 4, + blink = 5, + swap = 7, + hide = 8 } /** @@ -66,101 +66,101 @@ */ string color( - const string str, - const fg c=fg.init, - const bg b=bg.init, - const mode m=mode.init + const string str, + const fg c=fg.init, + const bg b=bg.init, + const mode m=mode.init ) pure { - return format("\033[%d;%d;%dm%s\033[0m", m, c, b, str); + return format("\033[%d;%d;%dm%s\033[0m", m, c, b, str); } unittest { - string ret; + string ret; - ret = "This is yellow".color(fg.yellow); - assert(ret == "\033[33mThis is yellow\033[0m"); + ret = "This is yellow".color(fg.yellow); + assert(ret == "\033[33mThis is yellow\033[0m"); - ret = "This is light green".color(fg.light_green); - assert(ret == "\033[92mThis is light green\033[0m"); + ret = "This is light green".color(fg.light_green); + assert(ret == "\033[92mThis is light green\033[0m"); - ret = "This is light blue with red background".color(fg.light_blue, bg.red); - assert(ret == "\033[0;94;41mThis is light blue with red background\033[0m"); + ret = "This is light blue with red background".color(fg.light_blue, bg.red); + assert(ret == "\033[0;94;41mThis is light blue with red background\033[0m"); - ret = "This is red on blue blinking".color(fg.red, bg.blue, mode.blink); - assert(ret == "\033[5;31;44mThis is red on blue blinking\033[0m"); + ret = "This is red on blue blinking".color(fg.red, bg.blue, mode.blink); + assert(ret == "\033[5;31;44mThis is red on blue blinking\033[0m"); - ret = color("This is magenta", "magenta"); - assert(ret == "\033[35mThis is magenta\033[0m"); + ret = color("This is magenta", "magenta"); + assert(ret == "\033[35mThis is magenta\033[0m"); } string colorHelper(const string str, const string name) pure { - int code; + int code; - switch(name) - { - case "init": code = 39; break; + switch(name) + { + case "init": code = 39; break; - case "black" : code = 30; break; - case "red" : code = 31; break; - case "green" : code = 32; break; - case "yellow" : code = 33; break; - case "blue" : code = 34; break; - case "magenta": code = 35; break; - case "cyan" : code = 36; break; - case "white" : code = 37; break; + case "black" : code = 30; break; + case "red" : code = 31; break; + case "green" : code = 32; break; + case "yellow" : code = 33; break; + case "blue" : code = 34; break; + case "magenta": code = 35; break; + case "cyan" : code = 36; break; + case "white" : code = 37; break; - case "light_black" : code = 90; break; - case "light_red" : code = 91; break; - case "light_green" : code = 92; break; - case "light_yellow" : code = 93; break; - case "light_blue" : code = 94; break; - case "light_magenta": code = 95; break; - case "light_cyan" : code = 96; break; - case "light_white" : code = 97; break; + case "light_black" : code = 90; break; + case "light_red" : code = 91; break; + case "light_green" : code = 92; break; + case "light_yellow" : code = 93; break; + case "light_blue" : code = 94; break; + case "light_magenta": code = 95; break; + case "light_cyan" : code = 96; break; + case "light_white" : code = 97; break; - case "bg_init": code = 49; break; + case "bg_init": code = 49; break; - case "bg_black" : code = 40; break; - case "bg_red" : code = 41; break; - case "bg_green" : code = 42; break; - case "bg_yellow" : code = 43; break; - case "bg_blue" : code = 44; break; - case "bg_magenta": code = 45; break; - case "bg_cyan" : code = 46; break; - case "bg_white" : code = 47; break; + case "bg_black" : code = 40; break; + case "bg_red" : code = 41; break; + case "bg_green" : code = 42; break; + case "bg_yellow" : code = 43; break; + case "bg_blue" : code = 44; break; + case "bg_magenta": code = 45; break; + case "bg_cyan" : code = 46; break; + case "bg_white" : code = 47; break; - case "bg_light_black" : code = 100; break; - case "bg_light_red" : code = 101; break; - case "bg_light_green" : code = 102; break; - case "bg_light_yellow" : code = 103; break; - case "bg_light_blue" : code = 104; break; - case "bg_light_magenta": code = 105; break; - case "bg_light_cyan" : code = 106; break; - case "bg_light_white" : code = 107; break; + case "bg_light_black" : code = 100; break; + case "bg_light_red" : code = 101; break; + case "bg_light_green" : code = 102; break; + case "bg_light_yellow" : code = 103; break; + case "bg_light_blue" : code = 104; break; + case "bg_light_magenta": code = 105; break; + case "bg_light_cyan" : code = 106; break; + case "bg_light_white" : code = 107; break; - case "mode_init": code = 0; break; - case "mode_bold" : code = 1; break; - case "mode_underline": code = 4; break; - case "mode_blink" : code = 5; break; - case "mode_swap" : code = 7; break; - case "mode_hide" : code = 8; break; + case "mode_init": code = 0; break; + case "mode_bold" : code = 1; break; + case "mode_underline": code = 4; break; + case "mode_blink" : code = 5; break; + case "mode_swap" : code = 7; break; + case "mode_hide" : code = 8; break; - default: - throw new Exception( - "Unknown fg color, bg color or mode \"" ~ name ~ "\"" - ); - } + default: + throw new Exception( + "Unknown fg color, bg color or mode \"" ~ name ~ "\"" + ); + } - return format("\033[%dm%s\033[0m", code, str); + return format("\033[%dm%s\033[0m", code, str); } string colorHelper(T)(const string str, const T t=T.init) pure - if(is(T : fg) || is(T : bg) || is(T : mode)) + if(is(T : fg) || is(T : bg) || is(T : mode)) { - return format("\033[%dm%s\033[0m", t, str); + return format("\033[%dm%s\033[0m", t, str); } alias colorHelper!bg background; @@ -174,12 +174,12 @@ unittest { - string ret; + string ret; - ret = "This is red on blue blinking" - .foreground(fg.red) - .background(bg.blue) - .style(mode.blink); + ret = "This is red on blue blinking" + .foreground(fg.red) + .background(bg.blue) + .style(mode.blink); - assert(ret == "\033[5m\033[44m\033[31mThis is red on blue blinking\033[0m\033[0m\033[0m"); + assert(ret == "\033[5m\033[44m\033[31mThis is red on blue blinking\033[0m\033[0m\033[0m"); } diff --git a/source/dub/internal/colorize/cwrite.d b/source/dub/internal/colorize/cwrite.d index 8c8c269..0f5d1f2 100644 --- a/source/dub/internal/colorize/cwrite.d +++ b/source/dub/internal/colorize/cwrite.d @@ -13,62 +13,62 @@ /// Coloured write. void cwrite(T...)(T args) if (!is(T[0] : File)) { - stdout.cwrite(args); + stdout.cwrite(args); } /// Coloured writef. void cwritef(Char, T...)(in Char[] fmt, T args) if (!is(T[0] : File)) { - stdout.cwritef(fmt, args); + stdout.cwritef(fmt, args); } /// Coloured writefln. void cwritefln(Char, T...)(in Char[] fmt, T args) { - stdout.cwritef(fmt ~ "\n", args); + stdout.cwritef(fmt ~ "\n", args); } /// Coloured writeln. void cwriteln(T...)(T args) { - // Most general instance - stdout.cwrite(args, '\n'); + // Most general instance + stdout.cwrite(args, '\n'); } /// Coloured writef to a File. void cwritef(Char, A...)(File f, in Char[] fmt, A args) { - import std.string : format; - auto s = format(fmt, args); - f.cwrite(s); + import std.string : format; + auto s = format(fmt, args); + f.cwrite(s); } /// Coloured writef to a File. void cwrite(S...)(File f, S args) { - import std.conv : to; + import std.conv : to; - string s = ""; - foreach(arg; args) - s ~= to!string(arg); + string s = ""; + foreach(arg; args) + s ~= to!string(arg); - version(Windows) - { - WinTermEmulation winterm; - winterm.initialize(); - foreach(dchar c ; s) - { - auto charAction = winterm.feed(c); - final switch(charAction) with (WinTermEmulation.CharAction) - { - case drop: break; - case write: f.write(c); break; - case flush: f.flush(); break; - } - } - } - else - { - f.write(s); - } + version(Windows) + { + WinTermEmulation winterm; + winterm.initialize(); + foreach(dchar c ; s) + { + auto charAction = winterm.feed(c); + final switch(charAction) with (WinTermEmulation.CharAction) + { + case drop: break; + case write: f.write(c); break; + case flush: f.flush(); break; + } + } + } + else + { + f.write(s); + } } diff --git a/source/dub/internal/colorize/winterm.d b/source/dub/internal/colorize/winterm.d index 3b12bb5..32b7be2 100644 --- a/source/dub/internal/colorize/winterm.d +++ b/source/dub/internal/colorize/winterm.d @@ -8,184 +8,184 @@ version(Windows) { - import core.sys.windows.windows; + import core.sys.windows.windows; - // Patch for DMD 2.065 compatibility - static if( __VERSION__ < 2066 ) private enum nogc = 1; + // Patch for DMD 2.065 compatibility + static if( __VERSION__ < 2066 ) private enum nogc = 1; - // This is a state machine to enable terminal colors on Windows. - // Parses and interpret ANSI/VT100 Terminal Control Escape Sequences. - // Only supports colour sequences, will output char incorrectly on invalid input. - struct WinTermEmulation - { - public: - @nogc void initialize() nothrow - { - // saves console attributes - _console = GetStdHandle(STD_OUTPUT_HANDLE); - _savedInitialColor = (0 != GetConsoleScreenBufferInfo(_console, &consoleInfo)); - _state = State.initial; - } + // This is a state machine to enable terminal colors on Windows. + // Parses and interpret ANSI/VT100 Terminal Control Escape Sequences. + // Only supports colour sequences, will output char incorrectly on invalid input. + struct WinTermEmulation + { + public: + @nogc void initialize() nothrow + { + // saves console attributes + _console = GetStdHandle(STD_OUTPUT_HANDLE); + _savedInitialColor = (0 != GetConsoleScreenBufferInfo(_console, &consoleInfo)); + _state = State.initial; + } - @nogc ~this() nothrow - { - // Restore initial text attributes on release - if (_savedInitialColor) - { - SetConsoleTextAttribute(_console, consoleInfo.wAttributes); - _savedInitialColor = false; - } - } + @nogc ~this() nothrow + { + // Restore initial text attributes on release + if (_savedInitialColor) + { + SetConsoleTextAttribute(_console, consoleInfo.wAttributes); + _savedInitialColor = false; + } + } - enum CharAction - { - write, - drop, - flush - } + enum CharAction + { + write, + drop, + flush + } - // Eat one character and update color state accordingly. - // Returns what to do with the fed character. - @nogc CharAction feed(dchar d) nothrow - { - final switch(_state) with (State) - { - case initial: - if (d == '\x1B') - { - _state = escaped; - return CharAction.flush; - } - break; + // Eat one character and update color state accordingly. + // Returns what to do with the fed character. + @nogc CharAction feed(dchar d) nothrow + { + final switch(_state) with (State) + { + case initial: + if (d == '\x1B') + { + _state = escaped; + return CharAction.flush; + } + break; - case escaped: - if (d == '[') - { - _state = readingAttribute; - _parsedAttr = 0; - return CharAction.drop; - } - break; + case escaped: + if (d == '[') + { + _state = readingAttribute; + _parsedAttr = 0; + return CharAction.drop; + } + break; + case readingAttribute: + if (d >= '0' && d <= '9') + { + _parsedAttr = _parsedAttr * 10 + (d - '0'); + return CharAction.drop; + } + else if (d == ';') + { + executeAttribute(_parsedAttr); + _parsedAttr = 0; + return CharAction.drop; + } + else if (d == 'm') + { + executeAttribute(_parsedAttr); + _state = State.initial; + return CharAction.drop; + } + break; + } - case readingAttribute: - if (d >= '0' && d <= '9') - { - _parsedAttr = _parsedAttr * 10 + (d - '0'); - return CharAction.drop; - } - else if (d == ';') - { - executeAttribute(_parsedAttr); - _parsedAttr = 0; - return CharAction.drop; - } - else if (d == 'm') - { - executeAttribute(_parsedAttr); - _state = State.initial; - return CharAction.drop; - } - break; - } - return CharAction.write; - } + return CharAction.write; + } - private: - HANDLE _console; - bool _savedInitialColor; - CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - State _state; - WORD _currentAttr; - int _parsedAttr; + private: + HANDLE _console; + bool _savedInitialColor; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + State _state; + WORD _currentAttr; + int _parsedAttr; - enum State - { - initial, - escaped, - readingAttribute - } + enum State + { + initial, + escaped, + readingAttribute + } - @nogc void setForegroundColor(WORD fgFlags) nothrow - { - _currentAttr = _currentAttr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); - _currentAttr = _currentAttr | fgFlags; - SetConsoleTextAttribute(_console, _currentAttr); - } + @nogc void setForegroundColor(WORD fgFlags) nothrow + { + _currentAttr = _currentAttr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); + _currentAttr = _currentAttr | fgFlags; + SetConsoleTextAttribute(_console, _currentAttr); + } - @nogc void setBackgroundColor(WORD bgFlags) nothrow - { - _currentAttr = _currentAttr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY); - _currentAttr = _currentAttr | bgFlags; - SetConsoleTextAttribute(_console, _currentAttr); - } + @nogc void setBackgroundColor(WORD bgFlags) nothrow + { + _currentAttr = _currentAttr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY); + _currentAttr = _currentAttr | bgFlags; + SetConsoleTextAttribute(_console, _currentAttr); + } - // resets to the same foreground color that was set on initialize() - @nogc void resetForegroundColor() nothrow - { - if (!_savedInitialColor) - return; + // resets to the same foreground color that was set on initialize() + @nogc void resetForegroundColor() nothrow + { + if (!_savedInitialColor) + return; - _currentAttr = _currentAttr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); - _currentAttr = _currentAttr | (consoleInfo.wAttributes & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)); - SetConsoleTextAttribute(_console, _currentAttr); - } + _currentAttr = _currentAttr & ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); + _currentAttr = _currentAttr | (consoleInfo.wAttributes & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)); + SetConsoleTextAttribute(_console, _currentAttr); + } - // resets to the same background color that was set on initialize() - @nogc void resetBackgroundColor() nothrow - { - if (!_savedInitialColor) - return; + // resets to the same background color that was set on initialize() + @nogc void resetBackgroundColor() nothrow + { + if (!_savedInitialColor) + return; - _currentAttr = _currentAttr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY); - _currentAttr = _currentAttr | (consoleInfo.wAttributes & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)); - SetConsoleTextAttribute(_console, _currentAttr); - } + _currentAttr = _currentAttr & ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY); + _currentAttr = _currentAttr | (consoleInfo.wAttributes & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)); + SetConsoleTextAttribute(_console, _currentAttr); + } - @nogc void executeAttribute(int attr) nothrow - { - switch (attr) - { - case 0: - // reset all attributes - SetConsoleTextAttribute(_console, consoleInfo.wAttributes); - break; + @nogc void executeAttribute(int attr) nothrow + { + switch (attr) + { + case 0: + // reset all attributes + SetConsoleTextAttribute(_console, consoleInfo.wAttributes); + break; - default: - if ( (30 <= attr && attr <= 37) || (90 <= attr && attr <= 97) ) - { - WORD color = 0; - if (90 <= attr && attr <= 97) - { - color = FOREGROUND_INTENSITY; - attr -= 60; - } - attr -= 30; - color |= (attr & 1 ? FOREGROUND_RED : 0) | (attr & 2 ? FOREGROUND_GREEN : 0) | (attr & 4 ? FOREGROUND_BLUE : 0); - setForegroundColor(color); - } - else if (attr == 39) // fg.init - { - resetForegroundColor(); - } + default: + if ( (30 <= attr && attr <= 37) || (90 <= attr && attr <= 97) ) + { + WORD color = 0; + if (90 <= attr && attr <= 97) + { + color = FOREGROUND_INTENSITY; + attr -= 60; + } + attr -= 30; + color |= (attr & 1 ? FOREGROUND_RED : 0) | (attr & 2 ? FOREGROUND_GREEN : 0) | (attr & 4 ? FOREGROUND_BLUE : 0); + setForegroundColor(color); + } + else if (attr == 39) // fg.init + { + resetForegroundColor(); + } - if ( (40 <= attr && attr <= 47) || (100 <= attr && attr <= 107) ) - { - WORD color = 0; - if (100 <= attr && attr <= 107) - { - color = BACKGROUND_INTENSITY; - attr -= 60; - } - attr -= 40; - color |= (attr & 1 ? BACKGROUND_RED : 0) | (attr & 2 ? BACKGROUND_GREEN : 0) | (attr & 4 ? BACKGROUND_BLUE : 0); - setBackgroundColor(color); - } - else if (attr == 49) // bg.init - { - resetBackgroundColor(); - } - } - } - } + if ( (40 <= attr && attr <= 47) || (100 <= attr && attr <= 107) ) + { + WORD color = 0; + if (100 <= attr && attr <= 107) + { + color = BACKGROUND_INTENSITY; + attr -= 60; + } + attr -= 40; + color |= (attr & 1 ? BACKGROUND_RED : 0) | (attr & 2 ? BACKGROUND_GREEN : 0) | (attr & 4 ? BACKGROUND_BLUE : 0); + setBackgroundColor(color); + } + else if (attr == 49) // bg.init + { + resetBackgroundColor(); + } + } + } + } } diff --git a/source/dub/internal/vibecompat/core/log.d b/source/dub/internal/vibecompat/core/log.d index d352e8a..404e4b5 100644 --- a/source/dub/internal/vibecompat/core/log.d +++ b/source/dub/internal/vibecompat/core/log.d @@ -1,8 +1,8 @@ /** +deprecated("Please use dub.logging") This module contained logging functions, but has been replaced by dub.logging - which provides colored output and other facilities. + which provides colored output and other facilities. - Copyright: © 2012 rejectedsoftware e.K., © 2018 Giacomo De Lazzari + Copyright: © 2012 rejectedsoftware e.K., © 2018 Giacomo De Lazzari License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Sönke Ludwig, Giacomo De Lazzari */ diff --git a/source/dub/logging.d b/source/dub/logging.d index daa7a4f..eb83395 100644 --- a/source/dub/logging.d +++ b/source/dub/logging.d @@ -1,54 +1,54 @@ /** - Handles all the console output of the Dub package manager, by providing useful - methods for handling colored text. The module also disables colors when stdout - and stderr are not a TTY in order to avoid ASCII escape sequences in piped - output. The module can autodetect and configure itself in this regard by - calling initLogging() at the beginning of the program. But, whether to color - text or not can also be set manually with printColorsInLog(bool). + Handles all the console output of the Dub package manager, by providing useful + methods for handling colored text. The module also disables colors when stdout + and stderr are not a TTY in order to avoid ASCII escape sequences in piped + output. The module can autodetect and configure itself in this regard by + calling initLogging() at the beginning of the program. But, whether to color + text or not can also be set manually with printColorsInLog(bool). - The output for the log levels error, warn and info is formatted like this: + The output for the log levels error, warn and info is formatted like this: - " " - '----------' - fixed width + " " + '----------' + fixed width - the "tag" part can be colored (most oftenly will be) and always has a fixed - width, which is defined as a const at the beginning of this module. + the "tag" part can be colored (most oftenly will be) and always has a fixed + width, which is defined as a const at the beginning of this module. - The output for the log levels debug and diagnostic will be just the plain - string. + The output for the log levels debug and diagnostic will be just the plain + string. - There are some default tag string and color values for some logging levels: - - warn: "Warning", yellow bold - - error: "Error", red bold + There are some default tag string and color values for some logging levels: + - warn: "Warning", yellow bold + - error: "Error", red bold - Actually, for error and warn levels, the tag color is fixed to the ones listed - above. + Actually, for error and warn levels, the tag color is fixed to the ones listed + above. - Also, the default tag string for the info level is "" (the empty string) and - the default color is white (usually it's manually set when calling logInfo - with the wanted tag string, but this allows to just logInfo("text") without - having to worry about the tag if it's not needed). + Also, the default tag string for the info level is "" (the empty string) and + the default color is white (usually it's manually set when calling logInfo + with the wanted tag string, but this allows to just logInfo("text") without + having to worry about the tag if it's not needed). - Usage: - After initializing the logging module with initLogging(), the functions - logDebug(..), logDiagnostic(..), logInfo(..), logWarning(..) and logError(..) - can be used to print log messages. Whether the messages are printed on stdout - or stderr depends on the log level (warning and error go to stderr). - The log(..) function can also be used. Check the signature and documentation - of the functions for more information. + Usage: + After initializing the logging module with initLogging(), the functions + logDebug(..), logDiagnostic(..), logInfo(..), logWarning(..) and logError(..) + can be used to print log messages. Whether the messages are printed on stdout + or stderr depends on the log level (warning and error go to stderr). + The log(..) function can also be used. Check the signature and documentation + of the functions for more information. - The minimum log level to print can be configured using setLogLevel(..), and - whether to color outputted text or not can be set with printColorsInLog(..). + The minimum log level to print can be configured using setLogLevel(..), and + whether to color outputted text or not can be set with printColorsInLog(..). - The color(str, color) function can be used to color text within a log - message, for instance like this: + The color(str, color) function can be used to color text within a log + message, for instance like this: - logInfo("Tag", Color.green, "My %s message", "colored".color(Color.red)) + logInfo("Tag", Color.green, "My %s message", "colored".color(Color.red)) - Copyright: © 2018 Giacomo De Lazzari - License: Subject to the terms of the MIT license, as written in the included LICENSE file. - Authors: Giacomo De Lazzari + Copyright: © 2018 Giacomo De Lazzari + License: Subject to the terms of the MIT license, as written in the included LICENSE file. + Authors: Giacomo De Lazzari */ module dub.logging; @@ -61,17 +61,17 @@ import dub.internal.colorize : fg, mode; /** - An enum listing possible colors for terminal output, useful to set the color - of a tag. Re-exported from d-colorize in dub.internal.colorize. See the enum - definition there for a list of possible values. + An enum listing possible colors for terminal output, useful to set the color + of a tag. Re-exported from d-colorize in dub.internal.colorize. See the enum + definition there for a list of possible values. */ public alias Color = fg; /** - An enum listing possible text "modes" for terminal output, useful to set the - text to bold, underline, blinking, etc... - Re-exported from d-colorize in dub.internal.colorize. See the enum definition - there for a list of possible values. + An enum listing possible text "modes" for terminal output, useful to set the + text to bold, underline, blinking, etc... + Re-exported from d-colorize in dub.internal.colorize. See the enum definition + there for a list of possible values. */ public alias Mode = mode; @@ -80,21 +80,21 @@ /// Possible log levels supported enum LogLevel { - debug_, - diagnostic, - info, - warn, - error, - none + debug_, + diagnostic, + info, + warn, + error, + none } // The current minimum log level to be printed private shared LogLevel _minLevel = LogLevel.info; /* - Whether to print text with colors or not, defaults to true but will be set - to false in initLogging() if stdout or stderr are not a TTY (which means the - output is probably being piped and we don't want ASCII escape chars in it) + Whether to print text with colors or not, defaults to true but will be set + to false in initLogging() if stdout or stderr are not a TTY (which means the + output is probably being piped and we don't want ASCII escape chars in it) */ private shared bool _printColors = true; @@ -102,282 +102,282 @@ extern (C) int isatty(int); /** - This function must be called at the beginning for the program, before any - logging occurs. It will detect whether or not stdout/stderr are a console/TTY - and will consequently disable colored output if needed. + This function must be called at the beginning for the program, before any + logging occurs. It will detect whether or not stdout/stderr are a console/TTY + and will consequently disable colored output if needed. - Forgetting to call the function will result in ASCII escape sequences in the - piped output, probably an undesiderable thing. + Forgetting to call the function will result in ASCII escape sequences in the + piped output, probably an undesiderable thing. */ void initLogging() { - import core.stdc.stdio; + import core.stdc.stdio; - // Initially enable colors, we'll disable them during this functions if we - // find any reason to - _printColors = true; + // Initially enable colors, we'll disable them during this functions if we + // find any reason to + _printColors = true; - // The following stuff depends on the platform - version (Windows) - { - version (CRuntime_DigitalMars) - { - if (!isatty(core.stdc.stdio.stdout._file) || - !isatty(core.stdc.stdio.stderr._file)) - _printColors = false; - } - else version (CRuntime_Microsoft) - { - if (!isatty(fileno(core.stdc.stdio.stdout)) || - !isatty(fileno(core.stdc.stdio.stderr))) - _printColors = false; - } - else - _printColors = false; - } - else version (Posix) - { - import core.sys.posix.unistd; + // The following stuff depends on the platform + version (Windows) + { + version (CRuntime_DigitalMars) + { + if (!isatty(core.stdc.stdio.stdout._file) || + !isatty(core.stdc.stdio.stderr._file)) + _printColors = false; + } + else version (CRuntime_Microsoft) + { + if (!isatty(fileno(core.stdc.stdio.stdout)) || + !isatty(fileno(core.stdc.stdio.stderr))) + _printColors = false; + } + else + _printColors = false; + } + else version (Posix) + { + import core.sys.posix.unistd; - if (!isatty(STDERR_FILENO) || !isatty(STDOUT_FILENO)) - _printColors = false; - } + if (!isatty(STDERR_FILENO) || !isatty(STDOUT_FILENO)) + _printColors = false; + } } /// Sets the minimum log level to be printed void setLogLevel(LogLevel level) nothrow { - _minLevel = level; + _minLevel = level; } /// Gets the minimum log level to be printed LogLevel getLogLevel() { - return _minLevel; + return _minLevel; } /// Set whether to print colors or not void printColorsInLog(bool enabled) { - _printColors = enabled; + _printColors = enabled; } /** - Shorthand function to log a message with debug/diagnostic level, no tag string - or tag color required (since there will be no tag). + Shorthand function to log a message with debug/diagnostic level, no tag string + or tag color required (since there will be no tag). - Params: - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logDebug(T...)(string fmt, lazy T args) nothrow { - log(LogLevel.debug_, false, "", Color.init, fmt, args); + log(LogLevel.debug_, false, "", Color.init, fmt, args); } /// ditto void logDiagnostic(T...)(string fmt, lazy T args) nothrow { - log(LogLevel.diagnostic, false, "", Color.init, fmt, args); + log(LogLevel.diagnostic, false, "", Color.init, fmt, args); } /** - Shorthand function to log a message with info level, with custom tag string - and tag color. + Shorthand function to log a message with info level, with custom tag string + and tag color. - Params: - tag = The string the tag at the beginning of the line should contain - tagColor = The color the tag string should have - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + tag = The string the tag at the beginning of the line should contain + tagColor = The color the tag string should have + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logInfo(T...)(string tag, Color tagColor, string fmt, lazy T args) nothrow { - log(LogLevel.info, false, tag, tagColor, fmt, args); + log(LogLevel.info, false, tag, tagColor, fmt, args); } /** - Shorthand function to log a message with info level, this version prints an - empty tag automatically (which is different from not having a tag - in this - case there will be an identation of TAG_WIDTH chars on the left anyway). + Shorthand function to log a message with info level, this version prints an + empty tag automatically (which is different from not having a tag - in this + case there will be an identation of TAG_WIDTH chars on the left anyway). - Params: - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logInfo(T...)(string fmt, lazy T args) nothrow if (!is(T[0] : Color)) { - log(LogLevel.info, false, "", Color.init, fmt, args); + log(LogLevel.info, false, "", Color.init, fmt, args); } /** - Shorthand function to log a message with info level, this version doesn't - print a tag at all, it effectively just prints the given string. + Shorthand function to log a message with info level, this version doesn't + print a tag at all, it effectively just prints the given string. - Params: - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logInfoNoTag(T...)(string fmt, lazy T args) nothrow if (!is(T[0] : Color)) { - log(LogLevel.info, true, "", Color.init, fmt, args); + log(LogLevel.info, true, "", Color.init, fmt, args); } /** - Shorthand function to log a message with warning level, with custom tag string. - The tag color is fixed to yellow. + Shorthand function to log a message with warning level, with custom tag string. + The tag color is fixed to yellow. - Params: - tag = The string the tag at the beginning of the line should contain - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + tag = The string the tag at the beginning of the line should contain + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logWarnTag(T...)(string tag, string fmt, lazy T args) nothrow { - log(LogLevel.warn, false, tag, Color.yellow, fmt, args); + log(LogLevel.warn, false, tag, Color.yellow, fmt, args); } /** - Shorthand function to log a message with warning level, using the default - tag "Warning". The tag color is also fixed to yellow. + Shorthand function to log a message with warning level, using the default + tag "Warning". The tag color is also fixed to yellow. - Params: - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logWarn(T...)(string fmt, lazy T args) nothrow { - log(LogLevel.warn, false, "Warning", Color.yellow, fmt, args); + log(LogLevel.warn, false, "Warning", Color.yellow, fmt, args); } /** - Shorthand function to log a message with error level, with custom tag string. - The tag color is fixed to red. + Shorthand function to log a message with error level, with custom tag string. + The tag color is fixed to red. - Params: - tag = The string the tag at the beginning of the line should contain - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + tag = The string the tag at the beginning of the line should contain + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logErrorTag(T...)(string tag, string fmt, lazy T args) nothrow { - log(LogLevel.error, false, tag, Color.red, fmt, args); + log(LogLevel.error, false, tag, Color.red, fmt, args); } /** - Shorthand function to log a message with error level, using the default - tag "Error". The tag color is also fixed to red. + Shorthand function to log a message with error level, using the default + tag "Error". The tag color is also fixed to red. - Params: - level = The log level for the logged message - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + level = The log level for the logged message + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void logError(T...)(string fmt, lazy T args) nothrow { - log(LogLevel.error, false, "Error", Color.red, fmt, args); + log(LogLevel.error, false, "Error", Color.red, fmt, args); } /** - Log a message with the specified log level and with the specified tag string - and color. If the log level is debug or diagnostic, the tag is not printed - thus the tag string and tag color will be ignored. If the log level is error - or warning, the tag will be in bold text. Also the tag can be disabled (for - any log level) by passing true as the second argument. + Log a message with the specified log level and with the specified tag string + and color. If the log level is debug or diagnostic, the tag is not printed + thus the tag string and tag color will be ignored. If the log level is error + or warning, the tag will be in bold text. Also the tag can be disabled (for + any log level) by passing true as the second argument. - Params: - level = The log level for the logged message - disableTag = Setting this to true disables the tag, no matter what - tag = The string the tag at the beginning of the line should contain - tagColor = The color the tag string should have - fmt = See http://dlang.org/phobos/std_format.html#format-string + Params: + level = The log level for the logged message + disableTag = Setting this to true disables the tag, no matter what + tag = The string the tag at the beginning of the line should contain + tagColor = The color the tag string should have + fmt = See http://dlang.org/phobos/std_format.html#format-string */ void log(T...)( - LogLevel level, - bool disableTag, - string tag, - Color tagColor, - string fmt, - lazy T args + LogLevel level, + bool disableTag, + string tag, + Color tagColor, + string fmt, + lazy T args ) nothrow { - if (level < _minLevel) - return; + if (level < _minLevel) + return; - auto hasTag = true; - if (level <= LogLevel.diagnostic) - hasTag = false; - if (disableTag) - hasTag = false; + auto hasTag = true; + if (level <= LogLevel.diagnostic) + hasTag = false; + if (disableTag) + hasTag = false; - auto boldTag = false; - if (level >= LogLevel.warn) - boldTag = true; + auto boldTag = false; + if (level >= LogLevel.warn) + boldTag = true; - try - { - string result = format(fmt, args); + try + { + string result = format(fmt, args); - if (hasTag) - result = tag.rightJustify(TAG_WIDTH, ' ').color(tagColor, boldTag ? Mode.bold : Mode.init) ~ " " ~ result; + if (hasTag) + result = tag.rightJustify(TAG_WIDTH, ' ').color(tagColor, boldTag ? Mode.bold : Mode.init) ~ " " ~ result; - import dub.internal.colorize : cwrite; + import dub.internal.colorize : cwrite; - File output = (level <= LogLevel.info) ? stdout : stderr; + File output = (level <= LogLevel.info) ? stdout : stderr; - if (output.isOpen) - { - output.cwrite(result, "\n"); - output.flush(); - } - } - catch (Exception e) - { - debug assert(false, e.msg); - } + if (output.isOpen) + { + output.cwrite(result, "\n"); + output.flush(); + } + } + catch (Exception e) + { + debug assert(false, e.msg); + } } /** - Colors the specified string with the specified color. The function is used to - print colored text within a log message. The function also checks whether - color output is enabled or disabled (when not outputting to a TTY) and, in the - last case, just returns the plain string. This allows to use it like so: + Colors the specified string with the specified color. The function is used to + print colored text within a log message. The function also checks whether + color output is enabled or disabled (when not outputting to a TTY) and, in the + last case, just returns the plain string. This allows to use it like so: - logInfo("Tag", Color.green, "My %s log message", "colored".color(Color.red)); + logInfo("Tag", Color.green, "My %s log message", "colored".color(Color.red)); - without worring whether or not colored output is enabled or not. + without worring whether or not colored output is enabled or not. - Also a mode can be specified, such as bold/underline/etc... + Also a mode can be specified, such as bold/underline/etc... - Params: - str = The string to color - color = The color to apply - mode = An optional mode, such as bold/underline/etc... + Params: + str = The string to color + color = The color to apply + mode = An optional mode, such as bold/underline/etc... */ string color(const string str, const Color color, const Mode mode = Mode.init) { - import dub.internal.colorize; + import dub.internal.colorize; - if (_printColors == true) - return dub.internal.colorize.color(str, color, bg.init, mode); - else - return str; + if (_printColors == true) + return dub.internal.colorize.color(str, color, bg.init, mode); + else + return str; } /** - This function is the same as the above one, but just accepts a mode. - It's useful, for instance, when outputting bold text without changing the - color. + This function is the same as the above one, but just accepts a mode. + It's useful, for instance, when outputting bold text without changing the + color. - Params: - str = The string to color - mode = The mode, such as bold/underline/etc... + Params: + str = The string to color + mode = The mode, such as bold/underline/etc... */ string color(const string str, const Mode m = Mode.init) { - import dub.internal.colorize; + import dub.internal.colorize; - if (_printColors == true) - return dub.internal.colorize.color(str, fg.init, bg.init, m); - else - return str; + if (_printColors == true) + return dub.internal.colorize.color(str, fg.init, bg.init, m); + else + return str; } diff --git a/source/dub/packagesuppliers/maven.d b/source/dub/packagesuppliers/maven.d index 8d85b9d..8163819 100644 --- a/source/dub/packagesuppliers/maven.d +++ b/source/dub/packagesuppliers/maven.d @@ -12,7 +12,7 @@ import dub.internal.utils : retryDownload, HTTPStatusException; import dub.internal.vibecompat.data.json : serializeToJson; import dub.internal.vibecompat.inet.url : URL; - import dub.logging; + import dub.logging; import std.datetime : Clock, Duration, hours, SysTime, UTC;