Skip to content

Commit 3949971

Browse files
committed
Add a log viewer view.
1 parent 6146f44 commit 3949971

File tree

7 files changed

+102
-3
lines changed

7 files changed

+102
-3
lines changed

src/gui2/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ def plugin(name, id, srcs, hdrs, romfsdir, deps):
514514
"./globals.h",
515515
"./imageview.cc",
516516
"./imageview.h",
517+
"./logview.cc",
518+
"./logview.h",
517519
"./physicalview.cc",
518520
"./physicalview.h",
519521
"./summaryview.cc",

src/gui2/datastore.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "lib/usb/usbfinder.h"
1818
#include "lib/vfs/vfs.h"
1919
#include "arch/arch.h"
20+
#include "logview.h"
2021
#include "globals.h"
2122
#include "datastore.h"
2223
#include "utils.h"
@@ -427,6 +428,7 @@ void wtRebuildConfiguration()
427428

428429
void Datastore::onLogMessage(const AnyLogMessage& message)
429430
{
431+
LogView::logMessage(message);
430432
std::visit(
431433
overloaded{
432434
/* Fallback --- do nothing */

src/gui2/fluxengine.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "summaryview.h"
1010
#include "configview.h"
1111
#include "controlpanelview.h"
12+
#include "logview.h"
1213
#include "diskprovider.h"
1314
#include "datastore.h"
1415

@@ -29,6 +30,7 @@ IMHEX_PLUGIN_SETUP("FluxEngine", "David Given", "FluxEngine integration")
2930
hex::ContentRegistry::Views::add<SummaryView>();
3031
hex::ContentRegistry::Views::add<ConfigView>();
3132
hex::ContentRegistry::Views::add<ControlPanelView>();
33+
hex::ContentRegistry::Views::add<LogView>();
3234

3335
Datastore::init();
3436
}

src/gui2/logview.cc

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <hex/api/content_registry/user_interface.hpp>
2+
#include <hex/api/theme_manager.hpp>
3+
#include <hex/helpers/logger.hpp>
4+
#include <fonts/vscode_icons.hpp>
5+
#include <fonts/tabler_icons.hpp>
6+
#include <fmt/format.h>
7+
#include "lib/core/globals.h"
8+
#include "lib/config/config.h"
9+
#include "lib/data/flux.h"
10+
#include "lib/data/sector.h"
11+
#include "lib/config/proto.h"
12+
#include "globals.h"
13+
#include "logview.h"
14+
#include "datastore.h"
15+
#include "utils.h"
16+
#include <implot.h>
17+
#include <implot_internal.h>
18+
19+
using namespace hex;
20+
21+
static std::stringstream logstream;
22+
static std::unique_ptr<LogRenderer> logRenderer =
23+
LogRenderer::create(logstream);
24+
static bool scrollToEndOnNextRedraw = false;
25+
26+
LogView::LogView(): View::Window("fluxengine.view.log.name", ICON_VS_DEBUG) {}
27+
28+
void LogView::drawContent()
29+
{
30+
ImGui::PushStyleColor(ImGuiCol_FrameBg, 0x00000000);
31+
ON_SCOPE_EXIT
32+
{
33+
ImGui::PopStyleColor();
34+
};
35+
36+
auto buffer = logstream.view();
37+
ImGui::InputTextMultiline("##logview",
38+
(char*)buffer.data(),
39+
buffer.size(),
40+
ImGui::GetContentRegionAvail(),
41+
ImGuiInputTextFlags_ReadOnly);
42+
43+
/* Hacky code to scroll to the end of the window if something's changed.
44+
* See https://github.com/ocornut/imgui/issues/5484
45+
*/
46+
47+
if (scrollToEndOnNextRedraw)
48+
{
49+
scrollToEndOnNextRedraw = false;
50+
51+
ImGuiContext& g = *GImGui;
52+
const char* child_window_name = NULL;
53+
ImFormatStringToTempBuffer(&child_window_name,
54+
NULL,
55+
"%s/%s_%08X",
56+
g.CurrentWindow->Name,
57+
"##logview",
58+
ImGui::GetID("##logview"));
59+
ImGuiWindow* child_window = ImGui::FindWindowByName(child_window_name);
60+
ImGui::SetScrollY(child_window, child_window->ScrollMax.y);
61+
}
62+
}
63+
64+
void LogView::logMessage(const AnyLogMessage& message)
65+
{
66+
logRenderer->add(message);
67+
scrollToEndOnNextRedraw = true;
68+
}

src/gui2/logview.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include "lib/core/logger.h"
4+
#include <hex/ui/view.hpp>
5+
6+
class LogView : public hex::View::Window
7+
{
8+
public:
9+
LogView();
10+
~LogView() override = default;
11+
12+
void drawContent() override;
13+
static void logMessage(const AnyLogMessage& message);
14+
15+
[[nodiscard]] bool shouldDraw() const override
16+
{
17+
return true;
18+
}
19+
[[nodiscard]] bool hasViewMenuItemEntry() const override
20+
{
21+
return true;
22+
}
23+
};

src/gui2/rsrc/auto_extract/workspaces/default.hexws

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

src/gui2/rsrc/lang/en_US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@
4040
"fluxengine.view.controlpanel.writeImage": "Save disk image",
4141
"fluxengine.view.controlpanel.rereadBad": "Re-read bad tracks",
4242
"fluxengine.view.controlpanel.createBlank": "Format disk",
43-
"fluxengine.view.controlpanel.stop": "Stop"
43+
"fluxengine.view.controlpanel.stop": "Stop",
44+
45+
"fluxengine.view.log.name": "FluxEngine log viewer"
4446
}

0 commit comments

Comments
 (0)