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>
|
* `reg <name> <content>`: set register <name> to <content>
|
||||||
* `select <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...`:
|
* `select <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...`:
|
||||||
replace the current selections with the one described in the argument
|
replace the current selections with the one described in the argument
|
||||||
* `debug {info,buffers,options,memory,shared-strings}`: print some debug
|
* `debug {info,buffers,options,memory,shared-strings,profile-hash-maps,faces}`:
|
||||||
information in the `*debug*` buffer
|
print some debug information in the `*debug*` buffer
|
||||||
|
|
||||||
Note that these commands are available in interactive command mode, but are
|
Note that these commands are available in interactive command mode, but are
|
||||||
not that useful in this context.
|
not that useful in this context.
|
||||||
|
@ -200,7 +200,7 @@ commands:
|
|||||||
*select* <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...::
|
*select* <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...::
|
||||||
replace the current selections with the one described in the argument
|
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
|
print some debug information in the *\*debug** buffer
|
||||||
|
|
||||||
Note that those commands are also available in the interactive mode, but
|
Note that those commands are also available in the interactive mode, but
|
||||||
|
@ -1116,14 +1116,15 @@ const CommandDesc debug_cmd = {
|
|||||||
"debug",
|
"debug",
|
||||||
nullptr,
|
nullptr,
|
||||||
"debug <command>: write some debug informations in the debug buffer\n"
|
"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},
|
ParameterDesc{{}, ParameterDesc::Flags::SwitchesOnlyAtStart, 1},
|
||||||
CommandFlags::None,
|
CommandFlags::None,
|
||||||
CommandHelper{},
|
CommandHelper{},
|
||||||
make_completer(
|
make_completer(
|
||||||
[](const Context& context, CompletionFlags flags,
|
[](const Context& context, CompletionFlags flags,
|
||||||
const String& prefix, ByteCount cursor_pos) -> Completions {
|
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) };
|
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
|
||||||
}),
|
}),
|
||||||
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
[](const ParametersParser& parser, Context& context, const ShellContext&)
|
||||||
@ -1173,6 +1174,12 @@ const CommandDesc debug_cmd = {
|
|||||||
{
|
{
|
||||||
profile_hash_maps();
|
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
|
else
|
||||||
throw runtime_error(format("unknown debug command '{}'", parser[0]));
|
throw runtime_error(format("unknown debug command '{}'", parser[0]));
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,37 @@ static Face parse_face(StringView facedesc)
|
|||||||
return res;
|
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)
|
Face FaceRegistry::operator[](const String& facedesc)
|
||||||
{
|
{
|
||||||
auto it = m_aliases.find(facedesc);
|
auto it = m_aliases.find(facedesc);
|
||||||
|
@ -20,13 +20,17 @@ public:
|
|||||||
|
|
||||||
CandidateList complete_alias_name(StringView prefix,
|
CandidateList complete_alias_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const;
|
ByteCount cursor_pos) const;
|
||||||
private:
|
|
||||||
struct FaceOrAlias
|
struct FaceOrAlias
|
||||||
{
|
{
|
||||||
Face face = {};
|
Face face = {};
|
||||||
String alias = {};
|
String alias = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
using AliasMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
using AliasMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
||||||
|
const AliasMap &aliases() const { return m_aliases; }
|
||||||
|
|
||||||
|
private:
|
||||||
AliasMap m_aliases;
|
AliasMap m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -37,6 +41,8 @@ inline Face get_face(const String& facedesc)
|
|||||||
return Face{};
|
return Face{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String to_string(Face face);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // face_registry_hh_INCLUDED
|
#endif // face_registry_hh_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user