Ferreteria/v0.6/clade/IO/O/View/TTY/Cell
Jump to navigation
Jump to search
|
The item documented here has been removed and is no longer in use.
|
| ||||||||||||
Code
Entire contents of file, as removed 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\cInt as QIntClass;
use Woozalia\Ferret\Data\Mem\QVar\iInt as QIntIface;
#
use Woozalia\Ferret\IO\O\Data\attr\eAlign as AlignEnum;
use Woozalia\Ferret\IO\O\Data\Element\Text\caCell as LayoutClass;
class cCell extends LayoutClass {
// ++ SETTINGS ++ //
private $osWid = NULL; protected function QWidth() : QIntIface { return $this->osWds ?? ($this->osWds = new QIntClass); }
// -- SETTINGS -- //
// ++ OUTPUT ++ //
public function Render() : string {
$osWid = $this->QWidth();
$this->HardAssert($osWid->HasIt(),'Cell width has not been set!');
$nWidth = $osWid->GetIt();
$sVal = $this->SText();
if ($sVal !== '') {
$nLength = $this->VisibleLength();
$eAlign = $this->GetAlign();
$nPad = $nWidth - $nLength;
switch ($eAlign) {
case AlignEnum::Left:
$ftCell = $sVal.str_repeat(' ',$nPad);
break;
case AlignEnum::Center:
$nPadL = floor($nPad/2);
$nPadR = $nPad-$nPadL;
$ftCell = str_repeat(' ',$nPadL).$sVal.str_repeat(' ',$nPadR);
break;
case AlignEnum::Right:
$ftCell = str_repeat(' ',$nPad).$sVal;
break;
}
} else {
$ftCell = '';
// FUTURE: could be a special format for empty cells
}
$osWid->ZapIt();
return " $ftCell |";
}
/**
* NEW
* OUTPUT: rendering of the cell, with proper alignment
*/
public function RenderWidth(int $nWidth) : string {
$this->QWidth()->SetIt($nWidth);
return $this->Render();
}
// -- OUTPUT -- //
// ++ CALC ++ //
/**
* NEW
* RETURNS: the width in characters of what appears on the screen
* This requires doing a character-count that excludes escape sequences.
*/
private $nViz = NULL;
public function VisibleLength() : int {
$nViz = $this->nViz;
if (is_null($nViz)) {
$oScrn = self::Screen();
$sVal = $this->SText();
$nViz = $oScrn->VisibleLength($sVal);
$this->nViz = $nViz;
}
return $nViz;
}
// -- CALC -- //
// ++ DIAGNOSTICS ++ //
public function DumpValue() : string { return $this->QValue()->GetItNz(); }
// -- DIAGNOSTICS -- //
}