Skip to content

Instantly share code, notes, and snippets.

@hishamhm
Created July 26, 2016 05:59
Show Gist options
  • Save hishamhm/c1b5badaf2cd03a1cdcce008d93c8606 to your computer and use it in GitHub Desktop.
Save hishamhm/c1b5badaf2cd03a1cdcce008d93c8606 to your computer and use it in GitHub Desktop.
Variation on Explorer09's graph-style-test-1 for htop
diff --git a/Meter.c b/Meter.c
index 5490028..3b7b94f 100644
--- a/Meter.c
+++ b/Meter.c
@@ -339,72 +339,38 @@ typedef struct GraphStyle_ {
// Num of bytes per multibyte character. Every character must be padded to
// this num of bytes.
char length;
- // Must be "\0\0"
- char reserved[2];
// Length of str[] should be ((pixPerRow+1)^2 * length) bytes.
char str[];
} GraphStyle;
-/*{
-typedef enum {
- GRAPHSTYLE_ASCII = 0, // Fallback default
- GRAPHSTYLE_UTF8 = 1, // UTF-8 default (braille)
- LAST_GRAPHSTYLE // Dummy & unused.
-} GraphStyleId;
-}*/
-
-static const GraphStyle GraphMeterMode_styles[] = {
- [GRAPHSTYLE_ASCII] = {
- .pixPerRow = 2,
- .length = 1,
- .reserved = "\0\0",
- .str =
- /*00*/" " /*01*/"." /*02*/":"
- /*10*/"." /*11*/"." /*12*/":"
- /*20*/":" /*21*/":" /*22*/":",
- },
+static const GraphStyle GraphStyle_ascii = {
+ .pixPerRow = 2,
+ .length = 1,
+ .str =
+ /*00*/" " /*01*/"." /*02*/":"
+ /*10*/"." /*11*/"." /*12*/":"
+ /*20*/":" /*21*/":" /*22*/":",
+};
#if HAVE_LIBNCURSESW
- [GRAPHSTYLE_UTF8] = {
- /* XXX: Can we make this 3 bytes per character? Not sure about how data
- * alignment affects performance. */
- .pixPerRow = 4,
- .length = 4,
- .reserved = "\0\0",
- .str =
- /*00 [ ] 01 [⢀] 02 [⢠] 03 [⢰] 04 [⢸]*/
- " \0\0\0" "\xe2\xa2\x80\0\xe2\xa2\xa0\0\xe2\xa2\xb0\0\xe2\xa2\xb8\0"
- /*10 [⡀] 11 [⣀] 12 [⣠] 13 [⣰] 14 [⣸]*/
- "\xe2\xa1\x80\0\xe2\xa3\x80\0\xe2\xa3\xa0\0\xe2\xa3\xb0\0\xe2\xa3\xb8\0"
- /*20 [⡄] 21 [⣄] 22 [⣤] 23 [⣴] 24 [⣼]*/
- "\xe2\xa1\x84\0\xe2\xa3\x84\0\xe2\xa3\xa4\0\xe2\xa3\xb4\0\xe2\xa3\xbc\0"
- /*30 [⡆] 31 [⣆] 32 [⣦] 33 [⣶] 34 [⣾]*/
- "\xe2\xa1\x86\0\xe2\xa3\x86\0\xe2\xa3\xa6\0\xe2\xa3\xb6\0\xe2\xa3\xbe\0"
- /*40 [⡇] 41 [⣇] 42 [⣧] 43 [⣷] 44 [⣿]*/
- "\xe2\xa1\x87\0\xe2\xa3\x87\0\xe2\xa3\xa7\0\xe2\xa3\xb7\0\xe2\xa3\xbf",
- },
-#endif // HAVE_LIBNCURSESW
-
-#if 0
- [GRAPHSTYLE_OLD] = {
- /* Pre-2.0 style perserved here for enthusiasts and also as an example.
- * Note that we avoid '*' and '~' because different fonts render these
- * characters at different heights. */
- .pixPerRow = 6,
- .length = 1,
- .reserved = "\0\0",
- .str =
- " _.-'`:"
- "_,.-'`:"
- "...-'`:"
- "----'`:"
- "'''''`:"
- "``````:"
- ":::::::",
- },
-#endif // unused
+static const GraphStyle GraphStyle_utf8 = {
+ .pixPerRow = 4,
+ .length = 4,
+ .str =
+ /*00 [ ] 01 [⢀] 02 [⢠] 03 [⢰] 04 [⢸]*/
+ " \0\0\0" "\xe2\xa2\x80\0\xe2\xa2\xa0\0\xe2\xa2\xb0\0\xe2\xa2\xb8\0"
+ /*10 [⡀] 11 [⣀] 12 [⣠] 13 [⣰] 14 [⣸]*/
+ "\xe2\xa1\x80\0\xe2\xa3\x80\0\xe2\xa3\xa0\0\xe2\xa3\xb0\0\xe2\xa3\xb8\0"
+ /*20 [⡄] 21 [⣄] 22 [⣤] 23 [⣴] 24 [⣼]*/
+ "\xe2\xa1\x84\0\xe2\xa3\x84\0\xe2\xa3\xa4\0\xe2\xa3\xb4\0\xe2\xa3\xbc\0"
+ /*30 [⡆] 31 [⣆] 32 [⣦] 33 [⣶] 34 [⣾]*/
+ "\xe2\xa1\x86\0\xe2\xa3\x86\0\xe2\xa3\xa6\0\xe2\xa3\xb6\0\xe2\xa3\xbe\0"
+ /*40 [⡇] 41 [⣇] 42 [⣧] 43 [⣷] 44 [⣿]*/
+ "\xe2\xa1\x87\0\xe2\xa3\x87\0\xe2\xa3\xa7\0\xe2\xa3\xb7\0\xe2\xa3\xbf",
};
+#endif
+
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData));
@@ -414,11 +380,11 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
const GraphStyle *graphStyle;
#ifdef HAVE_LIBNCURSESW
if (CRT_utf8) {
- graphStyle = &GraphMeterMode_styles[GRAPHSTYLE_ASCII];
+ graphStyle = &GraphStyle_utf8;
} else
#endif
{
- graphStyle = &GraphMeterMode_styles[GRAPHSTYLE_UTF8];
+ graphStyle = &GraphStyle_ascii;
}
int pixPerRow = (int) graphStyle->pixPerRow;
@@ -464,9 +430,9 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
int line2 = CLAMP(v2 - (pixPerRow * (GRAPH_HEIGHT - 1 - line)), 0, pixPerRow);
attrset(CRT_colors[colorIdx]);
- const char *str = &graphStyle->str[((int) graphStyle->length) *
+ const char *str = &graphStyle->str[graphStyle->length *
((line1 * (pixPerRow + 1) + line2))];
- mvaddnstr(y+line, x+k, str, (int) graphStyle->length);
+ mvaddnstr(y+line, x+k, str, graphStyle->length);
colorIdx = GRAPH_2;
}
}
diff --git a/Meter.h b/Meter.h
index 29d0aff..4318805 100644
--- a/Meter.h
+++ b/Meter.h
@@ -128,11 +128,8 @@ ListItem* Meter_toListItem(Meter* this, bool moving);
/* ---------- GraphMeterMode ---------- */
-typedef enum {
- GRAPHSTYLE_ASCII = 0, // Fallback default
- GRAPHSTYLE_UTF8 = 1, // UTF-8 default (braille)
- LAST_GRAPHSTYLE // Dummy & unused.
-} GraphStyleId;
+#if HAVE_LIBNCURSESW
+#endif
/* ---------- LEDMeterMode ---------- */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment