Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Write tests #58

Merged
merged 22 commits into from
Nov 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
de466b7
Console: Ensure `STDIN` is defined before using it.
Hywan Oct 26, 2015
6e605a7
Console: Add the `setTput` static method.
Hywan Oct 26, 2015
7ed67a2
Test: Write test suite for `Hoa\Console`.
Hywan Oct 26, 2015
9d5ac13
Test: Write test suite for `Hoa\Console\Parser`.
Hywan Oct 26, 2015
001b415
Test: Write test suite for `Hoa\Console\Tput`.
Hywan Oct 26, 2015
651aab9
Test: Write test suite for `Hoa\Console\Cursor`.
Hywan Oct 26, 2015
a134d4e
Window: The constructor must be private.
Hywan Oct 27, 2015
c93d576
Test: Write test suite for `Hoa\Console\Window`.
Hywan Oct 27, 2015
bc62391
Mouse: New constants representing pointer codes.
Hywan Oct 28, 2015
a5bd983
Mouse: Untrack when tracking fails.
Hywan Oct 28, 2015
0419f78
Test: Write test suite for `Hoa\Console\Mouse`.
Hywan Oct 28, 2015
3082bd3
CS: Clean namespaces and fix some styles.
Hywan Oct 28, 2015
a0e4bc1
GetOption: Reset the `$optionValue` all the time.
Hywan Oct 29, 2015
00033a1
Test: Write test suite for `Hoa\Console\GetOption`.
Hywan Oct 29, 2015
73d8c5c
Readline: Use `Console::getInput`.
Hywan Oct 29, 2015
6eb8f33
Test: Write test suite for `…Autocompleter\Word`.
Hywan Oct 29, 2015
31a08c9
Test: Write test suite for `…Autocompleter\Path`.
Hywan Oct 29, 2015
1d795bb
Terminfo: Add the `xterm-256color` database.
Hywan Oct 29, 2015
073fdbb
Test: Use `beforeTestMethod` instead of `setUp`.
Hywan Oct 29, 2015
e01a6bc
Test: Write test suite for `…e\Readline\Password`.
Hywan Oct 29, 2015
af6e9ea
Test: Write test suite for `…completer\Aggregate`.
Hywan Nov 10, 2015
0e9a4cf
Test: Add specificity for Windows.
Hywan Nov 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
namespace Hoa\Console;

use Hoa\Core;
use Hoa\Stream;

/**
* Class \Hoa\Console.
Expand Down Expand Up @@ -165,7 +164,9 @@ public static function advancedInteraction($force = false)
return self::$_advanced = false;
}

if (false === $force && false === self::isDirect(STDIN)) {
if (false === $force &&
true === defined('STDIN') &&
false === self::isDirect(STDIN)) {
return self::$_advanced = false;
}

Expand Down Expand Up @@ -370,6 +371,20 @@ public static function getOutput()
return static::$_output;
}

/**
* Set tput.
*
* @param \Hoa\Console\Tput $tput Tput.
* @return \Hoa\Console\Tput
*/
public static function setTput(Tput $tput)
{
$old = static::$_tput;
static::$_tput = $tput;

return $old;
}

