#ifndef JUCI_TERMINAL_H_ #define JUCI_TERMINAL_H_ #include #include #include "gtkmm.h" #include #include #include #include #include "process.hpp" #include "dispatcher.h" class Terminal : public Gtk::TextView { public: class InProgress { public: InProgress(const std::string& start_msg); ~InProgress(); void done(const std::string& msg); void cancel(const std::string& msg); private: void start(const std::string& msg); size_t line_nr; std::atomic stop; std::thread wait_thread; }; private: Terminal(); public: static Terminal &get() { static Terminal singleton; return singleton; } 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=""); void async_process(const std::string &command, const boost::filesystem::path &path="", std::function callback=nullptr); void kill_last_async_process(bool force=false); void kill_async_processes(bool force=false); size_t print(const std::string &message, bool bold=false); std::shared_ptr print_in_progress(std::string start_msg); void async_print(const std::string &message, bool bold=false); void async_print(size_t line_nr, const std::string &message); protected: bool on_key_press_event(GdkEventKey *event); private: Dispatcher dispatcher; Glib::RefPtr bold_tag; std::vector > processes; std::mutex processes_mutex; std::string stdin_buffer; size_t deleted_lines=0; }; #endif // JUCI_TERMINAL_H_