Version 1
[yaffs-website] / vendor / psy / psysh / src / Psy / Readline / HoaConsole.php
diff --git a/vendor/psy/psysh/src/Psy/Readline/HoaConsole.php b/vendor/psy/psysh/src/Psy/Readline/HoaConsole.php
new file mode 100644 (file)
index 0000000..1ef7ac9
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+/*
+ * This file is part of Psy Shell.
+ *
+ * (c) 2012-2017 Justin Hileman
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Psy\Readline;
+
+use Hoa\Console\Readline\Readline as HoaReadline;
+use Psy\Exception\BreakException;
+
+/**
+ * Hoa\Console Readline implementation.
+ */
+class HoaConsole implements Readline
+{
+    /** @var HoaReadline */
+    private $hoaReadline;
+
+    /**
+     * @return bool
+     */
+    public static function isSupported()
+    {
+        return class_exists('\Hoa\Console\Console', true);
+    }
+
+    public function __construct()
+    {
+        $this->hoaReadline = new HoaReadline();
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function addHistory($line)
+    {
+        $this->hoaReadline->addHistory($line);
+
+        return true;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function clearHistory()
+    {
+        $this->hoaReadline->clearHistory();
+
+        return true;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function listHistory()
+    {
+        $i = 0;
+        $list = array();
+        while (($item = $this->hoaReadline->getHistory($i++)) !== null) {
+            $list[] = $item;
+        }
+
+        return $list;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function readHistory()
+    {
+        return true;
+    }
+
+    /**
+     * {@inheritdoc}
+     *
+     * @throws BreakException if user hits Ctrl+D
+     *
+     * @return string
+     */
+    public function readline($prompt = null)
+    {
+        return $this->hoaReadline->readLine($prompt);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function redisplay()
+    {
+        // noop
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function writeHistory()
+    {
+        return true;
+    }
+}