# Separator

`Separator` draws one full-width horizontal line, with an optional title placed left, centered or right. It separates sections of terminal output — build steps, test groups, report blocks — and is always exactly one row: the line spans the terminal width (80 columns when the terminal reports none) or a width you give, and a title too wide for it is cropped with an ellipsis, never wrapped.

A live demo is available in the [showcase](/manual/CLI/UI/Base/Separator/showcase).

## Instance

The component is instantiated with the `Output`:

```php
use const Bootgly\CLI;
use Bootgly\CLI\UI\Base\Separator;

$Separator = new Separator(CLI->Terminal->Output);
```

## A plain line

With nothing else set, `render()` writes a line across the terminal:

```php
$Separator->render();
```

```
────────────────────────────────────────────────────────────────────────────────
```

## A titled line

Give it a title — it accepts markup — and pick where it sits with `Alignment`. A centered title is the default; left and right titles keep two glyphs before (or after) them:

```php
use Bootgly\CLI\UI\Base\Separator\Alignments;

$Separator->title = 'Build';
$Separator->Alignment = Alignments::Left;
$Separator->render();

$Separator->title = 'Tests';
$Separator->Alignment = Alignments::Center;
$Separator->render();

$Separator->title = '@#green:Deploy@;';
$Separator->Alignment = Alignments::Right;
$Separator->render();
```

```
── Build ───────────────────────────────────────────────────────────────────────
──────────────────────────────────── Tests ─────────────────────────────────────
────────────────────────────────────────────────────────────────────── Deploy ──
```

When the line leaves an odd column around a centered title, the extra column goes to the right side.

## Glyphs

The line takes its glyph from the same border sets as [Frame](/manual/CLI/UI/Base/Frame) — `Borders::Sharp` (the default), `Round`, `Double`, `Heavy`, or `None` for a blank line — or from any string, which repeats as a pattern:

```php
use Bootgly\CLI\UI\Base\Frame\Borders;

$Separator->glyph = Borders::Double;   // ════════ Title ════════
$Separator->glyph = Borders::Heavy;    // ━━━━━━━━ Title ━━━━━━━━
$Separator->glyph = '·•';              // ·•·•·•·• Title ·•·•·•·•
```

The pattern starts over on each side of the title. A wide glyph (two columns) never passes the width: an odd last column is left blank. A glyph string must draw something on one row, so an empty string, a control character, a combining mark, a zero-width or format character and invalid UTF-8 are refused with an `InvalidArgumentException`.

## Color

On a terminal the line is painted with `color` — Template markup, dim (`@#Black:`) by default. Only the color's SGR escape codes are used, the title keeps its own markup, and the line's color never bleeds into the title:

```php
$Separator->color = '@#cyan:';
$Separator->title = '@#White:Results@;';
$Separator->render();
```

## Width

`width` fixes the line's columns; `null` (the default) follows the terminal. A width of `0` or less is refused with an `InvalidArgumentException`:

```php
$Separator->width = 40;
$Separator->render();
```

Every width is a display width. A wide title (CJK, `日本語`) costs two columns per glyph, a combining mark and a zero-width joiner cost none, and markup costs nothing — so the line ends on the last column. Every format character except the zero-width (non-)joiners — a soft hyphen, a bidi override, a zero-width space, a byte order mark — and every line or paragraph separator is dropped from the title.

Display width follows the Unicode tables PHP ships, and terminals do not all agree with them: an emoji sequence joined with zero-width joiners may leave the line a few columns short, and on terminals that draw an emoji with the `U+FE0F` presentation selector as two columns (kitty, WezTerm, iTerm2, Windows Terminal) such a title takes one column more than measured. Conjoining Hangul vowels and finals (`U+1160`–`U+11FF`) count one column each, while terminals that compose them into syllables draw none.

## Long titles

A title wider than the line is cropped to fit, ending in `…`; markup is never cut in two and a wide glyph that does not fit is dropped:

```php
$Separator->width = 32;
$Separator->title = 'A very long title that cannot fit in thirty-two columns';
$Separator->render();
```

```
── A very long title that ca… ──
```

A line too narrow for any title (under seven columns) is drawn plain.

## Plain output

On pipes and CI logs the separator writes zero escape codes — the title's markup included. `decoration` forces either behavior: `false` always plain, `true` always painted, `null` (the default) follows the terminal.

The title is Template markup written by the program: its directives are interpreted, and a complete SGR sequence in it styles the title when the line is painted. Any other control character — a newline, a cursor or OSC escape, a C1 control — is shown as a visible escape (`\n`, `\u001b`), so a title never breaks the row. Text the program did not write (user input, a file name) goes through `Escaped::scrub(Controls::escape(mb_scrub($text, 'UTF-8')))` before it is placed in a title — `Controls` (`Bootgly\ABI\Code\__String\Controls`) turns its escape codes, SGR included, into visible text, and `Escaped` (`Bootgly\ABI\Templates\Template\Escaped`) removes the markup.

## Reference

```php
public null|bool $decoration;
```

Painting switch — `null` (default) follows the terminal, `false` forces plain output, `true` forces the color.

```php
public Borders|string $glyph;
```

The line glyph. A `Borders` case draws its horizontal glyph (`Borders::None` a blank line); a string repeats as a pattern. Default `Borders::Sharp`. Assigning an empty string, invalid UTF-8, or a string with a control, format, combining or line/paragraph-separator character throws `InvalidArgumentException`.

```php
public null|int $width;
```

The line's columns. `null` (default) follows the terminal width, 80 columns when it reports none. Assigning `0` or a negative width throws `InvalidArgumentException`.

```php
public Alignments $Alignment;
```

Where the title sits — `Alignments::Left`, `Alignments::Center` (default) or `Alignments::Right`.

```php
public string $color;
```

The line color as Template markup. Default `'@#Black:'`. Only its SGR escape codes are used.

```php
public string $title;
```

The title shown inside the line, as Template markup. Default `''` — a plain line.

```php
public function render (int $mode = self::WRITE_OUTPUT): null|string
```

Renders the line. `WRITE_OUTPUT` writes it (with its trailing newline) to the `Output` and returns `null`; `RETURN_OUTPUT` returns it instead.
