Skip to content

Commit 0293d86

Browse files
authored
Merge pull request #337 from UNF0X/master
Pull request for master
2 parents f9d7288 + 1675910 commit 0293d86

File tree

6 files changed

+75
-17
lines changed

6 files changed

+75
-17
lines changed

packager/buildSrc/DefaultPlugin.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use httpclient\HttpClient;
99
use httpclient\HttpRequest;
1010
use packager\cli\Console;
11+
use packager\Colors;
1112
use packager\Event;
1213
use packager\Package;
1314
use packager\PackageDependencyTree;
@@ -91,19 +92,19 @@ function init(Event $event)
9192
Console::error("Failed to init, package '{0}' already exists", $dir . '/' . Package::FILENAME);
9293
exit(-1);
9394
}
94-
95-
Console::log("Init new package in dir '$dir'':");
95+
Console::log(Colors::withColor("JPHP Packager", 'silver') . " " . Colors::withColor($event->packager()->getVersion(), 'bold'));
96+
Console::log("Init new package in dir '$dir':");
9697

9798
$name = fs::name(fs::parent($dir . "/foo"));
9899
$version = "1.0.0";
99100

100101
if ($event->isFlag('y', 'yes')) {
101102
$addAppPlugin = true;
102103
} else {
103-
$name = Console::read("Enter name ($name):", $name);
104-
$version = Console::read("Enter version ($version):", $version);
105-
$description = Console::read("Enter description:", '');
106-
$addAppPlugin = Console::readYesNo("Add 'jphp app' plugin? (default = Yes)", 'yes');
104+
$name = Console::read("Enter ".Colors::withColor('name', 'bold')." ($name):", $name);
105+
$version = Console::read("Enter ".Colors::withColor('version', 'bold')." ($version):", $version);
106+
$description = Console::read("Enter ".Colors::withColor('description', 'bold').":", '');
107+
$addAppPlugin = Console::readYesNo("Add '".Colors::withColor('jphp app', 'bold')."' plugin? (default = Yes)", 'yes');
107108
}
108109

109110
$data = [
@@ -134,7 +135,7 @@ function init(Event $event)
134135
Console::log("Success, {0} has been created.", Package::FILENAME);
135136
}
136137

137-
Console::log("Done.");
138+
Console::log("Done.");
138139
}
139140

