prefix stringlengths 512 512 | suffix stringlengths 256 256 | middle stringlengths 14 229 | meta dict |
|---|---|---|---|
l` means "not set" - the value will be inherited from parent styles during merge
* - An explicit value (even if zero/false) means "explicitly set" - overrides inheritance
*
* This applies to:
* - `padding` - null (inherit) vs Padding instance (explicit, even if all zeros)
* - `border` - null (inherit) vs Border in... | roperties will inherit from parent rules
* $style = new Style()->withColor('red');
* $style->getPadding(); // null - will inherit
* $style->getBold(); // null - will inherit
*
* // Explicit bold=false to override a parent's bold=tru | `italic`, `strikethrough`, `underline`, `reverse` - null (inherit) vs bool (explicit true/false)
* - `hidden` - null (inherit) vs bool (true = hidden, false = explicitly visible)
*
* Examples:
*
* // Color only - other p | {
"filepath": "src/Symfony/Component/Tui/Style/Style.php",
"language": "php",
"file_size": 25071,
"cut_index": 1331,
"middle_length": 229
} |
e:
* - FQCN: 'Symfony\Component\Tui\Widget\Input' or Input::class
* - FQCN with state: 'Symfony\Component\Tui\Widget\Input:focus'
* - CSS class: '.sidebar'
* - CSS class with state: '.sidebar:focus'
* - Standalone pseudo-class: ':root' (matches the root widget)
* - Universal: '*' (matches all widgets)
* - Sub-el... | ass)
* 3. CSS class selectors (e.g., '.header')
* 4. State selectors (e.g., ':root', Input::class.':focus')
* 5. Instance style (widget's own setStyle())
*
* All style properties use `null` to mean "inherit from earlier rules":
*
* // This rule | h state: '.my-list::selected:focus'
*
* ## Style Inheritance
*
* When resolving styles, rules are applied in this order (later rules override earlier):
* 1. Universal selector ('*')
* 2. Widget FQCN selector (e.g., Text::cl | {
"filepath": "src/Symfony/Component/Tui/Style/StyleSheet.php",
"language": "php",
"file_size": 16070,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Focus;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Tui\Event\FocusEvent;
use Symfony\Component\Tui\Input\Key;
use Symfony\Component\Tui\Input\Keybindings;
use Symfony\Component\Tui\Render\RenderRequestorInterfac... | vious' => ['shift+f6'],
];
private ?AbstractWidget $focused = null;
/** @var array<int, FocusableInterface&AbstractWidget> */
private array $focusables = [];
private Keybindings $keybindings;
/**
* @internal constructed by | ngs: F6 (next) and Shift+F6 (previous).
*
* @experimental
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class FocusManager
{
private const DEFAULT_BINDINGS = [
'focus_next' => [Key::F6],
'focus_pre | {
"filepath": "src/Symfony/Component/Tui/Focus/FocusManager.php",
"language": "php",
"file_size": 5926,
"cut_index": 716,
"middle_length": 229
} |
mfony\Component\Tui\Style\VerticalAlign;
use Symfony\Component\Tui\Widget\AbstractWidget;
use Symfony\Component\Tui\Widget\Figlet\FontRegistry;
use Symfony\Component\Tui\Widget\ParentInterface;
use Symfony\Component\Tui\Widget\VerticallyExpandableInterface;
/**
* Lays out children vertically or horizontally with gap,... | racker $positionTracker,
private readonly FontRegistry $fontRegistry,
) {
}
/**
* Layout children based on direction.
*
* @param AbstractWidget[] $children
*
* @return string[]
*/
public function layou | * @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class LayoutEngine
{
public function __construct(
private readonly WidgetRendererInterface $widgetRenderer,
private readonly PositionT | {
"filepath": "src/Symfony/Component/Tui/Render/LayoutEngine.php",
"language": "php",
"file_size": 17172,
"cut_index": 921,
"middle_length": 229
} |
gn;
use Symfony\Component\Tui\Style\DefaultStyleSheet;
use Symfony\Component\Tui\Style\Direction;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\StyleSheet;
use Symfony\Component\Tui\Widget\AbstractWidget;
use Symfony\Component\Tui\Widget\ContainerWidget;
use Symfony\Component\Tui\Widget\Figlet\... | dget content
*
* All widget types are rendered through the Renderer: containers via
* renderContainer(), and leaf widgets by delegating to widget->render().
*
* @experimental
*
* @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
fina | cade (* → FQCN → CSS class → state → instance)
* 2. Computes layout (vertical/horizontal with gap and fill children)
* 3. Calls widget->render() with enriched context
* 4. Applies chrome (padding, border, background) around wi | {
"filepath": "src/Symfony/Component/Tui/Render/Renderer.php",
"language": "php",
"file_size": 13600,
"cut_index": 921,
"middle_length": 229
} |
EncoderInterface, DecoderInterface, NormalizationAwareInterface, SerializerAwareInterface
{
use SerializerAwareTrait;
public const FORMAT = 'xml';
public const AS_COLLECTION = 'as_collection';
/**
* An array of ignored XML node types while decoding, each one of the DOM Predefined XML_* constant... | _* constants for loading XML documents.
*/
public const LOAD_OPTIONS = 'load_options';
/**
* A bit field of LIBXML_* constants for saving XML documents.
*/
public const SAVE_OPTIONS = 'save_options';
public const REMOVE_EMP | onstants.
*/
public const ENCODER_IGNORED_NODE_TYPES = 'encoder_ignored_node_types';
public const ENCODING = 'xml_encoding';
public const FORMAT_OUTPUT = 'xml_format_output';
/**
* A bit field of LIBXML | {
"filepath": "src/Symfony/Component/Serializer/Encoder/XmlEncoder.php",
"language": "php",
"file_size": 20680,
"cut_index": 1331,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface... | }
$resolve = $container->getParameterBag()->resolveValue(...);
$taggedClasses = [];
foreach ($container->getDefinitions() as $id => $definition) {
if (!$definition->hasTag('serializer.attribute_metadata')) {
| uteMetadataPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('serializer.mapping.attribute_loader')) {
return;
| {
"filepath": "src/Symfony/Component/Serializer/DependencyInjection/AttributeMetadataPass.php",
"language": "php",
"file_size": 2686,
"cut_index": 563,
"middle_length": 229
} |
rmats:
* - Basic 16 ANSI colors (named: 'black', 'red', 'green', etc.)
* - 256-color palette (integers 0-255)
* - True color RGB (hex strings like '#ff5500' or '#f50')
*
* @experimental
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class Color
{
// Basic 16 ANSI color codes (foreground)
pri... | 'bright_cyan' => 96,
'bright_white' => 97,
// Aliases
'gray' => 90,
'grey' => 90,
];
/** Standard RGB values for named ANSI colors (xterm defaults). */
private const NAMED_RGB = [
'black' => [0, 0, 0] | 'white' => 37,
'default' => 39,
'bright_black' => 90,
'bright_red' => 91,
'bright_green' => 92,
'bright_yellow' => 93,
'bright_blue' => 94,
'bright_magenta' => 95,
| {
"filepath": "src/Symfony/Component/Tui/Style/Color.php",
"language": "php",
"file_size": 11402,
"cut_index": 921,
"middle_length": 229
} |
asses are parsed from widget style classes and dynamically
* converted to Style objects. They coexist with regular CSS-like rules
* and take precedence over them in the cascade (they are "immutable").
*
* ## Supported utility classes
*
* ### Padding
* p-{n} All sides
* px-{n} ... | border
* border-{pattern} Pattern: normal, rounded, double, tall, wide, tall-medium, wide-medium, tall-large, wide-large
* border-{color} Color: {family}-{shade}, [#hex], or palette index
*
* ### Background color
* bg-{family}-{ | All sides, width n
* border-t border-r border-b border-l Individual side, width 1
* border-t-{n} border-r-{n} border-b-{n} border-l-{n} Individual side, width n
* border-none Remove | {
"filepath": "src/Symfony/Component/Tui/Style/TailwindStylesheet.php",
"language": "php",
"file_size": 15404,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Ansi;
use Symfony\Component\Tui\Style\Color;
use Symfony\Component\Tui\Terminal\ScreenBuffer;
/**
* Renders a ScreenBuffer to HTML with inline CSS styles.
*
* @experimental
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class ScreenBu... | ffer to HTML with inline styles.
*/
public function convert(ScreenBuffer $screen): string
{
$cells = $screen->getCells();
$height = $screen->getHeight();
$result = '';
$lastNonEmptyEnd = 0;
for ($row = | ltBackground = null,
) {
$this->defaultForeground = $defaultForeground ?? Color::hex('#d4d4d4');
$this->defaultBackground = $defaultBackground ?? Color::hex('#1e1e1e');
}
/**
* Convert a ScreenBu | {
"filepath": "src/Symfony/Component/Tui/Ansi/ScreenBufferHtmlRenderer.php",
"language": "php",
"file_size": 7077,
"cut_index": 716,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Render;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\TextAlign;
use Symfony\Component\Tui\Widget\AbstractWidget;
/**
* Applies chrome (padding, border, background) around widget conte... | ) {
}
/**
* Apply chrome (padding, border, background) to rendered lines.
*
* @param string[] $lines
*
* @return string[]
*/
public function apply(array $lines, int $width, Style $style, AbstractWidget $widget): | mance.
*
* @experimental
*
* @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class ChromeApplier
{
public function __construct(
private readonly WidgetRendererInterface $widgetRenderer,
| {
"filepath": "src/Symfony/Component/Tui/Render/ChromeApplier.php",
"language": "php",
"file_size": 7999,
"cut_index": 716,
"middle_length": 229
} |
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Serializer\Extractor;
use Symfony\Component\PropertyI... | objectClassResolver ?? 'get_class')(...);
}
public function getProperties(object $object, array $context = []): ?array
{
$class = ($this->objectClassResolver)($object);
return $this->propertyListExtractor->getProperties($class | Closure $objectClassResolver;
public function __construct(
private PropertyListExtractorInterface $propertyListExtractor,
?callable $objectClassResolver = null,
) {
$this->objectClassResolver = ($ | {
"filepath": "src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractor.php",
"language": "php",
"file_size": 1018,
"cut_index": 512,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Style;
use Symfony\Component\Tui\Widget\CancellableLoaderWidget;
use Symfony\Component\Tui\Widget\EditorWidget;
use Symfony\Component\Tui\Widget\InputW... | .
*
* @experimental
*
* @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class DefaultStyleSheet
{
public static function create(): StyleSheet
{
return new StyleSheet([
// Heading classes (used by <h1> | ngsListWidget;
/**
* Default TUI stylesheet with base styling rules.
*
* Provides sensible defaults for all core widget sub-elements.
* These can be overridden by application or theme stylesheets
* via the cascade mechanism | {
"filepath": "src/Symfony/Component/Tui/Style/DefaultStyleSheet.php",
"language": "php",
"file_size": 4482,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Render;
use Symfony\Component\Tui\Widget\AbstractWidget;
/**
* Tracks absolute positions of rendered widgets on screen.
*
* Maintains a stack of ab... | .
*
* @var list<array{int, int}>
*/
private array $positionStack = [];
public function __construct()
{
$this->widgetPositions = new \WeakMap();
}
/**
* Reset the position stack for a new render pass.
* | ien@symfony.com>
*/
final class PositionTracker
{
/** @var \WeakMap<AbstractWidget, WidgetRect> */
private \WeakMap $widgetPositions;
/**
* Stack of absolute [row, col] offsets for the current rendering context | {
"filepath": "src/Symfony/Component/Tui/Render/PositionTracker.php",
"language": "php",
"file_size": 4356,
"cut_index": 614,
"middle_length": 229
} |
The 3x3 strategy matrix is used by renderers to decide how to swap colors
* for block-style borders:
* - 0: border color on inner background (standard border rendering)
* - 1: border color on outer background (blend with outer background)
* - 2: reverse video border/outer — filled part shows outer bg, empty part s... | ;
public const TALL_MEDIUM = 'tall-medium';
public const WIDE_MEDIUM = 'wide-medium';
public const TALL_LARGE = 'tall-large';
public const WIDE_LARGE = 'wide-large';
/**
* @param array<int, array<int, string>> $chars
* @param | al class BorderPattern
{
public const NONE = 'none';
public const NORMAL = 'normal';
public const ROUNDED = 'rounded';
public const DOUBLE = 'double';
public const TALL = 'tall';
public const WIDE = 'wide' | {
"filepath": "src/Symfony/Component/Tui/Style/BorderPattern.php",
"language": "php",
"file_size": 13793,
"cut_index": 921,
"middle_length": 229
} |
terminal
* - Managing cursor position for differential rendering
*
* @experimental
*
* @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class ScreenWriter
{
private const PRINTABLE_ASCII = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'... |
private ?array $previousCursorPos = null;
public function __construct(
private readonly TerminalInterface $terminal,
) {
}
public function setShowHardwareCursor(bool $enabled): void
{
if ($this->showHardwareCursor | maxLinesRendered = 0;
private bool $showHardwareCursor = true;
private int $scrollOffset = 0;
/** @var string[] */
private array $previousRawLines = [];
/** @var array{row: int, col: int, shape: int}|null */ | {
"filepath": "src/Symfony/Component/Tui/Render/ScreenWriter.php",
"language": "php",
"file_size": 18674,
"cut_index": 1331,
"middle_length": 229
} |
pe, positions the hardware cursor, and
* sets the cursor style via `ESC [ N SP q`.
*
* @see cursorMarker()
*/
public const CURSOR_MARKER_PREFIX = "\x1b_pi:c;";
/**
* Full SGR reset and OSC 8 reset sequence.
*/
public const SEGMENT_RESET = "\x1b[0m\x1b]8;;\x07";
/**
*... | RAM_CHARS = '0123456789:;<=>?';
/**
* Character set for CSI intermediate bytes (0x20-0x2F).
*/
private const CSI_INTERMEDIATE_CHARS = " !\"#\$%&'()*+,-./";
/**
* Create a cursor marker embedding the given shape.
*
* T | N = '/\x1b(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|[P\]_\^X][^\x07\x1b]*(?:\x07|\x1b\\\\)|[\x20-\x2F]+[\x30-\x7E]|[\x30-\x7E])/';
/**
* Character set for CSI parameter bytes (0x30-0x3F).
*/
private const CSI_PA | {
"filepath": "src/Symfony/Component/Tui/Ansi/AnsiUtils.php",
"language": "php",
"file_size": 22931,
"cut_index": 1331,
"middle_length": 229
} |
umentException;
use Symfony\Component\Tui\Style\Border;
use Symfony\Component\Tui\Style\BorderPattern;
use Symfony\Component\Tui\Style\Color;
use Symfony\Component\Tui\Style\Style;
class BorderTest extends TestCase
{
public function testNegativeValuesClampedToZero()
{
$border = new Border(-5, -3, -1, -... |
$this->assertSame($top, $border->top);
$this->assertSame($right, $border->right);
$this->assertSame($bottom, $border->bottom);
$this->assertSame($left, $border->left);
}
/**
* @return iterable<string, array{l |
/**
* @param list<int> $input
*/
#[DataProvider('fromArrayProvider')]
public function testFromArray(array $input, int $top, int $right, int $bottom, int $left)
{
$border = Border::from($input); | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/BorderTest.php",
"language": "php",
"file_size": 10713,
"cut_index": 921,
"middle_length": 229
} |
idget\TextWidget;
class ContainerTest extends TestCase
{
public function testRender()
{
$container = new ContainerWidget();
$container->add(new TextWidget('First'));
$container->add(new TextWidget('Second'));
$lines = $this->renderContainer($container);
$content = impl... | tainerWidget();
$container->setStyle(new Style(border: Border::all(1)));
$lines = $this->renderContainer($container);
$stripped = array_map(static fn ($l) => AnsiUtils::stripAnsiCodes($l), $lines);
// Should have at least | {
$container = new ContainerWidget();
$lines = $this->renderContainer($container);
$this->assertSame([], $lines);
}
public function testRenderEmptyWithBorder()
{
$container = new Con | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/ContainerTest.php",
"language": "php",
"file_size": 22165,
"cut_index": 1331,
"middle_length": 229
} |
space
$this->assertSame('Hell', $editor->getText());
}
#[DataProvider('deleteWordBackwardProvider')]
public function testDeleteWordBackward(string $keySequence, string $description)
{
$editor = new EditorWidget();
$editor->setText('hello world');
$editor->handleInput("... | +Backspace (Kitty protocol)' => ["\x1b[127;3u", 'Kitty Alt+Backspace'];
}
public function testEnterCreatesNewLine()
{
$editor = new EditorWidget();
$editor->setText('Hello');
// Move cursor to end using Ctrl+E
$ |
*/
public static function deleteWordBackwardProvider(): iterable
{
yield 'Alt+Backspace (legacy: ESC + DEL)' => ["\x1b\x7f", 'Alt+Backspace'];
yield 'Ctrl+W' => ["\x17", 'Ctrl+W'];
yield 'Alt | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/EditorTest.php",
"language": "php",
"file_size": 50484,
"cut_index": 2151,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Exception\InvalidArgumentException;
use Symfony\Component\Tui\Render\RenderContext;
use Symf... | rWithFont(string $font, int $expectedLines)
{
$widget = new TextWidget('Hi');
$lines = $this->renderWidgetWithFont($widget, $font, 80, 24);
$this->assertCount($expectedLines, $lines);
}
/**
* @return iterable<stri | Tui\Widget\ContainerWidget;
use Symfony\Component\Tui\Widget\Figlet\FontRegistry;
use Symfony\Component\Tui\Widget\TextWidget;
class FigletTest extends TestCase
{
#[DataProvider('fontProvider')]
public function testRende | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/FigletTest.php",
"language": "php",
"file_size": 8949,
"cut_index": 716,
"middle_length": 229
} |
Symfony\Component\Tui\Event\CancelEvent;
use Symfony\Component\Tui\Event\ChangeEvent;
use Symfony\Component\Tui\Event\SubmitEvent;
use Symfony\Component\Tui\Render\RenderContext;
use Symfony\Component\Tui\Terminal\VirtualTerminal;
use Symfony\Component\Tui\Tui;
use Symfony\Component\Tui\Widget\InputWidget;
class Inpu... | lo');
$lines = $input->render(new RenderContext(40, 24));
$this->assertCount(1, $lines);
// Full width available for text, no prompt prefix
$this->assertSame(40, AnsiUtils::visibleWidth($lines[0]));
$stripped = Ansi | (1, $lines);
$this->assertStringContainsString('>', $lines[0]);
}
public function testRenderWithEmptyPrompt()
{
$input = new InputWidget();
$input->setPrompt('');
$input->setValue('Hel | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/InputTest.php",
"language": "php",
"file_size": 15395,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Exception\InvalidArgumentException;
use Symfony\Component\Tui\Render\RenderContext;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\StyleSheet;
use Symfony\Co... | essage
$this->assertSame('', $lines[0]);
$this->assertCount(2, $lines);
}
public function testRenderIncludesSpinnerAndMessage()
{
$loader = new LoaderWidget(message: 'Working...');
$loader->start();
$li | lankLine()
{
$loader = new LoaderWidget(message: 'Test');
$loader->start();
$lines = $loader->render(new RenderContext(80, 24));
// First line should be blank, second line has the spinner + m | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/LoaderTest.php",
"language": "php",
"file_size": 8048,
"cut_index": 716,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Render\RenderContext;
use Symfony\Compo... | r(new RenderContext(40, 24));
$this->assertSame([], $lines);
}
/**
* @param list<string> $expectedSubstrings substrings to find in the joined output
*/
#[DataProvider('markdownElementProvider')]
public function testRende | get;
#[IgnoreDeprecations('League\\\\CommonMark\\\\Util\\\\ArrayCollection')]
class MarkdownTest extends TestCase
{
public function testRenderEmpty()
{
$md = $this->createMarkdown('');
$lines = $md->rende | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/MarkdownTest.php",
"language": "php",
"file_size": 7894,
"cut_index": 716,
"middle_length": 229
} |
ymfony\Component\Tui\Style\StyleSheet;
use Symfony\Component\Tui\Terminal\VirtualTerminal;
use Symfony\Component\Tui\Tui;
use Symfony\Component\Tui\Widget\ProgressBarWidget;
/**
* @covers \Symfony\Component\Tui\Widget\ProgressBarWidget
*/
class ProgressBarTest extends TestCase
{
public function testConstructionD... | tProgress());
}
public function testAdvance()
{
$bar = new ProgressBarWidget(100);
$bar->advance(10);
$this->assertSame(10, $bar->getProgress());
$this->assertEqualsWithDelta(0.1, $bar->getProgressPercent(), 0. | (0.0, $bar->getProgressPercent());
}
public function testConstructionIndeterminate()
{
$bar = new ProgressBarWidget();
$this->assertSame(0, $bar->getMaxSteps());
$this->assertSame(0, $bar->ge | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/ProgressBarTest.php",
"language": "php",
"file_size": 16539,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Event\CancelEvent;
use Symfony\Component\Tui\Event\SelectEvent;
use Symfony\Component\Tui\Ev... | tringContainsString('Option 1', $lines[0]);
}
public function testRenderShowsSelectedIndicator()
{
$list = $this->createTestList();
$lines = $list->render(new RenderContext(80, 24));
// First item should have arrow ind | lectListWidget;
class SelectListTest extends TestCase
{
public function testRenderShowsItems()
{
$list = $this->createTestList();
$lines = $list->render(new RenderContext(80, 24));
$this->assertS | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/SelectListTest.php",
"language": "php",
"file_size": 7242,
"cut_index": 716,
"middle_length": 229
} |
ymfony\Component\Tui\Event\SelectEvent;
use Symfony\Component\Tui\Event\SettingChangeEvent;
use Symfony\Component\Tui\Render\RenderContext;
use Symfony\Component\Tui\Render\Renderer;
use Symfony\Component\Tui\Style\Border;
use Symfony\Component\Tui\Style\Padding;
use Symfony\Component\Tui\Style\Style;
use Symfony\Compo... | t(80, 24));
$this->assertStringContainsString('Theme', $lines[0]);
}
public function testCycleValueRight()
{
[$widget, $tui] = $this->createWithTui();
$this->assertSame('dark', $widget->getValue('theme'));
// | get\SettingsListWidget;
class SettingsListTest extends TestCase
{
public function testRenderShowsItems()
{
$widget = new SettingsListWidget($this->createItems());
$lines = $widget->render(new RenderContex | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/SettingsListTest.php",
"language": "php",
"file_size": 10332,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Render\RenderContext;
use Symfony\Component\Tui\Render\Renderer;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Widget\Te... | Hello');
$text->setStyle($style);
$lines = $this->renderWidget($text, 20, 24);
// Should have 1 top padding + 1 content + 1 bottom padding = 3 lines
$this->assertCount(3, $lines);
// All lines should be full width
| $this->assertCount(1, $lines);
$this->assertStringContainsString('Hello', $lines[0]);
}
public function testRenderWithPadding()
{
$style = Style::padding([1, 2]);
$text = new TextWidget(' | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/TextTest.php",
"language": "php",
"file_size": 7825,
"cut_index": 716,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Focus\FocusManager;
use Symfony\Component\Tui\Input\Keybindings;
use Symfony\Co... | e $tree;
protected function setUp(): void
{
$terminal = new VirtualTerminal(80, 24);
$tui = new Tui(terminal: $terminal);
$this->tree = new WidgetTree($tui, new Keybindings(), new FocusManager($this->createStub(RenderReques | \Tui\Widget\ContainerWidget;
use Symfony\Component\Tui\Widget\TextWidget;
use Symfony\Component\Tui\Widget\WidgetContext;
use Symfony\Component\Tui\Widget\WidgetTree;
class WidgetTreeTest extends TestCase
{
private WidgetTre | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/WidgetTreeTest.php",
"language": "php",
"file_size": 3638,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Util;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Widget\Util\KillRing;
class KillRingTest extends TestCase
{
public fu... | $ring->add('hello', false);
$ring->add(' world', false);
$this->assertSame('hello world', $ring->peek());
}
public function testConsecutiveKillsPrepend()
{
$ring = new KillRing();
$ring->add('world', true);
| ingIsIgnored()
{
$ring = new KillRing();
$ring->add('', false);
$this->assertNull($ring->peek());
}
public function testConsecutiveKillsAppend()
{
$ring = new KillRing();
| {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Util/KillRingTest.php",
"language": "php",
"file_size": 4900,
"cut_index": 614,
"middle_length": 229
} |
ne;
class LineTest extends TestCase
{
// --- bounds clamping ---
public function testConstructorClampsNegativeCursor()
{
$line = new Line('hello', -5);
$this->assertSame(0, $line->getCursor());
}
public function testConstructorClampsCursorBeyondEnd()
{
$line = new Line... | getCursor());
}
public function testSetTextAdjustsCursorWhenBeyondNewLength()
{
$line = new Line('hello world', 10);
$line->setText('hi');
$this->assertSame('hi', $line->getText());
$this->assertSame(2, $line->g | rsor(-1);
$this->assertSame(0, $line->getCursor());
}
public function testSetCursorClampsBeyondEnd()
{
$line = new Line('hello', 0);
$line->setCursor(100);
$this->assertSame(5, $line-> | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Util/LineTest.php",
"language": "php",
"file_size": 11188,
"cut_index": 921,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Util;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPU... | yield 'mixed (control in text)' => ["hello\x00world", true];
yield 'printable ASCII' => ['hello', false];
yield 'latin accents' => ['café', false];
yield 'emoji' => ['👋', false];
yield 'emoji mixed with text' => ['hello 🎉 wo | ay{string, bool}>
*/
public static function hasControlCharsProvider(): iterable
{
yield 'null byte' => ["\x00", true];
yield 'escape' => ["\x1b", true];
yield 'del' => ["\x7f", true];
| {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Util/StringUtilsTest.php",
"language": "php",
"file_size": 2029,
"cut_index": 537,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Util;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Widget\Util\WordNavigator;
... | then word (from mid)' => ['hello world', 7, 0];
yield 'skips punctuation (from end)' => ['hello...world', 13, 8];
yield 'skips punctuation (from mid)' => ['hello...world', 8, 5];
yield 'skips word after punctuation' => ['hello...w |
yield 'at start of string' => ['hello world', 0, 0];
yield 'skips word' => ['hello world', 11, 6];
yield 'skips whitespace then word (from end)' => ['hello world', 12, 7];
yield 'skips whitespace | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Util/WordNavigatorTest.php",
"language": "php",
"file_size": 4092,
"cut_index": 614,
"middle_length": 229
} |
r\EditorDocument;
class EditorDocumentTest extends TestCase
{
// --- Text Operations ---
public function testSetTextReturnsWhetherStateChanged()
{
$doc = new EditorDocument();
$this->assertTrue($doc->setText('hello'), 'setText should return true when text changes');
$this->assertF... | e 2\nline 3");
$doc->moveCursorDown();
$doc->moveCursorDown();
$doc->setText('new');
$this->assertSame(0, $doc->getCursorLine());
$this->assertSame(0, $doc->getCursorCol());
}
public function testSetTextCl | $doc->setText("a\r\nb\rc");
$this->assertSame("a\nb\nc", $doc->getText());
}
public function testSetTextResetsCursorPosition()
{
$doc = new EditorDocument();
$doc->setText("line 1\nlin | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Editor/EditorDocumentTest.php",
"language": "php",
"file_size": 16694,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Editor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Style\CursorShape;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Widget\Editor\EditorRenderer;
class EditorRende... |
{
$lines = $this->renderSimple(['Line 1', 'Line 2', 'Line 3'], 0, 0, 40, 10);
// Top border + 3 content lines + bottom border
$this->assertCount(5, $lines);
}
public function testRenderLinesDoNotExceedWidth()
{
| erEmptyDocument()
{
$lines = $this->renderSimple([''], 0, 0, 40, 10);
// Top border + 1 content line + bottom border
$this->assertCount(3, $lines);
}
public function testRenderMultipleLines() | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Editor/EditorRendererTest.php",
"language": "php",
"file_size": 5422,
"cut_index": 716,
"middle_length": 229
} |
= "\x1b[?25l";
private const SHOW_CURSOR = "\x1b[?25h";
// --- Full render (initial) ---
public function testFirstRenderWritesAllLines()
{
$terminal = new VirtualTerminal(80, 24);
$writer = new ScreenWriter($terminal);
$writer->writeLines(['Line 1', 'Line 2', 'Line 3']);
... | sString('Line 1', $output);
$this->assertStringContainsString('Line 2', $output);
$this->assertStringContainsString('Line 3', $output);
// Plain text lines should be separated by \r\n without reset
$this->assertStringContai | g(self::SYNC_END, $output);
// Should NOT clear screen on first render
$this->assertStringNotContainsString(self::CLEAR_SCREEN, $output);
// All lines should be present
$this->assertStringContain | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/ScreenWriterTest.php",
"language": "php",
"file_size": 20911,
"cut_index": 1331,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Render;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\F... | /**
* @return iterable<string, array{int, int, bool}>
*/
public static function containsProvider(): iterable
{
// Inside
yield 'top-left corner' => [5, 10, true];
yield 'center' => [15, 30, true];
yield 'b | $col, bool $expected)
{
// Rect at (5, 10) with size 40x20 → covers rows 5..24, cols 10..49
$rect = new WidgetRect(5, 10, 40, 20);
$this->assertSame($expected, $rect->contains($row, $col));
}
| {
"filepath": "src/Symfony/Component/Tui/Tests/Render/WidgetRectTest.php",
"language": "php",
"file_size": 1745,
"cut_index": 537,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Widget\Figlet;
use Symfony\Component\Tui\Render\Compositor;
use Symfony\Component\Tui\Style\Color;
... | nt mode: spaces at the end of lines won't carry styling that
* would prevent lower layers from showing through.
*
* @experimental
*
* @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class FigletRenderer
{
public function __ | lines.
*
* When a color is provided, each line is wrapped with the foreground ANSI
* escape code. Since trailing whitespace is already stripped, the colored
* output is safe for use with the {@see Compositor}
* in transpare | {
"filepath": "src/Symfony/Component/Tui/Widget/Figlet/FigletRenderer.php",
"language": "php",
"file_size": 2578,
"cut_index": 563,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Widget\Figlet;
use Symfony\Component\Tui\Exception\InvalidArgumentException;
/**
* Registry for FI... | Style(font: 'custom'));
* $widget->addStyleClass('font-custom');
*
* @experimental
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class FontRegistry
{
private const string BUNDLED_FONTS_DIR = __DIR__.'/fonts';
private const a | gistered by name:
*
* $registry = new FontRegistry();
* $registry->register('custom', '/path/to/custom.flf');
*
* Fonts are referenced by name throughout the Style system:
*
* $stylesheet->addRule('.title', new | {
"filepath": "src/Symfony/Component/Tui/Widget/Figlet/FontRegistry.php",
"language": "php",
"file_size": 2734,
"cut_index": 563,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests;
/**
* Handles key sequence parsing for TUI tests.
*
* This centralizes the key name to esc... | ift+Tab>' => "\x1b[Z",
'<F6>' => "\x1b[17~",
'<Shift+F6>' => "\x1b[17;2~",
'<Backspace>' => "\x7f",
'<Up>' => "\x1b[A",
'<Down>' => "\x1b[B",
'<Right>' => "\x1b[C",
'<Left>' => "\x1b[D",
'<Hom |
*
* @var array<string, string>
*/
private const KEY_MAP = [
'<Enter>' => "\r",
'<Return>' => "\r",
'<Escape>' => "\x1b",
'<Esc>' => "\x1b",
'<Tab>' => "\t",
'<Sh | {
"filepath": "src/Symfony/Component/Tui/Tests/KeySequenceParser.php",
"language": "php",
"file_size": 2275,
"cut_index": 563,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class StateDiffTest extends TestCase
{
public function testI... | => 0, 'unchanged' => 0], $result['stats']);
}
public function testAddedLines()
{
$expected = "Line 1\nLine 2";
$actual = "Line 1\nLine 2\nLine 3";
$result = StateDiff::compare($expected, $actual);
$this->asser | sertSame('Outputs are identical', $result['summary']);
$this->assertSame([], $result['diff_lines']);
$this->assertSame('', $result['diff_text']);
$this->assertSame(['added' => 0, 'removed' => 0, 'changed' | {
"filepath": "src/Symfony/Component/Tui/Tests/StateDiffTest.php",
"language": "php",
"file_size": 4864,
"cut_index": 614,
"middle_length": 229
} |
omponent\Tui\Event\TickEvent;
use Symfony\Component\Tui\Exception\InvalidArgumentException;
use Symfony\Component\Tui\Input\Key;
use Symfony\Component\Tui\Input\Keybindings;
use Symfony\Component\Tui\Render\Renderer;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\StyleSheet;
use Symfony\Componen... | d'));
$tui->start();
$tui->processRender();
$output = $terminal->getOutput();
$this->assertStringContainsString('Hello World', $output);
}
public function testMultipleComponents()
{
$terminal = new Vir | TextWidget;
class TuiTest extends TestCase
{
public function testBasicRender()
{
$terminal = new VirtualTerminal(40, 10);
$tui = new Tui(terminal: $terminal);
$tui->add(new TextWidget('Hello Worl | {
"filepath": "src/Symfony/Component/Tui/Tests/TuiTest.php",
"language": "php",
"file_size": 16049,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Style;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Exception\InvalidArgumentException;
use Symfony\Component\Tui\Style\BorderPattern;
use Symfony\Component\Tui\Style\Color;
use Symfony\C... | omName->getChars());
$this->assertSame($fromMethod->getStrategies(), $fromName->getStrategies());
}
$this->assertSame($isNone, $fromName->isNone());
}
/**
* @return iterable<string, array{string, ?string, bool}>
| ring $method, bool $isNone)
{
$fromName = BorderPattern::fromName($name);
if (null !== $method) {
$fromMethod = BorderPattern::$method();
$this->assertSame($fromMethod->getChars(), $fr | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/BorderPatternTest.php",
"language": "php",
"file_size": 5691,
"cut_index": 716,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Style;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symf... | this->assertSame($right, $padding->right);
$this->assertSame($bottom, $padding->bottom);
$this->assertSame($left, $padding->left);
}
/**
* @return iterable<string, array{list<int>, int, int, int, int}>
*/
public stati | ovider('fromArrayProvider')]
public function testFromArray(array $input, int $top, int $right, int $bottom, int $left)
{
$padding = Padding::from($input);
$this->assertSame($top, $padding->top);
$ | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/PaddingTest.php",
"language": "php",
"file_size": 2974,
"cut_index": 563,
"middle_length": 229
} |
fony\Component\Tui\Style\Border;
use Symfony\Component\Tui\Style\BorderPattern;
use Symfony\Component\Tui\Style\Color;
use Symfony\Component\Tui\Style\CursorShape;
use Symfony\Component\Tui\Style\Direction;
use Symfony\Component\Tui\Style\Padding;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\T... | me(2, $border->left);
$this->assertSame(BorderPattern::double()->getChars(), $border->pattern->getChars());
$this->assertSame(BorderPattern::double()->getStrategies(), $border->pattern->getStrategies());
$this->assertSame(
| rderPattern::DOUBLE, 'red');
$border = $style->getBorder();
$this->assertSame(2, $border->top);
$this->assertSame(2, $border->right);
$this->assertSame(2, $border->bottom);
$this->assertSa | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/StyleTest.php",
"language": "php",
"file_size": 15452,
"cut_index": 921,
"middle_length": 229
} |
*/
public static function paddingProvider(): iterable
{
yield 'all' => ['p-2', 2, 2, 2, 2];
yield 'zero' => ['p-0', 0, 0, 0, 0];
yield 'horizontal' => ['px-3', 0, 3, 0, 3];
yield 'vertical' => ['py-1', 1, 0, 1, 0];
}
public function testPaddingIndividualSides()
{
... | );
$this->assertSame(3, $resolved->getPadding()->bottom);
$this->assertSame(4, $resolved->getPadding()->left);
}
public function testPaddingLastWins()
{
$stylesheet = new TailwindStylesheet();
$widget = new Text | leClass('pb-3');
$widget->addStyleClass('pl-4');
$resolved = $stylesheet->resolve($widget);
$this->assertSame(1, $resolved->getPadding()->top);
$this->assertSame(2, $resolved->getPadding()->right | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/TailwindStylesheetTest.php",
"language": "php",
"file_size": 39590,
"cut_index": 2151,
"middle_length": 229
} |
Renderer;
use Symfony\Component\Tui\Style\Color;
use Symfony\Component\Tui\Terminal\ScreenBuffer;
class ScreenBufferHtmlRendererTest extends TestCase
{
/**
* @param string[] $expectedCss
*/
#[DataProvider('ansiToHtmlProvider')]
public function testAnsiToHtmlConversion(string $ansi, array $expecte... | => ["\x1b[1;32mHello\x1b[0m", ['font-weight: bold', 'color: #00cd00']];
yield 'background color' => ["\x1b[41mHello\x1b[0m", ['background-color: #cd0000']];
yield 'bright foreground' => ["\x1b[91mHello\x1b[0m", ['color: #ff0000']];
| iterable<string, array{string, string[]}>
*/
public static function ansiToHtmlProvider(): iterable
{
yield 'foreground color' => ["\x1b[32mHello\x1b[0m", ['color: #00cd00']];
yield 'bold with color' | {
"filepath": "src/Symfony/Component/Tui/Tests/Ansi/ScreenBufferHtmlRendererTest.php",
"language": "php",
"file_size": 10606,
"cut_index": 921,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Focus;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Event\FocusEvent;
use Symfony\Component\Tui\Input\Key;
use Symfony\Component\Tui... | new InputWidget();
$second = new InputWidget();
$focusManager->add($first)->add($second);
$tui->setFocus($first);
$this->assertSame($first, $tui->getFocus());
$focusManager->focusNext();
$this->assertSame( | Widget;
class FocusManagerTest extends TestCase
{
public function testFocusNavigation()
{
$tui = new Tui(terminal: new VirtualTerminal(80, 24));
$focusManager = $tui->getFocusManager();
$first = | {
"filepath": "src/Symfony/Component/Tui/Tests/Focus/FocusManagerTest.php",
"language": "php",
"file_size": 3504,
"cut_index": 614,
"middle_length": 229
} |
gumentException;
use Symfony\Component\Tui\Render\CellBuffer;
class CellBufferTest extends TestCase
{
/**
* @return iterable<string, array{int, int, string}>
*/
public static function invalidDimensionsProvider(): iterable
{
yield 'zero width' => [0, 5, 'CellBuffer dimensions must be at le... | [DataProvider('invalidDimensionsProvider')]
public function testConstructorRejectsInvalidDimensions(int $width, int $height, string $expectedMessage)
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionM | least 1x1, got -1x5'];
yield 'negative height' => [10, -3, 'CellBuffer dimensions must be at least 1x1, got 10x-3'];
yield 'both zero' => [0, 0, 'CellBuffer dimensions must be at least 1x1, got 0x0'];
}
# | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/CellBufferTest.php",
"language": "php",
"file_size": 13766,
"cut_index": 921,
"middle_length": 229
} |
fony\Component\Tui\Style\Border;
use Symfony\Component\Tui\Style\Direction;
use Symfony\Component\Tui\Style\Padding;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Widget\ContainerWidget;
use Symfony\Component\Tui\Widget\TextWidget;
class LayoutEngineTest extends TestCase
{
public function testLa... | $root = new ContainerWidget();
$root->add(new TextWidget('First'));
$root->add(new TextWidget('Second'));
$result = $renderer->render($root, 80, 24);
$this->assertCount(2, $result);
$this->assertStringContainsSt | ot, 80, 24);
$this->assertCount(1, $result);
$this->assertStringContainsString('Hello', $result[0]);
}
public function testLayoutVerticalMultipleChildren()
{
$renderer = new Renderer();
| {
"filepath": "src/Symfony/Component/Tui/Tests/Render/LayoutEngineTest.php",
"language": "php",
"file_size": 13049,
"cut_index": 921,
"middle_length": 229
} |
ertStringContainsString('After', $after[0]);
}
public function testRenderCacheInvalidatedWhenDimensionsChange()
{
$renderer = new Renderer();
$fill = new ContainerWidget();
$fill->expandVertically(true);
$fill->add(new TextWidget('A'));
$root = new ContainerWidget()... | = new Renderer();
$root = new ContainerWidget();
$root->add(new TextWidget('First'));
$oneChild = $renderer->render($root, 40, 10);
$root->add(new TextWidget('Second'));
$twoChildren = $renderer->render($root, 40, | rows
$this->assertNotSame($small, $large);
$this->assertCount(5, $small);
$this->assertCount(10, $large);
}
public function testRenderCacheInvalidatedWhenChildrenChange()
{
$renderer | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/RendererTest.php",
"language": "php",
"file_size": 36302,
"cut_index": 2151,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Widget\BracketedPasteTrait;
class BracketedPasteHandler
{
use BracketedPasteTrait {
processBracketedPaste as public;
isBufferingPaste as public;
}
}
class ... | tMultiChunkPaste()
{
$handler = $this->createHandler();
// First chunk: start marker + partial content
$data = "\x1b[200~hello ";
$result = $handler->processBracketedPaste($data);
$this->assertNull($result);
| $result = $handler->processBracketedPaste($data);
$this->assertSame('hello world', $result);
$this->assertSame('', $data);
$this->assertFalse($handler->isBufferingPaste());
}
public function tes | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/BracketedPasteTraitTest.php",
"language": "php",
"file_size": 5952,
"cut_index": 716,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Widget\Markdown;
use Tempest\Highlight\TerminalTheme;
use Tempest\Highligh... | gb = match ($tokenType) {
TokenTypeEnum::KEYWORD => [255, 122, 178], // #ff7ab2
TokenTypeEnum::TYPE => [172, 242, 228], // #acf2e4
TokenTypeEnum::PROPERTY => [120, 199, 255], // #78c7ff (variable)
Tok | * @internal
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class DarkTerminalTheme implements TerminalTheme
{
use EscapesTerminalTheme;
public function before(TokenType $tokenType): string
{
$r | {
"filepath": "src/Symfony/Component/Tui/Widget/Markdown/DarkTerminalTheme.php",
"language": "php",
"file_size": 1803,
"cut_index": 537,
"middle_length": 229
} |
d: int, unchanged: int}
* }
*/
public static function compare(string $expected, string $actual): array
{
if ($expected === $actual) {
return [
'identical' => true,
'summary' => 'Outputs are identical',
'diff_lines' => [],
... | y' => \sprintf(
'%d added, %d removed, %d changed, %d unchanged',
$stats['added'],
$stats['removed'],
$stats['changed'],
$stats['unchanged']
),
'diff_li |
$actualLines = explode("\n", $actual);
$diff = self::computeDiff($expectedLines, $actualLines);
$stats = self::computeStats($diff);
return [
'identical' => false,
'summar | {
"filepath": "src/Symfony/Component/Tui/Tests/StateDiff.php",
"language": "php",
"file_size": 25837,
"cut_index": 1331,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Render;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Render\PositionTracker;
use Symfony\Component\Tui\Render\WidgetRect;
use Symfon... | acker();
$widget = new TextWidget('hello');
$this->assertNull($tracker->getWidgetRect($widget));
}
public function testSetAndGetWidgetRect()
{
$tracker = new PositionTracker();
$widget = new TextWidget('hello') | ----------------------
// Widget position tracking
// ---------------------------------------------------------------
public function testGetWidgetRectReturnsNullForUntracked()
{
$tracker = new PositionTr | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/PositionTrackerTest.php",
"language": "php",
"file_size": 4778,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Event\CancelEvent;
use Symfony\Component\Tui\Terminal\VirtualTerminal;
use Symf... | assertSame($loader, $event->getTarget());
});
// Escape key = \x1b
$loader->handleInput("\x1b");
$this->assertTrue($loader->isCancelled());
$this->assertTrue($cancelCalled);
}
public function testCancelVia | [$loader, $tui] = $this->createLoaderWithTui();
$cancelCalled = false;
$tui->addListener(function (CancelEvent $event) use (&$cancelCalled, $loader): void {
$cancelCalled = true;
$this-> | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/CancellableLoaderWidgetTest.php",
"language": "php",
"file_size": 4673,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Render\Renderer;
use Symfony\Component\Tui\Style\Color;
use Symfony\Component\Tui\Styl... |
$stylesheet = $renderer->getStyleSheet();
// Default stylesheet should resolve a basic widget
$widget = new TextWidget('test');
$style = $stylesheet->resolve($widget);
// Style should have some defaults from the st | fabien@symfony.com>
*/
class TuiCascadingStylesheetTest extends TestCase
{
public function testWithoutUserStylesheet()
{
// When no stylesheets are provided, defaults are used
$renderer = new Renderer();
| {
"filepath": "src/Symfony/Component/Tui/Tests/TuiCascadingStylesheetTest.php",
"language": "php",
"file_size": 4558,
"cut_index": 614,
"middle_length": 229
} |
$stylesheet = new StyleSheet();
$widget = new TextWidget('Hello');
$resolved = $stylesheet->resolve($widget);
$this->assertNull($resolved->getPadding());
$this->assertNull($resolved->getBorder());
$this->assertNull($resolved->getBackground());
$this->assertNull($resolv... | testResolveWithFqcnSelector()
{
$stylesheet = new StyleSheet()
->addRule(TextWidget::class, new Style()->withColor('red'));
$widget = new TextWidget('Hello');
$resolved = $stylesheet->resolve($widget);
$thi | = new TextWidget('Hello');
$resolved = $stylesheet->resolve($widget);
$this->assertSame(1, $resolved->getPadding()->top);
$this->assertSame(2, $resolved->getPadding()->right);
}
public function | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/StyleSheetTest.php",
"language": "php",
"file_size": 32935,
"cut_index": 1331,
"middle_length": 229
} |
(string $input, int $expected)
{
$this->assertSame($expected, AnsiUtils::visibleWidth($input));
}
public function testVisibleWidthWithAnsiCodes()
{
// Red "Hello" with reset
$this->assertSame(5, AnsiUtils::visibleWidth("\x1b[31mHello\x1b[0m"));
// Bold + colors
... | >assertSame(2, AnsiUtils::visibleWidth('日'));
$this->assertSame(4, AnsiUtils::visibleWidth('日本'));
}
public function testVisibleWidthConsistencyBetweenSlowPathAndGraphemeWidth()
{
// Ensure visibleWidth (which uses mb_strwidth | ssertSame(2, AnsiUtils::visibleWidth('😀'));
$this->assertSame(4, AnsiUtils::visibleWidth('😀😀'));
}
public function testVisibleWidthWithWideChars()
{
// CJK characters are 2 columns wide
$this- | {
"filepath": "src/Symfony/Component/Tui/Tests/Ansi/AnsiUtilsTest.php",
"language": "php",
"file_size": 19256,
"cut_index": 1331,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Render;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Render\Renderer;
use Symfony\Component\Tui\Style\Align;
use Symfony\Component\Tui\Style\Styl... | StyleSheet([
'.parent' => new Style(align: Align::Center),
'.child' => new Style(maxColumns: 10),
]));
$root = new ContainerWidget();
$root->addStyleClass('parent');
$child = new TextWidget('Hello'); | et;
use Symfony\Component\Tui\Widget\TextWidget;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
final class AlignTest extends TestCase
{
public function testAlignCenter()
{
$renderer = new Renderer(new | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/AlignTest.php",
"language": "php",
"file_size": 8882,
"cut_index": 716,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Editor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Widget\Editor\EditorViewport;
class EditorViewportTest extends TestCase... | $this->assertLessThan($result['scroll_offset'] + $result['visible_line_count'], 20);
}
public function testComputeViewportScrollsUpWhenCursorAbove()
{
$viewport = new EditorViewport();
$lines = [];
for ($i = 0; $i < | "Line $i";
}
// Cursor at line 20, viewport shows 10 rows
$result = $viewport->computeViewport($lines, 20, 10, 80, false, 1);
$this->assertGreaterThanOrEqual($result['scroll_offset'], 20);
| {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Editor/EditorViewportTest.php",
"language": "php",
"file_size": 4023,
"cut_index": 614,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Figlet;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Widget\Figlet\FigletFont;
use Symfony\Component\Tui\Widget\Figlet\FigletRenderer;
class FigletRendererTest extends TestCase
{
private const FONTS_DIR = __DIR__.'/../../.... | nes = $renderer->render('A');
// big font is 8 tall, trailing blank lines stripped; should be ≤ 8 and ≥ 1
$this->assertGreaterThanOrEqual(1, \count($lines));
$this->assertLessThanOrEqual(8, \count($lines));
// Should conta | $this->assertSame([], $renderer->render(''));
}
public function testRenderSingleCharacter()
{
$font = FigletFont::load(self::FONTS_DIR.'/big.flf');
$renderer = new FigletRenderer($font);
$li | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Figlet/FigletRendererTest.php",
"language": "php",
"file_size": 6003,
"cut_index": 716,
"middle_length": 229
} |
hp
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Event;
use PHPUnit\Framework\Attributes\DataPr... | ());
}
public static function isBlankProvider(): iterable
{
yield 'empty string' => ['', true];
yield 'whitespace only' => [' ', true];
yield 'tabs and spaces' => ["\t \n", true];
yield 'non-empty value' => [' | er('isBlankProvider')]
public function testIsBlank(string $value, bool $expected)
{
$event = new ChangeEvent($this->createStub(AbstractWidget::class), $value);
$this->assertSame($expected, $event->isBlank | {
"filepath": "src/Symfony/Component/Tui/Tests/Event/ChangeEventTest.php",
"language": "php",
"file_size": 1099,
"cut_index": 515,
"middle_length": 229
} |
hp
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Event;
use PHPUnit\Framework\Attributes\DataPr... | ());
}
public static function isBlankProvider(): iterable
{
yield 'empty string' => ['', true];
yield 'whitespace only' => [' ', true];
yield 'tabs and spaces' => ["\t \n", true];
yield 'non-empty value' => [' | er('isBlankProvider')]
public function testIsBlank(string $value, bool $expected)
{
$event = new SubmitEvent($this->createStub(AbstractWidget::class), $value);
$this->assertSame($expected, $event->isBlank | {
"filepath": "src/Symfony/Component/Tui/Tests/Event/SubmitEventTest.php",
"language": "php",
"file_size": 1099,
"cut_index": 515,
"middle_length": 229
} |
class StdinBufferTest extends TestCase
{
/**
* @param string[] $expectedSequences
*/
#[DataProvider('sequenceProvider')]
public function testProcess(string $input, array $expectedSequences)
{
$buffer = new StdinBuffer();
$sequences = [];
$buffer->onData(static function... | complete, waiting for more
],
'double escape' => [
"\x1b\x1b",
[], // Need to wait for third char to decide
],
'escape then down arrow' => [
"\x1b\x1b[B",
|
/**
* @return array<string, array{string, string[]}>
*/
public static function sequenceProvider(): array
{
return [
'single escape' => [
"\x1b",
[], // In | {
"filepath": "src/Symfony/Component/Tui/Tests/Input/StdinBufferTest.php",
"language": "php",
"file_size": 13335,
"cut_index": 921,
"middle_length": 229
} |
}
/**
* @return iterable<string, array{int, int, string, string}>
*/
public static function writeAndGetScreenProvider(): iterable
{
yield 'simple text' => [40, 10, 'Hello, World!', 'Hello, World!'];
yield 'newlines' => [40, 10, "Line 1\nLine 2\nLine 3", "Line 1\nLine 2\nLine 3"];... | e' => [20, 3, "A\nB\nC\nD\nE\nF", "D\nE\nF"];
yield 'wide character plain text' => [40, 10, '你好世界', '你好世界'];
yield 'wide character multiline' => [40, 10, "你好\n世界", "你好\n世界"];
}
public function testCursorMovement()
{
$sc | aracters' => [40, 10, "→ Option 1\n Option 2\n✓ Selected", "→ Option 1\n Option 2\n✓ Selected"];
yield 'scroll up' => [20, 3, "Line 1\nLine 2\nLine 3\nLine 4", "Line 2\nLine 3\nLine 4"];
yield 'scroll up multipl | {
"filepath": "src/Symfony/Component/Tui/Tests/Terminal/ScreenBufferTest.php",
"language": "php",
"file_size": 22067,
"cut_index": 1331,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Terminal;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Terminal\VirtualTerminal;
cla... | this->assertSame(['a', 'b', 'c'], $received);
$terminal->stop();
}
public function testSimulateInputForwardsPasteContent()
{
$terminal = new VirtualTerminal();
$received = [];
$terminal->start(
sta | l->start(
static function (string $data) use (&$received) { $received[] = $data; },
static function () {},
static function () {},
);
$terminal->simulateInput('abc');
$ | {
"filepath": "src/Symfony/Component/Tui/Tests/Terminal/VirtualTerminalTest.php",
"language": "php",
"file_size": 3846,
"cut_index": 614,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Loop;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Exce... | Accumulator(60.0, 5);
$this->assertSame(0, $accumulator->computeSteps(1.0 / 120.0));
$this->assertSame(1, $accumulator->computeSteps(1.0 / 120.0));
}
public function testComputeStepsCapsLargeDelta()
{
$accumulator = ne | ts()
{
$this->expectException(InvalidArgumentException::class);
new FixedStepAccumulator(0.0);
}
public function testComputeStepsAccumulatesFractionalDelta()
{
$accumulator = new FixedStep | {
"filepath": "src/Symfony/Component/Tui/Tests/Loop/FixedStepAccumulatorTest.php",
"language": "php",
"file_size": 1750,
"cut_index": 537,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
/**
* Tests ... | lic static function parseKeysProvider(): array
{
return [
'enter' => ['<Enter>', "\r"],
'return' => ['<Return>', "\r"],
'escape' => ['<Escape>', "\x1b"],
'esc' => ['<Esc>', "\x1b"],
't | public function testParseKeys(string $input, string $expected)
{
$this->assertSame($expected, KeySequenceParser::parseKeys($input));
}
/**
* @return array<string, array{string, string}>
*/
pub | {
"filepath": "src/Symfony/Component/Tui/Tests/KeySequenceParserTest.php",
"language": "php",
"file_size": 2955,
"cut_index": 563,
"middle_length": 229
} |
class AnsiCodeTrackerTest extends TestCase
{
private AnsiCodeTracker $tracker;
protected function setUp(): void
{
$this->tracker = new AnsiCodeTracker();
}
// --------------------------------------------------
// Basic SGR attributes on/off
// ------------------------------------... | gh' => [9, 29];
}
#[DataProvider('sgrAttributeOnOffProvider')]
public function testSgrAttributeOnAndOff(int $onCode, int $offCode)
{
$this->tracker->process("\x1b[{$onCode}m");
$this->assertTrue($this->tracker->hasActiveCod | yield 'dim' => [2, 22];
yield 'italic' => [3, 23];
yield 'underline' => [4, 24];
yield 'blink' => [5, 25];
yield 'inverse' => [7, 27];
yield 'hidden' => [8, 28];
yield 'strikethrou | {
"filepath": "src/Symfony/Component/Tui/Tests/Ansi/AnsiCodeTrackerTest.php",
"language": "php",
"file_size": 15828,
"cut_index": 921,
"middle_length": 229
} |
Symfony\Component\Tui\Render\ChromeApplier;
use Symfony\Component\Tui\Render\RenderContext;
use Symfony\Component\Tui\Render\WidgetRendererInterface;
use Symfony\Component\Tui\Style\Border;
use Symfony\Component\Tui\Style\Padding;
use Symfony\Component\Tui\Style\Style;
use Symfony\Component\Tui\Style\TextAlign;
use Sy... |
public function testComputeInnerDimensions(int $columns, int $rows, Style $style, array $expected)
{
$applier = $this->createApplier();
$this->assertSame($expected, $applier->computeInnerDimensions($columns, $rows, $style));
} | ------------------------
// computeInnerDimensions
// ---------------------------------------------------------------
/**
* @param array{int, int} $expected
*/
#[DataProvider('innerDimensionsProvider')] | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/ChromeApplierTest.php",
"language": "php",
"file_size": 13457,
"cut_index": 921,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Figlet;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Exception\InvalidArgu... | R__, 3).'/Widget/Figlet/fonts';
$registry->register('my-font', $fontsDir.'/small.flf');
$this->assertTrue($registry->has('my-font'));
$font = $registry->get('my-font');
$this->assertSame(5, $font->getHeight()); // small fo | try();
$font = $registry->get('big');
$this->assertSame(8, $font->getHeight());
}
public function testRegisterCustomFont()
{
$registry = new FontRegistry();
$fontsDir = \dirname(__DI | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Figlet/FontRegistryTest.php",
"language": "php",
"file_size": 3002,
"cut_index": 563,
"middle_length": 229
} |
This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Event;
use PHPUnit\Framework\TestCase;
use Symfony\Comp... | efault()
{
$event = new TickEvent();
$this->assertFalse($event->hasBusyHint());
$this->assertFalse($event->isBusy());
}
public function testSetBusyTrueMarksBusy()
{
$event = new TickEvent();
$event- | ent->getDeltaTime());
}
public function testDeltaTimeCanBeProvided()
{
$event = new TickEvent(0.125);
$this->assertSame(0.125, $event->getDeltaTime());
}
public function testHasNoBusyHintByD | {
"filepath": "src/Symfony/Component/Tui/Tests/Event/TickEventTest.php",
"language": "php",
"file_size": 1349,
"cut_index": 524,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Terminal;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\... | dForget');
$start = microtime(true);
$method->invoke($terminal, ['sleep', '10']);
$elapsed = microtime(true) - $start;
// Should return nearly instantly, not wait 10 seconds
$this->assertLessThan(1.0, $elapsed);
| get uses Unix shell syntax and is only invoked on macOS.');
}
}
public function testFireAndForgetDoesNotBlock()
{
$terminal = new Terminal();
$method = new \ReflectionMethod($terminal, 'fireAn | {
"filepath": "src/Symfony/Component/Tui/Tests/Terminal/TerminalTest.php",
"language": "php",
"file_size": 1883,
"cut_index": 537,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Render;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Ansi\AnsiUtils;
use Symfony\Component\Tui\Render\Renderer;
use Symfony\Component\Tui\Style\TailwindStylesheet;
use Symfony\Component\T... | new TextWidget('Hi');
$text->addStyleClass($styleClass);
$root->add($text);
$lines = $renderer->render($root, 10, 5);
$this->assertCount(1, $lines);
$this->assertSame($expectedVisible, AnsiUtils::stripAnsiCodes($li | r('textAlignProvider')]
public function testTextAlignment(string $styleClass, string $expectedVisible)
{
$renderer = new Renderer(new TailwindStylesheet());
$root = new ContainerWidget();
$text = | {
"filepath": "src/Symfony/Component/Tui/Tests/Render/TextAlignTest.php",
"language": "php",
"file_size": 5661,
"cut_index": 716,
"middle_length": 229
} |
ymfony\Component\Tui\Ansi\TextWrapper;
class TextWrapperTest extends TestCase
{
/**
* @param string[] $expected
*/
#[DataProvider('wrapBasicProvider')]
public function testWrapBasic(string $input, int $width, array $expected)
{
$this->assertSame($expected, TextWrapper::wrapTextWithAns... | ", 20, ['Hello', 'World']];
yield 'multiple spaces preserved' => ['Hello World', 20, ['Hello World']];
}
public function testWrapWithAnsiCodes()
{
$styled = "\x1b[31mHello World\x1b[0m";
$lines = TextWrapper::wrapTe | e fits' => ['Hello', 20, ['Hello']];
yield 'empty string' => ['', 20, ['']];
yield 'long line wraps at word boundary' => ['Hello World', 5, ['Hello', 'World']];
yield 'newlines preserved' => ["Hello\nWorld | {
"filepath": "src/Symfony/Component/Tui/Tests/Ansi/TextWrapperTest.php",
"language": "php",
"file_size": 10426,
"cut_index": 921,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\Tui\Tests\Input;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Input\Key;
use Symfony\Component\Tui\Input\KeyParser;
class KeyParserTest extends TestCase
{
private KeyParser $parser;
prote... | er(): iterable
{
yield 'enter (CR)' => ["\r", Key::ENTER];
yield 'enter (LF)' => ["\n", Key::ENTER];
yield 'escape' => ["\x1b", Key::ESCAPE];
yield 'tab' => ["\t", Key::TAB];
yield 'backspace' => ["\x7f", Key::BA | {
$result = $this->parser->parse($input);
$this->assertSame($expectedKey, $result['key']);
}
/**
* @return iterable<string, array{string, string}>
*/
public static function parseKeyProvid | {
"filepath": "src/Symfony/Component/Tui/Tests/Input/KeyParserTest.php",
"language": "php",
"file_size": 8229,
"cut_index": 716,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Loop;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Tui\Loop\AdaptativeTicker;
use Symfony\Component\Tui\Loop\TickRuntimeInterface;
clas... | ticker));
} finally {
$ticker->stop();
}
}
public function testRefreshDisablesPollingWhenExplicitlyIdleWithoutOtherWork()
{
$runtime = new TestTickRuntime();
$ticker = new AdaptativeTicker($runtime); | tativeTicker($runtime);
try {
$ticker->refresh(true, false, null, true, null);
$this->assertSame(0.25, $this->getCurrentInterval($ticker));
$this->assertNotNull($this->getCallbackId($ | {
"filepath": "src/Symfony/Component/Tui/Tests/Loop/AdaptativeTickerTest.php",
"language": "php",
"file_size": 3147,
"cut_index": 614,
"middle_length": 229
} |
umentException;
use Symfony\Component\Tui\Style\Color;
class ColorTest extends TestCase
{
#[DataProvider('namedColorProvider')]
public function testNamedColor(string $name, string $expectedFg, string $expectedBg)
{
$color = Color::named($name);
$this->assertSame($expectedFg, $color->toForeg... | 'yellow' => ['yellow', "\x1b[33m", "\x1b[43m"];
yield 'blue' => ['blue', "\x1b[34m", "\x1b[44m"];
yield 'magenta' => ['magenta', "\x1b[35m", "\x1b[45m"];
yield 'cyan' => ['cyan', "\x1b[36m", "\x1b[46m"];
yield 'white' => [' | on namedColorProvider(): iterable
{
yield 'black' => ['black', "\x1b[30m", "\x1b[40m"];
yield 'red' => ['red', "\x1b[31m", "\x1b[41m"];
yield 'green' => ['green', "\x1b[32m", "\x1b[42m"];
yield | {
"filepath": "src/Symfony/Component/Tui/Tests/Style/ColorTest.php",
"language": "php",
"file_size": 9932,
"cut_index": 921,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Widget\Figlet;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCa... | => ['small', 5];
yield 'slant' => ['slant', 6];
yield 'standard' => ['standard', 6];
yield 'mini' => ['mini', 4];
}
#[DataProvider('bundledFontProvider')]
public function testLoadBundledFont(string $name, int $expectedH | IR__.'/../../../Widget/Figlet/fonts';
/**
* @return iterable<string, array{string, int}>
*/
public static function bundledFontProvider(): iterable
{
yield 'big' => ['big', 8];
yield 'small' | {
"filepath": "src/Symfony/Component/Tui/Tests/Widget/Figlet/FigletFontTest.php",
"language": "php",
"file_size": 3627,
"cut_index": 614,
"middle_length": 229
} |
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Tests\Terminal;
use PHPUnit\Framework\TestCase;
u... | irtualTerminal();
$secondary = new VirtualTerminal();
$tee = new TeeTerminal($primary, $secondary);
$tee->bell();
$this->assertSame("\x07", $primary->getOutput());
$this->assertSame("\x07", $secondary->getOutput()) | $terminal = new VirtualTerminal();
$terminal->bell();
$this->assertSame("\x07", $terminal->getOutput());
}
public function testBellOnTeeTerminalWritesToBothTerminals()
{
$primary = new V | {
"filepath": "src/Symfony/Component/Tui/Tests/Terminal/BellTest.php",
"language": "php",
"file_size": 1007,
"cut_index": 512,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter;
use Symfony\Component\RateLimiter\Exception\MaxWaitDurationExceed... | *
* @param int $tokens the number of tokens required
* @param float|null $maxTime maximum accepted waiting time in seconds
*
* @throws MaxWaitDurationExceededException if $maxTime is set and the process needs to wait longer | until the required number of tokens is available.
*
* The reserved tokens will be taken into account when calculating
* future token consumptions. Do not use this method if you intend
* to skip this process.
| {
"filepath": "src/Symfony/Component/RateLimiter/LimiterInterface.php",
"language": "php",
"file_size": 1667,
"cut_index": 537,
"middle_length": 229
} |
This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter;
use Symfony\Component\RateLimiter\Exception\RateLimi... | * @throws RateLimitExceededException if not accepted
*/
public function ensureAccepted(): static
{
if (!$this->accepted) {
throw new RateLimitExceededException($this);
}
return $this;
}
public fu | DateTimeImmutable $retryAfter,
private bool $accepted,
private int $limit,
) {
}
public function isAccepted(): bool
{
return $this->accepted;
}
/**
* @return $this
*
| {
"filepath": "src/Symfony/Component/RateLimiter/RateLimit.php",
"language": "php",
"file_size": 1487,
"cut_index": 524,
"middle_length": 229
} |
hp
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Exception;
use Symfony\Component\RateLimiter... | Limit;
}
public function getRetryAfter(): \DateTimeImmutable
{
return $this->rateLimit->getRetryAfter();
}
public function getRemainingTokens(): int
{
return $this->rateLimit->getRemainingTokens();
}
publi | mit,
int $code = 0,
?\Throwable $previous = null,
) {
parent::__construct('Rate Limit Exceeded', $code, $previous);
}
public function getRateLimit(): RateLimit
{
return $this->rate | {
"filepath": "src/Symfony/Component/RateLimiter/Exception/RateLimitExceededException.php",
"language": "php",
"file_size": 1086,
"cut_index": 515,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\RateLimiter\LimiterStateInterface;
/**
* State of a fixed wi... | s->id;
}
public function getPeriodStart(): \DateTimeImmutable
{
return $this->periodStart;
}
public function getPeriodEnd(): \DateTimeImmutable
{
return $this->periodEnd;
}
public function getExpirationTim | private string $id,
private int $maxSize,
private \DateTimeImmutable $periodStart,
private \DateTimeImmutable $periodEnd,
) {
}
public function getId(): string
{
return $thi | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/CalendarAlignedWindow.php",
"language": "php",
"file_size": 2367,
"cut_index": 563,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\RateLimiter\Exception\MaxWaitDurationExceededException;
use Symfony\Component\RateLimiter\LimiterInterface;
use Symfony\Component\RateLimiter\RateLimit;
use Symfony\Componen... | he window is aligned to a calendar starting at this datetime
* and resetting every $interval, instead of starting on the first hit.
* The anchor's timezone is prese | inal class FixedWindowLimiter implements LimiterInterface
{
use ResetLimiterTrait;
private int $intervalInSeconds;
private \DateInterval $interval;
/**
* @param \DateTimeImmutable|null $anchorAt When set, t | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/FixedWindowLimiter.php",
"language": "php",
"file_size": 6754,
"cut_index": 716,
"middle_length": 229
} |
hp
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\RateLimiter\Li... | oat $maxTime = null): Reservation
{
return new Reservation(microtime(true), new RateLimit(\PHP_INT_MAX, new \DateTimeImmutable(), true, \PHP_INT_MAX));
}
public function consume(int $tokens = 1): RateLimit
{
return new Rate | implementation requires a
* limiter, but no rate limit should be enforced.
*
* @author Wouter de Jong <wouter@wouterj.nl>
*/
final class NoLimiter implements LimiterInterface
{
public function reserve(int $tokens = 1, ?fl | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/NoLimiter.php",
"language": "php",
"file_size": 1122,
"cut_index": 515,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\RateLimiter\Util\TimeUtil;
/**
* Data object representing the fill rate of a token bucket.
*
* @author Wouter... | ('PT1M'), $rate);
}
public static function perHour(int $rate = 1): self
{
return new static(new \DateInterval('PT1H'), $rate);
}
public static function perDay(int $rate = 1): self
{
return new static(new \DateInter | static function perSecond(int $rate = 1): self
{
return new static(new \DateInterval('PT1S'), $rate);
}
public static function perMinute(int $rate = 1): self
{
return new static(new \DateInterval | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/Rate.php",
"language": "php",
"file_size": 3151,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\RateLimiter\Exception\InvalidIntervalException;
use Symfony\Component\RateLimiter\LimiterStateInterface;
/**
* ... | Exception(\sprintf('The interval must be positive integer, "%d" given.', $intervalInSeconds));
}
$this->windowEndAt = microtime(true) + $intervalInSeconds;
}
public static function createFromPreviousWindow(self $window, int $interv | Window = 0;
private float $windowEndAt;
public function __construct(
private string $id,
private int $intervalInSeconds,
) {
if ($intervalInSeconds < 1) {
throw new InvalidInterval | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php",
"language": "php",
"file_size": 4314,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\RateLimiter\Exception\MaxWaitDurationExceededException;
use Symfony\Com... | are currently 25% into
* the current window. We have made 3 hits in the current window so far.
* That means our sliding window hit count is (75% * 8) + 3 = 9.
*
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
final class SlidingWindowLimiter impl | Symfony\Component\RateLimiter\Util\TimeUtil;
/**
* The sliding window algorithm will look at your last window and the current one.
* It is good algorithm to reduce bursts.
*
* Example:
* Last time window we did 8 hits. We | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/SlidingWindowLimiter.php",
"language": "php",
"file_size": 4753,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\RateLimiter\LimiterStateInterface;
/**
* @author Wouter de Jong <wouter@wouterj.nl>
*
* @internal
*/
final c... | null $timer the current timer of the bucket, defaulting to microtime(true)
*/
public function __construct(
private string $id,
int $initialTokens,
private Rate $rate,
?float $timer = null,
) {
if | ifier for this bucket
* @param int $initialTokens the initial number of tokens in the bucket (i.e. the max burst size)
* @param Rate $rate the fill rate and time of this bucket
* @param float| | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/TokenBucket.php",
"language": "php",
"file_size": 3755,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\RateLimiter\Exception\MaxWaitDurationExceededException;
use Symfony\Com... | private Rate $rate,
StorageInterface $storage,
?LockInterface $lock = null,
) {
$this->id = $id;
$this->storage = $storage;
$this->lock = $lock;
}
/**
* Waits until the required number of tokens | *
* @author Wouter de Jong <wouter@wouterj.nl>
*/
final class TokenBucketLimiter implements LimiterInterface
{
use ResetLimiterTrait;
public function __construct(
string $id,
private int $maxBurst,
| {
"filepath": "src/Symfony/Component/RateLimiter/Policy/TokenBucketLimiter.php",
"language": "php",
"file_size": 4584,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Policy;
use Symfony\Component\RateLimiter\LimiterStateInterface;
/**
* @author Wouter de Jong <wouter@wouterj.nl>
*
* @internal
*/
final c... | ring
{
return $this->id;
}
public function getExpirationTime(): ?int
{
// Keep the entry alive long enough for any reservation debt to be
// carried forward, otherwise resets that span an idle interval would
| private int $intervalInSeconds,
int $windowSize,
?float $timer = null,
) {
$this->maxSize = $windowSize;
$this->timer = $timer ?? microtime(true);
}
public function getId(): st | {
"filepath": "src/Symfony/Component/RateLimiter/Policy/Window.php",
"language": "php",
"file_size": 3877,
"cut_index": 614,
"middle_length": 229
} |
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Tests;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ClockMock;
use Symfony\Component\Rate... |
ClockMock::register(InMemoryStorage::class);
}
public function testConsume()
{
$limiter1 = $this->createLimiter(4, new \DateInterval('PT1S'));
$limiter2 = $this->createLimiter(8, new \DateInterval('PT10S'));
$ | r\Storage\InMemoryStorage;
#[Group('time-sensitive')]
class CompoundLimiterTest extends TestCase
{
private InMemoryStorage $storage;
protected function setUp(): void
{
$this->storage = new InMemoryStorage(); | {
"filepath": "src/Symfony/Component/RateLimiter/Tests/CompoundLimiterTest.php",
"language": "php",
"file_size": 3779,
"cut_index": 614,
"middle_length": 229
} |
This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Co... | cts($this->once())
->method('create')
->with('foo')
->willReturn($this->createStub(LimiterInterface::class))
;
$factory2 = $this->createMock(RateLimiterFactoryInterface::class);
$factory2
| iterFactoryInterface;
class CompoundRateLimiterFactoryTest extends TestCase
{
public function testCreate()
{
$factory1 = $this->createMock(RateLimiterFactoryInterface::class);
$factory1
->expe | {
"filepath": "src/Symfony/Component/RateLimiter/Tests/CompoundRateLimiterFactoryTest.php",
"language": "php",
"file_size": 1357,
"cut_index": 524,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Lock\... | => 'token_bucket',
'limit' => 10,
'rate' => ['interval' => '1 second'],
]);
$limiter = $factory->create('127.0.0.1');
$this->assertInstanceOf(TokenBucketLimiter::class, $limiter);
}
public function | Symfony\Component\RateLimiter\Storage\StorageInterface;
class LimiterTest extends TestCase
{
public function testTokenBucket()
{
$factory = $this->createFactory([
'id' => 'test',
'policy' | {
"filepath": "src/Symfony/Component/RateLimiter/Tests/LimiterTest.php",
"language": "php",
"file_size": 2007,
"cut_index": 537,
"middle_length": 229
} |
ge.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Tui\Input;
/**
* Helper class for creating key identifiers.
*
* Provides constants and factory method... | e';
public const END = 'end';
public const PAGE_UP = 'page_up';
public const PAGE_DOWN = 'page_down';
// Arrow keys
public const UP = 'up';
public const DOWN = 'down';
public const LEFT = 'left';
public const RIGHT = 'right | const ENTER = 'enter';
public const TAB = 'tab';
public const SPACE = 'space';
public const BACKSPACE = 'backspace';
public const DELETE = 'delete';
public const INSERT = 'insert';
public const HOME = 'hom | {
"filepath": "src/Symfony/Component/Tui/Input/Key.php",
"language": "php",
"file_size": 2211,
"cut_index": 563,
"middle_length": 229
} |
part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\RateLimiter\Tests;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framewo... | Limit, $rateLimit->ensureAccepted());
}
public function testEnsureAcceptedThrowsRateLimitExceptionIfNotAccepted()
{
$rateLimit = new RateLimit(10, $retryAfter = new \DateTimeImmutable(), false, 10);
try {
$rateLimi | ')]
class RateLimitTest extends TestCase
{
public function testEnsureAcceptedDoesNotThrowExceptionIfAccepted()
{
$rateLimit = new RateLimit(10, new \DateTimeImmutable(), true, 10);
$this->assertSame($rate | {
"filepath": "src/Symfony/Component/RateLimiter/Tests/RateLimitTest.php",
"language": "php",
"file_size": 1860,
"cut_index": 537,
"middle_length": 229
} |
buted with this source code.
*/
namespace Symfony\Component\RateLimiter\Tests;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ClockMock;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symf... | gProvider')]
public function testValidConfig(string $expectedClass, array $config)
{
$factory = new RateLimiterFactory($config, new InMemoryStorage());
$rateLimiter = $factory->create('key');
$this->assertInstanceOf($expecte | teLimiter\Policy\TokenBucketLimiter;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
class RateLimiterFactoryTest extends TestCase
{
#[DataProvider('validConfi | {
"filepath": "src/Symfony/Component/RateLimiter/Tests/RateLimiterFactoryTest.php",
"language": "php",
"file_size": 6182,
"cut_index": 716,
"middle_length": 229
} |
miter\Util\TimeUtil;
#[Group('time-sensitive')]
class FixedWindowLimiterTest extends TestCase
{
private InMemoryStorage $storage;
protected function setUp(): void
{
$this->storage = new InMemoryStorage();
ClockMock::register(InMemoryStorage::class);
ClockMock::register(RateLimit::... | assertSame(10, $rateLimit->getLimit());
$this->assertTrue($rateLimit->isAccepted());
$rateLimit = $limiter->consume();
$this->assertFalse($rateLimit->isAccepted());
$this->assertSame(10, $rateLimit->getLimit());
// W | er = $this->createLimiter();
// fill 9 tokens in 45 seconds
for ($i = 0; $i < 9; ++$i) {
$limiter->consume();
sleep(5);
}
$rateLimit = $limiter->consume();
$this-> | {
"filepath": "src/Symfony/Component/RateLimiter/Tests/Policy/FixedWindowLimiterTest.php",
"language": "php",
"file_size": 19953,
"cut_index": 1331,
"middle_length": 229
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.