Skip to content

[Console] Separate styling helpers out of SymfonyStyle #39184

Closed
@apfelbox

Description

@apfelbox

Description
SymfonyStyle is a mix of styling decisions (symbols and colors mostly) and some useful helpers. While you might want to customize the look + feel (some colors, lines, default table styles, etc..) you might still want to use all the helpers from the class.

You can extend it, but you soon will encounter issues, as important helper functions are private.
(Then you copy this method to your class, but then $this->buffer is private... You could just copy & paste the whole class, but then you lose all updates.)

So maybe these methods can be made protected or the class can be refactored, so that one can customize the styling decisions while keep using the helpers.

Example

For example when trying to reimplement title(), you can't do it as $this->autoPrependBlock() is private.

/**
    * {@inheritdoc}
    */
public function title(string $message)
{
    $this->autoPrependBlock(); // oops
    $this->writeln([
        sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
        // change some color and symbol here
        sprintf('<fg=magenta>%s</>', str_repeat('#', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
    ]);
    $this->newLine();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConsoleHelp wantedIssues and PRs which are looking for volunteers to complete them.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions