Table-ify logcat
This commit is contained in:
parent
18551db53a
commit
fbf717db33
|
@ -6,47 +6,53 @@
|
||||||
#include "../logcat_entry.h"
|
#include "../logcat_entry.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
static std::string leftpad(std::string str, size_t characters) {
|
static inline void render_table(ImFont* monospace_font, std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets) {
|
||||||
if (str.size() < characters) {
|
|
||||||
return str.insert(0, characters - str.size(), ' ');
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void main_scrolling_region(ImFont* monospace_font, std::vector<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets) {
|
|
||||||
ImGui::PushFont(monospace_font);
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||||
|
|
||||||
|
ImGui::TableSetupScrollFreeze(0, 1);
|
||||||
|
ImGui::TableSetupColumn("Time", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("User", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("PID", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("TID", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("Buffer", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("Priority", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("Tag", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_None);
|
||||||
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
|
ImGui::PushFont(monospace_font);
|
||||||
|
|
||||||
ImGuiListClipper clipper;
|
ImGuiListClipper clipper;
|
||||||
clipper.Begin(static_cast<int>(filtered_logcat_entry_offsets.size()));
|
clipper.Begin(static_cast<int>(filtered_logcat_entry_offsets.size()));
|
||||||
while (clipper.Step()) {
|
while (clipper.Step()) {
|
||||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||||
LogcatEntry* logcat_entry = &logcat_entries[filtered_logcat_entry_offsets[static_cast<size_t>(i)]];
|
const LogcatEntry* logcat_entry = &logcat_entries[filtered_logcat_entry_offsets[static_cast<size_t>(i)]];
|
||||||
char time_as_str[128] = {0};
|
char time_as_str[128] = {0};
|
||||||
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&logcat_entry->time));
|
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&logcat_entry->time));
|
||||||
|
|
||||||
std::string header = std::string(1, '[') + time_as_str + ' '
|
ImGui::TableNextRow();
|
||||||
+ leftpad(logcat_entry->user.value_or(" "), 5) + ' '
|
ImGui::TableSetColumnIndex(0); ImGui::TextUnformatted(time_as_str);
|
||||||
+ leftpad(std::to_string(logcat_entry->pid), 5) + ' '
|
if (logcat_entry->user) {
|
||||||
+ leftpad(std::to_string(logcat_entry->tid), 5) + ' '
|
ImGui::TableSetColumnIndex(1);
|
||||||
+ leftpad(buffer_to(logcat_entry->buffer), 6) + ' '
|
ImGui::TextUnformatted(logcat_entry->user->data(), &logcat_entry->user->data()[logcat_entry->user->size()]);
|
||||||
+ leftpad(priority_to(logcat_entry->priority), 7) + "] ";
|
}
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
|
ImGui::TableSetColumnIndex(2); ImGui::Text("%zu", logcat_entry->pid);
|
||||||
ImGui::TextUnformatted(header.data(), &header[header.size()]);
|
ImGui::TableSetColumnIndex(3); ImGui::Text("%zu", logcat_entry->tid);
|
||||||
ImGui::PopStyleColor();
|
ImGui::TableSetColumnIndex(4); ImGui::TextUnformatted(buffer_to(logcat_entry->buffer));
|
||||||
|
ImGui::TableSetColumnIndex(5); ImGui::TextUnformatted(priority_to(logcat_entry->priority));
|
||||||
std::string line = logcat_entry->tag + ": " + logcat_entry->message;
|
ImGui::TableSetColumnIndex(6); ImGui::TextUnformatted(logcat_entry->tag.data(), &logcat_entry->tag.data()[logcat_entry->tag.size()]);
|
||||||
ImGui::SameLine();
|
ImGui::TableSetColumnIndex(7); ImGui::TextUnformatted(logcat_entry->message.data(), &logcat_entry->message.data()[logcat_entry->message.size()]);
|
||||||
ImGui::TextUnformatted(line.data(), &line[line.size()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clipper.End();
|
clipper.End();
|
||||||
|
|
||||||
ImGui::PopStyleVar();
|
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
ImGui::PopStyleVar();
|
||||||
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
|
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
|
||||||
ImGui::SetScrollHereY(1.0f);
|
ImGui::SetScrollHereY(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_window(bool latest_log_entries_read, ImFont* monospace_font,
|
void main_window(bool latest_log_entries_read, ImFont* monospace_font,
|
||||||
|
@ -87,9 +93,10 @@ void main_window(bool latest_log_entries_read, ImFont* monospace_font,
|
||||||
// copied from imgui/imgui_demo.cpp: [SECTION] Example App: Debug Console / ShowExampleAppConsole()
|
// copied from imgui/imgui_demo.cpp: [SECTION] Example App: Debug Console / ShowExampleAppConsole()
|
||||||
// and [SECTION] Example App: Long Text / ShowExampleAppLongText()
|
// and [SECTION] Example App: Long Text / ShowExampleAppLongText()
|
||||||
// and [SECTION] Example App: Debug Log / ShowExampleAppLog()
|
// and [SECTION] Example App: Debug Log / ShowExampleAppLog()
|
||||||
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) {
|
// and Tables/Vertical scrolling, with clipping
|
||||||
main_scrolling_region(monospace_font, logcat_entries, filtered_logcat_entry_offsets);
|
const constexpr ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_ScrollX | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
|
||||||
|
if (ImGui::BeginTable("logcat", 8, flags)) {
|
||||||
|
render_table(monospace_font, logcat_entries, filtered_logcat_entry_offsets);
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue