diff --git a/src/render.cpp b/src/render.cpp index a69566c..93ea1a3 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -424,14 +424,14 @@ Ansi_Color viewer_to_ansi_color(const Viewer &viewer, const Term_Viewer &tviewer if (col == imcol(viewer.col_page_start)) return tviewer.col_page_start; if (col == imcol(viewer.col_checksum)) return tviewer.col_checksum; if (col == imcol(viewer.col_highlight)) return tviewer.col_highlight; - for (u64 section = 0; section < Sec_COUNT; ++section) + for (u64 section = 1; section < Sec_COUNT; ++section) if (col == imcol(viewer.col_section[section])) return tviewer.col_section[section]; return ACol_None; } internal -String8 render_legend_to_string(Arena *arena, const Term_Viewer &viewer) +String8 render_legend_to_string(Arena *arena, const Term_Viewer &viewer, const App_State &app) { Temp scratch = scratch_begin(&arena, 1); defer { scratch_end(scratch); }; @@ -441,12 +441,24 @@ String8 render_legend_to_string(Arena *arena, const Term_Viewer &viewer) String8 str; } *head = nullptr, *tail = nullptr; - u64 tot_len = 0; - for (u64 section = 0; section < Sec_COUNT; ++section) { + String8 color_none = ansi_color_table[ACol_None]; + u64 tot_len = 0; + for (u64 section = 1; section < Sec_COUNT; ++section) { Ansi_Color color = viewer.col_section[section]; String8 color_str = ansi_color_table[color]; String8 sec_name = section_names[section]; - String8 s = push_str8f(scratch.arena, "%s%s ", color_str.c(), sec_name.c()); + Byte_Range range = get_section_range(app, static_cast(section)); + String8 s; + if (range.len) + s = push_str8f(scratch.arena, "%s%20s %s0x%lX - 0x%lX [%lu B]\n", + color_str.c(), sec_name.c(), color_none.c(), + range.start, range.end(), range.len); + else if (section == Sec_Page) + s = push_str8f(scratch.arena, "%s%20s %s(%lu) [%lu B] \n", + color_str.c(), sec_name.c(), color_none.c(), app.rndata.n_pages, app.rndata.tot_page_size); + else if (section == Sec_Page_List) + s = push_str8f(scratch.arena, "%s%20s %s(%lu) [%lu B]\n", + color_str.c(), sec_name.c(), color_none.c(), app.rndata.n_cluster_groups, app.rndata.tot_page_list_size); String8_Node *node = arena_push(scratch.arena); node->str = s; if (!tail) { @@ -475,12 +487,23 @@ String8 render_range_to_string(Arena *arena, App_State &app, u64 len, u64 n_cols { Term_Viewer viewer = make_term_viewer(n_cols); - String8 legend = render_legend_to_string(arena, viewer); + String8 legend = render_legend_to_string(arena, viewer, app); + // scratch must be created after `render_legend_to_string` + Temp scratch = scratch_begin(&arena, 1); + defer { scratch_end(scratch); }; + + String8 ntpl_desc = rntuple_description(scratch.arena, app.rndata); + String8 header_str = push_str8f(scratch.arena, "RNTuple '%s' (%s) from file \"%s\"", + app.ntpl_name.c(), ntpl_desc.c(), app.inspected_file.name.c()); + // NOTE: +3 because we need 2 chars for each byte + 1 whitespace. u64 buf_size = (ACOL_MAX_LEN + 3) * len; u64 n_newlines = len / viewer.max_cols; buf_size += n_newlines; + buf_size += 1; // initial newline + buf_size += header_str.size; + buf_size += 2; // two newlines buf_size += 2; // two newlines buf_size += legend.size; buf_size += 1; // trailing zero @@ -497,10 +520,15 @@ String8 render_range_to_string(Arena *arena, App_State &app, u64 len, u64 n_cols assert(start <= max_addr); len = min(len, max_addr - start); - Temp scratch = scratch_begin(&arena, 1); - defer { scratch_end(scratch); }; - u8 *cur = buf; + *cur++ = '\n'; + + // header + memcpy(cur, header_str.str, header_str.size); + cur += header_str.size; + *cur++ = '\n'; + *cur++ = '\n'; + for (u64 i = 0; i < len; ++i) { u64 off = start + i; diff --git a/src/rntviewer.cpp b/src/rntviewer.cpp index 9d77290..f604c20 100644 --- a/src/rntviewer.cpp +++ b/src/rntviewer.cpp @@ -28,6 +28,9 @@ #define GLFW_INCLUDE_NONE #include +#define V_MAJOR "0" +#define V_MINOR "1" + #include "root/root_inc.h" #include "root/RMicroFileReader.hxx" @@ -79,8 +82,9 @@ internal void print_help(const char *argv0) { fprintf(stderr, - "Usage: %s [-t] [-s START] [-l LEN] [-w WIDTH] " + "rntviewer v" V_MAJOR "." V_MINOR " by silverweed" "\n" + "\nUsage: %s [-t] [-s START] [-l LEN] [-w WIDTH] " "\n\t-t: no graphics, output to terminal" "\n\t-s: set first displayed byte to START" "\n\t-l: display LEN bytes (only in terminal mode)"