Hoa central
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
Hoa\Console\Mouse Class Reference
Inheritance diagram for Hoa\Console\Mouse:

Public Member Functions

 on ($listenerId, $callable)
 

Static Public Member Functions

static getInstance ()
 
static track ()
 
static untrack ()
 

Protected Attributes

 $_on = null
 

Static Protected Attributes

static $_instance = null
 
static $_enabled = false
 

Private Member Functions

 __construct ()
 

Detailed Description

Class .

Allow to listen the mouse.

Definition at line 49 of file Mouse.php.

Constructor & Destructor Documentation

Hoa\Console\Mouse::__construct ( )
private

Constructor.

Returns
void

Definition at line 79 of file Mouse.php.

80  {
81  $this->_on = new Core\Event\Listener($this, [
82  'mouseup',
83  'mousedown',
84  'wheelup',
85  'wheeldown',
86  ]);
87 
88  return;
89  }

Member Function Documentation

static Hoa\Console\Mouse::getInstance ( )
static

Singleton.

Returns

Definition at line 96 of file Mouse.php.

97  {
98  if (null === static::$_instance) {
99  static::$_instance = new static();
100  }
101 
102  return static::$_instance;
103  }
Hoa\Console\Mouse::on (   $listenerId,
  $callable 
)

Attach a callable to a listenable component.

Parameters
string$listenerIdListener ID.
mixed$callableCallable.
Returns
Exceptions

Implements Hoa\Core\Event\Listenable.

Definition at line 244 of file Mouse.php.

245  {
246  $this->_on->attach($listenerId, $callable);
247 
248  return $this;
249  }
static Hoa\Console\Mouse::track ( )
static

Track the mouse.

Returns
bool

Definition at line 110 of file Mouse.php.

111  {
112  if (true === static::$_enabled) {
113  return;
114  }
115 
116  static::$_enabled = true;
117 
118  echo "\033[1;2'z";
119  echo "\033[?1000h";
120  echo "\033[?1003h";
121 
122  $instance = static::getInstance();
123  $bucket = [
124  'x' => 0,
125  'y' => 0,
126  'button' => null,
127  'shift' => false,
128  'meta' => false,
129  'ctrl' => false
130  ];
131  $read = [STDIN];
132 
133  while (true) {
134  @stream_select($read, $write, $except, 30);
135 
136  $string = fread(STDIN, 1);
137 
138  if ("\033" !== $string) {
139  continue;
140  }
141 
142  $char = fread(STDIN, 1);
143 
144  if ('[' !== $char) {
145  continue;
146  }
147 
148  $char = fread(STDIN, 1);
149 
150  if ('M' !== $char) {
151  continue;
152  }
153 
154  $data = fread(STDIN, 3);
155  $cb = ord($data[0]);
156  $cx = ord($data[1]) - 32;
157  $cy = ord($data[2]) - 32;
158 
159  $bucket['x'] = $cx;
160  $bucket['y'] = $cy;
161  $bucket['shift'] = 0 !== ($cb & 4);
162  $bucket['meta'] = 0 !== ($cb & 8);
163  $bucket['ctrl'] = 0 !== ($cb & 16);
164 
165  $cb = ($cb | 28) ^ 28; // 28 = 4 | 8 | 16
166  $cb -= 32;
167 
168  switch ($cb) {
169  case 64:
170  $instance->_on->fire(
171  'wheelup',
172  new Core\Event\Bucket($bucket)
173  );
174 
175  break;
176 
177  case 65:
178  $instance->_on->fire(
179  'wheeldown',
180  new Core\Event\Bucket($bucket)
181  );
182 
183  break;
184 
185  case 3:
186  $instance->_on->fire(
187  'mouseup',
188  new Core\Event\Bucket($bucket)
189  );
190  $bucket['button'] = null;
191 
192  break;
193 
194  default:
195  if (0 === $cb) {
196  $bucket['button'] = 'left';
197  } elseif (1 === $cb) {
198  $bucket['button'] = 'middle';
199  } elseif (2 === $cb) {
200  $bucket['button'] = 'right';
201  } else {
202 
203  // hover
204  continue 2;
205  }
206 
207  $instance->_on->fire(
208  'mousedown',
209  new Core\Event\Bucket($bucket)
210  );
211  }
212  }
213 
214  return;
215  }
static getInstance()
Definition: Core.php:193

Here is the call graph for this function:

static Hoa\Console\Mouse::untrack ( )
static

Untrack the mouse.

Returns
void

Definition at line 222 of file Mouse.php.

223  {
224  if (false === static::$_enabled) {
225  return;
226  }
227 
228  echo "\033[?1003l";
229  echo "\033[?1000l";
230 
231  static::$_enabled = false;
232 
233  return;
234  }

Member Data Documentation

Hoa\Console\Mouse::$_enabled = false
staticprotected

Definition at line 63 of file Mouse.php.

Hoa\Console\Mouse::$_instance = null
staticprotected

Definition at line 56 of file Mouse.php.

Hoa\Console\Mouse::$_on = null
protected

Definition at line 70 of file Mouse.php.


The documentation for this class was generated from the following file: