diff --git a/repos/gems/src/app/sculpt_manager/graph.h b/repos/gems/src/app/sculpt_manager/graph.h index 67369da1a6..56ea94f85a 100644 --- a/repos/gems/src/app/sculpt_manager/graph.h +++ b/repos/gems/src/app/sculpt_manager/graph.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace Sculpt { struct Graph; } @@ -127,6 +128,7 @@ struct Sculpt::Graph _runtime_config.for_each_component([&] (Component const &component) { Start_name const name = component.name; + Start_name const pretty_name { Pretty(name) }; /* omit sculpt's helpers from the graph */ bool const blacklisted = (name == "runtime_view" @@ -158,7 +160,7 @@ struct Sculpt::Graph xml.attribute("selected", "yes"); xml.node("label", [&] () { - xml.attribute("text", name); + xml.attribute("text", pretty_name); }); }); diff --git a/repos/gems/src/app/sculpt_manager/model/route.h b/repos/gems/src/app/sculpt_manager/model/route.h index ac5a28d76c..e24a39e178 100644 --- a/repos/gems/src/app/sculpt_manager/model/route.h +++ b/repos/gems/src/app/sculpt_manager/model/route.h @@ -110,7 +110,7 @@ struct Sculpt::Route : List_model::Element { Genode::print(out, _pretty_name(required)); if (required_label.valid()) - Genode::print(out, " (", required_label, ") "); + Genode::print(out, " (", Pretty(required_label), ") "); } void gen_xml(Xml_generator &xml) const diff --git a/repos/gems/src/app/sculpt_manager/model/service.h b/repos/gems/src/app/sculpt_manager/model/service.h index 241181c5b4..c117d6d5ba 100644 --- a/repos/gems/src/app/sculpt_manager/model/service.h +++ b/repos/gems/src/app/sculpt_manager/model/service.h @@ -14,7 +14,7 @@ #ifndef _MODEL__SERVICE_H_ #define _MODEL__SERVICE_H_ -#include "types.h" +#include namespace Sculpt { struct Service; } @@ -67,7 +67,7 @@ struct Sculpt::Service * Constructor for child service */ Service(Start_name const &server, Type type, Label const &label) - : server(server), type(type), label(label), info(server) { } + : server(server), type(type), label(label), info(Subst("_", " ", server)) { } /** * Constructor for parent service diff --git a/repos/gems/src/app/sculpt_manager/string.h b/repos/gems/src/app/sculpt_manager/string.h new file mode 100644 index 0000000000..36e33f428a --- /dev/null +++ b/repos/gems/src/app/sculpt_manager/string.h @@ -0,0 +1,77 @@ +/* + * \brief Utilities for string handling + * \author Norman Feske + * \date 2019-03-01 + */ + +/* + * Copyright (C) 2019 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +/* Genode includes */ +#include +#include + +/* local includes */ +#include "types.h" + +namespace Sculpt { + + class Subst; + class Pretty; +} + + +class Sculpt::Subst +{ + private: + + char const * const _pattern; + size_t const _pattern_len = strlen(_pattern); + char const * const _replacement; + char const * const _input; + + public: + + /* + * This utility is currently limited to strings. It should better + * act as a filter that accepts any printable type as 'input' + * argument. However the automatic deduction of class template + * arguments from a constuctor calls is not suppored before C++17. + */ + + Subst(char const *pattern, char const *replacement, char const *input) + : _pattern(pattern), _replacement(replacement), _input(input) { } + + template + Subst(char const *pattern, char const *replacement, String const &input) + : Subst(pattern, replacement, input.string()) { } + + void print(Output &out) const + { + for (char const *curr = _input; *curr; ) { + if (_pattern_len && strcmp(curr, _pattern, _pattern_len) == 0) { + Genode::print(out, _replacement); + curr += _pattern_len; + } else { + Genode::print(out, Char(*curr)); + curr++; + } + } + } +}; + + +struct Sculpt::Pretty : Subst +{ + template + Pretty(String const &input) : Subst("_", " ", input) { } +}; + +#endif /* _XML_H_ */ diff --git a/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc b/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc index 6cac254d55..67cb7730fd 100644 --- a/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc +++ b/repos/gems/src/app/sculpt_manager/view/popup_dialog.cc @@ -12,6 +12,7 @@ */ #include +#include using namespace Sculpt; @@ -32,7 +33,7 @@ void Popup_dialog::_gen_pkg_elements(Xml_generator &xml, { typedef Component::Info Info; - _gen_sub_menu_title(xml, "back", Menu::Name("Add ", _construction_name)); + _gen_sub_menu_title(xml, "back", Menu::Name("Add ", Pretty(_construction_name))); _gen_pkg_info(xml, component); @@ -107,7 +108,7 @@ void Popup_dialog::_gen_menu_elements(Xml_generator &xml) const if (_runtime_info.present_in_runtime(info.path)) return; - _gen_menu_entry(xml, info.path, info.path, false); + _gen_menu_entry(xml, info.path, Pretty(info.path), false); }); _gen_menu_entry(xml, "depot", "Depot ...", false); @@ -197,7 +198,7 @@ void Popup_dialog::_gen_menu_elements(Xml_generator &xml) const selected = true; }); - String<100> const text(name, " " "(", version, ")", + String<100> const text(Pretty(name), " " "(", version, ")", installing ? " installing... " : "..."); _gen_menu_entry(xml, id, text, selected);