tell the view range in render_term.cpp

This commit is contained in:
silverweed 2024-08-16 10:10:18 +02:00
parent 73a67d0a9f
commit a529719ffd

View file

@ -70,14 +70,16 @@ String8_Node *render_legend_to_string(Arena *arena, const Term_Viewer &viewer, c
} }
internal internal
String8_Node *render_info_to_string(Arena *arena, const App_State &app, String8_Node *prev) String8_Node *render_info_to_string(Arena *arena, Byte_Range range, const App_State &app, String8_Node *prev)
{ {
String8_Node *res = push_str8_node(arena, prev, String8_Node *res = push_str8_node(arena, prev,
"\n" "\n"
" Displaying: 0x%lX - 0x%lX / 0x%lX\n"
" ROOT version: %u.%u.%u\n" " ROOT version: %u.%u.%u\n"
" TFile compression: %u\n" " TFile compression: %u\n"
" Num pages: %lu\n" " Num pages: %lu\n"
" Num elements: %lu\n", " Num elements: %lu\n",
range.start, range.end(), app.inspected_file.size,
app.tfile_data.root_version_major, app.tfile_data.root_version_minor, app.tfile_data.root_version_patch, app.tfile_data.root_version_major, app.tfile_data.root_version_minor, app.tfile_data.root_version_patch,
app.tfile_data.compression, app.tfile_data.compression,
app.rndata.n_pages, app.rndata.n_pages,
@ -93,10 +95,13 @@ String8_Node *render_info_to_string(Arena *arena, const App_State &app, String8_
} }
internal internal
String8 render_range_bytes_to_string(Arena *arena, Arena *scratch_arena, App_State &app, Term_Viewer &viewer, u64 len, u64 n_cols) String8 render_range_bytes_to_string(Arena *arena, Arena *scratch_arena, App_State &app, Term_Viewer &viewer, Byte_Range range, u64 n_cols)
{ {
if (n_cols == 0) if (n_cols == 0)
n_cols = 32; n_cols = 32;
u64 start = range.start;
u64 len = range.len;
u64 n_lines = len / n_cols; u64 n_lines = len / n_cols;
u64 max_addr = app.inspected_file.size; u64 max_addr = app.inspected_file.size;
@ -119,8 +124,6 @@ String8 render_range_bytes_to_string(Arena *arena, Arena *scratch_arena, App_Sta
char *buf = arena_push_array_nozero<char>(arena, buf_size); char *buf = arena_push_array_nozero<char>(arena, buf_size);
buf[len] = 0; buf[len] = 0;
u64 start = app.base_display_addr;
// We need to properly initialize this before calling mem_edit_bg_color_fn! // We need to properly initialize this before calling mem_edit_bg_color_fn!
app.last_pinfo = &invalid_pinfo; app.last_pinfo = &invalid_pinfo;
@ -185,16 +188,17 @@ String8_Node *render_range_to_string(Arena *arena, App_State &app, u64 len, u64
String8_Node *result = push_str8_node(arena, nullptr, "RNTuple '%s' (%s) from file \"%s\"\n", String8_Node *result = push_str8_node(arena, nullptr, "RNTuple '%s' (%s) from file \"%s\"\n",
app.ntpl_name.c(), ntpl_desc.c(), app.inspected_file.name.c()); app.ntpl_name.c(), ntpl_desc.c(), app.inspected_file.name.c());
String8_Node *result_tail = result; String8_Node *result_tail = result;
// Bytes view // Bytes view
String8_Node *bytes_view = arena_push<String8_Node>(arena); String8_Node *bytes_view = arena_push<String8_Node>(arena);
bytes_view->str = render_range_bytes_to_string(arena, scratch.arena, app, viewer, len, n_cols); Byte_Range range = { app.base_display_addr, min(app.inspected_file.size - app.base_display_addr, len) };
bytes_view->str = render_range_bytes_to_string(arena, scratch.arena, app, viewer, range, n_cols);
result_tail->next = bytes_view; result_tail->next = bytes_view;
result_tail = bytes_view; result_tail = bytes_view;
// Footer // Footer
result_tail = render_legend_to_string(arena, viewer, app, result_tail); result_tail = render_legend_to_string(arena, viewer, app, result_tail);
result_tail = render_info_to_string(arena, app, result_tail); result_tail = render_info_to_string(arena, range, app, result_tail);
return result; return result;
} }