mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
#ifndef JUCI_TERMINAL_H_ |
|
#define JUCI_TERMINAL_H_ |
|
|
|
#include <mutex> |
|
#include <functional> |
|
#include "gtkmm.h" |
|
#include <boost/filesystem.hpp> |
|
#include <thread> |
|
#include <atomic> |
|
#include <iostream> |
|
#include "process.hpp" |
|
#include "dispatcher.h" |
|
#include <unordered_set> |
|
//Temporary fix for current Arch Linux boost linking problem |
|
#ifdef __GNUC_PREREQ |
|
#if __GNUC_PREREQ(5,1) |
|
#include <regex> |
|
#define REGEX_NS std |
|
#endif |
|
#endif |
|
#ifndef REGEX_NS |
|
#include <boost/regex.hpp> |
|
#define REGEX_NS boost |
|
#endif |
|
|
|
class Terminal : public Gtk::TextView { |
|
public: |
|
class InProgress { |
|
friend class Terminal; |
|
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<bool> 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<void(int exit_status)> 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<InProgress> 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); |
|
|
|
void configure(); |
|
|
|
void clear(); |
|
protected: |
|
bool on_motion_notify_event (GdkEventMotion* motion_event) override; |
|
bool on_button_press_event(GdkEventButton* button_event) override; |
|
bool on_key_press_event(GdkEventKey *event) override; |
|
private: |
|
Dispatcher dispatcher; |
|
Glib::RefPtr<Gtk::TextTag> bold_tag; |
|
Glib::RefPtr<Gtk::TextTag> link_tag; |
|
Glib::RefPtr<Gdk::Cursor> link_mouse_cursor; |
|
Glib::RefPtr<Gdk::Cursor> default_mouse_cursor; |
|
size_t deleted_lines=0; |
|
const static REGEX_NS::regex link_regex; |
|
void apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter); |
|
|
|
std::vector<std::shared_ptr<Process> > processes; |
|
std::mutex processes_mutex; |
|
std::string stdin_buffer; |
|
|
|
std::unordered_set<InProgress*> in_progresses; |
|
std::mutex in_progresses_mutex; |
|
}; |
|
|
|
#endif // JUCI_TERMINAL_H_
|
|
|