From a6572fb085853b65910dd8eb5906be2d9568ff68 Mon Sep 17 00:00:00 2001 From: blankie Date: Tue, 7 Mar 2023 18:02:18 +0700 Subject: [PATCH] Add buttons to add test logcat entries --- event_loop.cpp | 2 +- windows/debug.cpp | 37 ++++++++++++++++++++++++++++++++++++- windows/debug.h | 7 ++++++- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/event_loop.cpp b/event_loop.cpp index d7afd66..18d9518 100644 --- a/event_loop.cpp +++ b/event_loop.cpp @@ -43,7 +43,7 @@ void event_loop(ImFont* monospace_font, Config& active_config, LogcatThread& log check_for_logcat_items(logcat_thread, active_config, logcat_entries, filtered_logcat_entry_offsets); #ifndef NDEBUG - debug_window(logcat_thread); + debug_window(logcat_thread, active_config, logcat_entries, filtered_logcat_entry_offsets); #endif if (show_settings_window) { diff --git a/windows/debug.cpp b/windows/debug.cpp index 2f0dcf8..238c95d 100644 --- a/windows/debug.cpp +++ b/windows/debug.cpp @@ -2,10 +2,14 @@ #include "../myimconfig.h" #include "../log.h" +#include "../config.h" +#include "../filters.h" +#include "../logcat_entry.h" #include "../logcat_thread.h" #include "debug.h" -void debug_window(LogcatThread& logcat_thread) { +void debug_window(LogcatThread& logcat_thread, const Config& active_config, + std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets) { static bool show_demo_window = false; static size_t add_log_entry_presses = 1; static bool log_entry_every_second = false; @@ -49,5 +53,36 @@ void debug_window(LogcatThread& logcat_thread) { } } + ImGui::Separator(); + auto add_logcat_entry = [&](LogcatEntry logcat_entry) { + logcat_entries.push_back(std::move(logcat_entry)); + if (matches(logcat_entries.back(), active_config.filters, active_config.exclusions)) { + filtered_logcat_entry_offsets.push_back(logcat_entries.size() - 1); + } + }; + if (ImGui::Button("Add test entry (w/ user)")) { + add_logcat_entry({ + .buffer = Buffer::Main, + .time = time(nullptr), + .user = "blankie", + .pid = 69, + .tid = 420, + .priority = Priority::Error, + .tag = "blanket, inc.", + .message = "Failed to make blanket", + }); + } + if (ImGui::Button("Add test entry (w/o user)")) { + add_logcat_entry({ + .buffer = Buffer::Crash, + .time = time(nullptr), + .pid = 420, + .tid = 69, + .priority = Priority::Fatal, + .tag = "blanket, inc.", + .message = "Failed to invent blankets", + }); + } + ImGui::End(); } diff --git a/windows/debug.h b/windows/debug.h index d73e390..5e5ce92 100644 --- a/windows/debug.h +++ b/windows/debug.h @@ -1,5 +1,10 @@ #pragma once +#include + +struct Config; // forward declaration from ../config.h +struct LogcatEntry; // forward declaration from ../logcat_entry.h class LogcatThread; // forward declaration from ../logcat_thread.h -void debug_window(LogcatThread& logcat_thread); +void debug_window(LogcatThread& logcat_thread, const Config& active_config, + std::vector& logcat_entries, std::vector& filtered_logcat_entry_offsets);