From 895678b0339c647e4f3047f3cede5522ed2c3bb9 Mon Sep 17 00:00:00 2001 From: "Franc[e]sco" Date: Mon, 22 Jan 2018 19:08:32 +0100 Subject: [PATCH] cli: add optional utf-8 graph --- main.c | 23 +++++++++++++++++++---- oppai.c | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 359a7c9..3f97653 100644 --- a/main.c +++ b/main.c @@ -187,14 +187,30 @@ internalfn void asciiplt(float (* getvalue)(void* data, size_t i), size_t n, void* data) { - static char const* charset = " _.-^"; + static char const* charset[] = { +#ifdef OPPAI_UTF8GRAPH + "\xe2\x96\x81", + "\xe2\x96\x82", + "\xe2\x96\x83", + "\xe2\x96\x84", + "\xe2\x96\x85", + "\xe2\x96\x86", + "\xe2\x96\x87", + "\xe2\x96\x88" +#else + " ", "_", ".", "-", "^" +#endif + }; + + static size_t const charsetsize = + sizeof(charset) / sizeof(charset[0]); + float values[ASCIIPLT_W]; float minval = get_inf(); float maxval = -get_inf(); float range; size_t i; size_t chunksize; - size_t charsetsize; size_t w = mymin(ASCIIPLT_W, n); memset(values, 0, sizeof(values)); @@ -217,7 +233,6 @@ void asciiplt(float (* getvalue)(void* data, size_t i), size_t n, } range = mymax(0.00001, maxval - minval); - charsetsize = strlen(charset); for (i = 0; i < w; ++i) { @@ -225,7 +240,7 @@ void asciiplt(float (* getvalue)(void* data, size_t i), size_t n, ((values[i] - minval) / range) * charsetsize ); chari = mymax(0, mymin(chari, charsetsize - 1)); - printf("%c", charset[chari]); + printf("%s", charset[chari]); } puts(""); diff --git a/oppai.c b/oppai.c index f750092..a1b74ca 100644 --- a/oppai.c +++ b/oppai.c @@ -51,7 +51,7 @@ #define OPPAI_VERSION_MAJOR 1 #define OPPAI_VERSION_MINOR 1 -#define OPPAI_VERSION_PATCH 43 +#define OPPAI_VERSION_PATCH 44 /* if your compiler doesn't have stdint, define this */ #ifdef OPPAI_NOSTDINT