summaryrefslogtreecommitdiff
path: root/markdown.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'markdown.cpp')
-rw-r--r--markdown.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/markdown.cpp b/markdown.cpp
index 3f2eb4e..b4d692f 100644
--- a/markdown.cpp
+++ b/markdown.cpp
@@ -3,11 +3,13 @@
#include <array>
#include <cstdio>
#include <fstream>
+#include <future>
#include <iostream>
#include <iterator>
#include <memory>
#include <string>
#include <string_view>
+#include <thread>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
@@ -22,6 +24,20 @@ ImFont * g_font_regular;
ImFont * g_font_bold;
ImFont * g_font_bold_large;
+static std::string get(const std::string & command)
+{
+ std::string result;
+ std::array<char, 512> buffer;
+ std::unique_ptr<FILE, decltype(&pclose)> opener(popen(command.c_str(), "r"), pclose);
+ if (!opener)
+ return std::string(); // TODO: time to do some error handling
+ while (nullptr != fgets(buffer.data(), buffer.size(), opener.get()))
+ {
+ result += buffer.data();
+ }
+ return result;
+}
+
struct Markdown : public imgui_md
{
ImFont * get_font() const override
@@ -43,7 +59,6 @@ struct Markdown : public imgui_md
void open_url() const override
{
- std::array<char, 512> buffer;
std::string command = "browse -f markdown ";
std::string_view prefix(m_href.data(), 4);
if (prefix == "http")
@@ -67,13 +82,9 @@ struct Markdown : public imgui_md
return; // TODO: also an error
}
}
- std::unique_ptr<FILE, decltype(&pclose)> opener(popen(command.c_str(), "r"), pclose);
- if (!opener)
- return; // TODO: time to do some error handling
- while (nullptr != fgets(buffer.data(), buffer.size(), opener.get()))
- {
- // TODO: Support reopening
- }
+ std::packaged_task<std::string (const std::string &)> task(get);
+ std::thread t(std::move(task), command);
+ t.detach();
}
};