Luminova Framework

Command Text Util

Last updated: 2024-05-03 18:17:18

Text Utils is one of the many powerful features offered by Luminova's Framework command-line interface. With this versatile class, you can enhance the appearance of your output text, taking your CLI tool to a new level of elegance and professionalism. Whether you're aiming to beautify your output for end users or simply improve readability during development, Text Utils provides functions to help you achieve your goals with ease.


  • Class namespace: \Luminova\Command\TextUtils

Constants

ConstantVisibilityTypeValue
ANSI_RESETpublicint0
ANSI_BOLDpublicint1
ANSI_ITALICpublicint3
ANSI_UNDERLINEpublicint4
ANSI_STRIKETHROUGHpublicint9

Methods

padStart

Pads string left

public static padStart(string $text, int $length, string $char = ' '): string

Parameters:

ParameterTypeDescription
$textstringstring to pad
$lengthint
$charstringPadding character

padEnd

Pads string right

public static padEnd(string $text, int $max, string $char = ' '): string

Parameters:

ParameterTypeDescription
$textstringstring to pad
$maxintmaximum padding
$charstringPadding character

border

Create a border around text.

public static border(string $text, ?int $padding = null): string

Parameters:

ParameterTypeDescription
$textstringstring to pad
$padding?int

Return Value:

string - Return text with border round.


center

Create a centered text

public static center(string $text, int|null $padding = null): string

Parameters:

ParameterTypeDescription
$textstringstring to pad
$paddingint|nullmaximum padding

Return Value:

string - Return centered text.


padding

Pads string both left and right.

public static padding(string $text, int $max, string $char = ' ', int $padd = STR_PAD_BOTH): string

Parameters:

ParameterTypeDescription
$textstringstring to pad
$maxintmaximum padding
$charstringPadding character
$paddintPadding location default is both left and right

fit

Pads string to fit same length

public static fit(string $text, int $max, int $extra = 2, int $indent): string

Parameters:

ParameterTypeDescription
$textstringstring to pad
$maxintmaximum padding
$extraintHow many extra spaces to add at the end
$indentint

strlen

Get the length of characters in a string and ignore styles

public static strlen(string $string = null, string $encoding = 'UTF-8'): int

Parameters:

ParameterTypeDescription
$stringstringOptional string
$encodingstringText encoding

Return Value:

int - The number of characters in the string


style

Apply style format on text string

public static style(string $text, int|null $format = null, bool $formatted = true): string

Parameters:

ParameterTypeDescription
$textstringText to style
$formatint|nullStyle to apply text.
$formattedboolReturn a formatted string or ansi style code

Return Value:

string - A style formatted ansi string


hasAnsi

Check if text already has ANSI method in place

public static hasAnsi(string $text): bool

Parameters:

ParameterTypeDescription
$textstringText string

Return Value:

bool - true or false


largest

Get the largest line from text.

public static largest(string $text): array<int,mixed>

Parameters:

ParameterTypeDescription
$textstringText to process.

Return Value:

array<int,mixed> - Return largest line from text and it length.