Browse Source

Added colors to terminal warnings and errors

pipelines/235045657
eidheim 5 years ago
parent
commit
7bf9752200
  1. 4
      src/cmake.cpp
  2. 2
      src/config.cpp
  3. 22
      src/directories.cpp
  4. 4
      src/juci.cpp
  5. 4
      src/meson.cpp
  6. 4
      src/notebook.cpp
  7. 16
      src/project.cpp
  8. 4
      src/snippets.cpp
  9. 8
      src/source.cpp
  10. 6
      src/source_base.cpp
  11. 6
      src/source_clang.cpp
  12. 2
      src/source_generic.cpp
  13. 2
      src/source_language_protocol.cpp
  14. 6
      src/terminal.cpp
  15. 34
      src/window.cpp

4
src/cmake.cpp

@ -51,7 +51,7 @@ bool CMake::update_default_build(const boost::filesystem::path &default_build_pa
boost::system::error_code ec; boost::system::error_code ec;
boost::filesystem::create_directories(default_build_path, ec); boost::filesystem::create_directories(default_build_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not create " + default_build_path.string() + ": " + ec.message() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not create " + default_build_path.string() + ": " + ec.message() + "\n", true);
return false; return false;
} }
} }
@ -112,7 +112,7 @@ bool CMake::update_debug_build(const boost::filesystem::path &debug_build_path,
boost::system::error_code ec; boost::system::error_code ec;
boost::filesystem::create_directories(debug_build_path, ec); boost::filesystem::create_directories(debug_build_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not create " + debug_build_path.string() + ": " + ec.message() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not create " + debug_build_path.string() + ": " + ec.message() + "\n", true);
return false; return false;
} }
} }

2
src/config.cpp

