Skip to content

[console] Add "truncate" method to Formatter helper #11977

@dantleech

Description

@dantleech

It would be really nice to add a truncate method to the formatter helper or similar. Which does the following:

public function truncate($text, $length, $suffix = '...')
{
    $computedLength = $length - strlen($suffix);
    return strlen($text) > $computedLength ? substr($text, 0, $computedLength) : $text;
}

This is a recurrent requirement and would be especially useful when combined with the Table class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions