diff --git a/lib/tiny-process-library b/lib/tiny-process-library index c9c8bf8..6e52608 160000 --- a/lib/tiny-process-library +++ b/lib/tiny-process-library @@ -1 +1 @@ -Subproject commit c9c8bf810ddad8cd17882b9a9ee628a690e779f5 +Subproject commit 6e52608b15d12a13e68269b111afda3013e7cf3a diff --git a/src/cmake.cpp b/src/cmake.cpp index 8d11a1b..2befb21 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -349,3 +349,19 @@ void CMake::parse_file(const std::string &src, std::map(api, "CMake") + .def_readwrite("project_path", &CMake::project_path) + .def("update_default_build", &CMake::update_default_build, + py::arg("default_build_path"), + py::arg("force") = false) + .def("update_debug_build", &CMake::update_debug_build, + py::arg("debug_build_path"), + py::arg("force") = false) + .def("get_executable", &CMake::get_executable, + py::arg("build_path"), + py::arg("file_path")) + + ; +} diff --git a/src/cmake.hpp b/src/cmake.hpp index bfc5485..e4d5002 100644 --- a/src/cmake.hpp +++ b/src/cmake.hpp @@ -3,16 +3,16 @@ #include #include #include +#include "python_bind.h" class CMake { public: CMake(const boost::filesystem::path &path); boost::filesystem::path project_path; - bool update_default_build(const boost::filesystem::path &default_build_path, bool force = false); bool update_debug_build(const boost::filesystem::path &debug_build_path, bool force = false); - boost::filesystem::path get_executable(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path); + static void init_module(py::module &api); private: std::vector paths; diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index e5912b9..e6118b0 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -276,3 +276,24 @@ bool CompileCommands::is_source(const boost::filesystem::path &path) { else return false; } + +void CompileCommands::init_module(py::module &api) { + py::class_ compile_commands(api, "CompileCommands"); + py::class_(compile_commands, "CompileCommands") + .def_readwrite("directory", &CompileCommands::Command::directory) + .def_readwrite("parameters", &CompileCommands::Command::parameters) + .def_readwrite("file", &CompileCommands::Command::file) + + ; + compile_commands + .def_readwrite("commands", &CompileCommands::commands) + .def_static("get_arguments", &CompileCommands::get_arguments, + py::arg("build_path"), + py::arg("file_path")) + .def_static("is_header", &CompileCommands::is_header, + py::arg("path")) + .def_static("is_source", &CompileCommands::is_source, + py::arg("path")) + + ; +} diff --git a/src/compile_commands.hpp b/src/compile_commands.hpp index a76ee8a..8ec4949 100644 --- a/src/compile_commands.hpp +++ b/src/compile_commands.hpp @@ -1,4 +1,5 @@ #pragma once +#include "python_bind.h" #include #include #include @@ -21,16 +22,14 @@ public: boost::filesystem::path directory; std::vector parameters; boost::filesystem::path file; - std::vector parameter_values(const std::string ¶meter_name) const; }; CompileCommands(const boost::filesystem::path &build_path); std::vector commands; - /// Return arguments for the given file using libclangmm static std::vector get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path); - static bool is_header(const boost::filesystem::path &path); static bool is_source(const boost::filesystem::path &path); + static void init_module(py::module &api); }; diff --git a/src/config.cpp b/src/config.cpp index 941f77e..771e876 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -222,3 +222,108 @@ void Config::read(const boost::property_tree::ptree &cfg) { std::cout << "Plugins enabled" << std::endl; } } + +void Config::init_module(py::module &api) { + py::class_> config(api, "Config"); + config + .def(py::init([]() { return &(Config::get()); })) + .def("load", &Config::load) + .def_readonly("version", &Config::version) + + ; + py::class_(config, "Menu") + .def_readwrite("keys", &Config::Menu::keys) + + ; + py::class_(config, "Theme") + .def_readwrite("name", &Config::Theme::name) + .def_readwrite("variant", &Config::Theme::variant) + .def_readwrite("font", &Config::Theme::font) + + ; + py::class_(config, "Terminal") + .def_readwrite("history_size", &Config::Terminal::history_size) + .def_readwrite("font", &Config::Terminal::font) + + ; + py::class_ project(config, "Project"); + py::class_(project, "CMake") + .def_readwrite("command", &Config::Project::CMake::command) + .def_readwrite("compile_command", &Config::Project::CMake::compile_command) + + ; + py::class_(project, "Meson") + .def_readwrite("command", &Config::Project::Meson::command) + .def_readwrite("compile_command", &Config::Project::Meson::compile_command) + + ; + project + .def_readwrite("default_build_path", &Config::Project::default_build_path) + .def_readwrite("debug_build_path", &Config::Project::debug_build_path) + .def_readwrite("cmake", &Config::Project::cmake) + .def_readwrite("meson", &Config::Project::meson) + .def_readwrite("save_on_compile_or_run", &Config::Project::save_on_compile_or_run) + .def_readwrite("clear_terminal_on_compile", &Config::Project::clear_terminal_on_compile) + .def_readwrite("ctags_command", &Config::Project::ctags_command) + .def_readwrite("python_command", &Config::Project::python_command) + + ; + py::class_ source(config, "Source"); + py::class_(source, "DocumentationSearch") + .def_readwrite("separator", &Config::Source::DocumentationSearch::separator) + .def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries) + + ; + source + .def_readwrite("style", &Config::Source::style) + .def_readwrite("font", &Config::Source::font) + .def_readwrite("spellcheck_language", &Config::Source::spellcheck_language) + .def_readwrite("cleanup_whitespace_characters", &Config::Source::cleanup_whitespace_characters) + .def_readwrite("show_whitespace_characters", &Config::Source::show_whitespace_characters) + .def_readwrite("format_style_on_save", &Config::Source::format_style_on_save) + .def_readwrite("format_style_on_save_if_style_file_found", &Config::Source::format_style_on_save_if_style_file_found) + .def_readwrite("smart_inserts", &Config::Source::smart_inserts) + .def_readwrite("show_map", &Config::Source::show_map) + .def_readwrite("map_font_size", &Config::Source::map_font_size) + .def_readwrite("show_git_diff", &Config::Source::show_git_diff) + .def_readwrite("show_background_pattern", &Config::Source::show_background_pattern) + .def_readwrite("show_right_margin", &Config::Source::show_right_margin) + .def_readwrite("right_margin_position", &Config::Source::right_margin_position) + .def_readwrite("auto_tab_char_and_size", &Config::Source::auto_tab_char_and_size) + .def_readwrite("default_tab_char", &Config::Source::default_tab_char) + .def_readwrite("default_tab_size", &Config::Source::default_tab_size) + .def_readwrite("tab_indents_line", &Config::Source::tab_indents_line) + .def_readwrite("wrap_lines", &Config::Source::wrap_lines) + .def_readwrite("highlight_current_line", &Config::Source::highlight_current_line) + .def_readwrite("show_line_numbers", &Config::Source::show_line_numbers) + .def_readwrite("enable_multiple_cursors", &Config::Source::enable_multiple_cursors) + .def_readwrite("auto_reload_changed_files", &Config::Source::auto_reload_changed_files) + .def_readwrite("clang_format_style", &Config::Source::clang_format_style) + .def_readwrite("clang_usages_threads", &Config::Source::clang_usages_threads) + .def_readwrite("documentation_searches", &Config::Source::documentation_searches) + + ; + + py::class_(config, "Log") + .def_readwrite("libclang", &Config::Log::libclang) + .def_readwrite("language_server", &Config::Log::language_server) + + ; + py::class_(config, "Plugins") + .def_readwrite("enabled", &Config::Plugins::enabled) + .def_readwrite("path", &Config::Plugins::path) + + ; + config + .def_readwrite("menu", &Config::menu) + .def_readwrite("theme", &Config::theme) + .def_readwrite("terminal", &Config::terminal) + .def_readwrite("project", &Config::project) + .def_readwrite("source", &Config::source) + .def_readwrite("log", &Config::log) + .def_readwrite("plugins", &Config::plugins) + .def_readwrite("home_path", &Config::home_path) + .def_readwrite("home_juci_path", &Config::home_juci_path) + + ; +} diff --git a/src/config.hpp b/src/config.hpp index 629314d..e7c2184 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -6,6 +6,7 @@ #include #include #include +#include "python_bind.h" class Config { public: @@ -141,6 +142,7 @@ public: boost::filesystem::path home_path; boost::filesystem::path home_juci_path; + static void init_module(py::module &api); private: /// Used to dispatch Terminal outputs after juCi++ GUI setup and configuration diff --git a/src/ctags.cpp b/src/ctags.cpp index ccde85e..f2a3596 100644 --- a/src/ctags.cpp +++ b/src/ctags.cpp @@ -278,3 +278,30 @@ std::vector Ctags::get_locations(const boost::filesystem::path return best_locations; } + +void Ctags::init_module(py::module &api) { + py::class_ ctags(api, "Ctags"); + py::class_(api, "Ctags") + .def_readwrite("file_path", &Ctags::Location::file_path) + .def_readwrite("line", &Ctags::Location::line) + .def_readwrite("index", &Ctags::Location::index) + .def_readwrite("symbol", &Ctags::Location::symbol) + .def_readwrite("scope", &Ctags::Location::scope) + .def_readwrite("source", &Ctags::Location::source) + .def("__bool__", &Ctags::Location::operator bool) + + ; + + ctags + .def_static("get_result", &Ctags::get_result, + py::arg("path")) + .def_static("get_location", &Ctags::get_location, + py::arg("line"), + py::arg("markup")) + .def_static("get_locations", &Ctags::get_locations, + py::arg("path"), + py::arg("name"), + py::arg("type")) + + ; +} \ No newline at end of file diff --git a/src/ctags.hpp b/src/ctags.hpp index d989006..ec891d1 100644 --- a/src/ctags.hpp +++ b/src/ctags.hpp @@ -1,4 +1,5 @@ #pragma once +#include "python_bind.h" #include #include #include @@ -28,6 +29,7 @@ public: std::stringstream output; static std::vector get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type, const std::string &languages = {}); + static void init_module(py::module &api); private: bool enable_scope, enable_kind; diff --git a/src/debug_lldb.cpp b/src/debug_lldb.cpp index e9dd9d8..5266df4 100644 --- a/src/debug_lldb.cpp +++ b/src/debug_lldb.cpp @@ -569,3 +569,80 @@ void Debug::LLDB::write(const std::string &buffer) { process->PutSTDIN(buffer.c_str(), buffer.size()); } } + +void Debug::LLDB::init_module(pybind11::module &api) { + py::class_> dbg(api, "LLDB"); + py::class_(dbg, "Frame") + .def_readwrite("index", &Debug::LLDB::Frame::index) + .def_readwrite("module_filename", &Debug::LLDB::Frame::module_filename) + .def_readwrite("file_path", &Debug::LLDB::Frame::file_path) + .def_readwrite("function_name", &Debug::LLDB::Frame::function_name) + .def_readwrite("line_nr", &Debug::LLDB::Frame::line_nr) + .def_readwrite("line_index", &Debug::LLDB::Frame::line_index) + + ; + py::class_(dbg, "Variable") + .def_readwrite("thread_index_id", &Debug::LLDB::Variable::thread_index_id) + .def_readwrite("frame_index", &Debug::LLDB::Variable::frame_index) + .def_readwrite("name", &Debug::LLDB::Variable::name) + .def_readwrite("value", &Debug::LLDB::Variable::value) + .def_readwrite("declaration_found", &Debug::LLDB::Variable::declaration_found) + .def_readwrite("file_path", &Debug::LLDB::Variable::file_path) + .def_readwrite("line_nr", &Debug::LLDB::Variable::line_nr) + .def_readwrite("line_index", &Debug::LLDB::Variable::line_index) + + ; + + // py::class_(api, "SBProcess"); + // .def_readwrite("on_start", &Debug::LLDB::on_start) + // .def_readwrite("on_event", &Debug::LLDB::on_event) + + dbg + .def(py::init([]() { return &(Debug::LLDB::get()); })) + .def_readwrite("on_exit", &Debug::LLDB::on_exit) + // .def_readwrite("mutex", &Debug::LLDB::mutex) + .def("continue_debug", &Debug::LLDB::continue_debug) + .def("stop", &Debug::LLDB::stop) + .def("kill", &Debug::LLDB::kill) + .def("step_over", &Debug::LLDB::step_over) + .def("step_into", &Debug::LLDB::step_into) + .def("step_out", &Debug::LLDB::step_out) + .def("cancel", &Debug::LLDB::cancel) + .def("is_invalid", &Debug::LLDB::is_invalid) + .def("is_stopped", &Debug::LLDB::is_stopped) + .def("is_running", &Debug::LLDB::is_running) + .def("get_backtrace", &Debug::LLDB::get_backtrace) + .def("get_variables", &Debug::LLDB::get_variables) + .def("cancel", &Debug::LLDB::cancel) + .def("start", &Debug::LLDB::start, + py::arg("command"), + py::arg("path") = "", + py::arg("breakpoints") = std::vector>(), + py::arg("startup_commands") = std::vector(), + py::arg("remote_host") = "") + .def("run_command", &Debug::LLDB::run_command, + py::arg("command")) + .def("select_frame", &Debug::LLDB::select_frame, + py::arg("frame_index"), + py::arg("thread_index_id") = 0) + .def("get_value", &Debug::LLDB::get_value, + py::arg("variable"), + py::arg("file_path"), + py::arg("line_nr"), + py::arg("line_index")) + .def("get_return_value", &Debug::LLDB::get_return_value, + py::arg("file_path"), + py::arg("line_nr"), + py::arg("line_index")) + .def("add_breakpoint", &Debug::LLDB::add_breakpoint, + py::arg("file_path"), + py::arg("line_nr")) + .def("remove_breakpoint", &Debug::LLDB::remove_breakpoint, + py::arg("file_path"), + py::arg("line_nr"), + py::arg("line_count")) + .def(" write", &Debug::LLDB::write, + py::arg("buffer")) + + ; +} diff --git a/src/debug_lldb.hpp b/src/debug_lldb.hpp index 21ea9ac..aef2f9e 100644 --- a/src/debug_lldb.hpp +++ b/src/debug_lldb.hpp @@ -5,6 +5,7 @@ #include #include #include +#include "python_bind.h" namespace Debug { class LLDB { @@ -84,6 +85,7 @@ namespace Debug { void remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count); void write(const std::string &buffer); + static void init_module(py::module &api); private: std::tuple, std::string, std::vector> parse_run_arguments(const std::string &command); diff --git a/src/dialogs.cpp b/src/dialogs.cpp index f0ef662..741fbb4 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -94,3 +94,20 @@ std::string Dialog::gtk_dialog(const boost::filesystem::path &path, const std::s dialog.add_button(button.first, button.second); return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; } + +void Dialog::init_module(py::module &api) { + py::class_(api, "Dialog") + .def_static("open_folder", Dialog::open_folder, + py::arg("path")) + + .def_static("open_file", Dialog::open_file, + py::arg("path")) + .def_static("new_file", Dialog::new_file, + py::arg("path")) + .def_static("new_folder", Dialog::new_folder, + py::arg("path")) + .def_static("save_file_as", Dialog::save_file_as, + py::arg("path")) + + ; +} diff --git a/src/dialogs.hpp b/src/dialogs.hpp index b4be549..28f019a 100644 --- a/src/dialogs.hpp +++ b/src/dialogs.hpp @@ -1,4 +1,5 @@ #pragma once +#include "python_bind.h" #include #include #include @@ -11,6 +12,7 @@ public: static std::string new_file(const boost::filesystem::path &path); static std::string new_folder(const boost::filesystem::path &path); static std::string save_file_as(const boost::filesystem::path &path); + static void init_module(py::module &api); class Message : public Gtk::Window { public: diff --git a/src/dispatcher.cpp b/src/dispatcher.cpp index 1e1b555..f13dedb 100644 --- a/src/dispatcher.cpp +++ b/src/dispatcher.cpp @@ -40,3 +40,11 @@ void Dispatcher::reset() { functions.clear(); connect(); } + +void Dispatcher::init_module(py::module &api) { + py::class_(api, "Dispatcher") + .def(py::init()) + .def("disconnect", &Dispatcher::disconnect) + .def("post", &Dispatcher::post &>) + + ; diff --git a/src/dispatcher.hpp b/src/dispatcher.hpp index fe8981c..38f1ac6 100644 --- a/src/dispatcher.hpp +++ b/src/dispatcher.hpp @@ -1,5 +1,6 @@ #pragma once #include "mutex.hpp" +#include "python_bind.h" #include #include #include @@ -32,4 +33,6 @@ public: /// Must be called from main GUI thread void reset(); + + static void init_module(py::module &api); }; diff --git a/src/plugins.cc b/src/plugins.cc index fae6f2f..935b75b 100644 --- a/src/plugins.cc +++ b/src/plugins.cc @@ -1,6 +1,28 @@ #include "plugins.h" +#include "cmake.h" +#include "compile_commands.h" #include "config.h" -#include "python_module.h" +#include "ctags.h" +#ifdef JUCI_ENABLE_DEBUG +#include "debug_lldb.h" +#endif +#include "dialogs.h" +#include "terminal.h" + +PyObject *Plugins::Module::init_jucipp_module() { + auto api = py::module("Jucipp", "API"); + CMake::init_module(api); + CompileCommands::init_module(api); + Config::init_module(api); + Ctags::init_module(api); +#ifdef JUCI_ENABLE_DEBUG + Debug::LLDB::init_module(api); +#endif + Dialog::init_module(api); + Dispatcher::init_module(api); + Terminal::init_module(api); + return api.ptr(); +}; Plugins::Plugins() : jucipp_module("Jucipp", Module::init_jucipp_module) { auto &config = Config::get(); diff --git a/src/plugins.h b/src/plugins.h index f7177b5..1b5079f 100644 --- a/src/plugins.h +++ b/src/plugins.h @@ -1,14 +1,38 @@ #pragma once - -#include #include "python_interpreter.h" +#include +#include + +namespace pybind11 { + namespace detail { + template <> + struct type_caster { + public: + PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str")); + bool load(handle src, bool) { + value = std::string(pybind11::str(src)); + return !PyErr_Occurred(); + } + + static handle cast(boost::filesystem::path src, return_value_policy, handle) { + return pybind11::str(src.string()); + } + }; + } // namespace detail +} // namespace pybind11 class __attribute__((visibility("default"))) Plugins { public: Plugins(); void load(); + private: + class Module { + public: + static PyObject *init_jucipp_module(); + }; + py::detail::embedded_module jucipp_module; Python::Interpreter interpreter; }; diff --git a/src/python_module.h b/src/python_module.h deleted file mode 100644 index eee365d..0000000 --- a/src/python_module.h +++ /dev/null @@ -1,342 +0,0 @@ -#pragma once -#include "cmake.h" -#include "compile_commands.h" -#include "config.h" -#include "ctags.h" -#include "python_bind.h" -#include "terminal.h" -#include -#include -#include -#ifdef JUCI_ENABLE_DEBUG -#include "debug_lldb.h" -#endif -#include "dialogs.h" - -namespace pybind11 { - namespace detail { - template <> - struct type_caster { - public: - PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str")); - bool load(handle src, bool) { - value = std::string(pybind11::str(src)); - return !PyErr_Occurred(); - } - - static handle cast(boost::filesystem::path src, return_value_policy, handle) { - return pybind11::str(src.string()); - } - }; - } // namespace detail -} // namespace pybind11 - -class Module { - static void init_terminal_module(pybind11::module &api) { - py::class_>(api, "Terminal") - .def(py::init([]() { return &(Terminal::get()); })) - .def("process", (int (Terminal::*)(const std::string &, const boost::filesystem::path &, bool)) & Terminal::process, - py::arg("command"), - py::arg("path") = "", - py::arg("use_pipes") = false) - .def("async_process", (void (Terminal::*)(const std::string &, const boost::filesystem::path &, const std::function &, bool)) & Terminal::async_process, - py::arg("command"), - py::arg("path") = "", - py::arg("callback") = nullptr, - py::arg("quiet") = false) - .def("kill_last_async_process", &Terminal::kill_last_async_process, - py::arg("force") = false) - .def("kill_async_processes", &Terminal::kill_async_processes, - py::arg("force") = false) - .def("print", &Terminal::print, - py::arg("message"), - py::arg("bold") = false) - .def("async_print", (void (Terminal::*)(const std::string &, bool)) & Terminal::async_print, - py::arg("message"), - py::arg("bold") = false) - .def("async_print", (void (Terminal::*)(size_t, const std::string &)) & Terminal::async_print, - py::arg("line_nr"), - py::arg("message")) - .def("configure", &Terminal::configure) - .def("clear", &Terminal::clear); - }; - - static void init_config_module(pybind11::module &api) { - py::class_> config(api, "Config"); - config - .def(py::init([]() { return &(Config::get()); })) - .def("load", &Config::load) - .def_readonly("version", &Config::version) - - ; - py::class_(config, "Menu") - .def_readwrite("keys", &Config::Menu::keys) - - ; - py::class_(config, "Theme") - .def_readwrite("name", &Config::Theme::name) - .def_readwrite("variant", &Config::Theme::variant) - .def_readwrite("font", &Config::Theme::font) - - ; - py::class_(config, "Terminal") - .def_readwrite("history_size", &Config::Terminal::history_size) - .def_readwrite("font", &Config::Terminal::font) - - ; - py::class_ project(config, "Project"); - py::class_(project, "CMake") - .def_readwrite("command", &Config::Project::CMake::command) - .def_readwrite("compile_command", &Config::Project::CMake::compile_command) - - ; - py::class_(project, "Meson") - .def_readwrite("command", &Config::Project::Meson::command) - .def_readwrite("compile_command", &Config::Project::Meson::compile_command) - - ; - project - .def_readwrite("default_build_path", &Config::Project::default_build_path) - .def_readwrite("debug_build_path", &Config::Project::debug_build_path) - .def_readwrite("cmake", &Config::Project::cmake) - .def_readwrite("meson", &Config::Project::meson) - .def_readwrite("save_on_compile_or_run", &Config::Project::save_on_compile_or_run) - .def_readwrite("clear_terminal_on_compile", &Config::Project::clear_terminal_on_compile) - .def_readwrite("ctags_command", &Config::Project::ctags_command) - .def_readwrite("python_command", &Config::Project::python_command) - - ; - py::class_ source(config, "Source"); - py::class_(source, "DocumentationSearch") - .def_readwrite("separator", &Config::Source::DocumentationSearch::separator) - .def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries) - - ; - source - .def_readwrite("style", &Config::Source::style) - .def_readwrite("font", &Config::Source::font) - .def_readwrite("spellcheck_language", &Config::Source::spellcheck_language) - .def_readwrite("cleanup_whitespace_characters", &Config::Source::cleanup_whitespace_characters) - .def_readwrite("show_whitespace_characters", &Config::Source::show_whitespace_characters) - .def_readwrite("format_style_on_save", &Config::Source::format_style_on_save) - .def_readwrite("format_style_on_save_if_style_file_found", &Config::Source::format_style_on_save_if_style_file_found) - .def_readwrite("smart_inserts", &Config::Source::smart_inserts) - .def_readwrite("show_map", &Config::Source::show_map) - .def_readwrite("map_font_size", &Config::Source::map_font_size) - .def_readwrite("show_git_diff", &Config::Source::show_git_diff) - .def_readwrite("show_background_pattern", &Config::Source::show_background_pattern) - .def_readwrite("show_right_margin", &Config::Source::show_right_margin) - .def_readwrite("right_margin_position", &Config::Source::right_margin_position) - .def_readwrite("auto_tab_char_and_size", &Config::Source::auto_tab_char_and_size) - .def_readwrite("default_tab_char", &Config::Source::default_tab_char) - .def_readwrite("default_tab_size", &Config::Source::default_tab_size) - .def_readwrite("tab_indents_line", &Config::Source::tab_indents_line) - .def_readwrite("wrap_lines", &Config::Source::wrap_lines) - .def_readwrite("highlight_current_line", &Config::Source::highlight_current_line) - .def_readwrite("show_line_numbers", &Config::Source::show_line_numbers) - .def_readwrite("enable_multiple_cursors", &Config::Source::enable_multiple_cursors) - .def_readwrite("auto_reload_changed_files", &Config::Source::auto_reload_changed_files) - .def_readwrite("clang_format_style", &Config::Source::clang_format_style) - .def_readwrite("clang_usages_threads", &Config::Source::clang_usages_threads) - .def_readwrite("documentation_searches", &Config::Source::documentation_searches) - - ; - - py::class_(config, "Log") - .def_readwrite("libclang", &Config::Log::libclang) - .def_readwrite("language_server", &Config::Log::language_server) - - ; - py::class_(config, "Plugins") - .def_readwrite("enabled", &Config::Plugins::enabled) - .def_readwrite("path", &Config::Plugins::path) - - ; - config - .def_readwrite("menu", &Config::menu) - .def_readwrite("theme", &Config::theme) - .def_readwrite("terminal", &Config::terminal) - .def_readwrite("project", &Config::project) - .def_readwrite("source", &Config::source) - .def_readwrite("log", &Config::log) - .def_readwrite("plugins", &Config::plugins) - .def_readwrite("home_path", &Config::home_path) - .def_readwrite("home_juci_path", &Config::home_juci_path) - - ; - } - - static void init_cmake_module(pybind11::module &api) { - py::class_(api, "CMake") - .def_readwrite("project_path", &CMake::project_path) - .def("update_default_build", &CMake::update_default_build, - py::arg("default_build_path"), - py::arg("force") = false) - .def("update_debug_build", &CMake::update_debug_build, - py::arg("debug_build_path"), - py::arg("force") = false) - .def("get_executable", &CMake::get_executable, - py::arg("build_path"), - py::arg("file_path")) - - ; - } - - static void init_compile_commands_module(pybind11::module &api) { - py::class_ compile_commands(api, "CompileCommands"); - py::class_(compile_commands, "CompileCommands") - .def_readwrite("directory", &CompileCommands::Command::directory) - .def_readwrite("parameters", &CompileCommands::Command::parameters) - .def_readwrite("file", &CompileCommands::Command::file) - - ; - compile_commands - .def_readwrite("commands", &CompileCommands::commands) - .def_static("get_arguments", &CompileCommands::get_arguments, - py::arg("build_path"), - py::arg("file_path")) - .def_static("is_header", &CompileCommands::is_header, - py::arg("path")) - .def_static("is_source", &CompileCommands::is_source, - py::arg("path")) - - ; - } - - static void init_compile_ctags_module(pybind11::module &api) { - py::class_ ctags(api, "Ctags"); - py::class_(api, "Ctags") - .def_readwrite("file_path", &Ctags::Location::file_path) - .def_readwrite("line", &Ctags::Location::line) - .def_readwrite("index", &Ctags::Location::index) - .def_readwrite("symbol", &Ctags::Location::symbol) - .def_readwrite("scope", &Ctags::Location::scope) - .def_readwrite("source", &Ctags::Location::source) - .def("__bool__", &Ctags::Location::operator bool) - - ; - - ctags - .def_static("get_result", &Ctags::get_result, - py::arg("path")) - .def_static("get_location", &Ctags::get_location, - py::arg("line"), - py::arg("markup")) - .def_static("get_locations", &Ctags::get_locations, - py::arg("path"), - py::arg("name"), - py::arg("type")) - - ; - } - -#ifdef JUCI_ENABLE_DEBUG - static void init_debug_LLDB_module(pybind11::module &api) { - py::class_> dbg(api, "LLDB"); - py::class_(dbg, "Frame") - .def_readwrite("index", &Debug::LLDB::Frame::index) - .def_readwrite("module_filename", &Debug::LLDB::Frame::module_filename) - .def_readwrite("file_path", &Debug::LLDB::Frame::file_path) - .def_readwrite("function_name", &Debug::LLDB::Frame::function_name) - .def_readwrite("line_nr", &Debug::LLDB::Frame::line_nr) - .def_readwrite("line_index", &Debug::LLDB::Frame::line_index) - - ; - py::class_(dbg, "Variable") - .def_readwrite("thread_index_id", &Debug::LLDB::Variable::thread_index_id) - .def_readwrite("frame_index", &Debug::LLDB::Variable::frame_index) - .def_readwrite("name", &Debug::LLDB::Variable::name) - .def_readwrite("value", &Debug::LLDB::Variable::value) - .def_readwrite("declaration_found", &Debug::LLDB::Variable::declaration_found) - .def_readwrite("file_path", &Debug::LLDB::Variable::file_path) - .def_readwrite("line_nr", &Debug::LLDB::Variable::line_nr) - .def_readwrite("line_index", &Debug::LLDB::Variable::line_index) - - ; - - // py::class_(api, "SBProcess"); - // .def_readwrite("on_start", &Debug::LLDB::on_start) - // .def_readwrite("on_event", &Debug::LLDB::on_event) - - dbg - .def(py::init([]() { return &(Debug::LLDB::get()); })) - .def_readwrite("on_exit", &Debug::LLDB::on_exit) - // .def_readwrite("mutex", &Debug::LLDB::mutex) - .def("continue_debug", &Debug::LLDB::continue_debug) - .def("stop", &Debug::LLDB::stop) - .def("kill", &Debug::LLDB::kill) - .def("step_over", &Debug::LLDB::step_over) - .def("step_into", &Debug::LLDB::step_into) - .def("step_out", &Debug::LLDB::step_out) - .def("cancel", &Debug::LLDB::cancel) - .def("is_invalid", &Debug::LLDB::is_invalid) - .def("is_stopped", &Debug::LLDB::is_stopped) - .def("is_running", &Debug::LLDB::is_running) - .def("get_backtrace", &Debug::LLDB::get_backtrace) - .def("get_variables", &Debug::LLDB::get_variables) - .def("cancel", &Debug::LLDB::cancel) - .def("start", &Debug::LLDB::start, - py::arg("command"), - py::arg("path") = "", - py::arg("breakpoints") = std::vector>(), - py::arg("startup_commands") = std::vector(), - py::arg("remote_host") = "") - .def("run_command", &Debug::LLDB::run_command, - py::arg("command")) - .def("select_frame", &Debug::LLDB::select_frame, - py::arg("frame_index"), - py::arg("thread_index_id") = 0) - .def("get_value", &Debug::LLDB::get_value, - py::arg("variable"), - py::arg("file_path"), - py::arg("line_nr"), - py::arg("line_index")) - .def("get_return_value", &Debug::LLDB::get_return_value, - py::arg("file_path"), - py::arg("line_nr"), - py::arg("line_index")) - .def("add_breakpoint", &Debug::LLDB::add_breakpoint, - py::arg("file_path"), - py::arg("line_nr")) - .def("remove_breakpoint", &Debug::LLDB::remove_breakpoint, - py::arg("file_path"), - py::arg("line_nr"), - py::arg("line_count")) - .def(" write", &Debug::LLDB::write, - py::arg("buffer")) - - ; - } -#endif - - static void init_dialogs_module(py::module &api) { - py::class_(api, "Dialog") - .def_static("open_folder", Dialog::open_folder, - py::arg("path")) - - .def_static("open_file", Dialog::open_file, - py::arg("path")) - .def_static("new_file", Dialog::new_file, - py::arg("path")) - .def_static("new_folder", Dialog::new_folder, - py::arg("path")) - .def_static("save_file_as", Dialog::save_file_as, - py::arg("path")) - - ; - } - -public: - static auto init_jucipp_module() { - auto api = py::module("Jucipp", "API"); - Module::init_terminal_module(api); - Module::init_config_module(api); - Module::init_cmake_module(api); - Module::init_compile_commands_module(api); -#ifdef JUCI_ENABLE_DEBUG - Module::init_debug_LLDB_module(api); -#endif - Module::init_dialogs_module(api); - return api.ptr(); - }; -}; diff --git a/src/terminal.cpp b/src/terminal.cpp index 332b602..77885a4 100644 --- a/src/terminal.cpp +++ b/src/terminal.cpp @@ -603,3 +603,34 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { } return true; } + +void Terminal::init_module(pybind11::module &api) { + py::class_>(api, "Terminal") + .def(py::init([]() { return &(Terminal::get()); })) + .def("process", (int (Terminal::*)(const std::string &, const boost::filesystem::path &, bool)) & Terminal::process, + py::arg("command"), + py::arg("path") = "", + py::arg("use_pipes") = false) + .def("async_process", (void (Terminal::*)(const std::string &, const boost::filesystem::path &, const std::function &, bool)) & Terminal::async_process, + py::arg("command"), + py::arg("path") = "", + py::arg("callback") = nullptr, + py::arg("quiet") = false) + .def("kill_last_async_process", &Terminal::kill_last_async_process, + py::arg("force") = false) + .def("kill_async_processes", &Terminal::kill_async_processes, + py::arg("force") = false) + .def("print", &Terminal::print, + py::arg("message"), + py::arg("bold") = false) + .def("async_print", (void (Terminal::*)(const std::string &, bool)) & Terminal::async_print, + py::arg("message"), + py::arg("bold") = false) + .def("async_print", (void (Terminal::*)(size_t, const std::string &)) & Terminal::async_print, + py::arg("line_nr"), + py::arg("message")) + .def("configure", &Terminal::configure) + .def("clear", &Terminal::clear) + + ; +} diff --git a/src/terminal.hpp b/src/terminal.hpp index 3781e72..31cf1f6 100644 --- a/src/terminal.hpp +++ b/src/terminal.hpp @@ -2,6 +2,7 @@ #include "dispatcher.hpp" #include "mutex.hpp" #include "process.hpp" +#include "python_bind.h" #include "source_base.hpp" #include #include @@ -33,6 +34,7 @@ public: void configure(); void clear(); + static void init_module(pybind11::module &api); std::function scroll_to_bottom;