@ -44,7 +44,7 @@ void Config::load() {
} }
catch(const std::exception &e) { catch(const std::exception &e) {
dispatcher.post([config_json = std::move(config_json), e_what = std::string(e.what())] { dispatcher.post([config_json = std::move(config_json), e_what = std::string(e.what())] {
::Terminal::get().print("Error: could not parse " + config_json.string() + ": " + e_what + "\n", true); ::Terminal::get().print("\e[31mError\e[m: could not parse " + config_json.string() + ": " + e_what + "\n", true);
}); });
std::stringstream ss; std::stringstream ss;
ss << default_config_file; ss << default_config_file;

22
src/directories.cpp

@ -56,7 +56,7 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::exists(target_path, ec)) { if(boost::filesystem::exists(target_path, ec)) {
Terminal::get().print("Error: could not move file: " + target_path.string() + " already exists\n", true); Terminal::get().print("\e[31mError\e[m: could not move file: " + target_path.string() + " already exists\n", true);
return false; return false;
} }
@ -66,7 +66,7 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat
boost::filesystem::rename(source_path, target_path, ec); boost::filesystem::rename(source_path, target_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not move file: " + ec.message() + '\n', true); Terminal::get().print("\e[31mError\e[m: could not move file: " + ec.message() + '\n', true);
return false; return false;
} }
@ -287,12 +287,12 @@ Directories::Directories() : Gtk::ListViewText(1) {
on_save_file(target_path); on_save_file(target_path);
} }
else { else {
Terminal::get().print("Error: could not create " + target_path.string() + '\n', true); Terminal::get().print("\e[31mError\e[m: could not create " + target_path.string() + '\n', true);
return; return;
} }
} }
else { else {
Terminal::get().print("Error: could not create " + target_path.string() + ": already exists\n", true); Terminal::get().print("\e[31mError\e[m: could not create " + target_path.string() + ": already exists\n", true);
return; return;
} }
@ -331,12 +331,12 @@ Directories::Directories() : Gtk::ListViewText(1) {
select(target_path); select(target_path);
} }
else { else {
Terminal::get().print("Error: could not create " + target_path.string() + ": " + ec.message(), true); Terminal::get().print("\e[31mError\e[m: could not create " + target_path.string() + ": " + ec.message(), true);
return; return;
} }
} }
else { else {
Terminal::get().print("Error: could not create " + target_path.string() + ": already exists\n", true); Terminal::get().print("\e[31mError\e[m: could not create " + target_path.string() + ": already exists\n", true);
return; return;
} }
@ -372,7 +372,7 @@ Directories::Directories() : Gtk::ListViewText(1) {
auto target_path = source_path.parent_path() / content; auto target_path = source_path.parent_path() / content;
if(boost::filesystem::exists(target_path, ec)) { if(boost::filesystem::exists(target_path, ec)) {
Terminal::get().print("Error: could not rename to " + target_path.string() + ": already exists\n", true); Terminal::get().print("\e[31mError\e[m: could not rename to " + target_path.string() + ": already exists\n", true);
return; return;
} }
@ -381,7 +381,7 @@ Directories::Directories() : Gtk::ListViewText(1) {
boost::filesystem::rename(source_path, target_path, ec); boost::filesystem::rename(source_path, target_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not rename " + source_path.string() + ": " + ec.message() + '\n', true); Terminal::get().print("\e[31mError\e[m: could not rename " + source_path.string() + ": " + ec.message() + '\n', true);
return; return;
} }
update(); update();
@ -412,7 +412,7 @@ Directories::Directories() : Gtk::ListViewText(1) {
if(view->language) if(view->language)
new_language_id = view->language->get_id(); new_language_id = view->language->get_id();
if(new_language_id != old_language_id) if(new_language_id != old_language_id)
Terminal::get().print("Warning: language for " + target_path.string() + " has changed. Please reopen the file\n"); Terminal::get().print("\e[33mWarning\e[m: language for " + target_path.string() + " has changed. Please reopen the file\n");
} }
} }
@ -448,7 +448,7 @@ Directories::Directories() : Gtk::ListViewText(1) {
boost::filesystem::remove_all(menu_popup_row_path, ec); boost::filesystem::remove_all(menu_popup_row_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not delete " + menu_popup_row_path.string() + ": " + ec.message() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not delete " + menu_popup_row_path.string() + ": " + ec.message() + "\n", true);
return; return;
} }
@ -495,7 +495,7 @@ Directories::~Directories() {
void Directories::open(const boost::filesystem::path &dir_path) { void Directories::open(const boost::filesystem::path &dir_path) {
boost::system::error_code ec; boost::system::error_code ec;
if(dir_path.empty() || !boost::filesystem::is_directory(dir_path, ec)) { if(dir_path.empty() || !boost::filesystem::is_directory(dir_path, ec)) {
Terminal::get().print("Error: could not open " + dir_path.string() + '\n', true); Terminal::get().print("\e[31mError\e[m: could not open " + dir_path.string() + '\n', true);
return; return;
} }

4
src/juci.cpp

@ -27,7 +27,7 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
boost::system::error_code current_path_ec; boost::system::error_code current_path_ec;
auto current_path = boost::filesystem::current_path(current_path_ec); auto current_path = boost::filesystem::current_path(current_path_ec);
if(current_path_ec) if(current_path_ec)
errors.emplace_back("Error: could not find current path\n"); errors.emplace_back("\e[31mError\e[m: could not find current path\n");
for(int c = 1; c < argc; c++) { for(int c = 1; c < argc; c++) {
boost::filesystem::path path(argv[c]); boost::filesystem::path path(argv[c]);
if(path.is_relative() && !current_path_ec) if(path.is_relative() && !current_path_ec)
@ -44,7 +44,7 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
if(path.is_absolute() && boost::filesystem::is_directory(path.parent_path(), ec)) if(path.is_absolute() && boost::filesystem::is_directory(path.parent_path(), ec))
files.emplace_back(path, 0); files.emplace_back(path, 0);
else else
errors.emplace_back("Error: could not create " + path.string() + ".\n"); errors.emplace_back("\e[31mError\e[m: could not create " + path.string() + ".\n");
} }
} }
} }

4
src/meson.cpp

@ -50,7 +50,7 @@ bool Meson::update_default_build(const boost::filesystem::path &default_build_pa
boost::system::error_code ec; boost::system::error_code ec;
boost::filesystem::create_directories(default_build_path, ec); boost::filesystem::create_directories(default_build_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not create " + default_build_path.string() + ": " + ec.message() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not create " + default_build_path.string() + ": " + ec.message() + "\n", true);
return false; return false;
} }
} }
@ -93,7 +93,7 @@ bool Meson::update_debug_build(const boost::filesystem::path &debug_build_path,
boost::system::error_code ec; boost::system::error_code ec;
boost::filesystem::create_directories(debug_build_path, ec); boost::filesystem::create_directories(debug_build_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not create " + debug_build_path.string() + ": " + ec.message() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not create " + debug_build_path.string() + ": " + ec.message() + "\n", true);
return false; return false;
} }
} }

