diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 6f6958b..e3d54b5 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -534,12 +534,20 @@ // execute the command try return cmd.execute(dub, remaining_args, command_args.appArgs); catch (UsageException e) { + // usage exceptions get thrown before any logging, so we are + // making the errors more narrow to better fit on small screens. + tagWidth.push(5); logError("%s", e.msg); logDebug("Full exception: %s", e.toString().sanitize); - logInfo(`Run "dub %s -h" for more information about the "%s" command.`, cmd.name, cmd.name); + logInfo(`Run "%s" for more information about the "%s" command.`, + text("dub ", cmd.name, " -h").color(Mode.bold), cmd.name.color(Mode.bold)); return 1; } catch (Exception e) { + // most exceptions get thrown before logging, so same thing here as + // above. However this might be subject to change if it results in + // weird behavior anywhere. + tagWidth.push(5); logError("%s", e.msg); logDebug("Full exception: %s", e.toString().sanitize); return 2; diff --git a/source/dub/dub.d b/source/dub/dub.d index c98d631..2057b3e 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -1177,7 +1177,9 @@ auto srcfile = m_project.rootPackage.recipePath; auto srcext = srcfile.head.name.extension; if (srcext == "."~destination_file_ext) { - logInfo("Package format is already %s.", destination_file_ext); + // no logging before this point + tagWidth.push(5); + logError("Package format is already %s.", destination_file_ext); return; } diff --git a/source/dub/internal/logging.d b/source/dub/internal/logging.d index 3b45cf7..3a01c45 100644 --- a/source/dub/internal/logging.d +++ b/source/dub/internal/logging.d @@ -76,8 +76,38 @@ */ public alias Mode = mode; -/// The tag width in chars, defined as a constant here -private const int TAG_WIDTH = 12; +/// Defines the current width of logging tags for justifying in chars. +/// Can be manipulated through push and pop. +struct TagWidth { + import core.atomic; + + private shared int value = 12; + private shared int index; + private shared int[16] stack; + + /// Gets the tag width in chars + public int get() { + return value; + } + + /// Changes the tag width for all following logging calls, until $(LREF pop) is called. + public void push(int width) { + int currentIndex = index; + index.atomicOp!"+="(1); + stack[currentIndex] = value; + assert(index < stack.length, "too many TagWidth.push without pop"); + value = width; + } + + /// Reverts the last $(LREF push) call. + public void pop() { + assert(index > 0); + value = stack[index.atomicOp!"-="(1)]; + } +} + +/// The global tag width instance used for logging. +public __gshared TagWidth tagWidth; /// Possible log levels supported enum LogLevel { @@ -201,7 +231,7 @@ /** 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). + case there will be an identation of tagWidth chars on the left anyway). Params: level = The log level for the logged message @@ -320,7 +350,7 @@ string result = format(fmt, args); if (hasTag) - result = tag.rightJustify(TAG_WIDTH, ' ').color(tagColor, boldTag ? Mode.bold : Mode.init) ~ " " ~ result; + result = tag.rightJustify(tagWidth.get, ' ').color(tagColor, boldTag ? Mode.bold : Mode.init) ~ " " ~ result; import dub.internal.colorize : cwrite;