aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-08 20:47:22 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-08 20:47:22 -0700
commit64659a1566d866b484b4768a870e22a7e83a3db8 (patch)
tree0597480ca7c8cffc706363f9b54b42b1f39fe885 /utils.h
parent9453ac360afedb9da323008e816ff238426d4d16 (diff)
Some cool debug viz stuff
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index 96c6de2..58cfdc4 100644
--- a/utils.h
+++ b/utils.h
@@ -6,6 +6,8 @@
#define check(cond, ...) do { if (!(cond)) { fprintf(stderr, __VA_ARGS__); fwrite("\n", 1, 1, stderr); _exit(1); } } while(0)
#define debug(...) do { if (verbose) fprintf(stderr, __VA_ARGS__); } while(0)
+static int visualize_delay = -1;
+
/*
* Helper function to skip past all spaces (and comments)
* Returns a pointer to the first non-space character.
@@ -37,3 +39,16 @@ static inline int matchchar(const char **str, char c)
return 0;
}
}
+
+static void visualize(const char *source, const char *ptr, const char *msg)
+{
+ if (visualize_delay < 0) return;
+ fprintf(stderr, "\033[0;1m\r\033[2A\033[K%.*s\033[0;2m%s\033[0m\n",
+ (int)(ptr-source), source, ptr);
+ fprintf(stderr, "\033[0;1m");
+ for (--ptr ; ptr > source; --ptr) putc(' ', stderr);
+ fprintf(stderr, "^\033[K\n");
+ if (msg)
+ fprintf(stderr, "\033[K\033[33;1m%s\033[0m", msg);
+ usleep(visualize_delay);
+}