mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-28 09:07:19 +03:00
Add debug faces
This commit is contained in:
parent
8e3e5b10c1
commit
53090c0dd3
@ -1573,8 +1573,8 @@ Some helper commands can be used to define composite commands:
|
||||
* `reg <name> <content>`: set register <name> to <content>
|
||||
* `select <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...`:
|
||||
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.
|
||||
|
@ -200,7 +200,7 @@ commands:
|
||||
*select* <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...::
|
||||
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
|
||||
|
@ -1116,14 +1116,15 @@ const CommandDesc debug_cmd = {
|
||||
"debug",
|
||||
nullptr,
|
||||
"debug <command>: 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]));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<String, FaceOrAlias, MemoryDomain::Faces>;
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user