diff --git a/src/notebook.cc b/src/notebook.cc index 4ecf9cc..3cb89cf 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -356,9 +356,12 @@ boost::filesystem::path Notebook::get_current_folder() { std::unique_ptr Notebook::get_project() { if(get_current_page()!=-1) { - if(get_current_view()->language->get_id()=="markdown") { - return std::unique_ptr(new ProjectMarkDown(*this)); - } + if(get_current_view()->language->get_id()=="markdown") + return std::unique_ptr(new ProjectMarkdown(*this)); + if(get_current_view()->language->get_id()=="python") + return std::unique_ptr(new ProjectPython(*this)); + if(get_current_view()->language->get_id()=="js") + return std::unique_ptr(new ProjectJavaScript(*this)); } return std::unique_ptr(new ProjectClang(*this)); diff --git a/src/project.cc b/src/project.cc index c9d8405..e3cf3ad 100644 --- a/src/project.cc +++ b/src/project.cc @@ -381,14 +381,14 @@ void ProjectClang::debug_delete() { } #endif -ProjectMarkDown::~ProjectMarkDown() { +ProjectMarkdown::~ProjectMarkdown() { if(!last_temp_path.empty()) { boost::filesystem::remove(last_temp_path); last_temp_path=boost::filesystem::path(); } } -void ProjectMarkDown::compile_and_run() { +void ProjectMarkdown::compile_and_run() { if(!last_temp_path.empty()) { boost::filesystem::remove(last_temp_path); last_temp_path=boost::filesystem::path(); @@ -412,3 +412,19 @@ void ProjectMarkDown::compile_and_run() { } } } + +void ProjectPython::compile_and_run() { + auto command="python "+notebook.get_current_view()->file_path.string(); + Terminal::get().print("Running "+command+"\n"); + Terminal::get().async_process(command, notebook.get_current_view()->file_path.parent_path(), [command](int exit_status) { + Terminal::get().async_print(command+" returned: "+std::to_string(exit_status)+'\n'); + }); +} + +void ProjectJavaScript::compile_and_run() { + auto command="node "+notebook.get_current_view()->file_path.string(); + Terminal::get().print("Running "+command+"\n"); + Terminal::get().async_process(command, notebook.get_current_view()->file_path.parent_path(), [command](int exit_status) { + Terminal::get().async_print(command+" returned: "+std::to_string(exit_status)+'\n'); + }); +} diff --git a/src/project.h b/src/project.h index 9cbb183..4e735ae 100644 --- a/src/project.h +++ b/src/project.h @@ -69,13 +69,27 @@ public: void debug_delete() override; }; -class ProjectMarkDown : public Project { +class ProjectMarkdown : public Project { public: - ProjectMarkDown(Notebook ¬ebook) : Project(notebook) {} - ~ProjectMarkDown(); + ProjectMarkdown(Notebook ¬ebook) : Project(notebook) {} + ~ProjectMarkdown(); boost::filesystem::path last_temp_path; void compile_and_run() override; }; +class ProjectPython : public Project { +public: + ProjectPython(Notebook ¬ebook) : Project(notebook) {} + + void compile_and_run() override; +}; + +class ProjectJavaScript : public Project { +public: + ProjectJavaScript(Notebook ¬ebook) : Project(notebook) {} + + void compile_and_run() override; +}; + #endif // JUCI_PROJECT_H_