Add buttons to add test logcat entries

This commit is contained in:
blankie 2023-03-07 18:02:18 +07:00
parent 562aa7e643
commit a6572fb085
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 43 additions and 3 deletions

View File

@ -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) {

View File

@ -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<LogcatEntry>& logcat_entries, std::vector<size_t>& 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();
}

View File

@ -1,5 +1,10 @@
#pragma once
#include <vector>
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<LogcatEntry>& logcat_entries, std::vector<size_t>& filtered_logcat_entry_offsets);