Ferreteria/v0.6/clade/IO/O/View/TTY/Row

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | IO‎ | O‎ | View‎ | TTY
Jump to navigation Jump to search
clade: IO\O\View\TTY\Row
Clade Family
Row Row (none)
Clade Aliases
Alias Clade
Subpages

Code

Entire contents of file as deleted on 2026-01-26:

<?php namespace  Woozalia\Ferret\IO\O\View\TTY;
/**
 * HISTORY:
 *  2024-09-17 moved from [WF]IO\O\Screen\TTY -> [WF]IO\O\Screen\Render\TTY
 *  2024-10-20 moved from [WF]IO\O\Screen\Render\TTY -> IO\O\Render\TTY
 */

use Woozalia\Ferret\Data\Mem\QVar\cArr as QArrClass;
use Woozalia\Ferret\Data\Mem\QVar\iArr as QArrIface;
use Woozalia\Ferret\IO\O\Data\Element\Branch\grid\caRow as BaseClass;

class cRow extends BaseClass {
    // ++ CONFIG ++ //

    protected function CellClass() : string { return cCell::class; }

    // -- CONFIG -- //
    // ++ SETTINGS ++ //

    private $osWds = NULL; protected function QWidths() : QArrIface { return $this->osWds ?? ($this->osWds = new QArrClass); }

    // -- SETTINGS -- //
    // ++ OUTPUT ++ //

    /**
     * USAGE: Call RenderWidths() instead.
     * TODO: This would be more efficient if we just stored Widths in the Table.
     */
    public function Render() : string {
        $osWds = $this->QWidths();
        $this->HardAssert($osWds->HasIt(),'Column widths have not been set!');
        $arWds = $osWds->GetIt();

        $oScrn = self::Screen();

        $arCells = $this->GetCells();
        $isHdr = $this->IsHeader();  // is this a header row?
        $ftRow = "|";
        foreach ($arCells as $dxCol => $oCell) {
            $nWd = $arWds[$dxCol];
            $ftCell = $oCell->RenderWidth($nWd);
            $ftRow .= $isHdr ? ($oScrn->GreenIt($oScrn->BoldIt($ftCell))) : $ftCell;
        }
        $osWds->ZapIt();
        return $ftRow.CRLF;
    }

    /**
     * INPUT: $arWds = list of column widths (as calculated from maximum width of text found in that column)
     */
    public function RenderWidths(array $arWds) : string {
        $this->QWidths()->SetIt($arWds);
        return $this->Render();
    }

    #protected function RenderIndentation() : string { return ''; }

    // -- OUTPUT -- //
    // ++ DIAGNOSTICS ++ //

    public function DumpLine() : string {
        $sOut = '';
        $arCells = $this->GetCells();
        foreach ($arCells as $dxCol => $oCell) {
            $sVal = $oCell->DumpValue();
            $sOut .= " [$sVal]";
        }
        return $sOut;
    }

    // -- DIAGNOSTICS -- //
}