aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Aaron Gyes <me@aaron.gy>2016-06-12 11:22:31 -0700
committerGravatar Aaron Gyes <me@aaron.gy>2016-06-12 11:22:31 -0700
commit02375982df20e5cd6f27f460b3387b2a0db7d79e (patch)
tree8289ca32c857e765ac64de906216ca91b01aa1fb
parent5435f60f31e1704957c1e4abca569f807bb445fd (diff)
Hand-build 256, 24-bit color esc strings same way
... using snprintf() for the 256-color function in same manner as the 24-bit function.
-rw-r--r--src/output.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/output.cpp b/src/output.cpp
index 05238e1e..85a1eeaf 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -44,8 +44,8 @@ void output_set_writer(int (*writer)(char)) {
int (*output_get_writer())(char) { return out; }
+// Returns true if we think the term256 support is "native" as opposed to forced.
static bool term256_support_is_native(void) {
- // Return YES if we think the term256 support is "native" as opposed to forced.
return max_colors >= 256;
}
@@ -63,17 +63,13 @@ unsigned char index_for_color(rgb_color_t c) {
static bool write_color_escape(char *todo, unsigned char idx, bool is_fg) {
bool result = false;
if (idx < 16 || term256_support_is_native()) {
- // Use tparm.
+ // Use tparm to emit color escape.
writembs(tparm(todo, idx));
result = true;
} else {
// We are attempting to bypass the term here. Generate the ANSI escape sequence ourself.
- char stridx[128];
- format_long_safe(stridx, idx);
- char buff[128] = "\x1b[";
- strcat(buff, is_fg ? "38;5;" : "48;5;");
- strcat(buff, stridx);
- strcat(buff, "m");
+ char buff[128] = "";
+ snprintf(buff, sizeof buff, "\x1b[%d;5;%dm", is_fg ? 38 : 48, idx);
int (*writer)(char) = output_get_writer();
if (writer) {