Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colored output #2268

Merged
merged 42 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b617473
New logging module - initial functionality
gdelazzari Jun 8, 2018
5b9a5cf
Fixed different logInfo variants colliding
gdelazzari Jun 8, 2018
003dd64
Added support for text mode in color() function
gdelazzari Jun 8, 2018
e7ff233
Making the output prettier - first changes
gdelazzari Jun 8, 2018
c0d919c
Fix tabs in logging module (using spaces)
gdelazzari Jun 9, 2018
d943fae
Fix build script
gdelazzari Jun 9, 2018
86d785b
Add possibility to log without tag
gdelazzari Jun 11, 2018
081d1a9
Fixed output of some commands
gdelazzari Jun 11, 2018
6fd58d4
Now checks if the output is a console or not
gdelazzari Jun 9, 2018
3bfc2e9
Fix logging module settings with threads
gdelazzari Jun 11, 2018
658e20d
Removed cwrite from colorize unittests
gdelazzari Jun 11, 2018
262c660
Re-added dub.internal.vibecompat.core.log as deprecated
gdelazzari Jun 11, 2018
7cbb18f
Updated file list for build script
gdelazzari Jun 11, 2018
e4dddef
Bold tag for errors and warnings
gdelazzari Jun 11, 2018
3875a57
More improvements and replacements
gdelazzari Jun 11, 2018
543c895
Improved dub init output
gdelazzari Jun 11, 2018
2299775
Output improvements in package management
gdelazzari Jun 11, 2018
1793ace
Fixed blue color missing for config in up-to-date
gdelazzari Jun 11, 2018
b257797
Fixed project upgrade message
gdelazzari Jun 11, 2018
9b37a79
Fix build on Windows
gdelazzari Jun 11, 2018
2426703
Fixed 3 failing test cases
gdelazzari Jun 11, 2018
3e62997
Fix PowerShell messed-up colors
gdelazzari Jun 11, 2018
d3ee6a0
Fix indentation style, now using tabs
gdelazzari Jun 11, 2018
5371819
Minor code style fix
gdelazzari Jun 11, 2018
b4c45c5
Revert logInfo to print a single line after a fetch
gdelazzari Jun 11, 2018
d9a33fc
Add --no-colors option to disable colors in terminal
gdelazzari Jun 11, 2018
a6e9906
Add --force-colors option to force colors enabled
gdelazzari Jun 12, 2018
fd520aa
Replace --no-colors & --force-colors with --colors={auto|on|off}
gdelazzari Jun 12, 2018
ad874d8
Fix really stupid error in previous commit
gdelazzari Jun 12, 2018
2ab6340
Fix some older DMD frontend versions not compiling logging.d
gdelazzari Jun 12, 2018
027c4b1
Add new test for colored output
gdelazzari Jun 13, 2018
1ff762c
Fix non robust test (issue1091-bogus-rebuild)
gdelazzari Jun 13, 2018
395d4d4
Fixed stuff that shouldn't have been committed
gdelazzari Jun 13, 2018
79b6344
Fix rebase errors
Zardoz89 Apr 3, 2021
29229f6
Fix/Update some tests and make some info messages more similar to ori…
Zardoz89 Apr 4, 2021
19da088
Keep logging functionality out of the public API as requested in http…
veelo Jun 13, 2022
9f2d74d
Resolve deprecations.
veelo Jun 13, 2022
d2a54aa
Address review by WebFreak001.
veelo Jul 20, 2022
f0122be
Make unittest independent of byte value escape sequence.
veelo Jul 20, 2022
48d7c11
Don't require PERL regex in unittest.
veelo Jul 20, 2022
8b5c680
Incorporate review by Jan Jurzitza <[email protected]>.
veelo Jul 28, 2022
60417cf
File has moved.
veelo Jul 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ source/dub/internal/sdlang/util.d
source/dub/internal/undead/xml.d
source/dub/internal/utils.d
source/dub/internal/vibecompat/core/file.d
source/dub/internal/vibecompat/core/log.d
source/dub/internal/vibecompat/data/json.d
source/dub/internal/vibecompat/data/serialization.d
source/dub/internal/vibecompat/data/utils.d
source/dub/internal/vibecompat/inet/path.d
source/dub/internal/vibecompat/inet/url.d
source/dub/internal/colorize/colors.d
source/dub/internal/colorize/cwrite.d
source/dub/internal/colorize/package.d
source/dub/internal/colorize/winterm.d
source/dub/internal/logging.d
source/dub/package_.d
source/dub/packagemanager.d
source/dub/packagesupplier.d
Expand Down
42 changes: 35 additions & 7 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import dub.dependency;
import dub.dub;
import dub.generators.generator;
import dub.internal.vibecompat.core.file;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.data.json;
import dub.internal.vibecompat.inet.path;
import dub.internal.logging;
import dub.package_;
import dub.packagemanager;
import dub.packagesuppliers;
Expand Down Expand Up @@ -165,6 +165,19 @@ struct CommandLineHandler
{
options.root_path = options.root_path.expandTilde.absolutePath.buildNormalizedPath;
}

