public function __construct() { // 讓 STDIN 只讀取一個字元就輸出 system("stty -icanon time 1"); // STDIN 沒東西就略過 stream_set_blocking(STDIN, 0); self::$sleep = self::$sleep_standard; }
private function captureKeyStroke() { $c = fread(STDIN, 1); if (in_array($c, ['='])) { $this->increaseSleep(); } elseif (in_array($c, ['-'])) { $this->decreaseSleep(); } elseif (in_array($c, ['q'])) { exit; } elseif (in_array($c, ['1'])) { $this->increaseNewRowProperty(); } elseif (in_array($c, ['2'])) { $this->decreaseNewRowProperty(); } elseif (in_array($c, ['z'])) { $this->increaseEmptyRowProperty(); } elseif (in_array($c, ['x'])) { $this->decreaseEmptyRowProperty(); } elseif (in_array($c, ['a'])) { $this->increaseMinRainLength(); } elseif (in_array($c, ['s'])) { $this->decreaseMinRainLength(); } elseif (in_array($c, ['c'])) { self::$color_style = (self::$color_style + 1) % count(Pixel::$color_256); } }