kakoune/src/face_registry.hh
Maxime Coste 4e24ba86cc Change faces alias to be a base that can be modified
Using <fg>,<bg>+<attr>@<base> will apply the given fg color,
bg color and attributes on top of base dynamically. Simply giving
<base> is a shorthand for default,default@<base>.

Inspired by the discussion in #2862
2019-04-23 23:15:23 +01:00

58 lines
1.5 KiB
C++

#ifndef face_registry_hh_INCLUDED
#define face_registry_hh_INCLUDED
#include "face.hh"
#include "utils.hh"
#include "hash_map.hh"
#include "ranges.hh"
#include "string.hh"
#include "safe_ptr.hh"
namespace Kakoune
{
class FaceRegistry : public SafeCountable
{
public:
FaceRegistry(FaceRegistry& parent) : SafeCountable{}, m_parent(&parent) {}
Face operator[](StringView facedesc) const;
void add_face(StringView name, StringView facedesc, bool override = false);
void remove_face(StringView name);
struct FaceSpec
{
Face face = {};
String base = {};
};
using FaceMap = HashMap<String, FaceSpec, MemoryDomain::Faces>;
auto flatten_faces() const
{
auto merge = [](auto&& first, const FaceMap& second) {
return concatenated(std::forward<decltype(first)>(first)
| filter([&second](auto& i) { return not second.contains(i.key); }),
second);
};
static const FaceMap empty;
auto& parent = m_parent ? m_parent->m_faces : empty;
auto& grand_parent = (m_parent and m_parent->m_parent) ? m_parent->m_parent->m_faces : empty;
return merge(merge(grand_parent, parent), m_faces);
}
private:
Face resolve_spec(const FaceSpec& spec) const;
friend class Scope;
FaceRegistry();
SafePtr<FaceRegistry> m_parent;
FaceMap m_faces;
};
String to_string(Face face);
}
#endif // face_registry_hh_INCLUDED