Compare commits
No commits in common. "44e97f8f053e0811feaec17fbf44d6c47fcda1ad" and "2a1233d95bc51bebbd67e40f22ab1488ae676651" have entirely different histories.
44e97f8f05
...
2a1233d95b
|
@ -7,13 +7,11 @@
|
||||||
#include "export.h"
|
#include "export.h"
|
||||||
|
|
||||||
enum class ExportAmount : int {
|
enum class ExportAmount : int {
|
||||||
All,
|
All = 0,
|
||||||
Filtered,
|
Filtered = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void export_logcat_entries(const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers, File& file);
|
static inline void export_logcat_entries(File& file, const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers);
|
||||||
static inline void export_logcat_entries_to_clipboard(const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers);
|
|
||||||
static inline void export_logcat_entries(const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers, auto cb);
|
|
||||||
static inline std::optional<File> save_file_picker();
|
static inline std::optional<File> save_file_picker();
|
||||||
|
|
||||||
void export_fragment(const LogcatEntries& logcat_entries) {
|
void export_fragment(const LogcatEntries& logcat_entries) {
|
||||||
|
@ -28,72 +26,23 @@ void export_fragment(const LogcatEntries& logcat_entries) {
|
||||||
if (ImGui::Button("Export to File")) {
|
if (ImGui::Button("Export to File")) {
|
||||||
std::optional<File> file = save_file_picker();
|
std::optional<File> file = save_file_picker();
|
||||||
if (file) {
|
if (file) {
|
||||||
|
export_logcat_entries(*file, logcat_entries, export_amount, export_buffers);
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
try {
|
|
||||||
export_logcat_entries(logcat_entries, export_amount, export_buffers, *file);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
log(std::string("Failed to export logcat entries: ") + e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Export to Clipboard")) {
|
if (ImGui::Button("Export to Clipboard")) {
|
||||||
ImGui::CloseCurrentPopup();
|
// TODO exist
|
||||||
try {
|
|
||||||
export_logcat_entries_to_clipboard(logcat_entries, export_amount, export_buffers);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
log(std::string("Failed to export logcat entries: ") + e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void export_logcat_entries(const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers, File& file) {
|
static inline void export_logcat_entries(File& file, const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers) {
|
||||||
export_logcat_entries(logcat_entries, export_amount, export_buffers, [&](std::string line) {
|
// TODO actually do the job
|
||||||
file.write(std::move(line));
|
file.write(std::string("Count of all entries: ") + std::to_string(logcat_entries.size_all()) + '\n');
|
||||||
file.write("\n", 1);
|
file.write(std::string("Count of filtered entries: ") + std::to_string(logcat_entries.size_filtered()) + '\n');
|
||||||
});
|
file.write(std::string("Export amount: ") + (export_amount == ExportAmount::All ? "all" : "filtered") + '\n');
|
||||||
}
|
file.write(std::string("Export buffers: ") + (export_buffers ? "true" : "false") + '\n');
|
||||||
|
|
||||||
static inline void export_logcat_entries_to_clipboard(const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers) {
|
|
||||||
std::string text;
|
|
||||||
export_logcat_entries(logcat_entries, export_amount, export_buffers, [&](std::string line) {
|
|
||||||
text += std::move(line);
|
|
||||||
text += '\n';
|
|
||||||
});
|
|
||||||
ImGui::SetClipboardText(text.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void export_logcat_entries(const LogcatEntries& logcat_entries, ExportAmount export_amount, bool export_buffers, auto cb) {
|
|
||||||
size_t size;
|
|
||||||
const LogcatEntry& (LogcatEntries::*get_fn)(size_t) const;
|
|
||||||
unsigned int buffers_printed = 0;
|
|
||||||
std::optional<Buffer> last_buffer;
|
|
||||||
|
|
||||||
switch (export_amount) {
|
|
||||||
case ExportAmount::All:
|
|
||||||
size = logcat_entries.size_all();
|
|
||||||
get_fn = &LogcatEntries::at_all;
|
|
||||||
break;
|
|
||||||
case ExportAmount::Filtered:
|
|
||||||
size = logcat_entries.size_filtered();
|
|
||||||
get_fn = &LogcatEntries::at_filtered;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
|
||||||
const LogcatEntry& entry = (logcat_entries.*get_fn)(i);
|
|
||||||
if (export_buffers && (!last_buffer || *last_buffer != entry.buffer)) {
|
|
||||||
const char* prefix = buffers_printed & static_cast<unsigned int>(entry.buffer)
|
|
||||||
? "switch to"
|
|
||||||
: "beginning of";
|
|
||||||
cb(std::string("--------- ") + prefix + ' ' + to_string_lower(entry.buffer));
|
|
||||||
buffers_printed |= static_cast<unsigned int>(entry.buffer);
|
|
||||||
last_buffer = entry.buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(to_string(entry));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline std::optional<File> save_file_picker() {
|
static inline std::optional<File> save_file_picker() {
|
||||||
|
|
|
@ -33,17 +33,6 @@ const char* to_string(Buffer buffer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* to_string_lower(Buffer buffer) {
|
|
||||||
switch (buffer) {
|
|
||||||
case Buffer::Main: return "main";
|
|
||||||
case Buffer::System: return "system";
|
|
||||||
case Buffer::Radio: return "radio";
|
|
||||||
case Buffer::Events: return "events";
|
|
||||||
case Buffer::Crash: return "crash";
|
|
||||||
case Buffer::Unknown: return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string leftpad(const std::string& str, size_t characters) {
|
static std::string leftpad(const std::string& str, size_t characters) {
|
||||||
return str.size() >= characters
|
return str.size() >= characters
|
||||||
? str
|
? str
|
||||||
|
|
|
@ -73,7 +73,6 @@ private:
|
||||||
|
|
||||||
const char* to_string(Priority priority);
|
const char* to_string(Priority priority);
|
||||||
const char* to_string(Buffer buffer);
|
const char* to_string(Buffer buffer);
|
||||||
const char* to_string_lower(Buffer buffer);
|
|
||||||
std::string to_string(const LogcatEntry& logcat_entry);
|
std::string to_string(const LogcatEntry& logcat_entry);
|
||||||
std::optional<LogcatEntry> try_parse_logcat_entry(char* buf, size_t length, Buffer buffer);
|
std::optional<LogcatEntry> try_parse_logcat_entry(char* buf, size_t length, Buffer buffer);
|
||||||
std::optional<Buffer> try_parse_buffer(char* buf, size_t length);
|
std::optional<Buffer> try_parse_buffer(char* buf, size_t length);
|
||||||
|
|
|
@ -167,10 +167,6 @@ void main_window(bool latest_log_entries_read, ImFont* monospace_font, LogcatThr
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Clear")) {
|
|
||||||
logcat_entries.clear();
|
|
||||||
}
|
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Export")) {
|
if (ImGui::Button("Export")) {
|
||||||
ImGui::OpenPopup("export_logcat");
|
ImGui::OpenPopup("export_logcat");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue