src/ANSI/EscapeSequenceGenerator.php
public function generateSequence(TerminalState $state, $reset) {

        // this will return null if there are no active styles
        $sequence = "";

        // build an array of the currently active style codes
        $styles = [];
        if ($state->isBold())          {$styles[] = self::BOLD;}
        if ($state->isUnderscore())    {$styles[] = self::UNDERSCORE;}
        if ($state->getTextColor()->isValid())     {$styles[] = $state->getTextColor()->generateColorCoding($this->mode);}
        if ($state->getFillColor()->isValid())     {$styles[] = $state->getFillColor()->generateColorCoding($this->mode, true);}

        // if there is anything in the style array
        if (count($styles)) {

            // start the sequence with the control sequence introducer and a clear code
            $sequence = self::CSI;
            
            // if a reset was desired
            if ($reset) {
                
                // add the clear code
                $sequence .= self::CLEAR . ";";
            } 

            // go through the array of style codes
            for ($i = 0; $i < count($styles); ++$i) {

                // append the code
                $sequence .= $styles[$i];

                // ensure this is not the last code
                if ($i < (count($styles) - 1)) {

                    // add the semi-colon separator (but not after the last one)
                    $sequence .= ";";

                }
            }

            // append the closing sequence
            $sequence .= self::CSE;

        } else {

            // if nothing is changing, only need to send something if the reset was requested
            if ($reset) {
                
                // it may be that just one thing is turning off, send the clear code
                $sequence .= self::generateClearSequence();  
                
            }

        }

        return $sequence;
    }
public function generateSequence(TerminalState $state, $reset) {

        // this will return null if there are no active styles
        $sequence = "";

        // build an array of the currently active style codes
        $styles = [];
        if ($state->isBold())          {$styles[] = self::BOLD;}
        if ($state->isUnderscore())    {$styles[] = self::UNDERSCORE;}
        if ($state->getTextColor()->isValid())     {$styles[] = $state->getTextColor()->generateColorCoding($this->mode);}
        if ($state->getFillColor()->isValid())     {$styles[] = $state->getFillColor()->generateColorCoding($this->mode, true);}

        // if there is anything in the style array
        if (count($styles)) {

            // start the sequence with the control sequence introducer and a clear code
            $sequence = self::CSI;
            
            // if a reset was desired
            if ($reset) {
                
                // add the clear code
                $sequence .= self::CLEAR . ";";
            } 

            // go through the array of style codes
            for ($i = 0; $i < count($styles); ++$i) {

                // append the code
                $sequence .= $styles[$i];

                // ensure this is not the last code
                if ($i < (count($styles) - 1)) {

                    // add the semi-colon separator (but not after the last one)
                    $sequence .= ";";

                }
            }

            // append the closing sequence
            $sequence .= self::CSE;

        } else {

            // if nothing is changing, only need to send something if the reset was requested
            if ($reset) {
                
                // it may be that just one thing is turning off, send the clear code
                $sequence .= self::generateClearSequence();  
                
            }

        }

        return $sequence;
    }
public function generateSequence ( TerminalState $ state , $ reset ) { // this will return null if there are no active styles $ sequence = "" ; // build an array of the currently active style codes $ styles = [ ] ; if ( $ state -> isBold ( ) ) { $ styles [ ] = self :: BOLD ; } if ( $ state -> isUnderscore ( ) ) { $ styles [ ] = self :: UNDERSCORE ; } if ( $ state -> getTextColor ( ) -> isValid ( ) ) { $ styles [ ] = $ state -> getTextColor ( ) -> generateColorCoding ( $ this -> mode ) ; } if ( $ state -> getFillColor ( ) -> isValid ( ) ) { $ styles [ ] = $ state -> getFillColor ( ) -> generateColorCoding ( $ this -> mode , true ) ; } // if there is anything in the style array if ( count ( $ styles ) ) { // start the sequence with the control sequence introducer and a clear code $ sequence = self :: CSI ; // if a reset was desired if ( $ reset ) { // add the clear code $ sequence .= self :: CLEAR . ";" ; } // go through the array of style codes for ( $ i = 0 ; $ i < count ( $ styles ) ; ++ $ i ) { // append the code $ sequence .= $ styles [ $ i ] ; // ensure this is not the last code if ( $ i < ( count ( $ styles ) - 1 ) ) { // add the semi-colon separator (but not after the last one) $ sequence .= ";" ; } } // append the closing sequence $ sequence .= self :: CSE ; } else { // if nothing is changing, only need to send something if the reset was requested if ( $ reset ) { // it may be that just one thing is turning off, send the clear code $ sequence .= self :: generateClearSequence ( ) ; } } return $ sequence ; }
Generate the escape sequencing for a particular state

@param TerminalState $state - the state to achieve
@param boolean $reset - whether the zero reset code needs to start this sequence
@return string
Generate the escape sequencing for a particular state