/**
* Get the current tput instance of the current process.
*
Expand Down
5 changes: 3 additions & 2 deletions GetOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ public function getOption(&$optionValue, $short = null)
{
static $first = true;

$optionValue = null;

if (true === $this->isPipetteEmpty() && true === $first) {
$first = false;
$optionValue = null;
$first = false;

return false;
}
Expand Down
60 changes: 53 additions & 7 deletions Mouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,48 @@
*/
class Mouse implements Core\Event\Listenable
{
/**
* Pointer code for left button.
*
* @const int
*/
const BUTTON_LEFT = 0;

/**
* Pointer code for the middle button.
*
* @const int
*/
const BUTTON_MIDDLE = 1;

/**
* Pointer code for the right button.
*
* @const int
*/
const BUTTON_RIGHT = 2;

/**
* Pointer code for the release of the button.
*
* @const int
*/
const BUTTON_RELEASE = 3;

/**
* Pointer code for the wheel up.
*
* @const int
*/
const WHEEL_UP = 64;

/**
* Pointer code for the wheel down.
*
* @const int
*/
const WHEEL_DOWN = 65;

/**
* Singleton.
*
Expand Down Expand Up @@ -134,7 +176,11 @@ public static function track()
$read = [$input->getStream()->getStream()];

while (true) {
@stream_select($read, $write, $except, 30);
if (false === @stream_select($read, $write, $except, 30)) {
static::untrack();

break;
}

$string = $input->readCharacter();

Expand Down Expand Up @@ -169,23 +215,23 @@ public static function track()
$cb -= 32;

switch ($cb) {
case 64:
case static::WHEEL_UP:
$instance->_on->fire(
'wheelup',
new Core\Event\Bucket($bucket)
);

break;

case 65:
case static::WHEEL_DOWN:
$instance->_on->fire(
'wheeldown',
new Core\Event\Bucket($bucket)
);

break;

case 3:
case static::BUTTON_RELEASE:
$instance->_on->fire(
'mouseup',
new Core\Event\Bucket($bucket)
Expand All @@ -195,11 +241,11 @@ public static function track()
break;

default:
if (0 === $cb) {
if (static::BUTTON_LEFT === $cb) {
$bucket['button'] = 'left';
} elseif (1 === $cb) {
} elseif (static::BUTTON_MIDDLE === $cb) {
$bucket['button'] = 'middle';
} elseif (2 === $cb) {
} elseif (static::BUTTON_RIGHT === $cb) {
$bucket['button'] = 'right';
} else {
// hover
Expand Down
3 changes: 1 addition & 2 deletions Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

namespace Hoa\Console;

use Hoa\File;
use Hoa\Stream;

/**
Expand Down Expand Up @@ -251,4 +250,4 @@ public function isMultiplexerConsidered()
{
return $this->_considerMultiplexer;
}
}
}
2 changes: 1 addition & 1 deletion Readline/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* Class \Hoa\Console\Readline\Password.
*
* Read, edit, bind… a password from STDIN.
* Read, edit, bind… a password from the input.
*
* @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
Expand Down
25 changes: 14 additions & 11 deletions Readline/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/**
* Class \Hoa\Console\Readline.
*
* Read, edit, bind… a line from STDIN.
* Read, edit, bind… a line from the input.
*
* @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
Expand Down Expand Up @@ -172,22 +172,24 @@ public function __construct()
}

/**
* Read a line from STDIN.
* Read a line from the input.
*
* @param string $prefix Prefix.
* @return string
*/
public function readLine($prefix = null)
{
if (feof(STDIN)) {
$input = Console::getInput();

if (true === $input->eof()) {
return false;
}

$direct = Console::isDirect(STDIN);
$direct = Console::isDirect($input->getStream()->getStream());
$output = Console::getOutput();

if (false === $direct || OS_WIN) {
$out = fgets(STDIN);
$out = $input->readLine();

if (false === $out) {
return false;
Expand All @@ -206,14 +208,14 @@ public function readLine($prefix = null)

$this->resetLine();
$this->setPrefix($prefix);
$read = [STDIN];
$read = [$input->getStream()->getStream()];
$output->writeAll($prefix);

while (true) {
@stream_select($read, $write, $except, 30, 0);

if (empty($read)) {
$read = [STDIN];
$read = [$input->getStream()->getStream()];

continue;
}
Expand Down Expand Up @@ -536,14 +538,14 @@ public function getAutocompleter()
}

/**
* Read on STDIN. Not for user.
* Read on input. Not for user.
*
* @param int $length Length.
* @return string
*/
public function _read($length = 512)
{
return fread(STDIN, $length);
return Console::getInput()->read($length);
}

/**
Expand Down Expand Up @@ -991,7 +993,8 @@ public function _bindTab(Readline $self)
Console\Cursor::show();

++$mColumns;
$read = [STDIN];
$input = Console::getInput();
$read = [$input->getStream()->getStream()];
$mColumn = -1;
$mLine = -1;
$coord = -1;
Expand Down Expand Up @@ -1051,7 +1054,7 @@ public function _bindTab(Readline $self)
@stream_select($read, $write, $except, 30, 0);

if (empty($read)) {
$read = [STDIN];
$read = [$input->getStream()->getStream()];

continue;
}
Expand Down
Binary file added Terminfo/78/xterm-256color
Binary file not shown.
Loading