Tests for the ANSI methods
All checks were successful
Gitea - Tutorials/php-kilo/master This commit looks good
All checks were successful
Gitea - Tutorials/php-kilo/master This commit looks good
This commit is contained in:
parent
b54221ed38
commit
a0e0f80223
23
src/ANSI.php
23
src/ANSI.php
@ -53,12 +53,20 @@ class ANSI {
|
|||||||
*/
|
*/
|
||||||
public static function color(int $color): string
|
public static function color(int $color): string
|
||||||
{
|
{
|
||||||
return sprintf("\e[%dm", $color);
|
return self::seq('%dm', $color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a sequence for an rgb color
|
||||||
|
*
|
||||||
|
* @param int $r
|
||||||
|
* @param int $g
|
||||||
|
* @param int $b
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public static function rgbColor(int $r, int $g, int $b): string
|
public static function rgbColor(int $r, int $g, int $b): string
|
||||||
{
|
{
|
||||||
return sprintf("\e[38;2;%d;%d;%bm", $r, $g, $b);
|
return self::seq('38;2;%d;%d;%dm', $r, $g, $b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +78,7 @@ class ANSI {
|
|||||||
*/
|
*/
|
||||||
public static function moveCursor(int $line, int $column): string
|
public static function moveCursor(int $line, int $column): string
|
||||||
{
|
{
|
||||||
return sprintf("\e[%d;%dH", $line, $column);
|
return self::seq('%d;%dH', $line, $column);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,7 +89,7 @@ class ANSI {
|
|||||||
*/
|
*/
|
||||||
public static function scrollUp(int $lines): string
|
public static function scrollUp(int $lines): string
|
||||||
{
|
{
|
||||||
return sprintf("\e[%dS", $lines);
|
return self::seq('%dS', $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +100,11 @@ class ANSI {
|
|||||||
*/
|
*/
|
||||||
public static function scrollDown(int $lines): string
|
public static function scrollDown(int $lines): string
|
||||||
{
|
{
|
||||||
return sprintf("\e[%dT", $lines);
|
return self::seq('%dT', $lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function seq(string $pattern, ...$args): string
|
||||||
|
{
|
||||||
|
return sprintf("\e[{$pattern}", ...$args);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,6 @@ namespace Aviat\Kilo;
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// ! App Constants
|
// ! App Constants
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
define('KILO_VERSION', '0.2.0');
|
const KILO_VERSION = '0.3.0';
|
||||||
define('KILO_TAB_STOP', 4);
|
const KILO_TAB_STOP = 4;
|
||||||
define('KILO_QUIT_TIMES', 3);
|
const KILO_QUIT_TIMES = 3;
|
||||||
|
Loading…
Reference in New Issue
Block a user