Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / src / Psy / Readline / HoaConsole.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Readline;
13
14 use Hoa\Console\Readline\Readline as HoaReadline;
15 use Psy\Exception\BreakException;
16
17 /**
18  * Hoa\Console Readline implementation.
19  */
20 class HoaConsole implements Readline
21 {
22     /** @var HoaReadline */
23     private $hoaReadline;
24
25     /**
26      * @return bool
27      */
28     public static function isSupported()
29     {
30         return class_exists('\Hoa\Console\Console', true);
31     }
32
33     public function __construct()
34     {
35         $this->hoaReadline = new HoaReadline();
36     }
37
38     /**
39      * {@inheritdoc}
40      */
41     public function addHistory($line)
42     {
43         $this->hoaReadline->addHistory($line);
44
45         return true;
46     }
47
48     /**
49      * {@inheritdoc}
50      */
51     public function clearHistory()
52     {
53         $this->hoaReadline->clearHistory();
54
55         return true;
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     public function listHistory()
62     {
63         $i = 0;
64         $list = array();
65         while (($item = $this->hoaReadline->getHistory($i++)) !== null) {
66             $list[] = $item;
67         }
68
69         return $list;
70     }
71
72     /**
73      * {@inheritdoc}
74      */
75     public function readHistory()
76     {
77         return true;
78     }
79
80     /**
81      * {@inheritdoc}
82      *
83      * @throws BreakException if user hits Ctrl+D
84      *
85      * @return string
86      */
87     public function readline($prompt = null)
88     {
89         return $this->hoaReadline->readLine($prompt);
90     }
91
92     /**
93      * {@inheritdoc}
94      */
95     public function redisplay()
96     {
97         // noop
98     }
99
100     /**
101      * {@inheritdoc}
102      */
103     public function writeHistory()
104     {
105         return true;
106     }
107 }