8000 [Console] Add markdown format to Table · symfony/symfony@cff05c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit cff05c0

Browse files
committed
[Console] Add markdown format to Table
1 parent eff9b52 commit cff05c0

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public function render(): void
417417
continue;
418418
}
419419

420-
if ($isHeader && !$isHeaderSeparatorRendered) {
420+
if ($isHeader && !$isHeaderSeparatorRendered && $this->style->getIntro()) {
421421
$this->renderRowSeparator(
422422
self::SEPARATOR_TOP,
423423
$hasTitle ? $this->headerTitle : null,
@@ -449,7 +449,10 @@ public function render(): void
449449
}
450450
}
451451
}
452-
$this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat());
452+
453+
if ($this->getStyle()->getOutro()) {
454+
$this->renderRowSeparator(self::SEPARATOR_BOTTOM, $this->footerTitle, $this->style->getFooterTitleFormat());
455+
}
453456

454457
$this->cleanup();
455458
$this->rendered = true;
@@ -868,6 +871,12 @@ private function cleanup(): void
868871
*/
869872
private static function initStyles(): array
870873
{
874+
$markdown = new TableStyle();
875+
$markdown
876+
->setDefaultCrossingChar('|')
877+
->setFraming(false, false)
878+
;
879+
871880
$borderless = new TableStyle();
872881
$borderless
873882
->setHorizontalBorderChars('=')
@@ -905,6 +914,7 @@ private static function initStyles(): array
905914

906915
return [
907916
'default' => new TableStyle(),
917+
'markdown' => $markdown,
908918
'borderless' => $borderless,
909919
'compact' => $compact,
910920
'symfony-style-guide' => $styleGuide,

src/Symfony/Component/Console/Helper/TableStyle.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class TableStyle
4646
private string $cellRowFormat = '%s';
4747
private string $cellRowContentFormat = ' %s ';
4848
private string $borderFormat = '%s';
49+
private bool $intro = true;
50+
private bool $outro = true;
4951
private int $padType = \STR_PAD_RIGHT;
5052

5153
/**
@@ -359,4 +361,21 @@ public function setFooterTitleFormat(string $format): static
359361

360362
return $this;
361363
}
364+
365+
public function setFraming(bool $intro = true, bool $outro = true): static
366+
{
367+
$this->intro = $intro;
368+
$this->outro = $outro;
369+
370+
return $this;
371+
}
372+
373+
public function getIntro(): bool
374+
{
375+
return $this->intro;
376+
}
377+
378+
public function getOutro(): bool{
379+
return $this->outro;
380+
}
362381
}

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ public static function renderProvider()
112112
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
113113
+---------------+--------------------------+------------------+
114114

115+
TABLE,
116+
],
117+
[
118+
['ISBN', 'Title', 'Author'],
119+
$books,
120+
'markdown',
121+
<<<'TABLE'
122+
| ISBN | Title | Author |
123+
|---------------|--------------------------|------------------|
124+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
125+
| 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
126+
| 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
127+
| 80-902734-1-6 | And Then There Were None | Agatha Christie |
128+
115129
TABLE,
116130
],
117131
[

0 commit comments

Comments
 (0)
0