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.

69 lines
2.0 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 <list>
class Terminal : public Gtk::TextView {
public:
class Config {
public:
std::string cmake_command;
std::string make_command;
int history_size;
};
class InProgress {
public:
InProgress(const std::string& start_msg);
~InProgress();
void done(const std::string& msg);
void cancel(const std::string& msg);
private:
11 years ago
void start(const std::string& msg);
10 years ago
size_t line_nr;
std::atomic<bool> stop;
Glib::Dispatcher waiting_print;
std::thread wait_thread;
};
Terminal();
int execute(const std::string &command, const boost::filesystem::path &path="");
void async_execute(const std::string &command, const boost::filesystem::path &path="", std::function<void(int exit_code)> callback=nullptr);
void kill_last_async_execute(bool force=false);
void kill_async_executes(bool force=false);
10 years ago
size_t print(const std::string &message, bool bold=false);
void print(size_t line_nr, const std::string &message);
std::shared_ptr<InProgress> print_in_progress(std::string start_msg);
void async_print(const std::string &message, bool bold=false);
void async_print(int line_nr, const std::string &message);
protected:
bool on_key_press_event(GdkEventKey *event);
private:
Glib::Dispatcher async_print_dispatcher;
Glib::Dispatcher async_print_on_line_dispatcher;
std::vector<std::pair<std::string, bool> > async_print_strings;
std::vector<std::pair<int, std::string> > async_print_on_line_strings;
std::mutex async_print_strings_mutex;
std::mutex async_print_on_line_strings_mutex;
Glib::RefPtr<Gtk::TextTag> bold_tag;
std::mutex async_executes_mutex;
#ifdef _WIN32
std::list<std::pair<void*, void*> > async_executes;
#else
std::list<std::pair<pid_t, int> > async_executes;
#endif
std::string stdin_buffer;
size_t deleted_lines=0;
};
#endif // JUCI_TERMINAL_H_