Add rudimentary logcat entry view
This commit is contained in:
parent
35ee4d3ff4
commit
5a31b38ef0
|
@ -14,25 +14,14 @@ static inline void write_config_and_update_structures(const Config& config) {
|
|||
}
|
||||
}
|
||||
|
||||
static inline void check_for_logcat_items(LogcatThread& logcat_thread) {
|
||||
static inline void check_for_logcat_items(LogcatThread& logcat_thread, std::vector<LogcatEntry>& filtered_logcat_entries) {
|
||||
LogcatThreadItem* logcat_thread_item;
|
||||
|
||||
while ((logcat_thread_item = logcat_thread.atomic_ring_buffer.get())) {
|
||||
if (std::holds_alternative<std::string>(*logcat_thread_item)) {
|
||||
log_raw(std::move(std::get<std::string>(*logcat_thread_item)), false);
|
||||
} else if (std::holds_alternative<LogcatEntry>(*logcat_thread_item)) {
|
||||
LogcatEntry logcat_entry = std::move(std::get<LogcatEntry>(*logcat_thread_item));
|
||||
log("Received new logcat entry");
|
||||
log(std::string(" - Buffer: ") + buffer_to(logcat_entry.buffer));
|
||||
log(std::string(" - Time: ") + std::to_string(logcat_entry.time));
|
||||
if (logcat_entry.user) {
|
||||
log(std::string(" - User: ") + *logcat_entry.user);
|
||||
}
|
||||
log(std::string(" - PID: ") + std::to_string(logcat_entry.pid));
|
||||
log(std::string(" - TID: ") + std::to_string(logcat_entry.tid));
|
||||
log(std::string(" - Priority: ") + priority_to(logcat_entry.priority));
|
||||
log(std::string(" - Tag: ") + logcat_entry.tag);
|
||||
log(std::string(" - Message: ") + logcat_entry.message);
|
||||
filtered_logcat_entries.push_back(std::move(std::get<LogcatEntry>(*logcat_thread_item)));
|
||||
} else {
|
||||
throw std::runtime_error("Cannot handle all possible logcat thread item variants");
|
||||
}
|
||||
|
@ -114,7 +103,8 @@ static inline void logs_window(ImFont* monospace_font, bool* autoscrolling, bool
|
|||
ImGui::End();
|
||||
}
|
||||
|
||||
static inline void main_window(bool latest_log_entries_read, bool* show_settings_window, bool* show_logs_window, bool* run_event_loop) {
|
||||
static inline void main_window(bool latest_log_entries_read, ImFont* monospace_font, std::vector<LogcatEntry>& filtered_logcat_entries,
|
||||
bool* show_settings_window, bool* show_logs_window, bool* run_event_loop) {
|
||||
if (!ImGui::Begin("LogMeow", run_event_loop)) {
|
||||
ImGui::End();
|
||||
return;
|
||||
|
@ -137,6 +127,46 @@ static inline void main_window(bool latest_log_entries_read, bool* show_settings
|
|||
ImGui::PopStyleColor(3);
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
// copied from imgui/imgui_demo.cpp: [SECTION] Example App: Debug Console / ShowExampleAppConsole()
|
||||
// and [SECTION] Example App: Long Text / ShowExampleAppLongText()
|
||||
// and [SECTION] Example App: Debug Log / ShowExampleAppLog()
|
||||
if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||
ImGui::PushFont(monospace_font);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
|
||||
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin(static_cast<int>(filtered_logcat_entries.size()));
|
||||
while (clipper.Step()) {
|
||||
for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||
LogcatEntry* logcat_entry = &filtered_logcat_entries[static_cast<size_t>(i)];
|
||||
char time_as_str[128] = {0};
|
||||
strftime(time_as_str, 127 * sizeof(char), "%c", localtime(&logcat_entry->time));
|
||||
|
||||
std::string header = std::string(1, '[') + time_as_str + " ";
|
||||
header += logcat_entry->user.value_or(" ") + " ";
|
||||
header += std::to_string(logcat_entry->pid) + " ";
|
||||
header += std::to_string(logcat_entry->tid) + " ";
|
||||
header += std::string(buffer_to(logcat_entry->buffer)) + " ";
|
||||
header += std::string(priority_to(logcat_entry->priority)) + "] ";
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]);
|
||||
ImGui::TextUnformatted(header.data(), &header[header.size()]);
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
std::string line = logcat_entry->tag + ": " + logcat_entry->message;
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(line.data(), &line[line.size()]);
|
||||
}
|
||||
}
|
||||
clipper.End();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopFont();
|
||||
if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
}
|
||||
}
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
@ -193,8 +223,9 @@ void event_loop(ImFont* monospace_font, Config& config, float* config_write_time
|
|||
static bool show_settings_window = false;
|
||||
static bool show_logs_window = false;
|
||||
static size_t log_entries_read = 0;
|
||||
static std::vector<LogcatEntry> filtered_logcat_entries;
|
||||
|
||||
check_for_logcat_items(logcat_thread);
|
||||
check_for_logcat_items(logcat_thread, filtered_logcat_entries);
|
||||
|
||||
#ifndef NDEBUG
|
||||
debug_window(logcat_thread);
|
||||
|
@ -219,5 +250,5 @@ void event_loop(ImFont* monospace_font, Config& config, float* config_write_time
|
|||
}
|
||||
|
||||
// log_entries must not be mutated until the show logs button
|
||||
main_window(log_entries_read == log_entries.size(), &show_settings_window, &show_logs_window, run_event_loop);
|
||||
main_window(log_entries_read == log_entries.size(), monospace_font, filtered_logcat_entries, &show_settings_window, &show_logs_window, run_event_loop);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue