From 74b83920ed63454bf8dd2cd5efed12888096f24a Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 16 Jul 2021 20:29:32 +0200 Subject: Added filename argument to CLI --- markdown.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'markdown.cpp') diff --git a/markdown.cpp b/markdown.cpp index a7c1312..e61601d 100644 --- a/markdown.cpp +++ b/markdown.cpp @@ -1,5 +1,9 @@ #include +#include +#include +#include + #include #include @@ -51,8 +55,11 @@ static void resized(GLFWwindow *, int width, int height) g_window_size.y = static_cast(height); } -int main(int, char **) +int main(int argc, char ** argv) { + if (2 != argc) + return 1; + glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return 1; @@ -84,6 +91,11 @@ int main(int, char **) ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(glsl_version); + std::ifstream in; + in.open(argv[1]); + std::string text(std::istreambuf_iterator(in), {}); + in.close(); + while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @@ -98,12 +110,7 @@ int main(int, char **) nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoSavedSettings ); - static const char * text = - "# Hello world!\n" // 15 - "Lorem ipsum dolor\n" // 18 33 - " * sit\n" // 7 40 - " * amet\n"; // 8 48 - markdown(text, text + 48); + markdown(text.data(), text.data() + text.size()); ImGui::End(); ImGui::Render(); -- cgit v1.1