Browse Source

Now uses grip when choosing Compile and run on a markdown file

merge-requests/365/head
eidheim 9 years ago
parent
commit
780fe03dd0
  1. 31
      src/project.cc
  2. 10
      src/terminal.cc
  3. 2
      src/terminal.h

31
src/project.cc

@ -629,33 +629,14 @@ void Project::Markdown::compile_and_run() {
} }
std::stringstream stdin_stream, stdout_stream; std::stringstream stdin_stream, stdout_stream;
auto exit_status=Terminal::get().process(stdin_stream, stdout_stream, "markdown "+filesystem::escape_argument(Notebook::get().get_current_view()->file_path.string())); auto exit_status=Terminal::get().process(stdin_stream, stdout_stream, "command -v grip");
if(exit_status==0) { if(exit_status==0) {
boost::system::error_code ec; auto command="grip -b "+filesystem::escape_argument(Notebook::get().get_current_view()->file_path.string());
auto temp_path=boost::filesystem::temp_directory_path(ec); Terminal::get().print("Running: "+command+" in a quiet background process\n");
if(!ec) { Terminal::get().async_process(command, "", nullptr, true);
temp_path/=boost::filesystem::unique_path();
temp_path+=".html";
if(!boost::filesystem::exists(temp_path)) {
last_temp_path=temp_path;
std::ofstream file_stream(temp_path.string(), std::fstream::binary);
file_stream << stdout_stream.rdbuf();
file_stream.close();
auto uri=temp_path.string();
#ifdef __APPLE__
Terminal::get().process("open "+filesystem::escape_argument(uri));
#else
#ifdef __linux
uri="file://"+uri;
#endif
GError* error=nullptr;
gtk_show_uri(nullptr, uri.c_str(), GDK_CURRENT_TIME, &error);
g_clear_error(&error);
#endif
}
}
} }
else
Terminal::get().print("Warning: install grip to preview Markdown files\n");
} }
void Project::Python::compile_and_run() { void Project::Python::compile_and_run() {

10
src/terminal.cc

@ -109,13 +109,15 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c
return process.get_exit_status(); return process.get_exit_status();
} }
void Terminal::async_process(const std::string &command, const boost::filesystem::path &path, std::function<void(int exit_status)> callback) { void Terminal::async_process(const std::string &command, const boost::filesystem::path &path, std::function<void(int exit_status)> callback, bool quiet) {
std::thread async_execute_thread([this, command, path, callback](){ std::thread async_execute_thread([this, command, path, callback, quiet]() {
std::unique_lock<std::mutex> processes_lock(processes_mutex); std::unique_lock<std::mutex> processes_lock(processes_mutex);
stdin_buffer.clear(); stdin_buffer.clear();
auto process=std::make_shared<Process>(command, path.string(), [this](const char* bytes, size_t n) { auto process=std::make_shared<Process>(command, path.string(), [this, quiet](const char* bytes, size_t n) {
if(!quiet)
async_print(std::string(bytes, n)); async_print(std::string(bytes, n));
}, [this](const char* bytes, size_t n) { }, [this, quiet](const char* bytes, size_t n) {
if(!quiet)
async_print(std::string(bytes, n), true); async_print(std::string(bytes, n), true);
}, true); }, true);
auto pid=process->get_id(); auto pid=process->get_id();

2
src/terminal.h

@ -41,7 +41,7 @@ public:
int process(const std::string &command, const boost::filesystem::path &path="", bool use_pipes=true); int process(const std::string &command, const boost::filesystem::path &path="", bool use_pipes=true);
int process(std::istream &stdin_stream, std::ostream &stdout_stream, const std::string &command, const boost::filesystem::path &path=""); int process(std::istream &stdin_stream, std::ostream &stdout_stream, const std::string &command, const boost::filesystem::path &path="");
void async_process(const std::string &command, const boost::filesystem::path &path="", std::function<void(int exit_status)> callback=nullptr); void async_process(const std::string &command, const boost::filesystem::path &path="", std::function<void(int exit_status)> callback=nullptr, bool quiet=false);
void kill_last_async_process(bool force=false); void kill_last_async_process(bool force=false);
void kill_async_processes(bool force=false); void kill_async_processes(bool force=false);

Loading…
Cancel
Save