PHP code example of survos / tui-extras-bundle
1. Go to this page and download the library: Download survos/tui-extras-bundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
survos / tui-extras-bundle example snippets
Survos\TuiExtrasBundle\SurvosTuiExtrasBundle::class => ['all' => true],
use Survos\TuiExtrasBundle\Model\TreeNode;
use Survos\TuiExtrasBundle\Widget\DetailPanelWidget;
use Survos\TuiExtrasBundle\Widget\TreeWidget;
use Symfony\Component\Tui\Style\Direction;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\StyleSheet;
use Symfony\Component\Tui\Tui;
use Symfony\Component\Tui\Widget\ContainerWidget;
$tree = new TreeWidget();
$tree->addRoot(TreeNode::branch('src/', null, true)
->addChild(TreeNode::leaf('Kernel.php', 'src/Kernel.php'))
->addChild(TreeNode::branch('Command/')
->addChild(TreeNode::leaf('MyCommand.php', 'src/Command/MyCommand.php'))
)
);
$detail = new DetailPanelWidget();
$tree->onCursorChange(fn($e) => $detail->setContent(
file_get_contents($e->node->data ?? ''),
(string) $e->node->data,
));
$split = (new ContainerWidget())->setStyle(new Style(direction: Direction::Horizontal, gap: 1));
$split->add($tree->setStyle(new Style(maxColumns: 40)));
$split->add($detail);
$tui = new Tui(new StyleSheet());
$tui->add($split);
$tui->setFocus($tree);
$tui->run();
use Survos\TuiExtrasBundle\Model\TuiColumn;
use Survos\TuiExtrasBundle\Source\SqliteTableSource;
use Survos\TuiExtrasBundle\Widget\DataTableWidget;
$pdo = new \PDO('sqlite:/path/to/data.sqlite');
// FTS5 virtual table: CREATE VIRTUAL TABLE fts_items USING fts5(name, description, content=items, content_rowid=id)
$source = new SqliteTableSource(
pdo: $pdo,
table: 'items',
ftsTable: 'fts_items',
columns: [
new TuiColumn(key: 'name', label: 'Name', sortable: true, searchable: true),
new TuiColumn(key: 'description', label: 'Description', searchable: true),
new TuiColumn(key: 'created_at', label: 'Created', width: 12, format: 'date', sortable: true),
],
);
$table = new DataTableWidget($source);
// Press / to search with FTS5, ↑↓ navigate, s sort, q quit
interface TuiTableSourceInterface {
/** @return TuiColumn[] */
public function columns(): array;
public function count(?string $search = null): int;
/** @return iterable<array<string,mixed>> */
public function rows(int $offset = 0, int $limit = 25, ?string $search = null, ?string $sortBy = null, string $sortDir = 'ASC'): iterable;
}
▼ src/
── ► Event/
▼ Highlighter/
──── SyntaxHighlighter.php
▼ Model/
──── TreeNode.php
──── TuiColumn.php
▼ Widget/
──── DataTableWidget.php │
──── DetailPanelWidget.php │
──── TreeWidget.php │ declare(strict_types=1);
▼ Source/ │
──── ArrayTableSource.php │ namespace Survos\TuiExtrasBundle\Highlighter;
──── FileSource.php │
──── SqliteTableSource.php │ /**
│ * Syntax highlighter that emits ANSI-colored
│ * lines compatible with DetailPanelWidget.
bash
php bin/console browse:functions # ~1300 PHP internal functions, SQLite FTS5