diff --git a/README.asciidoc b/README.asciidoc index 2c96216a7..a49d5d845 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -1573,8 +1573,8 @@ Some helper commands can be used to define composite commands: * `reg `: set register to * `select .,.:...`: replace the current selections with the one described in the argument - * `debug {info,buffers,options,memory,shared-strings}`: print some debug - information in the `*debug*` buffer + * `debug {info,buffers,options,memory,shared-strings,profile-hash-maps,faces}`: + print some debug information in the `*debug*` buffer Note that these commands are available in interactive command mode, but are not that useful in this context. diff --git a/doc/manpages/commands.asciidoc b/doc/manpages/commands.asciidoc index 90bfd5fc1..97d6af6d6 100644 --- a/doc/manpages/commands.asciidoc +++ b/doc/manpages/commands.asciidoc @@ -200,7 +200,7 @@ commands: *select* .,.:...:: replace the current selections with the one described in the argument -*debug* {info,buffers,options,memory,shared-strings}:: +*debug* {info,buffers,options,memory,shared-strings,profile-hash-maps,faces}:: print some debug information in the *\*debug** buffer Note that those commands are also available in the interactive mode, but diff --git a/src/commands.cc b/src/commands.cc index a52c34e35..016323c16 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1116,14 +1116,15 @@ const CommandDesc debug_cmd = { "debug", nullptr, "debug : write some debug informations in the debug buffer\n" - "existing commands: info, buffers, options, memory, shared-strings, profile-hash-maps", + "existing commands: info, buffers, options, memory, shared-strings, profile-hash-maps, faces", ParameterDesc{{}, ParameterDesc::Flags::SwitchesOnlyAtStart, 1}, CommandFlags::None, CommandHelper{}, make_completer( [](const Context& context, CompletionFlags flags, const String& prefix, ByteCount cursor_pos) -> Completions { - auto c = {"info", "buffers", "options", "memory", "shared-strings", "profile-hash-maps"}; + auto c = {"info", "buffers", "options", "memory", "shared-strings", + "profile-hash-maps", "faces"}; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) }; }), [](const ParametersParser& parser, Context& context, const ShellContext&) @@ -1173,6 +1174,12 @@ const CommandDesc debug_cmd = { { profile_hash_maps(); } + else if (parser[0] == "faces") + { + write_to_debug_buffer("Faces:"); + for (auto& face : FaceRegistry::instance().aliases()) + write_to_debug_buffer(format(" * {}: {}", face.key, face.value.face)); + } else throw runtime_error(format("unknown debug command '{}'", parser[0])); } diff --git a/src/face_registry.cc b/src/face_registry.cc index 44de99538..0ae1ae46a 100644 --- a/src/face_registry.cc +++ b/src/face_registry.cc @@ -42,6 +42,37 @@ static Face parse_face(StringView facedesc) return res; } +String attributes_to_str(Attribute attributes) +{ + if (attributes == Attribute::Normal) + return ""; + + struct Attr { Attribute attr; StringView name; } + attrs[] { + { Attribute::Exclusive, "e" }, + { Attribute::Underline, "u" }, + { Attribute::Reverse, "r" }, + { Attribute::Blink, "B" }, + { Attribute::Bold, "b" }, + { Attribute::Dim, "d" }, + { Attribute::Italic, "i" }, + }; + + auto filteredAttrs = attrs | + filter([=](const Attr& a) { return attributes & a.attr; }) | + transform([](const Attr& a) { return a.name; }); + + return accumulate(filteredAttrs, String{"+"}, std::plus<>{}); +} + +String to_string(Face face) +{ + return format("{},{}{}", + color_to_str(face.fg), + color_to_str(face.bg), + attributes_to_str(face.attributes)); +} + Face FaceRegistry::operator[](const String& facedesc) { auto it = m_aliases.find(facedesc); diff --git a/src/face_registry.hh b/src/face_registry.hh index bbb3ea0bd..e6e276aa5 100644 --- a/src/face_registry.hh +++ b/src/face_registry.hh @@ -20,13 +20,17 @@ public: CandidateList complete_alias_name(StringView prefix, ByteCount cursor_pos) const; -private: + struct FaceOrAlias { Face face = {}; String alias = {}; }; + using AliasMap = HashMap; + const AliasMap &aliases() const { return m_aliases; } + +private: AliasMap m_aliases; }; @@ -37,6 +41,8 @@ inline Face get_face(const String& facedesc) return Face{}; } +String to_string(Face face); + } #endif // face_registry_hh_INCLUDED