From 5844ee66a68c19bbcff3f7300756ed1df31c4c3a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 25 Mar 2025 16:39:30 +0100 Subject: [PATCH] [Console] Tweak the tree helper --- components/console/helpers/tree.rst | 250 ++++++++++++++-------------- 1 file changed, 129 insertions(+), 121 deletions(-) diff --git a/components/console/helpers/tree.rst b/components/console/helpers/tree.rst index ae0c24ff01f..1161d00e942 100644 --- a/components/console/helpers/tree.rst +++ b/components/console/helpers/tree.rst @@ -67,7 +67,7 @@ This exampe would output the following: ├── templates/ └── tests/ -The given contents can be defined in a multi-dimensional array: +The given contents can be defined in a multi-dimensional array:: $tree = TreeHelper::createTree($io, null, [ 'src' => [ @@ -125,126 +125,132 @@ Built-in Tree Styles ~~~~~~~~~~~~~~~~~~~~ The tree helper provides a few built-in styles that you can use to customize the -output of the tree. - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::default` - - .. code-block:: terminal - - ├── config - │ ├── packages - │ └── routes - │ ├── framework.yaml - │ └── web_profiler.yaml - ├── src - │ ├── Command - │ ├── Controller - │ │ └── DefaultController.php - │ └── Kernel.php - └── templates - └── base.html.twig - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::box` - - .. code-block:: terminal - - ┃╸ config - ┃ ┃╸ packages - ┃ ┗╸ routes - ┃ ┃╸ framework.yaml - ┃ ┗╸ web_profiler.yaml - ┃╸ src - ┃ ┃╸ Command - ┃ ┃╸ Controller - ┃ ┃ ┗╸ DefaultController.php - ┃ ┗╸ Kernel.php - ┗╸ templates - ┗╸ base.html.twig - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::doubleBox` - - .. code-block:: terminal - - ╠═ config - ║ ╠═ packages - ║ ╚═ routes - ║ ╠═ framework.yaml - ║ ╚═ web_profiler.yaml - ╠═ src - ║ ╠═ Command - ║ ╠═ Controller - ║ ║ ╚═ DefaultController.php - ║ ╚═ Kernel.php - ╚═ templates - ╚═ base.html.twig - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::compact` - - .. code-block:: terminal - - ├ config - │ ├ packages - │ └ routes - │ ├ framework.yaml - │ └ web_profiler.yaml - ├ src - │ ├ Command - │ ├ Controller - │ │ └ DefaultController.php - │ └ Kernel.php - └ templates - └ base.html.twig - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::light` - - .. code-block:: terminal - - |-- config - | |-- packages - | `-- routes - | |-- framework.yaml - | `-- web_profiler.yaml - |-- src - | |-- Command - | |-- Controller - | | `-- DefaultController.php - | `-- Kernel.php - `-- templates - `-- base.html.twig - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::minimal` - - .. code-block:: terminal - - . config - . . packages - . . routes - . . framework.yaml - . . web_profiler.yaml - . src - . . Command - . . Controller - . . . DefaultController.php - . . Kernel.php - . templates - . base.html.twig - -:method:`Symfony\\Component\\Console\\Helper\\TreeStyle::rounded` - - .. code-block:: terminal - - ├─ config - │ ├─ packages - │ ╰─ routes - │ ├─ framework.yaml - │ ╰─ web_profiler.yaml - ├─ src - │ ├─ Command - │ ├─ Controller - │ │ ╰─ DefaultController.php - │ ╰─ Kernel.php - ╰─ templates - ╰─ base.html.twig +output of the tree:: + + use Symfony\Component\Console\Helper\TreeStyle; + // ... + + $tree = TreeHelper::createTree($io, $node, [], TreeStyle::compact()); + $tree->render(); + +``TreeHelper::createTree($io, $node, [], TreeStyle::default())`` (`details`_) + +.. code-block:: terminal + + ├── config + │ ├── packages + │ └── routes + │ ├── framework.yaml + │ └── web_profiler.yaml + ├── src + │ ├── Command + │ ├── Controller + │ │ └── DefaultController.php + │ └── Kernel.php + └── templates + └── base.html.twig + +``TreeHelper::createTree($io, $node, [], TreeStyle::box())`` (`details`_) + +.. code-block:: terminal + + ┃╸ config + ┃ ┃╸ packages + ┃ ┗╸ routes + ┃ ┃╸ framework.yaml + ┃ ┗╸ web_profiler.yaml + ┃╸ src + ┃ ┃╸ Command + ┃ ┃╸ Controller + ┃ ┃ ┗╸ DefaultController.php + ┃ ┗╸ Kernel.php + ┗╸ templates + ┗╸ base.html.twig + +``TreeHelper::createTree($io, $node, [], TreeStyle::doubleBox())`` (`details`_) + +.. code-block:: terminal + + ╠═ config + ║ ╠═ packages + ║ ╚═ routes + ║ ╠═ framework.yaml + ║ ╚═ web_profiler.yaml + ╠═ src + ║ ╠═ Command + ║ ╠═ Controller + ║ ║ ╚═ DefaultController.php + ║ ╚═ Kernel.php + ╚═ templates + ╚═ base.html.twig + +``TreeHelper::createTree($io, $node, [], TreeStyle::compact())`` (`details`_) + +.. code-block:: terminal + + ├ config + │ ├ packages + │ └ routes + │ ├ framework.yaml + │ └ web_profiler.yaml + ├ src + │ ├ Command + │ ├ Controller + │ │ └ DefaultController.php + │ └ Kernel.php + └ templates + └ base.html.twig + +``TreeHelper::createTree($io, $node, [], TreeStyle::light())`` (`details`_) + +.. code-block:: terminal + + |-- config + | |-- packages + | `-- routes + | |-- framework.yaml + | `-- web_profiler.yaml + |-- src + | |-- Command + | |-- Controller + | | `-- DefaultController.php + | `-- Kernel.php + `-- templates + `-- base.html.twig + +``TreeHelper::createTree($io, $node, [], TreeStyle::minimal())`` (`details`_) + +.. code-block:: terminal + + . config + . . packages + . . routes + . . framework.yaml + . . web_profiler.yaml + . src + . . Command + . . Controller + . . . DefaultController.php + . . Kernel.php + . templates + . base.html.twig + +``TreeHelper::createTree($io, $node, [], TreeStyle::rounded())`` (`details`_) + +.. code-block:: terminal + + ├─ config + │ ├─ packages + │ ╰─ routes + │ ├─ framework.yaml + │ ╰─ web_profiler.yaml + ├─ src + │ ├─ Command + │ ├─ Controller + │ │ ╰─ DefaultController.php + │ ╰─ Kernel.php + ╰─ templates + ╰─ base.html.twig Making a Custom Tree Style ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -285,3 +291,5 @@ The above code will output the following tree: 🔵 🟢 🟠 🟡 Kernel.php 🔵 🟠 🟡 templates 🔵 🔴 🟠 🟡 base.html.twig + +.. _`details`: https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/Console/Helper/TreeStyle.php