Browse Source

Merge pull request #180 from eidheim/suggestion-terminal-and-fonts

Terminal and fonts
merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
105678a7aa
  1. 40
      src/config.cc
  2. 5
      src/config.h
  3. 11
      src/files.h
  4. 9
      src/project.cc
  5. 1
      src/source.cc
  6. 58
      src/terminal.cc
  7. 13
      src/terminal.h
  8. 1
      src/window.cc

40
src/config.cc

@ -97,18 +97,22 @@ void Config::retrieve_config() {
window.version = cfg.get<std::string>("version");
window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")};
project.save_on_compile_or_run=cfg.get<bool>("project.save_on_compile_or_run");
project.default_build_path=cfg.get<std::string>("project.default_build_path");
project.debug_build_path=cfg.get<std::string>("project.debug_build_path");
project.make_command=cfg.get<std::string>("project.make_command");
project.cmake_command=cfg.get<std::string>("project.cmake_command");
project.save_on_compile_or_run=cfg.get<bool>("project.save_on_compile_or_run");
project.clear_terminal_on_compile=cfg.get<bool>("project.clear_terminal_on_compile");
terminal.history_size=cfg.get<int>("terminal_history_size");
terminal.history_size=cfg.get<int>("terminal.history_size");
terminal.font=cfg.get<std::string>("terminal.font");
terminal.clang_format_command="clang-format";
#ifdef __linux
if(terminal.clang_format_command=="clang-format" &&
!boost::filesystem::exists("/usr/bin/clang-format") && !boost::filesystem::exists("/usr/local/bin/clang-format")) {
if(boost::filesystem::exists("/usr/bin/clang-format-3.7"))
if(boost::filesystem::exists("/usr/bin/clang-format-3.8"))
terminal.clang_format_command="/usr/bin/clang-format-3.8";
else if(boost::filesystem::exists("/usr/bin/clang-format-3.7"))
terminal.clang_format_command="/usr/bin/clang-format-3.7";
else if(boost::filesystem::exists("/usr/bin/clang-format-3.6"))
terminal.clang_format_command="/usr/bin/clang-format-3.6";
@ -118,10 +122,10 @@ void Config::retrieve_config() {
#endif
}
bool Config::check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path) {
bool Config::add_missing_nodes(const boost::property_tree::ptree &default_cfg, std::string parent_path) {
if(parent_path.size()>0)
parent_path+=".";
bool exists=true;
bool unchanged=true;
for(auto &node: default_cfg) {
auto path=parent_path+node.first;
try {
@ -129,15 +133,29 @@ bool Config::check_config_file(const boost::property_tree::ptree &default_cfg, s
}
catch(const std::exception &e) {
cfg.add(path, node.second.data());
exists=false;
unchanged=false;
}
unchanged&=add_missing_nodes(node.second, path);
}
return unchanged;
}
bool Config::remove_deprecated_nodes(const boost::property_tree::ptree &default_cfg, boost::property_tree::ptree &config_cfg, std::string parent_path) {
if(parent_path.size()>0)
parent_path+=".";
bool unchanged=true;
for(auto &node: config_cfg) {
auto path=parent_path+node.first;
try {
exists&=check_config_file(node.second, path);
default_cfg.get<std::string>(path);
unchanged&=remove_deprecated_nodes(default_cfg, node.second, path);
}
catch(const std::exception &e) {
config_cfg.erase(node.first);
unchanged=false;
}
}
return exists;
return unchanged;
}
void Config::update_config_file() {
@ -159,10 +177,10 @@ void Config::update_config_file() {
std::cerr << "Error reading json-file: " << e.what() << std::endl;
cfg_ok=false;
}
cfg_ok&=check_config_file(default_cfg);
if(!cfg_ok) {
cfg_ok&=add_missing_nodes(default_cfg);
cfg_ok&=remove_deprecated_nodes(default_cfg, cfg);
if(!cfg_ok)
boost::property_tree::write_json((home/"config"/"config.json").string(), cfg);
}
}
void Config::get_source() {

5
src/config.h

@ -26,6 +26,7 @@ public:
public:
std::string clang_format_command;
int history_size;
std::string font;
#ifdef _WIN32
boost::filesystem::path msys2_mingw_path;
@ -39,6 +40,7 @@ public:
std::string cmake_command;
std::string make_command;
bool save_on_compile_or_run;
bool clear_terminal_on_compile;
};
class Source {
@ -90,7 +92,8 @@ public:
private:
void find_or_create_config_files();
void retrieve_config();
bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path="");
bool add_missing_nodes(const boost::property_tree::ptree &default_cfg, std::string parent_path="");
bool remove_deprecated_nodes(const boost::property_tree::ptree &default_cfg, boost::property_tree::ptree &config_cfg, std::string parent_path="");
void update_config_file();
void get_source();

11
src/files.h

@ -2,7 +2,7 @@
#define JUCI_FILES_H_
#include <string>
#define JUCI_VERSION "1.1.1"
#define JUCI_VERSION "1.1.2-rc1"
const std::string configjson =
"{\n"
@ -11,13 +11,17 @@ const std::string configjson =
" \"width\": 800,\n"
" \"height\": 600\n"
" },\n"
" \"terminal_history_size\": 1000,\n"
" \"gtk_theme\": {\n"
" \"name_comment\": \"Use \\\"\\\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\",\n"
" \"name\": \"Adwaita\",\n"
" \"variant_comment\": \"Use \\\"\\\" for default variant, and \\\"dark\\\" for dark theme variant\",\n"
" \"variant\": \"\"\n"
" },\n"
" \"terminal\": {\n"
" \"history_size\": 1000,\n"
" \"font_comment\": \"Use \\\"\\\" to use source.font with slightly smaller size\",\n"
" \"font\": \"\"\n"
" },\n"
" \"source\": {\n"
" \"style_comment\": \"Use \\\"\\\" for default style, and for instance juci-dark or juci-dark-blue together with dark gtk_theme variant. Styles from normal gtksourceview install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\",\n"
" \"style\": \"juci-light\",\n"
@ -130,7 +134,8 @@ const std::string configjson =
" \"cmake_command\": \"cmake\",\n"
#endif
" \"make_command\": \"cmake --build .\",\n"
" \"save_on_compile_or_run\": true\n"
" \"save_on_compile_or_run\": true,\n"
" \"clear_terminal_on_compile\": true\n"
" },\n"
" \"documentation_searches\": {\n"
" \"clang\": {\n"

9
src/project.cc

@ -167,6 +167,9 @@ void Project::Clang::compile() {
if(default_build_path.empty() || !build->update_default_build())
return;
if(Config::get().project.clear_terminal_on_compile)
Terminal::get().clear();
compiling=true;
Terminal::get().print("Compiling project "+build->project_path.string()+"\n");
Terminal::get().async_process(Config::get().project.make_command, default_build_path, [this](int exit_status) {
@ -199,6 +202,9 @@ void Project::Clang::compile_and_run() {
arguments=filesystem::escape_argument(arguments);
}
if(Config::get().project.clear_terminal_on_compile)
Terminal::get().clear();
compiling=true;
Terminal::get().print("Compiling and running "+arguments+"\n");
Terminal::get().async_process(Config::get().project.make_command, default_build_path, [this, arguments, project_path](int exit_status){
@ -278,6 +284,9 @@ void Project::Clang::debug_start() {
}
}
if(Config::get().project.clear_terminal_on_compile)
Terminal::get().clear();
debugging=true;
Terminal::get().print("Compiling and debugging "+run_arguments+"\n");
Terminal::get().async_process(Config::get().project.make_command, debug_build_path, [this, breakpoints, run_arguments, project_path](int exit_status){

1
src/source.cc

@ -284,7 +284,6 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
tab_str="<space>";
else
tab_str="<tab>";
Terminal::get().print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+std::to_string(tab_char_and_size.second)+".\n");
}
tab_char=tab_char_and_size.first;

58
src/terminal.cc

@ -9,7 +9,9 @@ Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
}
Terminal::InProgress::~InProgress() {
stop_mutex.lock();
stop=true;
stop_mutex.unlock();
if(wait_thread.joinable())
wait_thread.join();
}
@ -18,7 +20,14 @@ void Terminal::InProgress::start(const std::string& msg) {
line_nr=Terminal::get().print(msg+"...\n");
wait_thread=std::thread([this](){
size_t c=0;
while(!stop) {
while(true) {
stop_mutex.lock();
if(stop) {
stop_mutex.unlock();
break;
}
else
stop_mutex.unlock();
if(c%100==0)
Terminal::get().async_print(line_nr-1, ".");
std::this_thread::sleep_for(std::chrono::milliseconds(10));
@ -28,17 +37,25 @@ void Terminal::InProgress::start(const std::string& msg) {
}
void Terminal::InProgress::done(const std::string& msg) {
stop_mutex.lock();
if(!stop) {
stop=true;
stop_mutex.unlock();
Terminal::get().async_print(line_nr-1, msg);
}
else
stop_mutex.unlock();
}
void Terminal::InProgress::cancel(const std::string& msg) {
stop_mutex.lock();
if(!stop) {
stop=true;
stop_mutex.unlock();
Terminal::get().async_print(line_nr-1, msg);
}
else
stop_mutex.unlock();
}
Terminal::Terminal() {
@ -205,7 +222,14 @@ size_t Terminal::print(const std::string &message, bool bold){
}
std::shared_ptr<Terminal::InProgress> Terminal::print_in_progress(std::string start_msg) {
std::shared_ptr<Terminal::InProgress> in_progress=std::shared_ptr<Terminal::InProgress>(new Terminal::InProgress(start_msg));
auto in_progress=std::shared_ptr<Terminal::InProgress>(new Terminal::InProgress(start_msg), [this](Terminal::InProgress *in_progress) {
in_progresses_mutex.lock();
in_progresses.erase(in_progress);
in_progresses_mutex.unlock();
});
in_progresses_mutex.lock();
in_progresses.emplace(in_progress.get());
in_progresses_mutex.unlock();
return in_progress;
}
@ -234,6 +258,36 @@ void Terminal::async_print(size_t line_nr, const std::string &message) {
});
}
void Terminal::configure() {
if(Config::get().terminal.font.size()>0) {
override_font(Pango::FontDescription(Config::get().terminal.font));
}
else if(Config::get().source.font.size()>0) {
Pango::FontDescription font_description(Config::get().source.font);
auto font_description_size=font_description.get_size();
if(font_description_size==0) {
Pango::FontDescription default_font_description(Gtk::Settings::get_default()->property_gtk_font_name());
font_description_size=default_font_description.get_size();
}
if(font_description_size>0)
font_description.set_size(font_description_size*0.95);
override_font(font_description);
}
}
void Terminal::clear() {
in_progresses_mutex.lock();
for(auto &in_progress: in_progresses) {
in_progress->stop_mutex.lock();
in_progress->stop=true;
in_progress->stop_mutex.unlock();
}
in_progresses_mutex.unlock();
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
get_buffer()->set_text("");
}
bool Terminal::on_key_press_event(GdkEventKey *event) {
processes_mutex.lock();
bool debug_is_running=false;

13
src/terminal.h

@ -10,10 +10,12 @@
#include <iostream>
#include "process.hpp"
#include "dispatcher.h"
#include <unordered_set>
class Terminal : public Gtk::TextView {
public:
class InProgress {
friend class Terminal;
public:
InProgress(const std::string& start_msg);
~InProgress();
@ -22,7 +24,9 @@ public:
private:
void start(const std::string& msg);
size_t line_nr;
std::atomic<bool> stop;
bool stop;
std::mutex stop_mutex;
std::thread wait_thread;
};
@ -45,6 +49,10 @@ public:
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_key_press_event(GdkEventKey *event);
private:
@ -56,6 +64,9 @@ private:
std::string stdin_buffer;
size_t deleted_lines=0;
std::unordered_set<InProgress*> in_progresses;
std::mutex in_progresses_mutex;
};
#endif // JUCI_TERMINAL_H_

1
src/window.cc

@ -146,6 +146,7 @@ void Window::configure() {
style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
Directories::get().update();
Menu::get().set_keys();
Terminal::get().configure();
}
void Window::set_menu_actions() {

Loading…
Cancel
Save