/** * Writes $message to $fd. * * @param string $message The message to print * @param Jm_Console_Output_TextStyle|string $style The text style * * @return Jm_Console_Output * * @throws Jm_Console_Output_Exception if fwrite fails */ public function write($message = '', $style = NULL) { if (is_null($style)) { $style = Jm_Console_TextStyle::getDefault(); } if (is_string($style)) { $style = Jm_Console_TextStyle::fromString($style); } $message = $this->colorize($message, $style); // when fd points to STDOUT we use echo instead of fwrite() // this will keep the ob_* functions working if ($this->fd === STDOUT) { echo $message; } else { $ret = @fwrite($this->fd, $message); // check for errors if ($ret === FALSE) { throw new Jm_Console_OutputException(sprintf('Failed to write at all', $message)); } else { if ($ret < strlen($message)) { $remaining = strlen($message) - $ret; throw new Jm_Console_OutputException(sprintf('Failed to write %s chars', $remaining)); } } } }