From 53fc82ecdfc7f2b27f3f87f446418d24cbbae352 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonathan=20Schleu=C3=9Fer?= <ParadoxSpiral@riseup.net>
Date: Sat, 29 Dec 2018 17:15:18 +0100
Subject: [PATCH] Update numtoa
This now allows byte slices with lengths different than 20, so
specific lengths based on the biggest possible value for each
number can be used.
---
src/color.rs | 8 ++++----
src/cursor.rs | 10 +++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/color.rs b/src/color.rs
index b0bfcf2..1a0498d 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -125,14 +125,14 @@ impl AnsiValue {
impl AnsiValue {
/// Returns the ANSI sequence as a string.
pub fn fg_string(self) -> String {
- let mut x = [0u8; 20];
+ let mut x = [0u8; 3];
let x = self.0.numtoa_str(10, &mut x);
[csi!("38;5;"), x, "m"].concat()
}
/// Returns the ANSI sequence as a string.
pub fn bg_string(self) -> String {
- let mut x = [0u8; 20];
+ let mut x = [0u8; 3];
let x = self.0.numtoa_str(10, &mut x);
[csi!("48;5;"), x, "m"].concat()
}
@@ -157,7 +157,7 @@ pub struct Rgb(pub u8, pub u8, pub u8);
impl Rgb {
/// Returns the ANSI sequence as a string.
pub fn fg_string(self) -> String {
- let (mut x, mut y, mut z) = ([0u8; 20], [0u8; 20], [0u8; 20]);
+ let (mut x, mut y, mut z) = ([0u8; 3], [0u8; 3], [0u8; 3]);
let (x, y, z) = (
self.0.numtoa_str(10, &mut x),
self.1.numtoa_str(10, &mut y),
@@ -169,7 +169,7 @@ impl Rgb {
/// Returns the ANSI sequence as a string.
pub fn bg_string(self) -> String {
- let (mut x, mut y, mut z) = ([0u8; 20], [0u8; 20], [0u8; 20]);
+ let (mut x, mut y, mut z) = ([0u8; 3], [0u8; 3], [0u8; 3]);
let (x, y, z) = (
self.0.numtoa_str(10, &mut x),
self.1.numtoa_str(10, &mut y),
diff --git a/src/cursor.rs b/src/cursor.rs
index b6a73c8..1de3782 100644
--- a/src/cursor.rs
+++ b/src/cursor.rs
@@ -43,7 +43,7 @@ pub struct Goto(pub u16, pub u16);
impl From<Goto> for String {
fn from(this: Goto) -> String {
- let (mut x, mut y) = ([0u8; 20], [0u8; 20]);
+ let (mut x, mut y) = ([0u8; 5], [0u8; 5]);
["\x1B[", this.1.numtoa_str(10, &mut x), ";", this.0.numtoa_str(10, &mut y), "H"].concat()
}
}
@@ -67,7 +67,7 @@ pub struct Left(pub u16);
impl From<Left> for String {
fn from(this: Left) -> String {
- let mut buf = [0u8; 20];
+ let mut buf = [0u8; 5];
["\x1B[", this.0.numtoa_str(10, &mut buf), "D"].concat()
}
}
@@ -84,7 +84,7 @@ pub struct Right(pub u16);
impl From<Right> for String {
fn from(this: Right) -> String {
- let mut buf = [0u8; 20];
+ let mut buf = [0u8; 5];
["\x1B[", this.0.numtoa_str(10, &mut buf), "C"].concat()
}
}
@@ -101,7 +101,7 @@ pub struct Up(pub u16);
impl From<Up> for String {
fn from(this: Up) -> String {
- let mut buf = [0u8; 20];
+ let mut buf = [0u8; 5];
["\x1B[", this.0.numtoa_str(10, &mut buf), "A"].concat()
}
}
@@ -118,7 +118,7 @@ pub struct Down(pub u16);
impl From<Down> for String {
fn from(this: Down) -> String {
- let mut buf = [0u8; 20];
+ let mut buf = [0u8; 5];
["\x1B[", this.0.numtoa_str(10, &mut buf), "B"].concat()
}
}
--
2.44.0