diff --git a/src/ANSI.php b/src/ANSI.php index 921e7f1..e337411 100644 --- a/src/ANSI.php +++ b/src/ANSI.php @@ -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); } } \ No newline at end of file diff --git a/src/constants.php b/src/constants.php index 9c3aa34..7a78500 100644 --- a/src/constants.php +++ b/src/constants.php @@ -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); \ No newline at end of file +const KILO_VERSION = '0.3.0'; +const KILO_TAB_STOP = 4; +const KILO_QUIT_TIMES = 3;