Skip to content

Commit

Permalink
Trivial: Fix dlang#2774 - Color codes on windows terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
MrcSnm authored Jan 23, 2024
1 parent 9d99061 commit 9357dd1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -1005,14 +1005,15 @@ class InitCommand : Command {

static string input(string caption, string default_value)
{
writef("%s [%s]: ", caption.color(Mode.bold), default_value);
stdout.flush();
import dub.internal.colorize;
cwritef("%s [%s]: ", caption.color(Mode.bold), default_value);
auto inp = readln();
return inp.length > 1 ? inp[0 .. $-1] : default_value;
}

static string select(string caption, bool free_choice, string default_value, const string[] options...)
{
import dub.internal.colorize.cwrite;
assert(options.length);
import std.math : floor, log10;
auto ndigits = (size_t val) => log10(cast(double) val).floor.to!uint + 1;
Expand All @@ -1035,17 +1036,17 @@ class InitCommand : Command {
auto user_to_idx = (size_t i) => cast(uint)i - 1;

assert(default_idx >= 0);
writeln((free_choice ? "Select or enter " : "Select ").color(Mode.bold), caption.color(Mode.bold), ":".color(Mode.bold));
cwriteln((free_choice ? "Select or enter " : "Select ").color(Mode.bold), caption.color(Mode.bold), ":".color(Mode.bold));
foreach (i, option; options_matrix)
{
if (i != 0 && (i % num_columns) == 0) writeln();
if (i != 0 && (i % num_columns) == 0) cwriteln();
if (!option.length)
continue;
auto user_id = idx_to_user(option);
writef("%*u)".color(Color.cyan, Mode.bold) ~ " %s", ndigits(options.length), user_id,
cwritef("%*u)".color(Color.cyan, Mode.bold) ~ " %s", ndigits(options.length), user_id,
leftJustifier(option, max_width));
}
writeln();
cwriteln();
immutable default_choice = (default_idx + 1).to!string;
while (true)
{
Expand All @@ -1069,7 +1070,7 @@ class InitCommand : Command {
free_choice ? " or enter a custom value" : null);
}
}

static string license_select(string def)
{
static immutable licenses = [
Expand Down

0 comments on commit 9357dd1

Please sign in to comment.