File tree Expand file tree Collapse file tree 4 files changed +69
-2
lines changed
tests/Unit/Extension/Console/Stage Expand file tree Collapse file tree 4 files changed +69
-2
lines changed Original file line number Diff line number Diff line change 7
7
use PhpBench \Pipeline \Extension \Console \Stage \Redraw ;
8
8
use PhpBench \Pipeline \Extension \Console \Stage \Table ;
9
9
use PhpBench \Pipeline \Extension \Console \Stage \BarChart ;
10
+ use PhpBench \Pipeline \Extension \Console \Stage \Title ;
10
11
11
12
class ConsoleExtension implements PipelineExtension
12
13
{
@@ -20,6 +21,7 @@ public function __construct()
20
21
$ this ->stages = [
21
22
'console/redraw ' => new Redraw (),
22
23
'console/table ' => new Table (),
24
+ 'console/title ' => new Title (),
23
25
'console/bar-chart ' => new BarChart (),
24
26
];
25
27
}
Original file line number Diff line number Diff line change @@ -32,10 +32,13 @@ public function __invoke(): Generator
32
32
break ;
33
33
}
34
34
35
- $ text = self ::ANSI_RESTORE_CURSOR_POS .$ text ;
35
+ if ($ firstLine ) {
36
+ $ text = self ::ANSI_RESTORE_CURSOR_POS .$ text ;
37
+ $ firstLine = false ;
38
+ }
39
+
36
40
$ lineLength = $ this ->maxLineLength ($ text , $ lineLength );
37
41
$ text = $ this ->maximizeLines ($ text , $ lineLength );
38
- break ;
39
42
}
40
43
41
44
list ($ config , $ data ) = yield $ data ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PhpBench \Pipeline \Extension \Console \Stage ;
4
+
5
+ use PhpBench \Pipeline \Core \Stage ;
6
+ use Generator ;
7
+ use PhpBench \Pipeline \Core \Schema ;
8
+
9
+ class Title implements Stage
10
+ {
11
+ public function __invoke (): Generator
12
+ {
13
+ list ($ config , $ data ) = yield ;
14
+ while (true ) {
15
+ list ($ config , $ data ) = yield [
16
+ $ this ->title ($ config ['text ' ]),
17
+ ];
18
+ }
19
+ }
20
+
21
+ public function configure (Schema $ schema )
22
+ {
23
+ $ schema ->setRequired ([
24
+ 'text '
25
+ ]);
26
+ $ schema ->setTypes ([
27
+ 'text ' => 'string '
28
+ ]);
29
+ }
30
+
31
+ private function title (string $ text ): string
32
+ {
33
+ return implode (PHP_EOL , [
34
+ $ text ,
35
+ str_repeat ('= ' , mb_strlen ($ text ))
36
+ ]);
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PhpBench \Pipeline \Tests \Unit \Extension \Console \Stage ;
4
+
5
+ use PhpBench \Pipeline \Tests \Unit \Extension \Console \ConsoleTestCase ;
6
+
7
+ class TitleTest extends ConsoleTestCase
8
+ {
9
+ public function testUnderlinedTitleText ()
10
+ {
11
+ $ pipeline = $ this ->pipeline ()
12
+ ->stage ('console/title ' , [
13
+ 'text ' => 'Hello World ' ,
14
+ ]);
15
+
16
+ $ output = $ pipeline ->build ()->generator ([])->current ();
17
+
18
+ $ this ->assertEquals ([ <<<EOT
19
+ Hello World
20
+ ===========
21
+ EOT
22
+ ], $ output );
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments