Пример #1
0
 /**
  * Asks the question
  *
  * @return array
  */
 public function ask()
 {
     $this->drawer->open();
     $phkey = new Detector();
     $listener = $phkey->getListenerInstance();
     $event = $listener->getEventDispatcher();
     $event->addListener('key:up', function () {
         $this->cursor->moveUp(count($this->choices));
         $this->draw();
     });
     $event->addListener('key:down', function () {
         $this->cursor->moveDown(count($this->choices));
         $this->draw();
     });
     $event->addListener('key:space', function () {
         $this->selectChoice();
         $this->draw();
     });
     $event->addListener('key:enter', function () use($event) {
         $event->dispatch('key:stop:listening');
         $this->drawer->closeWindow();
     });
     $this->draw();
     $listener->start();
     return $this->getAnswers();
 }
Пример #2
0
 public function testPositionChange()
 {
     $steps = mt_rand(1, 10);
     $cursor = new Cursor();
     $cursor->moveDown($steps);
     $this->assertEquals(1, $cursor->getPosition());
     $cursor->moveUp($steps);
     $this->assertEquals(0, $cursor->getPosition());
     $cursor->moveUp($steps);
     $this->assertEquals($steps - 1, $cursor->getPosition());
 }