Gets line from file pointer

@param mixed $message
@param bool  $nl
@param array $opts
[
'stream' => \STDIN
]
@return string
323201
public static function readln($message = null, $nl = false, array $opts = []): string
    {
        if ($message) {
            self::write($message, $nl);
        }

        $opts = \array_merge([
            'length' => 1024,
            'stream' => \STDIN,
        ], $opts);

        return \trim(\fgets($opts['stream'], $opts['length']));
    }
1091173
public function write($message, $options = 0)
    {
        if ($message instanceof \Exception || (interface_exists('\Throwable') && $message instanceof \Throwable)) {
            echo $message;
            return $this;
        } elseif ($message instanceof \JsonSerializable) {
            echo json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            return $this;
        } elseif ($message instanceof \Serializable) {
            echo serialize($message);
            return $this;
        } elseif (!is_array($message)) {
            echo (string)$message;
            return $this;
        }

        if (!isset($message[0]) || !is_string($message[0])) {
            echo json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            return $this;
        }

        if (substr_count($message[0], '%') + 1 >= ($count = count($message)) && isset($message[$count - 1])) {
            foreach ((array)$message as $k => $v) {
                if ($k === 0 || is_scalar($v) || $v === null) {
                    continue;
                }

                if ($v instanceof \Exception || (interface_exists('\Throwable') && $v instanceof \Throwable)) {
                    $message[$k] = (string)$v;
                } elseif (is_array($v) || $v instanceof \JsonSerializable) {
                    $message[$k] = json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                }
            }
            /** @noinspection ArgumentUnpackingCanBeUsedInspection */
            echo call_user_func_array('sprintf', $message);

            return $this;
        }

        if (count($message) === 2) {
            if (isset($message[1]) && strpos($message[0], ':1') === false) {
                if (is_scalar($message[1])) {
                    echo json_encode($message, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                    return $this;
                } else {
                    $message[0] = rtrim($message[0], ': ') . ': :1';
                }
            }
        } elseif (count($message) === 3) {
            if (isset($message[1], $message[2]) && strpos($message[0], ':1') === false) {
                if (is_scalar($message[1]) && !is_scalar($message[2])) {
                    $message[0] = rtrim($message[0], ': ') . ': :1 => :2';
                } else {
                    echo json_encode($message, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
                    return $this;
                }
            }
        }

        if (strpos($message[0], ':') === false) {
            echo $this->colorize($message[0], $options);
        } else {
            $replaces = [];

            foreach ((array)$message as $k => $v) {
                if ($k === 0) {
                    continue;
                }

                if (is_int($v)) {
                    if (!$options && strpos($v, "\033[") === false) {
                        $v = $this->colorize($v, self::FC_GREEN);
                    }
                } elseif (is_string($v)) {
                    if (!$options && strpos($v, "\033[") === false) {
                        $v = $this->colorize($v, self::FC_CYAN);
                    }
                } elseif ($v instanceof \Exception || (interface_exists('\Throwable') && $v instanceof \Throwable)) {
                    $v = (string)$v;
                } elseif (is_array($v) || $v instanceof \JsonSerializable) {
                    $v = json_encode($v, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
                } elseif ($v instanceof \Serializable) {
                    $v = serialize($v);
                } elseif ($v === null || is_scalar($v)) {
                    $v = json_encode($v);
                } else {
                    $v = (string)$v;
                }

                $replaces[':' . $k] = $v;
            }

            echo $this->colorize(strtr($message[0], $replaces), $options);
        }

        return $this;
    }
97225
public static function message($message = null, $newLine = true)
    {
        if( ! static::enableTool() or ! $message)
            return;

        // Run
        static::$performance->message($message, $newLine);
    }
1353047
public static function ask(string $question, array $options) : string
    {
        self::out($question);
        fscanf(STDIN, '%s\n', $answer);
        if ($answer === null) {
            $answer = $options[true];
        }
        if (!in_array($answer, $options)) {
            return self::ask($question, $options);
        }
        return $answer;
    }
1361718
public function getError($error, $opts=array()) {
		if (is_array($error) && isset($error['filter'])) {
			return $this->getErrorMessage($error['filter'], $error+$opts);
		} elseif (is_int($error)) {
			return $this->getErrorMessage($error, $opts);
		} else {
			return $this->getErrorMessage(0, $opts);
		}
	}
846633
public function confirmation($message, $choices = ['y' => true, 'n' => false], $default = false)
    {
        $message = is_array($message) ? call_user_func_array('sprintf', $message) : $message;

        $answers = [];
        foreach ($choices as $answer => $value) {
            $answers[$answer] = $answer;
            if ($value === $default) $answers[$answer] = ucfirst($answer);
        }
        
        $this->send(sprintf('%s [%s]: ', $message, join('/', $answers)), '');
        $answer = $this->readline();
        if ($answer === '') return $default;

        if (array_key_exists($answer, $choices)) {
            return $choices[$answer];
        } else {
            foreach ($choices as $key => $value) {
                if ($answer === substr($key, 0, strlen($answer))) return $value;
            }
            return $default;
        }
    }
448437
public static function get ($message1, $message2 = null, $n = null)
	{
		$in = self::getInstance ();
		return $in->getText ($message1, $message2, $n);
	}
1187325
public static function getLines($filename, $reverse = false, $maxLines = null, $lineCallback = null) {
		if (file_exists ( $filename )) {
			if ($reverse && isset ( $maxLines )) {
				$result = [ ];
				$fl = fopen ( $filename, "r" );
				for($x_pos = 0, $ln = 0, $lines = [ ]; fseek ( $fl, $x_pos, SEEK_END ) !== - 1; $x_pos --) {
					$char = fgetc ( $fl );
					if ($char === "\n") {
						if (is_callable ( $lineCallback )) {
							$lineCallback ( $result, $lines [$ln] );
						} else {
							$result [] = $lines [$ln];
						}
						if (isset ( $maxLines ) && sizeof ( $result ) >= $maxLines) {
							fclose ( $fl );
							return $result;
						}
						$ln ++;
						continue;
					}
					$lines [$ln] = $char . ((array_key_exists ( $ln, $lines )) ? $lines [$ln] : '');
				}
				fclose ( $fl );
				return $result;
			} else {
				return self::getLinesByLine ( $filename, $reverse, $maxLines, $lineCallback );
			}
		}
		return [ ];
	}
698789
public function publish(array $message, array $options = [])
    {
        if (!$this->em) {
            return '';
        }

        $doctrineMessage = new DoctrineMessage();
        $doctrineMessage->setQueue($this->name)
                ->setDelivered(false)
                ->setMessage($message)
                ->setLength(strlen(serialize($message)));

        $this->em->persist($doctrineMessage);
        $this->em->flush();

        return (string) $doctrineMessage->getId();
    }
54589
public function sendMessage($message, $getResponse = true, $eol = "\r\n") {
		fputs($this->conn, $message . $eol);
		
		if (!$getResponse) return null;
		
		// read answer from server
		return $this->getResponse();
	}
208467
public function startRead($message, array $options = null) {
		return $this->startEvent($message, ProfileInterface::TYPE_READ, $options);
	}
191592
private function parseMessage($message)
    {
        if (!$message) {
            return false;
        }

        $startLine = null;
        $headers = [];
        $body = '';

        // Iterate over each line in the message, accounting for line endings
        $lines = preg_split('/(\\r?\\n)/', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
        for ($i = 0, $totalLines = count($lines); $i < $totalLines; $i += 2) {

            $line = $lines[$i];

            // If two line breaks were encountered, then this is the end of body
            if (empty($line)) {
                if ($i < $totalLines - 1) {
                    $body = implode('', array_slice($lines, $i + 2));
                }
                break;
            }

            // Parse message headers
            if (!$startLine) {
                $startLine = explode(' ', $line, 3);
            } elseif (strpos($line, ':')) {
                $parts = explode(':', $line, 2);
                $key = trim($parts[0]);
                $value = isset($parts[1]) ? trim($parts[1]) : '';
                if (!isset($headers[$key])) {
                    $headers[$key] = $value;
                } elseif (!is_array($headers[$key])) {
                    $headers[$key] = [$headers[$key], $value];
                } else {
                    $headers[$key][] = $value;
                }
            }
        }

        return [
            'start_line' => $startLine,
            'headers'    => $headers,
            'body'       => $body
        ];
    }
1038897
public function gettext($message) {
		$args = func_get_args();
		$methodArgsNumber = 1;
		$message = $this->callMethodAndSprintf(__FUNCTION__, $args, $methodArgsNumber);
		return $message;
	}
953954
public static function writeln($message, $quit = false, array $opts = []): int
    {
        return self::write($message, true, $quit, $opts);
    }
537793
public function read(array $opts) {
        $translatorevents = [];

        $feedback = parent::parseFeedback($opts);

        // Push question statements to $translatorevents['events'].
        foreach ($feedback->questions as $questionId => $questionAttempt) {
            array_push(
                $translatorevents,
                $this->questionStatement(
                    parent::read($opts)[0],
                    $questionAttempt
                )
            );
        }

        return $translatorevents;
    }
855844
public function splitMessage($message, $splitLength)
		{
			// Split up
			$messages = $this->wordwrapArray($message, $splitLength);

			// Add counter to each message
			$total = count($messages);
			if ($total > 1) {
				$count = 1;

				foreach ($messages as $key => $currMsgWrapped) {
					$messages[$key] = "$currMsgWrapped ($count/$total)";
					$count++;
				}
			}

			return $messages;
		}
257422
public static function readSafe($message = null, bool $nl = false, array $opts = []): string
    {
        if ($message) {
            self::write($message, $nl);
        }

        $opts = \array_merge([
            'length' => 1024,
            'stream' => \STDIN,
            'allowTags' => null,
        ], $opts);

        return \trim(\fgetss($opts['stream'], $opts['length'], $opts['allowTags']));
    }