Tests for the ANSI methods
Gitea - Tutorials/php-kilo/master This commit looks good Details

This commit is contained in:
Timothy Warren 2019-12-05 14:54:00 -05:00
parent b54221ed38
commit a0e0f80223
2 changed files with 21 additions and 8 deletions

View File

@ -53,12 +53,20 @@ class ANSI {
*/
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
{
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
{
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
{
return sprintf("\e[%dS", $lines);
return self::seq('%dS', $lines);
}
/**
@ -92,6 +100,11 @@ class ANSI {
*/
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);
}
}

View File

@ -5,6 +5,6 @@ namespace Aviat\Kilo;
// -----------------------------------------------------------------------------
// ! App Constants
// -----------------------------------------------------------------------------
define('KILO_VERSION', '0.2.0');
define('KILO_TAB_STOP', 4);
define('KILO_QUIT_TIMES', 3);
const KILO_VERSION = '0.3.0';
const KILO_TAB_STOP = 4;
const KILO_QUIT_TIMES = 3;