4
src/notebook.cpp

@ -117,7 +117,7 @@ bool Notebook::open(Source::View *view) {
bool Notebook::open(const boost::filesystem::path &file_path_, Position position) { bool Notebook::open(const boost::filesystem::path &file_path_, Position position) {
boost::system::error_code ec; boost::system::error_code ec;
if(file_path_.empty() || (boost::filesystem::exists(file_path_, ec) && !boost::filesystem::is_regular_file(file_path_, ec))) { if(file_path_.empty() || (boost::filesystem::exists(file_path_, ec) && !boost::filesystem::is_regular_file(file_path_, ec))) {
Terminal::get().print("Error: could not open " + file_path_.string() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not open " + file_path_.string() + "\n", true);
return false; return false;
} }
@ -147,7 +147,7 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position
if(boost::filesystem::exists(file_path, ec)) { if(boost::filesystem::exists(file_path, ec)) {
std::ifstream can_read(file_path.string()); std::ifstream can_read(file_path.string());
if(!can_read) { if(!can_read) {
Terminal::get().print("Error: could not open " + file_path.string() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not open " + file_path.string() + "\n", true);
return false; return false;
} }
can_read.close(); can_read.close();

16
src/project.cpp

@ -363,11 +363,11 @@ void Project::LLDB::debug_start() {
*run_arguments = build->get_executable(view ? view->file_path : Directories::get().path).string(); *run_arguments = build->get_executable(view ? view->file_path : Directories::get().path).string();
if(run_arguments->empty()) { if(run_arguments->empty()) {
if(build->is_valid()) { if(build->is_valid()) {
Terminal::get().print("Warning: could not find executable.\n"); Terminal::get().print("\e[33mWarning\e[m: could not find executable.\n");
Terminal::get().print("Solution: either use Project Set Run Arguments, or open a source file within a directory where an executable is defined.\n"); Terminal::get().print("\e[32mSolution\e[m: either use Project Set Run Arguments, or open a source file within a directory where an executable is defined.\n");
} }
else else
Terminal::get().print("Error: build folder no longer valid, please rebuild project.\n", true); Terminal::get().print("\e[31mError\e[m: build folder no longer valid, please rebuild project.\n", true);
return; return;
} }
size_t pos = run_arguments->find(default_build_path.string()); size_t pos = run_arguments->find(default_build_path.string());
@ -875,11 +875,11 @@ void Project::Clang::compile_and_run() {
auto executable = build->get_executable(view ? view->file_path : Directories::get().path); auto executable = build->get_executable(view ? view->file_path : Directories::get().path);
if(executable.empty()) { if(executable.empty()) {
if(build->is_valid()) { if(build->is_valid()) {
Terminal::get().print("Warning: could not find executable.\n"); Terminal::get().print("\e[33mWarning\e[m: could not find executable.\n");
Terminal::get().print("Solution: either use Project Set Run Arguments, or open a source file within a directory where an executable is defined.\n"); Terminal::get().print("\e[32mSolution\e[m: either use Project Set Run Arguments, or open a source file within a directory where an executable is defined.\n");
} }
else else
Terminal::get().print("Error: build folder no longer valid, please rebuild project.\n", true); Terminal::get().print("\e[31mError\e[m: build folder no longer valid, please rebuild project.\n", true);
return; return;
} }
arguments = filesystem::escape_argument(filesystem::get_short_path(executable).string()); arguments = filesystem::escape_argument(filesystem::get_short_path(executable).string());
@ -945,7 +945,7 @@ void Project::Clang::recreate_build() {
} }
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Terminal::get().print(std::string("Error: could not remove build: ") + e.what() + "\n", true); Terminal::get().print(std::string("\e[31mError\e[m: could not remove build: ") + e.what() + "\n", true);
return; return;
} }
} }
@ -974,7 +974,7 @@ void Project::Markdown::compile_and_run() {
auto command = Config::get().project.markdown_command + ' ' + filesystem::escape_argument(filesystem::get_short_path(view->file_path).string()); auto command = Config::get().project.markdown_command + ' ' + filesystem::escape_argument(filesystem::get_short_path(view->file_path).string());
Terminal::get().async_process(command, "", [command](int exit_status) { Terminal::get().async_process(command, "", [command](int exit_status) {
if(exit_status == 127) if(exit_status == 127)
Terminal::get().async_print("Error: executable not found: " + command + "\n", true); Terminal::get().async_print("\e[31mError\e[m: executable not found: " + command + "\n", true);
}, true); }, true);
} }
} }

4
src/snippets.cpp

@ -34,13 +34,13 @@ void Snippets::load() {
if(!key_string.empty()) { if(!key_string.empty()) {
gtk_accelerator_parse(key_string.c_str(), &key, &modifier); gtk_accelerator_parse(key_string.c_str(), &key, &modifier);
if(key == 0 && modifier == 0) if(key == 0 && modifier == 0)
Terminal::get().async_print("Error: could not parse key string: " + key_string + "\n", true); Terminal::get().async_print("\e[31mError\e[m: could not parse key string: " + key_string + "\n", true);
} }
snippets.back().second.emplace_back(Snippet{snippet_it->second.get<std::string>("prefix", ""), key, modifier, snippet_it->second.get<std::string>("body"), snippet_it->second.get<std::string>("description", "")}); snippets.back().second.emplace_back(Snippet{snippet_it->second.get<std::string>("prefix", ""), key, modifier, snippet_it->second.get<std::string>("body"), snippet_it->second.get<std::string>("description", "")});
} }
} }
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Terminal::get().async_print(std::string("Error: ") + e.what() + "\n", true); Terminal::get().async_print(std::string("\e[31mError\e[m: ") + e.what() + "\n", true);
} }
} }

8
src/source.cpp

@ -317,13 +317,13 @@ Source::View::View(const boost::filesystem::path &file_path, const Glib::RefPtr<
use_tmp_file = true; use_tmp_file = true;
file_path = boost::filesystem::temp_directory_path(ec); file_path = boost::filesystem::temp_directory_path(ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not get temporary directory folder\n", true); Terminal::get().print("\e[31mError\e[m: could not get temporary directory folder\n", true);
return methods; return methods;
} }
file_path /= "jucipp_get_methods" + std::to_string(get_current_process_id()); file_path /= "jucipp_get_methods" + std::to_string(get_current_process_id());
boost::filesystem::create_directory(file_path, ec); boost::filesystem::create_directory(file_path, ec);
if(ec) { if(ec) {
Terminal::get().print("Error: could not create temporary folder\n", true); Terminal::get().print("\e[31mError\e[m: could not create temporary folder\n", true);
return methods; return methods;
} }
file_path /= this->file_path.filename().string() + (is_cpp_standard_header ? ".hpp" : ""); file_path /= this->file_path.filename().string() + (is_cpp_standard_header ? ".hpp" : "");
@ -411,7 +411,7 @@ bool Source::View::save() {
} }
} }
catch(const Glib::Error &error) { catch(const Glib::Error &error) {
Terminal::get().print("Error: Could not save file " + filesystem::get_short_path(file_path).string() + ": " + error.what() + '\n', true); Terminal::get().print("\e[31mError\e[m: Could not save file " + filesystem::get_short_path(file_path).string() + ": " + error.what() + '\n', true);
return false; return false;
} }
@ -942,7 +942,7 @@ void Source::View::setup_format_style(bool is_generic_view) {
} }
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Terminal::get().print(std::string("Error: error parsing clang-format output: ") + e.what() + '\n', true); Terminal::get().print(std::string("\e[31mError\e[m: error parsing clang-format output: ") + e.what() + '\n', true);
} }
get_buffer()->end_user_action(); get_buffer()->end_user_action();
} }

6
src/source_base.cpp

@ -246,7 +246,7 @@ bool Source::BaseView::load(bool not_undoable_action) {
} }
} }
catch(const Glib::Error &error) { catch(const Glib::Error &error) {
Terminal::get().print("Error: Could not read file " + filesystem::get_short_path(file_path).string() + ": " + error.what() + '\n', true); Terminal::get().print("\e[31mError\e[m: Could not read file " + filesystem::get_short_path(file_path).string() + ": " + error.what() + '\n', true);
return false; return false;
} }
} }
@ -316,7 +316,7 @@ void Source::BaseView::replace_text(const std::string &new_text) {
} }
} }
catch(...) { catch(...) {
Terminal::get().print("Error: Could not replace text in buffer\n", true); Terminal::get().print("\e[31mError\e[m: Could not replace text in buffer\n", true);
} }
get_buffer()->end_user_action(); get_buffer()->end_user_action();
@ -1542,7 +1542,7 @@ void Source::BaseView::insert_snippet(Gtk::TextIter iter, const std::string &sni
parse_snippet(false); parse_snippet(false);
} }
catch(...) { catch(...) {
Terminal::get().print("Error: could not parse snippet: " + snippet + '\n', true); Terminal::get().print("\e[31mError\e[m: could not parse snippet: " + snippet + '\n', true);
return; return;
} }

6
src/source_clang.cpp

@ -196,7 +196,7 @@ void Source::ClangViewParse::parse_initialize() {
parse_state = ParseState::stop; parse_state = ParseState::stop;
parse_mutex.unlock(); parse_mutex.unlock();
dispatcher.post([this] { dispatcher.post([this] {
Terminal::get().print("Error: failed to reparse " + this->file_path.string() + ".\n", true); Terminal::get().print("\e[31mError\e[m: failed to reparse " + this->file_path.string() + ".\n", true);
status_state = ""; status_state = "";
if(update_status_state) if(update_status_state)
update_status_state(this); update_status_state(this);
@ -911,7 +911,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
}; };
autocomplete.on_add_rows_error = [this] { autocomplete.on_add_rows_error = [this] {
Terminal::get().print("Error: autocomplete failed, reparsing " + this->file_path.string() + '\n', true); Terminal::get().print("\e[31mError\e[m: autocomplete failed, reparsing " + this->file_path.string() + '\n', true);
selected_completion_string = nullptr; selected_completion_string = nullptr;
code_complete_results = nullptr; code_complete_results = nullptr;
full_reparse(); full_reparse();
@ -1253,7 +1253,7 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file
usages_renamed.emplace_back(&usage); usages_renamed.emplace_back(&usage);
} }
else else
Terminal::get().print("Error: could not write to file " + usage.path.string() + '\n', true); Terminal::get().print("\e[31mError\e[m: could not write to file " + usage.path.string() + '\n', true);
} }
} }

2
src/source_generic.cpp

@ -31,7 +31,7 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const
boost::property_tree::xml_parser::read_xml(language_file.string(), pt); boost::property_tree::xml_parser::read_xml(language_file.string(), pt);
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Terminal::get().print("Error: error parsing language file " + language_file.string() + ": " + e.what() + '\n', true); Terminal::get().print("\e[31mError\e[m: error parsing language file " + language_file.string() + ": " + e.what() + '\n', true);
} }
bool has_context_class = false; bool has_context_class = false;
parse_language_file(has_context_class, pt); parse_language_file(has_context_class, pt);

2
src/source_language_protocol.cpp

@ -861,7 +861,7 @@ void Source::LanguageProtocolView::setup_navigation_and_refactoring() {
changes_renamed.emplace_back(change); changes_renamed.emplace_back(change);
} }
else else
Terminal::get().print("Error: could not write to file " + change->file + '\n', true); Terminal::get().print("\e[31mError\e[m: could not write to file " + change->file + '\n', true);
} }
for(auto &pair : changes_in_opened_files) { for(auto &pair : changes_in_opened_files) {

6
src/terminal.cpp

@ -209,7 +209,7 @@ int Terminal::process(const std::string &command, const boost::filesystem::path
process = std::make_unique<TinyProcessLib::Process>(command, path.string()); process = std::make_unique<TinyProcessLib::Process>(command, path.string());
if(process->get_id() <= 0) { if(process->get_id() <= 0) {
async_print("Error: failed to run command: " + command + "\n", true); async_print("\e[31mError\e[m: failed to run command: " + command + "\n", true);
return -1; return -1;
} }
@ -235,7 +235,7 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c
}, true); }, true);
if(process.get_id() <= 0) { if(process.get_id() <= 0) {
async_print("Error: failed to run command: " + command + "\n", true); async_print("\e[31mError\e[m: failed to run command: " + command + "\n", true);
return -1; return -1;
} }
@ -282,7 +282,7 @@ std::shared_ptr<TinyProcessLib::Process> Terminal::async_process(const std::stri
auto pid = process->get_id(); auto pid = process->get_id();
if(pid <= 0) { if(pid <= 0) {
async_print("Error: failed to run command: " + command + "\n", true); async_print("\e[31mError\e[m: failed to run command: " + command + "\n", true);
if(callback) if(callback)
callback(-1); callback(-1);
return process; return process;

34
src/window.cpp

@ -234,7 +234,7 @@ void Window::configure() {
get_style_context()->add_provider_for_screen(screen, css_provider_fonts, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); get_style_context()->add_provider_for_screen(screen, css_provider_fonts, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} }
catch(const Gtk::CssProviderError &e) { catch(const Gtk::CssProviderError &e) {
Terminal::get().print("Error: could not override fonts: " + e.what() + '\n', true); Terminal::get().print("\e[31mError\e[m: could not override fonts: " + e.what() + '\n', true);
} }
} }
@ -249,7 +249,7 @@ void Window::configure() {
if(scheme) if(scheme)
style = scheme->get_style("def:note"); style = scheme->get_style("def:note");
else { else {
Terminal::get().print("Error: Could not find gtksourceview style: " + Config::get().source.style + '\n', true); Terminal::get().print("\e[31mError\e[m: Could not find gtksourceview style: " + Config::get().source.style + '\n', true);
} }
} }
auto foreground_value = style && style->property_foreground_set() ? style->property_foreground().get_value() : get_style_context()->get_color().to_string(); auto foreground_value = style && style->property_foreground_set() ? style->property_foreground().get_value() : get_style_context()->get_color().to_string();
@ -292,7 +292,7 @@ void Window::set_menu_actions() {
if(!path.empty()) { if(!path.empty()) {
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::exists(path, ec)) { if(boost::filesystem::exists(path, ec)) {
Terminal::get().print("Error: " + path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + path.string() + " already exists.\n", true);
} }
else { else {
if(filesystem::write(path)) { if(filesystem::write(path)) {
@ -304,7 +304,7 @@ void Window::set_menu_actions() {
Terminal::get().print("New file " + path.string() + " created.\n"); Terminal::get().print("New file " + path.string() + " created.\n");
} }
else else
Terminal::get().print("Error: could not create new file " + path.string() + ".\n", true); Terminal::get().print("\e[31mError\e[m: could not create new file " + path.string() + ".\n", true);
} }
} }
}); });
@ -322,7 +322,7 @@ void Window::set_menu_actions() {
Terminal::get().print("New folder " + path.string() + " created.\n"); Terminal::get().print("New folder " + path.string() + " created.\n");
} }
else else
Terminal::get().print("Error: " + path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + path.string() + " already exists.\n", true);
Directories::get().select(path); Directories::get().select(path);
} }
}); });
@ -346,22 +346,22 @@ void Window::set_menu_actions() {
build_config = "project('" + project_name + "', 'c')\n\nadd_project_arguments('-std=c11', '-Wall', '-Wextra', language: 'c')\n\nexecutable('" + project_name + "', 'main.c')\n"; build_config = "project('" + project_name + "', 'c')\n\nadd_project_arguments('-std=c11', '-Wall', '-Wextra', language: 'c')\n\nexecutable('" + project_name + "', 'main.c')\n";
} }
else { else {
Terminal::get().print("Error: build management system " + Config::get().project.default_build_management_system + " not supported.\n", true); Terminal::get().print("\e[31mError\e[m: build management system " + Config::get().project.default_build_management_system + " not supported.\n", true);
return; return;
} }
auto c_main_path = project_path / "main.c"; auto c_main_path = project_path / "main.c";
auto clang_format_path = project_path / ".clang-format"; auto clang_format_path = project_path / ".clang-format";
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::exists(build_config_path, ec)) { if(boost::filesystem::exists(build_config_path, ec)) {
Terminal::get().print("Error: " + build_config_path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + build_config_path.string() + " already exists.\n", true);
return; return;
} }
if(boost::filesystem::exists(c_main_path, ec)) { if(boost::filesystem::exists(c_main_path, ec)) {
Terminal::get().print("Error: " + c_main_path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + c_main_path.string() + " already exists.\n", true);
return; return;
} }
if(boost::filesystem::exists(clang_format_path, ec)) { if(boost::filesystem::exists(clang_format_path, ec)) {
Terminal::get().print("Error: " + clang_format_path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + clang_format_path.string() + " already exists.\n", true);
return; return;
} }
std::string c_main = "#include <stdio.h>\n\nint main() {\n printf(\"Hello World!\\n\");\n}\n"; std::string c_main = "#include <stdio.h>\n\nint main() {\n printf(\"Hello World!\\n\");\n}\n";
@ -373,7 +373,7 @@ void Window::set_menu_actions() {
Terminal::get().print("C project " + project_name + " created.\n"); Terminal::get().print("C project " + project_name + " created.\n");
} }
else else
Terminal::get().print("Error: Could not create project " + project_path.string() + "\n", true); Terminal::get().print("\e[31mError\e[m: Could not create project " + project_path.string() + "\n", true);
} }
}); });
menu.add_action("file_new_project_cpp", []() { menu.add_action("file_new_project_cpp", []() {
@ -396,22 +396,22 @@ void Window::set_menu_actions() {
build_config = "project('" + project_name + "', 'cpp')\n\nadd_project_arguments('-std=c++1y', '-Wall', '-Wextra', language: 'cpp')\n\nexecutable('" + project_name + "', 'main.cpp')\n"; build_config = "project('" + project_name + "', 'cpp')\n\nadd_project_arguments('-std=c++1y', '-Wall', '-Wextra', language: 'cpp')\n\nexecutable('" + project_name + "', 'main.cpp')\n";
} }
else { else {
Terminal::get().print("Error: build management system " + Config::get().project.default_build_management_system + " not supported.\n", true); Terminal::get().print("\e[31mError\e[m: build management system " + Config::get().project.default_build_management_system + " not supported.\n", true);
return; return;
} }
auto cpp_main_path = project_path / "main.cpp"; auto cpp_main_path = project_path / "main.cpp";
auto clang_format_path = project_path / ".clang-format"; auto clang_format_path = project_path / ".clang-format";
boost::system::error_code ec; boost::system::error_code ec;
if(boost::filesystem::exists(build_config_path, ec)) { if(boost::filesystem::exists(build_config_path, ec)) {
Terminal::get().print("Error: " + build_config_path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + build_config_path.string() + " already exists.\n", true);
return; return;
} }
if(boost::filesystem::exists(cpp_main_path, ec)) { if(boost::filesystem::exists(cpp_main_path, ec)) {
Terminal::get().print("Error: " + cpp_main_path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + cpp_main_path.string() + " already exists.\n", true);
return; return;
} }
if(boost::filesystem::exists(clang_format_path, ec)) { if(boost::filesystem::exists(clang_format_path, ec)) {
Terminal::get().print("Error: " + clang_format_path.string() + " already exists.\n", true); Terminal::get().print("\e[31mError\e[m: " + clang_format_path.string() + " already exists.\n", true);
return; return;
} }
std::string cpp_main = "#include <iostream>\n\nint main() {\n std::cout << \"Hello World!\\n\";\n}\n"; std::string cpp_main = "#include <iostream>\n\nint main() {\n std::cout << \"Hello World!\\n\";\n}\n";
@ -423,7 +423,7 @@ void Window::set_menu_actions() {
Terminal::get().print("C++ project " + project_name + " created.\n"); Terminal::get().print("C++ project " + project_name + " created.\n");
} }
else else
Terminal::get().print("Error: Could not create project " + project_path.string() + "\n", true); Terminal::get().print("\e[31mError\e[m: Could not create project " + project_path.string() + "\n", true);
} }
}); });
@ -447,13 +447,13 @@ void Window::set_menu_actions() {
if(boost::filesystem::exists(view->file_path, ec)) { if(boost::filesystem::exists(view->file_path, ec)) {
std::ifstream can_read(view->file_path.string()); std::ifstream can_read(view->file_path.string());
if(!can_read) { if(!can_read) {
Terminal::get().print("Error: could not read " + view->file_path.string() + "\n", true); Terminal::get().print("\e[31mError\e[m: could not read " + view->file_path.string() + "\n", true);
return; return;
} }
can_read.close(); can_read.close();
} }
else { else {
Terminal::get().print("Error: " + view->file_path.string() + " does not exist\n", true); Terminal::get().print("\e[31mError\e[m: " + view->file_path.string() + " does not exist\n", true);
return; return;
} }

Loading…
Cancel
Save