aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2017-01-23 22:45:13 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2017-01-23 22:45:13 +0100
commitfccfd1dd3b3e256db8759cfd6dba7cf6c3952e37 (patch)
tree011097892e2e03277e33bff533d57c3a5b4a9604
parent95be2d94d752b20d3d57c1006af8d518a6c1b843 (diff)
downloadhex-fccfd1dd3b3e256db8759cfd6dba7cf6c3952e37.tar.gz
hex-fccfd1dd3b3e256db8759cfd6dba7cf6c3952e37.tar.xz
hex-fccfd1dd3b3e256db8759cfd6dba7cf6c3952e37.zip
Color the ASCII column instead
-rw-r--r--hex.c25
-rw-r--r--tui.c14
2 files changed, 28 insertions, 11 deletions
diff --git a/hex.c b/hex.c
index 1c28ae6..6756d8a 100644
--- a/hex.c
+++ b/hex.c
@@ -544,9 +544,9 @@ app_make_row (struct row_buffer *buf, int64_t addr, int attrs)
row_buffer_append (buf, row_addr_str, attrs);
free (row_addr_str);
- struct str ascii;
- str_init (&ascii);
- str_append (&ascii, " ");
+ struct row_buffer ascii;
+ row_buffer_init (&ascii);
+ row_buffer_append (&ascii, " ", attrs);
int64_t end_addr = g_ctx.data_offset + g_ctx.data_len;
for (int x = 0; x < ROW_SIZE; x++)
@@ -559,29 +559,32 @@ app_make_row (struct row_buffer *buf, int64_t addr, int attrs)
|| cell_addr >= end_addr)
{
row_buffer_append (buf, " ", attrs);
- str_append_c (&ascii, ' ');
+ row_buffer_append (&ascii, " ", attrs);
}
else
{
- int cell_attrs = attrs;
+ int attrs_mark = attrs;
struct marks_by_offset *marks = app_marks_at_offset (cell_addr);
if (marks && marks->color >= 0)
- cell_attrs = g_ctx.attrs[marks->color].attrs;
+ attrs_mark = g_ctx.attrs[marks->color].attrs;
+ int highlight = 0;
if (cell_addr >= g_ctx.view_cursor
&& cell_addr < g_ctx.view_cursor + 8)
- cell_attrs |= A_UNDERLINE;
+ highlight = A_UNDERLINE;
+ // TODO: leave it up to the user to decide what should be colored
uint8_t cell = g_ctx.data[cell_addr - g_ctx.data_offset];
char *hex = xstrdup_printf ("%02x", cell);
- row_buffer_append (buf, hex, cell_attrs);
+ row_buffer_append (buf, hex, attrs | highlight);
free (hex);
- str_append_c (&ascii, (cell >= 32 && cell < 127) ? cell : '.');
+ char s[2] = { (cell >= 32 && cell < 127) ? cell : '.', 0 };
+ row_buffer_append (&ascii, s, attrs_mark | highlight);
}
}
- row_buffer_append (buf, ascii.str, attrs);
- str_free (&ascii);
+ row_buffer_append_buffer (buf, &ascii);
+ row_buffer_free (&ascii);
}
static void
diff --git a/tui.c b/tui.c
index 726ec57..d313bcb 100644
--- a/tui.c
+++ b/tui.c
@@ -154,6 +154,20 @@ row_buffer_append_args (struct row_buffer *self, const char *s, ...)
va_end (ap);
}
+static void
+row_buffer_append_buffer (struct row_buffer *self, const struct row_buffer *rb)
+{
+ while (self->chars_alloc - self->chars_len < rb->chars_len)
+ self->chars = xreallocarray (self->chars,
+ sizeof *self->chars, (self->chars_alloc <<= 1));
+
+ memcpy (self->chars + self->chars_len, rb->chars,
+ rb->chars_len * sizeof *rb->chars);
+
+ self->chars_len += rb->chars_len;
+ self->total_width += rb->total_width;
+}
+
/// Pop as many codepoints as needed to free up "space" character cells.
/// Given the suffix nature of combining marks, this should work pretty fine.
static int