src/Synapse/CliCommand/CliCommandExecutor.php
protected function parseOutput($output)
    {
        $lines = explode("\n", $output);

        // This is the escape sequence that kills the stuff on the line, then
        // adds new text to it. The fake lines are separated by CRs instead of
        // NLs. You can thank whoever invented Bash for that
        $escapeStr = "\x1b\x5b\x4b";

        $actualLines = array();
        foreach ($lines as $line) {
            if (stripos($line, $escapeStr) !== false) {
                // Explode on the CR and take the last item, as that is the
                // actual line we want to show
                $parts = explode("\r", $line);

                $actualLine = array_pop($parts);

                // Remove the escape sequence
                $actualLines[] = str_replace($escapeStr, '', $actualLine);
            } else {
                $actualLines[] = $line;
            }
        }

        return trim(implode("\n", $actualLines));
    }
protected function parseOutput($output)
    {
        $lines = explode("\n", $output);

        // This is the escape sequence that kills the stuff on the line, then
        // adds new text to it. The fake lines are separated by CRs instead of
        // NLs. You can thank whoever invented Bash for that
        $escapeStr = "\x1b\x5b\x4b";

        $actualLines = array();
        foreach ($lines as $line) {
            if (stripos($line, $escapeStr) !== false) {
                // Explode on the CR and take the last item, as that is the
                // actual line we want to show
                $parts = explode("\r", $line);

                $actualLine = array_pop($parts);

                // Remove the escape sequence
                $actualLines[] = str_replace($escapeStr, '', $actualLine);
            } else {
                $actualLines[] = $line;
            }
        }

        return trim(implode("\n", $actualLines));
    }
protected function parseOutput ( $ output ) { $ lines = explode ( "\n" , $ output ) ; // This is the escape sequence that kills the stuff on the line, then // adds new text to it. The fake lines are separated by CRs instead of // NLs. You can thank whoever invented Bash for that $ escapeStr = "\x1b\x5b\x4b" ; $ actualLines = array ( ) ; foreach ( $ lines as $ line ) { if ( stripos ( $ line , $ escapeStr ) !== false ) { // Explode on the CR and take the last item, as that is the // actual line we want to show $ parts = explode ( "\r" , $ line ) ; $ actualLine = array_pop ( $ parts ) ; // Remove the escape sequence $ actualLines [ ] = str_replace ( $ escapeStr , '' , $ actualLine ) ; } else { $ actualLines [ ] = $ line ; } } return trim ( implode ( "\n" , $ actualLines ) ) ; }
Parses output from shell into usable string

@param  string $output the output from a shell commmand
@return string         the actual lines of output
Parses output from shell into usable string