140141
/**

packager/package.php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: jppm
2-
version: 0.5.5
2+
version: 0.5.6
33

44
plugins: [GitHub, Hub, Doc]
55

packager/src-php/Tasks.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static function copy(string $path, string $intoDir, bool $ignoreErrs = false)
9393
*/
9494
static function createFile(string $path, string $content = '', bool $ignoreErrs = false): bool
9595
{
96-
Console::log("-> create new file '{0}'", $path);
96+
Console::info("Create new file '{0}'", $path);
9797

9898
try {
9999
fs::ensureParent($path);
@@ -117,7 +117,7 @@ static function createFile(string $path, string $content = '', bool $ignoreErrs
117117
static function deleteFile(string $path, bool $ignoreErrs = false): bool
118118
{
119119
if (fs::exists($path)) {
120-
Console::log("-> delete file '{0}'", $path);
120+
Console::info("Delete file '{0}'", $path);
121121

122122
if (fs::delete($path)) {
123123
return true;
@@ -143,7 +143,7 @@ static function deleteFile(string $path, bool $ignoreErrs = false): bool
143143
static function cleanDir(string $path, array $filter = [], bool $ignoreErrs = false): bool
144144
{
145145
if (fs::isDir($path)) {
146-
Console::log("-> clean dir '{0}'", $path);
146+
Console::info("Clean dir '{0}'", $path);
147147

148148
$result = fs::clean($path, $filter);
149149

@@ -178,7 +178,7 @@ static function createDir(string $path, bool $ignoreErrs = false): bool
178178
return true;
179179
}
180180

181-
Console::log("-> create dir '{0}'", $path);
181+
Console::info("Create dir '{0}'", $path);
182182

183183
if (fs::makeDir($path)) {
184184
return true;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
namespace packager;
3+
4+
use php\lib\char;
5+
6+
class Colors{
7+
public static $ANSI_CODES = array(
8+
"off" => 0,
9+
"bold" => 1,
10+
"italic" => 3,
11+
"underline" => 4,
12+
"blink" => 5,
13+
"inverse" => 7,
14+
"hidden" => 8,
15+
"gray" => 30,
16+
"red" => 31,
17+
"green" => 32,
18+
"yellow" => 33,
19+
"blue" => 34,
20+
"magenta" => 35,
21+
"cyan" => 36,
22+
"silver" => "0;37",
23+
"white" => 37,
24+
"black_bg" => 40,
25+
"red_bg" => 41,
26+
"green_bg" => 42,
27+
"yellow_bg" => 43,
28+
"blue_bg" => 44,
29+
"magenta_bg" => 45,
30+
"cyan_bg" => 46,
31+
"white_bg" => 47,
32+
);
33+
34+
public static function withColor($str, $color)
35+
{
36+
37+
if(Package::getOS()=='win'){
38+
return $str;
39+
}
40+
$color_attrs = explode("+", $color);
41+
$ansi_str = "";
42+
43+
foreach ($color_attrs as $attr) {
44+
$ansi_str .= char::of(27) . "[" . self::$ANSI_CODES[$attr] . "m";
45+
}
46+
47+
$ansi_str .= $str . char::of(27) . "[" . self::$ANSI_CODES["off"] . "m";
48+
return $ansi_str;
49+
}
50+
}
51+
?>

packager/src-php/packager/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function findPackage(string $name, string $versionPattern, ?PackageLock $
396396
if ($foundVersionSource instanceof ExternalRepository) {
397397
$foundVersionInfo = $this->getVersionInfoFromExternal($foundVersionSource, $name, $foundVersion);
398398

399-
Console::log("-> download package {0}@{1} from '{$foundVersionSource->getSource()}'", $name, $foundVersion);
399+
Console::info("-> ".Colors::withColor('Download Package', 'green')." {0}@{1} from '{$foundVersionSource->getSource()}'", $name, $foundVersion);
400400

401401
$indexFile = "$this->dir/$name/$foundVersion.json";
402402
$archFile = "$this->dir/$name/$foundVersion.tar.gz";

packager/src-php/packager/cli/Console.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace packager\cli;
33

44

5+
use packager\Colors;
56
use php\io\Stream;
67
use php\lang\System;
78
use php\lib\arr;
@@ -32,18 +33,23 @@ public static function debug($message, ...$args)
3233
{
3334
global $app;
3435
if ($app->isDebug()) {
35-
static::log("[DEBUG] $message", ...$args);
36+
static::log(Colors::withColor('(debug)', 'silver')." $message", ...$args);
3637
}
3738
}
3839

3940
public static function warn($message, ...$args)
4041
{
41-
static::log("[WARNING] $message", ...$args);
42+
static::log(Colors::withColor('(warning)', 'yellow')." $message", ...$args);
4243
}
4344

4445
public static function error($message, ...$args)
4546
{
46-
static::log("[ERROR] $message", ...$args);
47+
static::log(Colors::withColor('(error)', 'red')." $message", ...$args);
48+
}
49+
50+
public static function info($message, ...$args)
51+
{
52+
static::log(Colors::withColor('(info)', 'magenta')." $message", ...$args);
4753
}
4854

4955
public static function readYesNo(string $message, bool $default = false): bool
@@ -53,7 +59,7 @@ public static function readYesNo(string $message, bool $default = false): bool
5359
if (arr::has(['yes', 'y'], $result)) return true;
5460
if (arr::has(['no', 'n'], $result)) return false;
5561

56-
static::log(" -> please enter Y (yes) or N (no), try again ...");
62+
static::log(" -> please enter ".Colors::withColor('Y', 'green')." (yes) or ".Colors::withColor('N', 'yellow')." (no), try again ...");
5763

5864
return static::readYesNo($message, $default);
5965
}

0 commit comments

Comments
 (0)