<commit_before><?php

namespace PhpSchool\CliMenu\MenuItem;

use Assert\Assertion;
use PhpSchool\CliMenu\MenuStyle;

/**
 * @author <NAME> <<EMAIL>>
 */
class AsciiArtItem implements MenuItemInterface
{
    /**
     * Possible positions of the ascii art
     */
    const POSITION_CENTER = 'center';
    const POSITION_LEFT   = 'left';
    const POSITION_RIGHT  = 'right';
    
    /**
     * @var string
     */
    private $text;

    /**
     * @var string
     */
    private $position;

    /**
     * @var string
     */
    private $alternateText;

    /**
     * @var int
     */
    private $artLength;

    public function __construct(string $text, string $position = self::POSITION_CENTER, string $alt = '')
    {
        Assertion::inArray($position, [self::POSITION_CENTER, self::POSITION_RIGHT, self::POSITION_LEFT]);
        
        $this->text      = $text;
        $this->position  = $position;
        $this->alternateText = $alt;
        $this->artLength = max(array_map('mb_strlen', explode("\n", $text)));
    }

    /**
     * The output text for the item
     */
    public function getRows(MenuStyle $style, bool $selected = false) : array
    {
        if ($this->artLength > $style->getContentWidth()) {
            $alternate = new StaticItem($this->alternateText);
            return $alternate->getRows($style, false);
        }

        return array_map(function ($row) use ($style) {
            $length = mb_strlen($row);

            $padding = $style->getContentWidth() - $length;

            switch ($this->position) {
                case self::POSITION_LEFT:
                    return $row;
                    break;
                case self::POSITION_RIGHT:
                    $row = rtrim($row);
                    $padding = $padding - ($this->artLength - mb_strlen($row));
                    $row = sprintf('%s%s', str_repeat(' ', $padding), $row);
                    break;
                case self::POSITION_CENTER:
                default:
                    $row = rtrim($row);
                    $padding = $padding - ($this->artLength - mb_strlen($row));
                    $left = ceil($padding/2);
                    $right = $padding - $left;
                    $row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right));
                    break;
            }

            return $row;
        }, explode("\n", $this->text));
    }

    /**
     * Can the item be selected
     */
    public function canSelect() : bool<commit_msg>Fix centering ascii art<commit_after><?php

namespace PhpSchool\CliMenu\MenuItem;

use Assert\Assertion;
use PhpSchool\CliMenu\MenuStyle;

/**
 * @author <NAME> <<EMAIL>>
 */
class AsciiArtItem implements MenuItemInterface
{
    /**
     * Possible positions of the ascii art
     */
    const POSITION_CENTER = 'center';
    const POSITION_LEFT   = 'left';
    const POSITION_RIGHT  = 'right';
    
    /**
     * @var string
     */
    private $text;

    /**
     * @var string
     */
    private $position;

    /**
     * @var string
     */
    private $alternateText;

    /**
     * @var int
     */
    private $artLength;

    public function __construct(string $text, string $position = self::POSITION_CENTER, string $alt = '')
    {
        Assertion::inArray($position, [self::POSITION_CENTER, self::POSITION_RIGHT, self::POSITION_LEFT]);
        
        $this->text      = $text;
        $this->position  = $position;
        $this->alternateText = $alt;
        $this->artLength = max(array_map('mb_strlen', explode("\n", $text)));
    }

    /**
     * The output text for the item
     */
    public function getRows(MenuStyle $style, bool $selected = false) : array
    {
        if ($this->artLength > $style->getContentWidth()) {
            $alternate = new StaticItem($this->alternateText);
            return $alternate->getRows($style, false);
        }

        return array_map(function ($row) use ($style) {
            $length = mb_strlen($row);

            $padding = $style->getContentWidth() - $length;

            switch ($this->position) {
                case self::POSITION_LEFT:
                    return $row;
                    break;
                case self::POSITION_RIGHT:
                    $row = rtrim($row);
                    $padding = $padding - ($this->artLength - mb_strlen($row));
                    $row = sprintf('%s%s', str_repeat(' ', $padding), $row);
                    break;
                case self::POSITION_CENTER:
                default:
                    $padding = $padding - ($this->artLength - $length);
                    $left = ceil($padding/2);
                    $right = $padding - $left;
                    $row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right));
                    break;
            }

            return $row;
        }, explode("\n", $this->text));
    }

    /**
     * Can the item be selected
     */
    public function canSelect() : bool
{'fraction_non_alphanumeric': 0.14274290283886445, 'fraction_numerical': 0.00039984006397441024, 'mean_word_length': 1.7473915431081823, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1052046', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1413, 'n_words': 314}