99namespace Inhere \Console \IO ;
1010
1111use Inhere \Console \Component \Style \Style ;
12+ use Inhere \Console \Console ;
1213use Inhere \Console \Traits \FormatOutputAwareTrait ;
1314use Inhere \Console \Util \Show ;
1415use Toolkit \Cli \Cli ;
@@ -22,14 +23,16 @@ class Output implements OutputInterface
2223 use FormatOutputAwareTrait;
2324
2425 /**
25- * 正常输出流
26- * Property outStream.
26+ * Normal output stream
27+ *
28+ * @var resource
2729 */
2830 protected $ outputStream = \STDOUT ;
2931
3032 /**
31- * 错误输出流
32- * Property errorStream.
33+ * Error output stream
34+ *
35+ * @var resource
3336 */
3437 protected $ errorStream = \STDERR ;
3538
@@ -62,25 +65,25 @@ public function __construct($outputStream = null)
6265 */
6366 public function startBuffer (): void
6467 {
65- Show ::startBuffer ();
68+ Console ::startBuffer ();
6669 }
6770
6871 /**
6972 * clear buffering
7073 */
7174 public function clearBuffer (): void
7275 {
73- Show ::clearBuffer ();
76+ Console ::clearBuffer ();
7477 }
7578
7679 /**
7780 * stop buffering and flush buffer text
7881 * {@inheritdoc}
79- * @see Show ::stopBuffer()
82+ * @see Console ::stopBuffer()
8083 */
8184 public function stopBuffer (bool $ flush = true , $ nl = false , $ quit = false , array $ opts = []): void
8285 {
83- Show ::stopBuffer ($ flush , $ nl , $ quit , $ opts );
86+ Console ::stopBuffer ($ flush , $ nl , $ quit , $ opts );
8487 }
8588
8689 /**
@@ -89,41 +92,35 @@ public function stopBuffer(bool $flush = true, $nl = false, $quit = false, array
8992 */
9093 public function flush (bool $ nl = false , $ quit = false , array $ opts = []): void
9194 {
92- $ this -> stopBuffer ( true , $ nl , $ quit , $ opts );
95+ Console:: flushBuffer ( $ nl , $ quit , $ opts );
9396 }
9497
9598 /***************************************************************************
9699 * Output Message
97100 ***************************************************************************/
98101
99102 /**
100- * 读取输入信息
103+ * Read input information
101104 * @param string $question 若不为空,则先输出文本
102105 * @param bool $nl true 会添加换行符 false 原样输出,不添加换行符
103106 * @return string
104107 */
105- public function read ($ question = null , $ nl = false ): string
108+ public function read (string $ question = '' , bool $ nl = false ): string
106109 {
107- if ($ question ) {
108- $ this ->write ($ question , $ nl );
109- }
110-
111- return \trim (\fgets (\STDIN ));
110+ return Console::read ($ question , $ nl );
112111 }
113112
114113 /**
115114 * Write a message to standard error output stream.
116115 * @param string $text
117116 * @param boolean $nl True (default) to append a new line at the end of the output string.
118- * @return $this
117+ * @return int
119118 */
120- public function stderr ($ text = '' , $ nl = true ): self
119+ public function stderr (string $ text = '' , $ nl = true ): int
121120 {
122- $ text = $ this ->getStyle ()->format ($ text );
123-
124- \fwrite ($ this ->errorStream , $ text . ($ nl ? "\n" : null ));
125-
126- return $ this ;
121+ return Console::write ($ text , $ nl , [
122+ 'steam ' => $ this ->errorStream ,
123+ ]);
127124 }
128125
129126 /***************************************************************************
0 commit comments