summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-10-22 21:46:57 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-10-22 21:46:57 +0300
commit19a846236d9bb8c68a13e5d8c27ad5aa3265356e (patch)
treef3c5db02fd6cb268595dc87ae401209b04b39506 /src
parent0322cba7799887e58f63f75e6e596d575a7d096a (diff)
memview: Make it possible to jump to offset with o
Diffstat (limited to 'src')
-rw-r--r--src/memview.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/memview.c b/src/memview.c
index 39ee94b..258779c 100644
--- a/src/memview.c
+++ b/src/memview.c
@@ -473,6 +473,51 @@ navigate(int arg)
}
}
+static const char*
+input(const char *prompt)
+{
+ static char input[255];
+ memset(input, 0, sizeof(input));
+ for (unsigned char i = 0; (size_t)i + 1 < sizeof(input); i += input[i] != 0) {
+ screen_cursor(0, ctx.term.ws.h);
+ screen_print(ESCA CLEAR_LINE);
+ screen_printf(FMT(FG YELLOW) "%s" FMT(PLAIN) " %s", prompt, input);
+ screen_flush();
+ fread(input + i, 1, 1, TERM_STREAM);
+
+ switch (input[i]) {
+ case 0x7f:
+ input[(i > 0 ? --i : 0)] = 0;
+ break;
+ case 0x04:
+ case 0x1b:
+ return NULL;
+ case '\n':
+ goto out;
+ }
+ }
+
+out:
+ return input;
+}
+
+static void
+goto_offset(int arg)
+{
+ (void)arg;
+ const char *v;
+ if (!(v = input("offset:")))
+ return;
+
+ if (v[0] == '+') {
+ ctx.hexview.offset += hexdecstrtoull(v, NULL);
+ } else if (v[0] == '-') {
+ ctx.hexview.offset -= hexdecstrtoull(v, NULL);
+ } else {
+ ctx.hexview.offset = hexdecstrtoull(v, NULL);
+ }
+}
+
static void
key_press(const struct key *key)
{
@@ -492,6 +537,7 @@ key_press(const struct key *key)
{ .seq = { 0x1b, '[', 'C' }, .fun = navigate, .arg = MOVE_RIGHT },
{ .seq = { 0x1b, '[', 'D' }, .fun = navigate, .arg = MOVE_LEFT },
{ .seq = { '^', 'I' }, .fun = next_region, .arg = 1 },
+ { .seq = { 'o' }, .fun = goto_offset },
};
for (size_t i = 0; i < ARRAY_SIZE(keys); ++i) {