Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1b3467

Browse files
committed
[Console] Fix formatting of SymfonyStyle::comment()
Remove decoration from frameworkbundle test (avoid testing the Console behaviour)Set background to defaultTest outputAdapt test for FrameworkBundleUse Helper::strlenWithoutDecoration rather than Helper::strlen(strip_tags(..))Improve logic for align all lines to the first in block()Tests more block() possible outputs
1 parentf4dbd30 commitd1b3467

File tree

9 files changed

+118
-51
lines changed

9 files changed

+118
-51
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
//This service is an alias for the service service_1
2+
 //This service is an alias for the service service_1
33

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
//This service is an alias for the service service_2
2+
 //This service is an alias for the service service_2
33

‎src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,53 +66,10 @@ public function __construct(InputInterface $input, OutputInterface $output)
6666
*/
6767
publicfunctionblock($messages,$type =null,$style =null,$prefix ='',$padding =false)
6868
{
69-
$this->autoPrependBlock();
7069
$messages =is_array($messages) ?array_values($messages) :array($messages);
71-
$indentLength =0;
72-
$lines =array();
73-
74-
if (null !==$type) {
75-
$typePrefix =sprintf('[%s]',$type);
76-
$indentLength =strlen($typePrefix);
77-
$lineIndentation =str_repeat('',$indentLength);
78-
}
79-
80-
// wrap and add newlines for each element
81-
foreach ($messagesas$key =>$message) {
82-
$message = OutputFormatter::escape($message);
83-
$lines =array_merge($lines,explode(PHP_EOL,wordwrap($message,$this->lineLength - Helper::strlen($prefix) -$indentLength,PHP_EOL,true)));
84-
85-
// prefix each line with a number of spaces equivalent to the type length
86-
if (null !==$type) {
87-
foreach ($linesas &$line) {
88-
$line =$lineIndentation ===substr($line,0,$indentLength) ?$line :$lineIndentation.$line;
89-
}
90-
}
91-
92-
if (count($messages) >1 &&$key <count($messages) -1) {
93-
$lines[] ='';
94-
}
95-
}
9670

97-
if (null !==$type) {
98-
$lines[0] =substr_replace($lines[0],$typePrefix,0,$indentLength);
99-
}
100-
101-
if ($padding &&$this->isDecorated()) {
102-
array_unshift($lines,'');
103-
$lines[] ='';
104-
}
105-
106-
foreach ($linesas &$line) {
107-
$line =sprintf('%s%s',$prefix,$line);
108-
$line .=str_repeat('',$this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(),$line));
109-
110-
if ($style) {
111-
$line =sprintf('<%s>%s</>',$style,$line);
112-
}
113-
}
114-
115-
$this->writeln($lines);
71+
$this->autoPrependBlock();
72+
$this->writeln($this->createBlock($messages,$type,$style,$prefix,$padding,true));
11673
$this->newLine();
11774
}
11875

@@ -177,11 +134,10 @@ public function text($message)
177134
publicfunctioncomment($message)
178135
{
179136
$messages =is_array($message) ?array_values($message) :array($message);
180-
foreach ($messagesas &$message) {
181-
$message =$this->getFormatter()->format($message);
182-
}
183137

184-
$this->block($messages,null,null,' //');
138+
$this->autoPrependBlock();
139+
$this->writeln($this->createBlock($messages,null,null,'<fg=default;bg=default> // </>'));
140+
$this->newLine();
185141
}
186142

187143
/**
@@ -437,4 +393,49 @@ private function reduceBuffer($messages)
437393
returnsubstr($value, -4);
438394
},array_merge(array($this->bufferedOutput->fetch()), (array)$messages));
439395
}
396+
397+
privatefunctioncreateBlock($messages,$type =null,$style =null,$prefix ='',$padding =false,$escape =false)
398+
{
399+
$indentLength =0;
400+
$lines =array();
401+
402+
if (null !==$type) {
403+
$type =sprintf('[%s]',$type);
404+
$indentLength =strlen($type);
405+
$lineIndentation =str_repeat('',$indentLength);
406+
}
407+
408+
// wrap and add newlines for each element
409+
foreach ($messagesas$key =>$message) {
410+
if ($escape) {
411+
$message = OutputFormatter::escape($message);
412+
}
413+
414+
$lines =array_merge($lines,explode(PHP_EOL,wordwrap($message,$this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(),$prefix) -$indentLength,PHP_EOL,true)));
415+
416+
if (count($messages) >1 &&$key <count($messages) -1) {
417+
$lines[] ='';
418+
}
419+
}
420+
421+
foreach ($linesas$i => &$line) {
422+
if (null !==$type) {
423+
$line =0 ===$i ?$type.$line :$lineIndentation.$line;
424+
}
425+
426+
$line =$prefix.$line;
427+
$line .=str_repeat('',$this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(),$line));
428+
429+
if ($style) {
430+
$line =sprintf('<%s>%s</>',$style,$line);
431+
}
432+
}
433+
434+
if ($padding &&$this->isDecorated()) {
435+
array_unshift($lines,'');
436+
$lines[] ='';
437+
}
438+
439+
return$lines;
440+
}
440441
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
useSymfony\Component\Console\Input\InputInterface;
4+
useSymfony\Component\Console\Output\OutputInterface;
5+
useSymfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
useSymfony\Component\Console\Style\SymfonyStyle;
7+
8+
// ensure that nested tags have no effect on the color of the '//' prefix
9+
returnfunction (InputInterface$input,OutputInterface$output) {
10+
$output->setDecorated(true);
11+
$output =newSymfonyStyle($input,$output);
12+
$output->comment(
13+
'Lorem ipsum dolor sit <comment>amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</comment> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum'
14+
);
15+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
useSymfony\Component\Console\Input\InputInterface;
4+
useSymfony\Component\Console\Output\OutputInterface;
5+
useSymfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
// ensure that block() behaves properly with a prefix and without type
8+
returnfunction (InputInterface$input,OutputInterface$output) {
9+
$output =newSymfonyStyleWithForcedLineLength($input,$output);
10+
$output->block(
11+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
12+
null,
13+
null,
14+
'$',
15+
true
16+
);
17+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
useSymfony\Component\Console\Input\InputInterface;
4+
useSymfony\Component\Console\Output\OutputInterface;
5+
useSymfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
// ensure that block() behaves properly with a type and without prefix
8+
returnfunction (InputInterface$input,OutputInterface$output) {
9+
$output =newSymfonyStyleWithForcedLineLength($input,$output);
10+
$output->block(
11+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
12+
'TEST'
13+
);
14+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
 // Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et 
3+
 // dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 
4+
 // commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 
5+
 // pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
6+
 // id est laborum
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
$ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
3+
$ aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
4+
$ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
5+
$ occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
[TEST] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
3+
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
4+
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
5+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
6+
laborum
7+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp