public function findChanges(TerminalStateInterface $desired) {
        
        // create a Terminal State object that will hold the changes needed to achieve the desired state
        $ret = new self();
        
        // bold is currently off, and the desired is to turn it on
        if (!$this->isBold() && $desired->isBold()) {
            
            // turn bold on the changes
            $ret->setBold(true);

        // bold is going from on to off, the only way to do that is through an overall clear
        } else if ($this->isBold() && !$desired->isBold()) {

            // a clear is needed, so no new changed object is needed, all of desired will be used
            return null;

        }

        // underscore is currently off, and the desired is to turn it on
        if (!$this->isUnderscore() && $desired->isUnderscore()) {

            // turn bold on the changes
            $ret->setUnderscore(true);

        // the underscore is going from on to off
        }  else if ($this->isUnderscore() && !$desired->isUnderscore()) {

            // a clear is needed
            return null;

        }
        
        // shortcuts to the current and desired text color
        $currentTextColor = $this->getTextColor();
        $desiredTextColor = $desired->getTextColor();
        
        // if there is no text color and one is desired
        if (!$currentTextColor->isValid() && $desiredTextColor->isValid()) {
            
            // set the text color
            $ret->setTextColor($desiredTextColor);
            
        // The text color is getting turned off
        } else if ($currentTextColor->isValid() && !$desiredTextColor->isValid()) {

            // a clear is needed
            return null;

        // both are valid colors
        } else if ($currentTextColor->isValid() && $desiredTextColor->isValid()) {
            
            // if the two colors are different
            if ($currentTextColor != $desiredTextColor) {
                
                // set the text color
                $ret->setTextColor($desiredTextColor);
                
            }
        }

        // shortcuts to the current and desired fill colors
        $currentFillColor = $this->getFillColor();
        $desiredFillColor = $desired->getFillColor();

        // if there is no text color and one is desired
        if (!$currentFillColor->isValid() && $desiredFillColor->isValid()) {

            // set the text color
            $ret->setFillColor($desiredFillColor);

            // both are valid    
        } else if ($currentFillColor->isValid() && !$desiredFillColor->isValid()) {

            // a clear is needed
            return null;

        } else if ($currentFillColor->isValid() && $desiredFillColor->isValid()) {

            // if the two colors are different
            if ($currentFillColor != $desiredFillColor) {

                // set the text color
                $ret->setFillColor($desiredFillColor);

            }
        }

        // we got here, so no clear was needed, return the object with the changed properties
        return $ret;
        
    }
public function findChanges(TerminalStateInterface $desired) {
        
        // create a Terminal State object that will hold the changes needed to achieve the desired state
        $ret = new self();
        
        // bold is currently off, and the desired is to turn it on
        if (!$this->isBold() && $desired->isBold()) {
            
            // turn bold on the changes
            $ret->setBold(true);

        // bold is going from on to off, the only way to do that is through an overall clear
        } else if ($this->isBold() && !$desired->isBold()) {

            // a clear is needed, so no new changed object is needed, all of desired will be used
            return null;

        }

        // underscore is currently off, and the desired is to turn it on
        if (!$this->isUnderscore() && $desired->isUnderscore()) {

            // turn bold on the changes
            $ret->setUnderscore(true);

        // the underscore is going from on to off
        }  else if ($this->isUnderscore() && !$desired->isUnderscore()) {

            // a clear is needed
            return null;

        }
        
        // shortcuts to the current and desired text color
        $currentTextColor = $this->getTextColor();
        $desiredTextColor = $desired->getTextColor();
        
        // if there is no text color and one is desired
        if (!$currentTextColor->isValid() && $desiredTextColor->isValid()) {
            
            // set the text color
            $ret->setTextColor($desiredTextColor);
            
        // The text color is getting turned off
        } else if ($currentTextColor->isValid() && !$desiredTextColor->isValid()) {

            // a clear is needed
            return null;

        // both are valid colors
        } else if ($currentTextColor->isValid() && $desiredTextColor->isValid()) {
            
            // if the two colors are different
            if ($currentTextColor != $desiredTextColor) {
                
                // set the text color
                $ret->setTextColor($desiredTextColor);
                
            }
        }

        // shortcuts to the current and desired fill colors
        $currentFillColor = $this->getFillColor();
        $desiredFillColor = $desired->getFillColor();

        // if there is no text color and one is desired
        if (!$currentFillColor->isValid() && $desiredFillColor->isValid()) {

            // set the text color
            $ret->setFillColor($desiredFillColor);

            // both are valid    
        } else if ($currentFillColor->isValid() && !$desiredFillColor->isValid()) {

            // a clear is needed
            return null;

        } else if ($currentFillColor->isValid() && $desiredFillColor->isValid()) {

            // if the two colors are different
            if ($currentFillColor != $desiredFillColor) {

                // set the text color
                $ret->setFillColor($desiredFillColor);

            }
        }

        // we got here, so no clear was needed, return the object with the changed properties
        return $ret;
        
    }
public function findChanges ( TerminalStateInterface $ desired ) { // create a Terminal State object that will hold the changes needed to achieve the desired state $ ret = new self ( ) ; // bold is currently off, and the desired is to turn it on if ( ! $ this -> isBold ( ) && $ desired -> isBold ( ) ) { // turn bold on the changes $ ret -> setBold ( true ) ; // bold is going from on to off, the only way to do that is through an overall clear } else if ( $ this -> isBold ( ) && ! $ desired -> isBold ( ) ) { // a clear is needed, so no new changed object is needed, all of desired will be used return null ; } // underscore is currently off, and the desired is to turn it on if ( ! $ this -> isUnderscore ( ) && $ desired -> isUnderscore ( ) ) { // turn bold on the changes $ ret -> setUnderscore ( true ) ; // the underscore is going from on to off } else if ( $ this -> isUnderscore ( ) && ! $ desired -> isUnderscore ( ) ) { // a clear is needed return null ; } // shortcuts to the current and desired text color $ currentTextColor = $ this -> getTextColor ( ) ; $ desiredTextColor = $ desired -> getTextColor ( ) ; // if there is no text color and one is desired if ( ! $ currentTextColor -> isValid ( ) && $ desiredTextColor -> isValid ( ) ) { // set the text color $ ret -> setTextColor ( $ desiredTextColor ) ; // The text color is getting turned off } else if ( $ currentTextColor -> isValid ( ) && ! $ desiredTextColor -> isValid ( ) ) { // a clear is needed return null ; // both are valid colors } else if ( $ currentTextColor -> isValid ( ) && $ desiredTextColor -> isValid ( ) ) { // if the two colors are different if ( $ currentTextColor != $ desiredTextColor ) { // set the text color $ ret -> setTextColor ( $ desiredTextColor ) ; } } // shortcuts to the current and desired fill colors $ currentFillColor = $ this -> getFillColor ( ) ; $ desiredFillColor = $ desired -> getFillColor ( ) ; // if there is no text color and one is desired if ( ! $ currentFillColor -> isValid ( ) && $ desiredFillColor -> isValid ( ) ) { // set the text color $ ret -> setFillColor ( $ desiredFillColor ) ; // both are valid     } else if ( $ currentFillColor -> isValid ( ) && ! $ desiredFillColor -> isValid ( ) ) { // a clear is needed return null ; } else if ( $ currentFillColor -> isValid ( ) && $ desiredFillColor -> isValid ( ) ) { // if the two colors are different if ( $ currentFillColor != $ desiredFillColor ) { // set the text color $ ret -> setFillColor ( $ desiredFillColor ) ; } } // we got here, so no clear was needed, return the object with the changed properties return $ ret ; }
Compare the desired state and capture any things that are going from off to on, if something is going
from on to off, then a clear needs to be sent along with all the desired state, in this case
this function returns null

@param TerminalStateInterface $desired
@return null | TerminalState - returns null if a clear is needed and the entire desired sequence needs to be created
otherwise it returns a TerminalState object that contains only the properties that are changing
between the actual and desired
Compare the desired state and capture any things that are going from off to on if something is going from on to off then a clear needs to be sent along with all the desired state in this case this function returns null