Skip to content

Commit

Permalink
Merge 7e61c69 into f485c61
Browse files Browse the repository at this point in the history
  • Loading branch information
maximerenou committed Jan 4, 2019
2 parents f485c61 + 7e61c69 commit 27217ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
36 changes: 36 additions & 0 deletions src/TerminalObject/Dynamic/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,40 @@ protected function buildCheckboxes(array $options)
{
return new Checkbox\RadioGroup($options);
}

/**
* Take the appropriate action based on the input character,
* returns whether to stop listening or not
*
* @param string $char
*
* @return bool
*/
protected function handleCharacter($char)
{
switch ($char) {
case ' ':
case "\n":
$this->checkboxes->toggleCurrent();
$this->output->sameLine()->write($this->util->cursor->defaultStyle());
$this->output->sameLine()->write("\e[0m");
return true; // Break the while loop as well

case "\e":
$this->handleAnsi();
break;
}

return false;
}

/**
* Format the prompt string
*
* @return string
*/
protected function promptFormatted()
{
return $this->prompt . ' (press <Enter> to select)';
}
}
24 changes: 1 addition & 23 deletions tests/RadioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,14 @@ public function it_will_select_only_one_item()
// Confirm entry
$this->shouldReadCharAndReturn("\n");

$this->shouldWrite("\e[mCurrent mood: (use <space> to select)\e[0m");
$this->shouldWrite("\e[mCurrent mood: (press <Enter> to select)\e[0m");
$this->shouldWrite("\e[m❯ ○ Happy" . str_repeat(' ', 71) . "\e[0m");
$this->shouldWrite("\e[m ○ Sad" . str_repeat(' ', 73) . "\e[0m");
$this->shouldReceiveSameLine();
$this->shouldWrite("\e[m ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");

$this->util->system->shouldReceive('exec')->with('stty -icanon');
$this->util->system->shouldReceive('exec')->with('stty sane');
$this->shouldHideCursor();

$this->shouldReceiveSameLine();
$this->shouldWrite("\e[2A\r", 4);

$this->shouldWrite("\e[m❯ ● Happy" . str_repeat(' ', 71) . "\e[0m");
$this->shouldWrite("\e[m ○ Sad" . str_repeat(' ', 73) . "\e[0m", 3);
$this->shouldReceiveSameLine();
$this->shouldWrite("\e[m ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m", 2);

$this->shouldWrite("\e[m ● Happy" . str_repeat(' ', 71) . "\e[0m", 2);
$this->shouldWrite("\e[m❯ ○ Sad" . str_repeat(' ', 73) . "\e[0m");
$this->shouldReceiveSameLine();

$this->shouldReceiveSameLine();
$this->shouldWrite("\e[m❯ ○ Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");

$this->shouldReceiveSameLine();
$this->shouldWrite("\e[m ○ Happy" . str_repeat(' ', 71) . "\e[0m");
$this->shouldWrite("\e[m❯ ● Thrilled" . str_repeat(' ', 68) . "\e[10D\e[8m\e[0m");

$this->shouldShowCursor();

$this->shouldReceiveSameLine();
$this->shouldWrite("\e[0m");
Expand Down

0 comments on commit 27217ae

Please sign in to comment.