improve legend
This commit is contained in:
parent
79787d6c2d
commit
5d9acf702c
2 changed files with 42 additions and 10 deletions
|
@ -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_page_start)) return tviewer.col_page_start;
|
||||||
if (col == imcol(viewer.col_checksum)) return tviewer.col_checksum;
|
if (col == imcol(viewer.col_checksum)) return tviewer.col_checksum;
|
||||||
if (col == imcol(viewer.col_highlight)) return tviewer.col_highlight;
|
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]))
|
if (col == imcol(viewer.col_section[section]))
|
||||||
return tviewer.col_section[section];
|
return tviewer.col_section[section];
|
||||||
return ACol_None;
|
return ACol_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal
|
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);
|
Temp scratch = scratch_begin(&arena, 1);
|
||||||
defer { scratch_end(scratch); };
|
defer { scratch_end(scratch); };
|
||||||
|
@ -441,12 +441,24 @@ String8 render_legend_to_string(Arena *arena, const Term_Viewer &viewer)
|
||||||
String8 str;
|
String8 str;
|
||||||
} *head = nullptr, *tail = nullptr;
|
} *head = nullptr, *tail = nullptr;
|
||||||
|
|
||||||
|
String8 color_none = ansi_color_table[ACol_None];
|
||||||
u64 tot_len = 0;
|
u64 tot_len = 0;
|
||||||
for (u64 section = 0; section < Sec_COUNT; ++section) {
|
for (u64 section = 1; section < Sec_COUNT; ++section) {
|
||||||
Ansi_Color color = viewer.col_section[section];
|
Ansi_Color color = viewer.col_section[section];
|
||||||
String8 color_str = ansi_color_table[color];
|
String8 color_str = ansi_color_table[color];
|
||||||
String8 sec_name = section_names[section];
|
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_Id>(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<String8_Node>(scratch.arena);
|
String8_Node *node = arena_push<String8_Node>(scratch.arena);
|
||||||
node->str = s;
|
node->str = s;
|
||||||
if (!tail) {
|
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);
|
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.
|
// NOTE: +3 because we need 2 chars for each byte + 1 whitespace.
|
||||||
u64 buf_size = (ACOL_MAX_LEN + 3) * len;
|
u64 buf_size = (ACOL_MAX_LEN + 3) * len;
|
||||||
u64 n_newlines = len / viewer.max_cols;
|
u64 n_newlines = len / viewer.max_cols;
|
||||||
buf_size += n_newlines;
|
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 += 2; // two newlines
|
||||||
buf_size += legend.size;
|
buf_size += legend.size;
|
||||||
buf_size += 1; // trailing zero
|
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);
|
assert(start <= max_addr);
|
||||||
len = min(len, max_addr - start);
|
len = min(len, max_addr - start);
|
||||||
|
|
||||||
Temp scratch = scratch_begin(&arena, 1);
|
|
||||||
defer { scratch_end(scratch); };
|
|
||||||
|
|
||||||
u8 *cur = buf;
|
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) {
|
for (u64 i = 0; i < len; ++i) {
|
||||||
u64 off = start + i;
|
u64 off = start + i;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
#define GLFW_INCLUDE_NONE
|
#define GLFW_INCLUDE_NONE
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#define V_MAJOR "0"
|
||||||
|
#define V_MINOR "1"
|
||||||
|
|
||||||
#include "root/root_inc.h"
|
#include "root/root_inc.h"
|
||||||
#include "root/RMicroFileReader.hxx"
|
#include "root/RMicroFileReader.hxx"
|
||||||
|
|
||||||
|
@ -79,8 +82,9 @@ internal
|
||||||
void print_help(const char *argv0)
|
void print_help(const char *argv0)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s [-t] [-s START] [-l LEN] [-w WIDTH] <ntuple_name> <ntuple_file.root>"
|
"rntviewer v" V_MAJOR "." V_MINOR " by silverweed"
|
||||||
"\n"
|
"\n"
|
||||||
|
"\nUsage: %s [-t] [-s START] [-l LEN] [-w WIDTH] <ntuple_name> <ntuple_file.root>"
|
||||||
"\n\t-t: no graphics, output to terminal"
|
"\n\t-t: no graphics, output to terminal"
|
||||||
"\n\t-s: set first displayed byte to START"
|
"\n\t-s: set first displayed byte to START"
|
||||||
"\n\t-l: display LEN bytes (only in terminal mode)"
|
"\n\t-l: display LEN bytes (only in terminal mode)"
|
||||||
|
|
Loading…
Reference in a new issue