Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
725d8100
Commit
725d8100
authored
Jun 14, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored console controller color option.
parent
f3cc5d1e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
26 deletions
+25
-26
Controller.php
framework/yii/console/Controller.php
+18
-25
HelpController.php
framework/yii/console/controllers/HelpController.php
+4
-0
MigrateController.php
framework/yii/console/controllers/MigrateController.php
+3
-1
No files found.
framework/yii/console/Controller.php
View file @
725d8100
...
@@ -35,34 +35,23 @@ class Controller extends \yii\base\Controller
...
@@ -35,34 +35,23 @@ class Controller extends \yii\base\Controller
public
$interactive
=
true
;
public
$interactive
=
true
;
/**
/**
* @var boolean whether to enable ANSI
style in
output.
* @var boolean whether to enable ANSI
color in the
output.
*
Defaults to null meaning auto-detec
t.
*
If not set, ANSI color will be enabled for terminals that support i
t.
*/
*/
p
rivate
$_colors
;
p
ublic
$color
;
/**
/**
*
Whether to enable ANSI style in output
.
*
Returns a value indicating whether ANSI color is enabled
.
*
*
*
Setting this will affect [[ansiFormat()]], [[stdout()]] and [[stderr()]].
*
ANSI color is enabled only if [[color]] is not set or is set true,
*
If not set it will be auto detected using [[yii\helpers\Console::streamSupportsAnsiColors()]] with STDOUT
*
and the terminal must support ANSI color.
*
for [[ansiFormat()]] and [[stdout()]] and STDERR for [[stderr()]].
*
* @param resource $stream
* @param resource $stream
the stream to check.
* @return boolean Whether to enable ANSI style in output.
* @return boolean Whether to enable ANSI style in output.
*/
*/
public
function
getColors
(
$stream
=
STDOUT
)
public
function
isColorEnabled
(
$stream
=
STDOUT
)
{
{
if
(
$this
->
_colors
===
null
)
{
return
(
$this
->
color
===
null
||
$this
->
color
)
&&
Console
::
streamSupportsAnsiColors
(
$stream
);
return
Console
::
streamSupportsAnsiColors
(
$stream
);
}
return
$this
->
_colors
;
}
/**
* Whether to enable ANSI style in output.
*/
public
function
setColors
(
$value
)
{
$this
->
_colors
=
(
bool
)
$value
;
}
}
/**
/**
...
@@ -151,6 +140,7 @@ class Controller extends \yii\base\Controller
...
@@ -151,6 +140,7 @@ class Controller extends \yii\base\Controller
* You may pass additional parameters using the constants defined in [[yii\helpers\base\Console]].
* You may pass additional parameters using the constants defined in [[yii\helpers\base\Console]].
*
*
* Example:
* Example:
*
* ~~~
* ~~~
* $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* ~~~
* ~~~
...
@@ -160,7 +150,7 @@ class Controller extends \yii\base\Controller
...
@@ -160,7 +150,7 @@ class Controller extends \yii\base\Controller
*/
*/
public
function
ansiFormat
(
$string
)
public
function
ansiFormat
(
$string
)
{
{
if
(
$this
->
getColors
())
{
if
(
$this
->
isColorEnabled
())
{
$args
=
func_get_args
();
$args
=
func_get_args
();
array_shift
(
$args
);
array_shift
(
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
...
@@ -175,6 +165,7 @@ class Controller extends \yii\base\Controller
...
@@ -175,6 +165,7 @@ class Controller extends \yii\base\Controller
* passing additional parameters using the constants defined in [[yii\helpers\base\Console]].
* passing additional parameters using the constants defined in [[yii\helpers\base\Console]].
*
*
* Example:
* Example:
*
* ~~~
* ~~~
* $this->stdout('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* $this->stdout('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* ~~~
* ~~~
...
@@ -184,7 +175,7 @@ class Controller extends \yii\base\Controller
...
@@ -184,7 +175,7 @@ class Controller extends \yii\base\Controller
*/
*/
public
function
stdout
(
$string
)
public
function
stdout
(
$string
)
{
{
if
(
$this
->
getColors
())
{
if
(
$this
->
isColorEnabled
())
{
$args
=
func_get_args
();
$args
=
func_get_args
();
array_shift
(
$args
);
array_shift
(
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
...
@@ -199,6 +190,7 @@ class Controller extends \yii\base\Controller
...
@@ -199,6 +190,7 @@ class Controller extends \yii\base\Controller
* passing additional parameters using the constants defined in [[yii\helpers\base\Console]].
* passing additional parameters using the constants defined in [[yii\helpers\base\Console]].
*
*
* Example:
* Example:
*
* ~~~
* ~~~
* $this->stderr('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* $this->stderr('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* ~~~
* ~~~
...
@@ -208,7 +200,7 @@ class Controller extends \yii\base\Controller
...
@@ -208,7 +200,7 @@ class Controller extends \yii\base\Controller
*/
*/
public
function
stderr
(
$string
)
public
function
stderr
(
$string
)
{
{
if
(
$this
->
getColors
(
STDERR
))
{
if
(
$this
->
isColorEnabled
(
STDERR
))
{
$args
=
func_get_args
();
$args
=
func_get_args
();
array_shift
(
$args
);
array_shift
(
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
...
@@ -221,6 +213,7 @@ class Controller extends \yii\base\Controller
...
@@ -221,6 +213,7 @@ class Controller extends \yii\base\Controller
*
*
* @param string $text prompt string
* @param string $text prompt string
* @param array $options the options to validate the input:
* @param array $options the options to validate the input:
*
* - required: whether it is required or not
* - required: whether it is required or not
* - default: default value if no input is inserted by the user
* - default: default value if no input is inserted by the user
* - pattern: regular expression pattern to validate user input
* - pattern: regular expression pattern to validate user input
...
@@ -281,6 +274,6 @@ class Controller extends \yii\base\Controller
...
@@ -281,6 +274,6 @@ class Controller extends \yii\base\Controller
*/
*/
public
function
globalOptions
()
public
function
globalOptions
()
{
{
return
array
(
'color
s
'
,
'interactive'
);
return
array
(
'color'
,
'interactive'
);
}
}
}
}
framework/yii/console/controllers/HelpController.php
View file @
725d8100
...
@@ -406,6 +406,10 @@ class HelpController extends Controller
...
@@ -406,6 +406,10 @@ class HelpController extends Controller
if
(
$type
===
null
)
{
if
(
$type
===
null
)
{
$type
=
gettype
(
$defaultValue
);
$type
=
gettype
(
$defaultValue
);
}
}
if
(
is_bool
(
$defaultValue
))
{
// show as integer to avoid confusion
$defaultValue
=
(
int
)
$defaultValue
;
}
$doc
=
"
$type
(defaults to "
.
var_export
(
$defaultValue
,
true
)
.
")"
;
$doc
=
"
$type
(defaults to "
.
var_export
(
$defaultValue
,
true
)
.
")"
;
}
elseif
(
trim
(
$type
)
!==
''
)
{
}
elseif
(
trim
(
$type
)
!==
''
)
{
$doc
=
$type
;
$doc
=
$type
;
...
...
framework/yii/console/controllers/MigrateController.php
View file @
725d8100
...
@@ -96,7 +96,9 @@ class MigrateController extends Controller
...
@@ -96,7 +96,9 @@ class MigrateController extends Controller
*/
*/
public
function
globalOptions
()
public
function
globalOptions
()
{
{
return
array
(
'migrationPath'
,
'migrationTable'
,
'db'
,
'templateFile'
,
'interactive'
);
return
array_merge
(
parent
::
globalOptions
(),
array
(
'migrationPath'
,
'migrationTable'
,
'db'
,
'templateFile'
,
'interactive'
));
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment