From e67799eec39665b0937ca7dff93d40fa90e28d3c Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 8 Sep 2020 19:19:49 +0200 Subject: [PATCH] Added and made use of gray color in terminal. Also made all error messages red. --- src/debug_lldb.cpp | 16 ++++++++-------- src/directories.cpp | 2 +- src/project.cpp | 32 ++++++++++++++++---------------- src/source_diff.cpp | 2 +- src/source_language_protocol.cpp | 4 ++-- src/terminal.cpp | 12 +++++++++++- src/terminal.hpp | 2 +- src/window.cpp | 4 ++-- 8 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/debug_lldb.cpp b/src/debug_lldb.cpp index e9dd9d8..fcad197 100644 --- a/src/debug_lldb.cpp +++ b/src/debug_lldb.cpp @@ -131,7 +131,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat auto target = debugger->CreateTarget(executable.c_str()); if(!target.IsValid()) { - Terminal::get().async_print("Error (debug): Could not create debug target to: " + executable + '\n', true); + Terminal::get().async_print("\e[31mError (debug)\e[m: Could not create debug target to: " + executable + '\n', true); for(auto &handler : on_exit) handler(-1); return; @@ -140,7 +140,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat //Set breakpoints for(auto &breakpoint : breakpoints) { if(!(target.BreakpointCreateByLocation(breakpoint.first.string().c_str(), breakpoint.second)).IsValid()) { - Terminal::get().async_print("Error (debug): Could not create breakpoint at: " + breakpoint.first.string() + ":" + std::to_string(breakpoint.second) + '\n', true); + Terminal::get().async_print("\e[31mError (debug)\e[m: Could not create breakpoint at: " + breakpoint.first.string() + ":" + std::to_string(breakpoint.second) + '\n', true); for(auto &handler : on_exit) handler(-1); return; @@ -152,7 +152,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat auto connect_string = "connect://" + remote_host; process = std::make_unique(target.ConnectRemote(*listener, connect_string.c_str(), "gdb-remote", error)); if(error.Fail()) { - Terminal::get().async_print(std::string("Error (debug): ") + error.GetCString() + '\n', true); + Terminal::get().async_print(std::string("\e[31mError (debug)\e[m: ") + error.GetCString() + '\n', true); for(auto &handler : on_exit) handler(-1); return; @@ -197,7 +197,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat } if(error.Fail()) { - Terminal::get().async_print(std::string("Error (debug): ") + error.GetCString() + '\n', true); + Terminal::get().async_print(std::string("\e[31mError (debug)\e[m: ") + error.GetCString() + '\n', true); for(auto &handler : on_exit) handler(-1); return; @@ -279,7 +279,7 @@ void Debug::LLDB::stop() { if(state == lldb::StateType::eStateRunning) { auto error = process->Stop(); if(error.Fail()) - Terminal::get().async_print(std::string("Error (debug): ") + error.GetCString() + '\n', true); + Terminal::get().async_print(std::string("\e[31mError (debug)\e[m: ") + error.GetCString() + '\n', true); } } @@ -288,7 +288,7 @@ void Debug::LLDB::kill() { if(process) { auto error = process->Kill(); if(error.Fail()) - Terminal::get().async_print(std::string("Error (debug): ") + error.GetCString() + '\n', true); + Terminal::get().async_print(std::string("\e[31mError (debug)\e[m: ") + error.GetCString() + '\n', true); } } @@ -534,7 +534,7 @@ void Debug::LLDB::add_breakpoint(const boost::filesystem::path &file_path, int l LockGuard lock(mutex); if(state == lldb::eStateStopped || state == lldb::eStateRunning) { if(!(process->GetTarget().BreakpointCreateByLocation(file_path.string().c_str(), line_nr)).IsValid()) - Terminal::get().async_print("Error (debug): Could not create breakpoint at: " + file_path.string() + ":" + std::to_string(line_nr) + '\n', true); + Terminal::get().async_print("\e[31mError (debug)\e[m: Could not create breakpoint at: " + file_path.string() + ":" + std::to_string(line_nr) + '\n', true); } } @@ -553,7 +553,7 @@ void Debug::LLDB::remove_breakpoint(const boost::filesystem::path &file_path, in breakpoint_path /= file_spec.GetFilename(); if(breakpoint_path == file_path) { if(!target.BreakpointDelete(breakpoint.GetID())) - Terminal::get().async_print("Error (debug): Could not delete breakpoint at: " + file_path.string() + ":" + std::to_string(line_nr) + '\n', true); + Terminal::get().async_print("\e[31mError (debug)\e[m: Could not delete breakpoint at: " + file_path.string() + ":" + std::to_string(line_nr) + '\n', true); return; } } diff --git a/src/directories.cpp b/src/directories.cpp index d8353c0..e5396fb 100644 --- a/src/directories.cpp +++ b/src/directories.cpp @@ -801,7 +801,7 @@ void Directories::colorize_path(boost::filesystem::path dir_path_, bool include_ status = repository->get_status(); } catch(const std::exception &e) { - Terminal::get().async_print(std::string("Error (git): ") + e.what() + '\n', true); + Terminal::get().async_print(std::string("\e[31mError (git)\e[m: ") + e.what() + '\n', true); } dispatcher.post([this, dir_path, include_parent_paths, status = std::move(status)] { diff --git a/src/project.cpp b/src/project.cpp index a857541..3fe4c86 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -381,7 +381,7 @@ void Project::LLDB::debug_start() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Compiling and debugging " + *run_arguments + "\n"); + Terminal::get().print("\e[2mCompiling and debugging " + *run_arguments + "\e[m\n"); Terminal::get().async_process(build->get_compile_command(), debug_build_path, [self = this->shared_from_this(), run_arguments, project_path](int exit_status) { if(exit_status != EXIT_SUCCESS) debugging = false; @@ -409,7 +409,7 @@ void Project::LLDB::debug_start() { Debug::LLDB::get().on_exit.erase(on_exit_it); Debug::LLDB::get().on_exit.emplace_back([self, run_arguments](int exit_status) { debugging = false; - Terminal::get().async_print(*run_arguments + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + *run_arguments + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); self->dispatcher.post([] { debug_update_status(""); }); @@ -852,7 +852,7 @@ void Project::Clang::compile() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Compiling project " + filesystem::get_short_path(build->project_path).string() + "\n"); + Terminal::get().print("\e[2mCompiling project " + filesystem::get_short_path(build->project_path).string() + "\e[m\n"); Terminal::get().async_process(build->get_compile_command(), default_build_path, [](int exit_status) { compiling = false; }); @@ -890,12 +890,12 @@ void Project::Clang::compile_and_run() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Compiling and running " + arguments + "\n"); + Terminal::get().print("\e[2mCompiling and running " + arguments + "\e[m\n"); Terminal::get().async_process(build->get_compile_command(), default_build_path, [arguments, project_path](int exit_status) { compiling = false; - if(exit_status == EXIT_SUCCESS) { + if(exit_status == 0) { Terminal::get().async_process(arguments, project_path, [arguments](int exit_status) { - Terminal::get().async_print(arguments + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + arguments + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); }); } }); @@ -999,9 +999,9 @@ void Project::Python::compile_and_run() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Running " + command + "\n"); + Terminal::get().print("\e[2mRunning " + command + "\e[m\n"); Terminal::get().async_process(command, path, [command](int exit_status) { - Terminal::get().async_print(command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); }); } @@ -1025,9 +1025,9 @@ void Project::JavaScript::compile_and_run() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Running " + command + "\n"); + Terminal::get().print("\e[2mRunning " + command + "\e[m\n"); Terminal::get().async_process(command, path, [command](int exit_status) { - Terminal::get().async_print(command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); }); } @@ -1038,9 +1038,9 @@ void Project::HTML::compile_and_run() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Running " + command + "\n"); + Terminal::get().print("\e[2mRunning " + command + "\e[m\n"); Terminal::get().async_process(command, build->project_path, [command](int exit_status) { - Terminal::get().async_print(command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + command + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); }); } else if(auto view = Notebook::get().get_current_view()) @@ -1066,7 +1066,7 @@ void Project::Rust::compile() { if(Config::get().terminal.clear_on_compile) Terminal::get().clear(); - Terminal::get().print("Compiling project " + filesystem::get_short_path(build->project_path).string() + "\n"); + Terminal::get().print("\e[2mCompiling project " + filesystem::get_short_path(build->project_path).string() + "\e[m\n"); auto command = build->get_compile_command(); Terminal::get().async_process(command, build->project_path, [](int exit_status) { @@ -1081,14 +1081,14 @@ void Project::Rust::compile_and_run() { Terminal::get().clear(); auto arguments = get_run_arguments().second; - Terminal::get().print("Compiling and running " + arguments + "\n"); + Terminal::get().print("\e[2mCompiling and running " + arguments + "\e[m\n"); auto self = this->shared_from_this(); Terminal::get().async_process(build->get_compile_command(), build->project_path, [self, arguments = std::move(arguments)](int exit_status) { compiling = false; - if(exit_status == EXIT_SUCCESS) { + if(exit_status == 0) { Terminal::get().async_process(arguments, self->build->project_path, [arguments](int exit_status) { - Terminal::get().async_print(arguments + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + arguments + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); }); } }); diff --git a/src/source_diff.cpp b/src/source_diff.cpp index 3a55fb3..22f683a 100644 --- a/src/source_diff.cpp +++ b/src/source_diff.cpp @@ -263,7 +263,7 @@ void Source::DiffView::configure() { get_buffer()->remove_tag(renderer->tag_removed_below, get_buffer()->begin(), get_buffer()->end()); get_buffer()->remove_tag(renderer->tag_removed_above, get_buffer()->begin(), get_buffer()->end()); renderer->queue_draw(); - Terminal::get().print(std::string("Error (git): ") + e_what + '\n', true); + Terminal::get().print(std::string("\e[31mError (git)\e[m: ") + e_what + '\n', true); }); } }); diff --git a/src/source_language_protocol.cpp b/src/source_language_protocol.cpp index 8180274..cf49a3d 100644 --- a/src/source_language_protocol.cpp +++ b/src/source_language_protocol.cpp @@ -352,7 +352,7 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view, LockGuard lock(read_write_mutex); auto id_it = handlers.find(message_id); if(id_it != handlers.end()) { - Terminal::get().async_print("Request to language server timed out. If you suspect the server has crashed, please close and reopen all project source files.\n", true); + Terminal::get().async_print("\e[33mWarning\e[m: request to language server timed out. If you suspect the server has crashed, please close and reopen all project source files.\n", true); auto function = std::move(id_it->second.second); handlers.erase(id_it); lock.unlock(); @@ -366,7 +366,7 @@ void LanguageProtocol::Client::write_request(Source::LanguageProtocolView *view, if(Config::get().log.language_server) std::cout << "Language client: " << content << std::endl; if(!process->write(message)) { - Terminal::get().async_print("Error writing to language protocol server. Please close and reopen all project source files.\n", true); + Terminal::get().async_print("\e[31mError\e[m: could not write to language server. Please close and reopen all project files.\n", true); auto id_it = handlers.find(message_id - 1); if(id_it != handlers.end()) { auto function = std::move(id_it->second.second); diff --git a/src/terminal.cpp b/src/terminal.cpp index 332b602..c73c545 100644 --- a/src/terminal.cpp +++ b/src/terminal.cpp @@ -30,6 +30,7 @@ Terminal::Terminal() : Source::SearchView() { blue_tag = get_buffer()->create_tag(); magenta_tag = get_buffer()->create_tag(); cyan_tag = get_buffer()->create_tag(); + gray_tag = get_buffer()->create_tag(); link_mouse_cursor = Gdk::Cursor::create(Gdk::CursorType::HAND1); default_mouse_cursor = Gdk::Cursor::create(Gdk::CursorType::XTERM); @@ -158,7 +159,7 @@ Terminal::Terminal() : Source::SearchView() { } else if(code == 48 || code == 58) break; // Do not read next arguments - else if(code == 0 || (code >= 30 && code <= 37)) + else if(code == 0 || code == 2 || code == 22 || (code >= 30 && code <= 37)) color = code; } catch(...) { @@ -182,6 +183,8 @@ Terminal::Terminal() : Source::SearchView() { get_buffer()->apply_tag(magenta_tag, (*last_color_sequence_mark)->get_iter(), start); else if(last_color == 36) get_buffer()->apply_tag(cyan_tag, (*last_color_sequence_mark)->get_iter(), start); + else if(last_color == 37 || last_color == 2) + get_buffer()->apply_tag(gray_tag, (*last_color_sequence_mark)->get_iter(), start); } if(color >= 0) { @@ -490,6 +493,13 @@ void Terminal::configure() { rgba.set_blue(normal_color.get_blue() + factor * (rgba.get_blue() - normal_color.get_blue())); cyan_tag->property_foreground_rgba() = rgba; + rgba.set_rgba(0.5, 0.5, 0.5); + factor = light_theme ? 0.6 : 0.4; + rgba.set_red(normal_color.get_red() + factor * (rgba.get_red() - normal_color.get_red())); + rgba.set_green(normal_color.get_green() + factor * (rgba.get_green() - normal_color.get_green())); + rgba.set_blue(normal_color.get_blue() + factor * (rgba.get_blue() - normal_color.get_blue())); + gray_tag->property_foreground_rgba() = rgba; + // Set search match style: get_buffer()->get_tag_table()->foreach([](const Glib::RefPtr &tag) { if(tag->property_background_set()) { diff --git a/src/terminal.hpp b/src/terminal.hpp index 3781e72..41d0386 100644 --- a/src/terminal.hpp +++ b/src/terminal.hpp @@ -46,7 +46,7 @@ private: Glib::RefPtr bold_tag; Glib::RefPtr link_tag; Glib::RefPtr invisible_tag; - Glib::RefPtr red_tag, green_tag, yellow_tag, blue_tag, magenta_tag, cyan_tag; + Glib::RefPtr red_tag, green_tag, yellow_tag, blue_tag, magenta_tag, cyan_tag, gray_tag; Glib::RefPtr link_mouse_cursor; Glib::RefPtr default_mouse_cursor; diff --git a/src/window.cpp b/src/window.cpp index 3d69dcc..ed73397 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1383,10 +1383,10 @@ void Window::set_menu_actions() { auto directory_folder = Project::get_preferably_directory_folder(); if(Config::get().terminal.clear_on_run_command) Terminal::get().clear(); - Terminal::get().async_print("Running: " + content + '\n'); + Terminal::get().async_print("\e[2mRunning: " + content + "\e[m\n"); Terminal::get().async_process(content, directory_folder, [content](int exit_status) { - Terminal::get().async_print(content + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); + Terminal::get().async_print("\e[2m" + content + " returned: " + (exit_status == 0 ? "\e[32m" : "\e[31m") + std::to_string(exit_status) + "\e[m\n"); }); } EntryBox::get().hide();