diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-05 10:26:19 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-05 10:26:19 -0500 |
commit | 665238f5318bee40f254fe43aa158e61bdd25392 (patch) | |
tree | 19d2c6828a6263ec3b2b9ee44363774ecdaaca5c /src/attrs.rs | |
parent | b24d69d51b3567f75630bb1b3a6875dac6e1c647 (diff) | |
download | vt100-rust-665238f5318bee40f254fe43aa158e61bdd25392.tar.gz vt100-rust-665238f5318bee40f254fe43aa158e61bdd25392.zip |
contents_formatted should return a Vec<u8>
the overall terminal escape sequence byte stream is not necessarily
utf8-safe, even if individual cell contents are
Diffstat (limited to 'src/attrs.rs')
-rw-r--r-- | src/attrs.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/attrs.rs b/src/attrs.rs index f1b59a6..95a5e76 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -87,11 +87,11 @@ impl Attrs { } } - pub fn escape_code_diff(&self, other: &Self) -> String { + pub fn escape_code_diff(&self, other: &Self) -> Vec<u8> { let mut opts = vec![]; if self != other && self == &Self::default() { - return "\x1b[m".to_string(); + return b"\x1b[m".to_vec(); } if self.fgcolor != other.fgcolor { @@ -159,8 +159,17 @@ impl Attrs { opts.push(if self.inverse() { 7 } else { 27 }); } - let strs: Vec<_> = - opts.iter().map(std::string::ToString::to_string).collect(); - format!("\x1b[{}m", strs.join(";")) + let mut bytes = b"\x1b[".to_vec(); + let mut first = true; + for opt in opts { + if first { + first = false; + } else { + bytes.push(b';'); + } + bytes.extend(opt.to_string().as_bytes()); + } + bytes.push(b'm'); + bytes } } |