Skip to content

Commit

Permalink
fix copying serial buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
p3p committed Jul 9, 2024
1 parent e6263f6 commit f95fc09
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/MarlinSimulator/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct SerialMonitor : public UiWindow {
bool streaming = false;
std::size_t stream_sent = 0, stream_total = 0;
std::mutex buffer_mutex {};
bool copy_buffer_signal = false;

MSerialT& serial_stream;
std::ifstream input_file;
Expand Down Expand Up @@ -230,7 +231,10 @@ struct SerialMonitor : public UiWindow {
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Edit")) {
if (ImGui::MenuItem("Copy Buffer")) {}
if (ImGui::MenuItem("Copy Buffer")) {
copy_buffer_signal = true;
ImGui::LogToClipboard();
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();
Expand All @@ -257,11 +261,18 @@ struct SerialMonitor : public UiWindow {
auto size = ImGui::GetContentRegionAvail();
size.y -= 25; // TODO: there must be a better way to fill 2 items on a line
if (ImGui::BeginChild(child_id, size, true, child_flags)) {
if (copy_buffer_signal) {
ImGui::LogToClipboard();
}
for (auto& line : line_buffer) {
if (line.count > 1) ImGui::TextWrapped("[%ld] %s", line.count, (char *)line.text.c_str());
else ImGui::TextWrapped("%s", (char *)line.text.c_str());
}
ImGui::TextWrapped("%s", (char *)working_buffer.c_str());
if (copy_buffer_signal) {
copy_buffer_signal = false;
ImGui::LogFinish();
}

// Automatically set follow when scrolled to max
if (ImGui::GetScrollY() != ImGui::GetScrollMaxY() || scroll_follow_state == 2) scroll_follow = false;
Expand Down

0 comments on commit f95fc09

Please sign in to comment.