diff options
author | David Robillard <d@drobilla.net> | 2016-08-01 03:43:23 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-08-01 03:44:00 -0400 |
commit | 902703efa9425a0630053c10229de911e23a2a43 (patch) | |
tree | 078b44cf205f8f7a3265142ff95b36f08f56fa05 | |
parent | ff6d8a87f9569a42c7827428f2329280c9b633b9 (diff) | |
download | ingen-902703efa9425a0630053c10229de911e23a2a43.tar.gz ingen-902703efa9425a0630053c10229de911e23a2a43.tar.bz2 ingen-902703efa9425a0630053c10229de911e23a2a43.zip |
Show colorized log output in messages window
-rw-r--r-- | ingen/Log.hpp | 5 | ||||
-rw-r--r-- | src/Log.cpp | 6 | ||||
-rw-r--r-- | src/gui/App.cpp | 16 | ||||
-rw-r--r-- | src/gui/MessagesWindow.cpp | 93 | ||||
-rw-r--r-- | src/gui/MessagesWindow.hpp | 23 | ||||
-rw-r--r-- | src/gui/ingen_gui.ui | 4 | ||||
-rw-r--r-- | wscript | 6 |
7 files changed, 133 insertions, 20 deletions
diff --git a/ingen/Log.hpp b/ingen/Log.hpp index a868e714..189754e2 100644 --- a/ingen/Log.hpp +++ b/ingen/Log.hpp @@ -17,6 +17,7 @@ #ifndef INGEN_LOG_HPP #define INGEN_LOG_HPP +#include <functional> #include <string> #include <boost/format.hpp> @@ -33,6 +34,8 @@ class URIs; class INGEN_API Log { public: + typedef std::function<int(LV2_URID, const char*, va_list)> Sink; + Log(LV2_Log_Log* log, URIs& uris); struct Feature : public LV2Features::Feature { @@ -60,12 +63,14 @@ public: void set_flush(bool f) { _flush = f; } void set_trace(bool f) { _trace = f; } + void set_sink(Sink s) { _sink = s; } private: void print(FILE* stream, const std::string& msg); LV2_Log_Log* _log; URIs& _uris; + Sink _sink; bool _flush; bool _trace; }; diff --git a/src/Log.cpp b/src/Log.cpp index b2d30b7d..46b88aec 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -98,7 +98,11 @@ int Log::vtprintf(LV2_URID type, const char* fmt, va_list args) { int ret = 0; - if (_log) { + if (type == _uris.log_Trace && !_trace) { + return 0; + } else if (_sink) { + ret = _sink(type, fmt, args); + } else if (_log) { ret = _log->vprintf(_log->handle, type, fmt, args); } else if (type == _uris.log_Error) { ColorContext ctx(stderr, ColorContext::Color::RED); diff --git a/src/gui/App.cpp b/src/gui/App.cpp index 2624d1e9..fad2f195 100644 --- a/src/gui/App.cpp +++ b/src/gui/App.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> + Copyright 2007-2016 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -91,6 +91,9 @@ App::App(Ingen::World* world) PluginModel::set_rdf_world(*world->rdf_world()); PluginModel::set_lilv_world(world->lilv_world()); + + using namespace std::placeholders; + world->log().set_sink(std::bind(&MessagesWindow::log, _messages_window, _1, _2, _3)); } App::~App() @@ -214,12 +217,7 @@ App::response(int32_t id, Status status, const std::string& subject) void App::error_message(const string& str) { - _messages_window->post(str); - - if (!_messages_window->is_visible()) - _messages_window->present(); - - _messages_window->set_urgency_hint(true); + _messages_window->post_error(str); } void @@ -321,6 +319,10 @@ App::gtk_main_iteration() if (!_client) return false; + if (_messages_window) { + _messages_window->flush(); + } + if (_world->engine()) { if (!_world->engine()->main_iteration()) { Gtk::Main::quit(); diff --git a/src/gui/MessagesWindow.cpp b/src/gui/MessagesWindow.cpp index 262cb817..fb29716c 100644 --- a/src/gui/MessagesWindow.cpp +++ b/src/gui/MessagesWindow.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> + Copyright 2007-2016 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -14,9 +14,13 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "MessagesWindow.hpp" #include <string> +#include "ingen/URIs.hpp" + +#include "App.hpp" +#include "MessagesWindow.hpp" + namespace Ingen { namespace GUI { using std::string; @@ -31,17 +35,96 @@ MessagesWindow::MessagesWindow(BaseObjectType* cobject, _clear_button->signal_clicked().connect(sigc::mem_fun(this, &MessagesWindow::clear_clicked)); _close_button->signal_clicked().connect(sigc::mem_fun(this, &Window::hide)); + + for (int s = Gtk::STATE_NORMAL; s <= Gtk::STATE_INSENSITIVE; ++s) { + _textview->modify_base((Gtk::StateType)s, Gdk::Color("#000000")); + _textview->modify_text((Gtk::StateType)s, Gdk::Color("#EEEEEC")); + } +} + +void +MessagesWindow::init_window(App& app) +{ + Glib::RefPtr<Gtk::TextTag> tag = Gtk::TextTag::create(); + tag->property_foreground() = "#EF2929"; + _tags.emplace(app.uris().log_Error, tag); + _error_tag = tag; + + tag = Gtk::TextTag::create(); + tag->property_foreground() = "#FCAF3E"; + _tags.emplace(app.uris().log_Warning, tag); + + tag = Gtk::TextTag::create(); + tag->property_foreground() = "#8AE234"; + _tags.emplace(app.uris().log_Trace, tag); + + for (const auto& t : _tags) { + _textview->get_buffer()->get_tag_table()->add(t.second); + } } void -MessagesWindow::post(const string& msg) +MessagesWindow::post_error(const string& msg) { Glib::RefPtr<Gtk::TextBuffer> text_buf = _textview->get_buffer(); - text_buf->insert(text_buf->end(), msg); + text_buf->insert_with_tag(text_buf->end(), msg, _error_tag); text_buf->insert(text_buf->end(), "\n"); - if (!_clear_button->is_sensitive()) + if (!_clear_button->is_sensitive()) { + _clear_button->set_sensitive(true); + } + + set_urgency_hint(true); + if (!is_visible()) { + present(); + } +} + +int +MessagesWindow::log(LV2_URID type, const char* fmt, va_list args) +{ + std::lock_guard<std::mutex> lock(_mutex); + +#ifdef HAVE_VASPRINTF + char* buf = NULL; + const int len = vasprintf(&buf, fmt, args); +#else + char* buf = g_strdup_vprintf(fmt, args); + const int len = strlen(buf); +#endif + + _stream << type << ' ' << buf << '\0'; + free(buf); + + return len; +} + +void +MessagesWindow::flush() +{ + LV2_URID type; + std::string line; + { + std::lock_guard<std::mutex> lock(_mutex); + if (!_stream.rdbuf()->in_avail()) { + return; + } + _stream >> type; + std::getline(_stream, line, '\0'); + } + + Glib::RefPtr<Gtk::TextBuffer> text_buf = _textview->get_buffer(); + + auto t = _tags.find(type); + if (t != _tags.end()) { + text_buf->insert_with_tag(text_buf->end(), line, t->second); + } else { + text_buf->insert(text_buf->end(), line); + } + + if (!_clear_button->is_sensitive()) { _clear_button->set_sensitive(true); + } } void diff --git a/src/gui/MessagesWindow.hpp b/src/gui/MessagesWindow.hpp index f3215daf..193ef18d 100644 --- a/src/gui/MessagesWindow.hpp +++ b/src/gui/MessagesWindow.hpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2015 David Robillard <http://drobilla.net/> + Copyright 2007-2016 David Robillard <http://drobilla.net/> Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -17,11 +17,14 @@ #ifndef INGEN_GUI_MESSAGESWINDOW_HPP #define INGEN_GUI_MESSAGESWINDOW_HPP +#include <mutex> +#include <sstream> #include <string> #include <gtkmm/builder.h> #include <gtkmm/button.h> #include <gtkmm/textview.h> +#include "lv2/lv2plug.in/ns/ext/log/log.h" #include "Window.hpp" @@ -41,14 +44,24 @@ public: MessagesWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& xml); - void post(const std::string& str); + void init_window(App& app); + + int log(LV2_URID type, const char* fmt, va_list args); + void flush(); + + void post_error(const std::string& str); private: void clear_clicked(); - Gtk::TextView* _textview; - Gtk::Button* _clear_button; - Gtk::Button* _close_button; + std::mutex _mutex; + std::stringstream _stream; + Gtk::TextView* _textview; + Gtk::Button* _clear_button; + Gtk::Button* _close_button; + + Glib::RefPtr<Gtk::TextTag> _error_tag; + std::map< LV2_URID, Glib::RefPtr<Gtk::TextTag> > _tags; }; } // namespace GUI diff --git a/src/gui/ingen_gui.ui b/src/gui/ingen_gui.ui index 646cd34d..7d250e69 100644 --- a/src/gui/ingen_gui.ui +++ b/src/gui/ingen_gui.ui @@ -1876,8 +1876,8 @@ See COPYING file included with this distribution, or http://www.gnu.org/licenses <object class="GtkTextView" id="messages_textview"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="pixels_above_lines">5</property> - <property name="pixels_below_lines">5</property> + <property name="pixels_above_lines">1</property> + <property name="pixels_below_lines">1</property> <property name="editable">False</property> <property name="wrap_mode">word</property> <property name="left_margin">5</property> @@ -92,6 +92,12 @@ def configure(conf): define_name = 'HAVE_ISATTY', mandatory = False) + conf.check(function_name = 'vasprintf', + header_name = 'stdio.h', + defines = '_GNU_SOURCE=1', + define_name = 'HAVE_VASPRINTF', + mandatory = False) + if not Options.options.no_socket: conf.check(function_name = 'socket', header_name = 'sys/socket.h', |