Ferreteria/v0.6/clade/boot/Screen

From Woozle Writes Code
< Ferreteria‎ | v0.6‎ | clade‎ | boot
Jump to navigation Jump to search
clade: boot\Screen
Clade Family
none Screen
Clade Aliases
Alias Clade
ClassAdmin Config\Classes
ElemIface IO\O\Data\Element
Globals [cs] Config\Globals
ListIface IO\O\Data\Element\Branch\List
Styles* [c,i] Config\Styles
TableIface IO\O\Data\Element\Branch\grid\Table
Subpages

About

  • Purpose: The dynamic class-family which does the work behind the scenes of implementing the Screen API
    • ...at least, the basic stuff with no other dependencies.
  • Availability: Before the Class Loader is functional, loaders can use any of these methods which don't require external classes (layout). The top-level loader (go.php) invokes Activate[?]Mode() according to the SAPI that PHP detects.

History

  • 2024-05-27 created
  • 2024-08-13 properly(ish) set up the interface
  • 2024-12-12 copied from [WFe]loaders/Screen* to [WFe]boot/Screen* for some experimental reorganizing of the startup process
    • (Leaving originals in place for now; hopefully can remove later/soon.)
  • 2024-12-16 made Screen() public so it could be accessed from enums (because they can't descend from a class that includes it, but are probably in the same file with a class that does).

Code

interface iScreen {
    // SETUP
    static function Me() : self;
    // CURSOR
    function NewLine() : string;
    // MARKS: formatting
    function OpenFixed() : string;
    function ShutFixed() : string;
    // MARKS: graphical elements
    function HorizLine() : string;
    function LeftArrow() : string;
    function RightArrow() : string;
    // FORMATS: character
    function BoldIt(?string $s) : string;
    function ItalIt(?string $s) : string;
    function SmallIt(?string $s) : string;
    function UBarIt(?string $s) : string;
    // FORMATS: colors
    function GreenIt(string $s) : string;
    function BlueIt(string $s) : string;
    function YellowIt(string $s) : string;
    // FORMATS: styles
    function Styles() : StylesIface;
    function ErrorIt(string $s) : string;
    function WarnIt(string $s) : string;
    function FaintIt(string $s) : string;
    function TitleIt(string $s) : string;
    function InfoIt(string $s) : string;
    function XMLTagIt(string $s) : string;
    // FORMATS: hypertext
    function LinkIt(string $sText, string $sURL) : string;
    // FORMATS: block
    function BoxIt(string $s) : string;
    function FixPitchIt(string $s) : string;
    function NewLineIt(string $s) : string; // make sure "\n"s cause linebreaks
    function HideDrop(string $sSummary, string $sContent) : string;
    function NewTable() : TableIface;
    function NewList() : ListIface;

    function MakeList(string $s) : string;  // convert CRLFs to list items

    // MARKUP
    function StripMarkup(string $s) : string;
    function RenderHTML(string $ht) : string;

    // for FerretMarks
    const KS_FMT_CRLF = '<<crlf>>';
    const KS_FMT_BOLD1 = '<<+b>>';
    const KS_FMT_BOLD0 = '<<-b>>';
    const KS_FMT_ITAL1 = '<<+i>>';
    const KS_FMT_ITAL0 = '<<-i>>';
    const KS_FMT_PRE1 = '<<+pre>>';
    const KS_FMT_PRE0 = '<<-pre>>';
    const KS_FMT_SMALL1 = '<<+sm>>';
    const KS_FMT_SMALL0 = '<<-sm>>';
    function RenderMarkup(string $ft) : string;
}
abstract class caScreen implements iScreen {

    // ++ CLASSES ++ //

    abstract protected function ElementClass() : string;
    abstract protected function FallbackStyleClass() : string;

    // -- CLASSES -- //
    // ++ SETUP ++ //

    static public function ActivateTextMode() {
        require_once(__DIR__.'/Screen/Text.php');
        new Screen\cText;
    }
    static public function ActivateWebMode() {
        require_once(__DIR__.'/Screen/Web.php');
        new Screen\cWeb;
    }

    static  private   $oMe = NULL;
            public    function __construct() { self::$oMe = $this; }
    static  public    function Me() : iScreen { return self::$oMe; }
    static  private   $osMe = NULL;

    // -- SETUP -- //
    // ++ OBJECTS ++ //

    private $oStyles=NULL;
    public function Styles() : StylesIface { return $this->oStyles ?? ($this->oStyles = StylesClass::AsNew()); }

    private $oElem = NULL; public function Element() : ElemIface { return $this->oElem ?? ($this->oElem = new ($this->ElementClass())); }
    public function NewTable() : TableIface { return ($this->Element()->NewTable()); }
    public function NewList() : ListIface { return ($this->Element()->NewList()); }

    // -- OBJECTS -- //
    // ++ OUTPUT ++ //

    public function WarnIt(string $s) : string { return $this->YellowIt($s); } // DEFAULT

    public function RenderMarkup(string $ft) : string {
        $sOut = str_replace(
          [
            self::KS_FMT_CRLF,
            self::KS_FMT_BOLD1,
            self::KS_FMT_BOLD0,
            self::KS_FMT_ITAL1,
            self::KS_FMT_ITAL0,
            self::KS_FMT_PRE1,
            self::KS_FMT_PRE0,
            self::KS_FMT_SMALL1,
            self::KS_FMT_SMALL0,
            ],
          [
            NEWLINE,
            $this->MarkForBold(TRUE),
            $this->MarkForBold(FALSE),
            $this->MarkForItal(TRUE),
            $this->MarkForItal(FALSE),
            $this->OpenFixed(),
            $this->ShutFixed(),
            $this->MarkForSmall(TRUE),
            $this->MarkForSmall(FALSE),
            ],
          $ft
          );
        return $sOut;
    }

    // -- OUTPUT -- //
    // ++ INTERNAL: markup ++ //

    abstract protected function MarkForBold(bool $bOn) : string;
    abstract protected function MarkForItal(bool $bOn) : string;
    abstract protected function MarkForSmall(bool $bOn) : string;

    // -- INTERNAL -- //
}