final switch (options.colors_mode) with (options.colors)
{
case automatic:
// Use default determined in internal.logging.initLogging().
break;
case on:
setLoggingColorsEnabled(true); // enable colors, no matter what
break;
case off:
setLoggingColorsEnabled(false); // disable colors, no matter what
break;
}
}

/** Get an instance of the requested command.
Expand Down Expand Up @@ -398,6 +411,10 @@ int runDubCommandLine(string[] args)
return [args0, "run", "-q", "--temp-build", "--single", file, "--"] ~ trailing;
}

// Initialize the logging module, ensure that whether stdout/stderr are a TTY
// or not is detected in order to disable colors if the output isn't a console
initLogging();

logDiagnostic("DUB version %s", getDUBVersion());

version(Windows){
Expand Down Expand Up @@ -536,6 +553,8 @@ struct CommonOptions {
bool help, annotate, bare;
string[] registry_urls;
string root_path;
enum colors { automatic, on, off } // Style violation in support of invalid option error formatting.
colors colors_mode = colors.automatic;
SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.none;
PlacementLocation placementLocation = PlacementLocation.user;

Expand Down Expand Up @@ -563,6 +582,13 @@ struct CommonOptions {
args.getopt("q|quiet", &quiet, ["Only print warnings and errors"]);
args.getopt("verror", &verror, ["Only print errors"]);
args.getopt("vquiet", &vquiet, ["Print no messages"]);
args.getopt("colors", &colors_mode, [
"Configure colored output. Accepted values:",
" automatic: Colored output on console/terminal,",
" unless NO_COLOR is set and non-empty (default)",
" on: Force colors enabled",
" off: Force colors disabled"
]);
args.getopt("cache", &placementLocation, ["Puts any fetched packages in the specified location [local|system|user]."]);

version_ = args.hasAppVersion;
Expand Down Expand Up @@ -1762,7 +1788,7 @@ class UpgradeCommand : Command {
enforceUsage(app_args.length == 0, "Unexpected application arguments.");
enforceUsage(!m_verify, "--verify is not yet implemented.");
enforce(loadCwdPackage(dub, true), "Failed to load package.");
logInfo("Upgrading project in %s", dub.projectPath.toNativeString());
logInfo("Upgrading", Color.cyan, "project in %s", dub.projectPath.toNativeString().color(Mode.bold));
auto options = UpgradeOptions.upgrade|UpgradeOptions.select;
if (m_missingOnly) options &= ~UpgradeOptions.upgrade;
if (m_prerelease) options |= UpgradeOptions.preRelease;
Expand Down Expand Up @@ -1875,9 +1901,11 @@ class FetchCommand : FetchRemoveCommand {
} else {
try {
dub.fetch(name, Dependency.any, location, fetchOpts);
logInfo("Finished", Color.green, "%s fetched", name.color(Mode.bold));
logInfo(
"Please note that you need to use `dub run <pkgname>` " ~
"or add it to dependencies of your package to actually use/run it.");
"or add it to dependencies of your package to actually use/run it. "
);
}
catch(Exception e){
logInfo("Getting a release version failed: %s", e.msg);
Expand Down Expand Up @@ -2086,10 +2114,10 @@ class ListCommand : Command {
const pname = pinfo.name;
const pvlim = Dependency(pinfo.version_ == "" ? "*" : pinfo.version_);
enforceUsage(app_args.length == 0, "The list command supports no application arguments.");
logInfo("Packages present in the system and known to dub:");
logInfoNoTag("Packages present in the system and known to dub:");
foreach (p; dub.packageManager.getPackageIterator()) {
if ((pname == "" || pname == p.name) && pvlim.matches(p.version_))
logInfo(" %s %s: %s", p.name, p.version_, p.path.toNativeString());
logInfo(" %s %s: %s", p.name.color(Mode.bold), p.version_, p.path.toNativeString());
}
logInfo("");
return 0;
Expand Down Expand Up @@ -2124,9 +2152,9 @@ class SearchCommand : Command {
justify += (~justify & 3) + 1; // round to next multiple of 4
foreach (desc, matches; res)
{
logInfo("==== %s ====", desc);
logInfoNoTag("==== %s ====", desc);
foreach (m; matches)
logInfo("%s%s", leftJustify(m.name ~ " (" ~ m.version_ ~ ")", justify), m.description);
logInfoNoTag(" %s%s", leftJustify(m.name ~ " (" ~ m.version_ ~ ")", justify), m.description);
}
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion source/dub/compilers/compiler.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public import dub.compilers.buildsettings;
deprecated("Please `import dub.dependency : Dependency` instead") public import dub.dependency : Dependency;
public import dub.platform : BuildPlatform, matchesSpecification;

import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.inet.path;

import dub.internal.logging;

import std.algorithm;
import std.array;
import std.exception;
Expand Down
2 changes: 1 addition & 1 deletion source/dub/compilers/dmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module dub.compilers.dmd;
import dub.compilers.compiler;
import dub.compilers.utils;
import dub.internal.utils;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.inet.path;
import dub.internal.logging;

import std.algorithm;
import std.array;
Expand Down
2 changes: 1 addition & 1 deletion source/dub/compilers/gdc.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module dub.compilers.gdc;
import dub.compilers.compiler;
import dub.compilers.utils;
import dub.internal.utils;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.inet.path;
import dub.internal.logging;

import std.algorithm;
import std.array;
Expand Down
2 changes: 1 addition & 1 deletion source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module dub.compilers.ldc;
import dub.compilers.compiler;
import dub.compilers.utils;
import dub.internal.utils;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.inet.path;
import dub.internal.logging;

import std.algorithm;
import std.array;
Expand Down
4 changes: 2 additions & 2 deletions source/dub/compilers/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module dub.compilers.utils;

import dub.compilers.buildsettings;
import dub.platform : BuildPlatform, archCheck, compilerCheck, platformCheck;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.inet.path;
import std.algorithm : canFind, endsWith, filter;
import dub.internal.logging;

import std.algorithm : canFind, endsWith, filter;

/**
Alters the build options to comply with the specified build requirements.
Expand Down
2 changes: 1 addition & 1 deletion source/dub/dependency.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
module dub.dependency;

import dub.internal.utils;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.core.file;
import dub.internal.vibecompat.data.json;
import dub.internal.vibecompat.inet.path;
import dub.package_;
import dub.semver;
import dub.internal.logging;

import std.algorithm;
import std.array;
Expand Down
2 changes: 1 addition & 1 deletion source/dub/dependencyresolver.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module dub.dependencyresolver;

import dub.dependency;
import dub.internal.vibecompat.core.log;
import dub.internal.logging;

import std.algorithm : all, canFind, filter, map, sort;
import std.array : appender, array, join;
Expand Down
26 changes: 13 additions & 13 deletions source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import dub.dependency;
import dub.dependencyresolver;
import dub.internal.utils;
import dub.internal.vibecompat.core.file;
import dub.internal.vibecompat.core.log;
import dub.internal.vibecompat.data.json;
import dub.internal.vibecompat.inet.url;
import dub.internal.logging;
import dub.package_;
import dub.packagemanager;
import dub.packagesuppliers;
Expand Down Expand Up @@ -549,19 +549,20 @@ class Dub {
if (basename == rootbasename) continue;

if (!m_project.selections.hasSelectedVersion(basename)) {
logInfo("Package %s would be selected with version %s.",
basename, ver);
logInfo("Upgrade", Color.cyan,
"Package %s would be selected with version %s", basename, ver);
any = true;
continue;
}
auto sver = m_project.selections.getSelectedVersion(basename);
if (!sver.path.empty || !sver.repository.empty) continue;
if (ver.version_ <= sver.version_) continue;
logInfo("Package %s would be upgraded from %s to %s.",
basename, sver, ver);
logInfo("Upgrade", Color.cyan,
"%s would be upgraded from %s to %s.",
basename.color(Mode.bold), sver, ver);
any = true;
}
if (any) logInfo("Use \"dub upgrade\" to perform those changes.");
if (any) logInfo("Use \"dub upgrade\" to perform those changes");
return;
}

Expand Down Expand Up @@ -727,7 +728,7 @@ class Dub {
/// Cleans intermediate/cache files of the given package
void cleanPackage(NativePath path)
{
logInfo("Cleaning package at %s...", path.toNativeString());
logInfo("Cleaning", Color.green, "package at %s", path.toNativeString().color(Mode.bold));
enforce(!Package.findPackageFile(path).empty, "No package found.", path.toNativeString());

// TODO: clear target files and copy files
Expand Down Expand Up @@ -793,13 +794,13 @@ class Dub {
packageId, ver, placement);
return existing;
} else {
logInfo("Removing %s %s to prepare replacement with a new version.", packageId, ver);
logInfo("Removing", Color.yellow, "%s %s to prepare replacement with a new version", packageId.color(Mode.bold), ver);
if (!m_dryRun) m_packageManager.remove(existing);
}
}

if (reason.length) logInfo("Fetching %s %s (%s)...", packageId, ver, reason);
else logInfo("Fetching %s %s...", packageId, ver);
if (reason.length) logInfo("Fetching", Color.yellow, "%s %s (%s)", packageId.color(Mode.bold), ver, reason);
else logInfo("Fetching", Color.yellow, "%s %s", packageId.color(Mode.bold), ver);
if (m_dryRun) return null;

logDebug("Acquiring package zip file");
Expand Down Expand Up @@ -851,7 +852,7 @@ class Dub {
*/
void remove(in Package pack)
{
logInfo("Removing %s in %s", pack.name, pack.path.toNativeString());
logInfo("Removing", Color.yellow, "%s (in %s)", pack.name.color(Mode.bold), pack.path.toNativeString());
if (!m_dryRun) m_packageManager.remove(pack);
}

Expand Down Expand Up @@ -914,7 +915,6 @@ class Dub {
foreach(pack; packages) {
try {
remove(pack);
logInfo("Removed %s, version %s.", package_id, pack.version_);
} catch (Exception e) {
logError("Failed to remove %s %s: %s", package_id, pack.version_, e.msg);
logInfo("Continuing with other packages (if any).");
Expand Down Expand Up @@ -1141,7 +1141,7 @@ class Dub {
}

//Act smug to the user.
logInfo("Successfully created an empty project in '%s'.", path.toNativeString());
logInfo("Success", Color.green, "created empty project in %s", path.toNativeString().color(Mode.bold));
}

private void runCustomInitialization(NativePath path, string type, string[] runArgs)
Expand Down
Loading