php-kilo/src/Enum/KeyType.php

49 lines
1.0 KiB
PHP
Raw Normal View History

2019-10-24 16:57:27 -04:00
<?php declare(strict_types=1);
2019-11-08 16:27:08 -05:00
namespace Aviat\Kilo\Enum;
2019-10-24 16:57:27 -04:00
2019-11-19 15:57:51 -05:00
use Aviat\Kilo\Traits;
2020-02-05 14:50:31 -05:00
use function Aviat\Kilo\ctrl_key;
2019-11-19 15:57:51 -05:00
2020-02-05 14:50:31 -05:00
/**
* Constants representing various control keys
*/
class KeyType {
2019-11-19 15:57:51 -05:00
use Traits\ConstList;
2019-11-19 13:48:12 -05:00
2019-10-24 16:57:27 -04:00
public const ARROW_DOWN = 'ARROW_DOWN';
public const ARROW_LEFT = 'ARROW_LEFT';
public const ARROW_RIGHT = 'ARROW_RIGHT';
public const ARROW_UP = 'ARROW_UP';
public const BACKSPACE = 'BACKSPACE';
public const DEL_KEY = 'DELETE';
public const END_KEY = 'END';
public const ENTER = 'ENTER';
public const ESCAPE = 'ESCAPE';
public const HOME_KEY = 'HOME';
public const PAGE_DOWN = 'PAGE_DOWN';
public const PAGE_UP = 'PAGE_UP';
2020-02-05 14:50:31 -05:00
/**
* Returns the ascii character for the specified
* ctrl + letter combo
*
* @param string $char
* @return string
*/
public static function CTRL(string $char): ?string
{
$char = strtolower($char);
$ord = ord($char);
// a = 0x61
// z = 0x7a
if ($ord >= 0x61 && $ord <= 0x7a)
{
return chr(ctrl_key($char));
}
// Invalid input, not an ascii letter
return NULL;
}
2019-10-24 16:57:27 -04:00
}