1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-29 01:24:52 +03:00

Change flag lines highlighter to use faces instead of colors

Fixes #130
This commit is contained in:
Maxime Coste 2015-08-23 12:13:14 +01:00
parent 504862fce7
commit dc504284c3
5 changed files with 28 additions and 21 deletions

View File

@ -22,6 +22,8 @@ hook global WinSetOption filetype=(?!git-status).* %{
decl line-flag-list git_blame_flags
decl line-flag-list git_diff_flags
face GitBlame default,magenta
def -shell-params \
-docstring %sh{printf "%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \
-shell-completion %{
@ -58,7 +60,7 @@ def -shell-params \
run_git_blame() {
(
echo "eval -client '$kak_client' %{
try %{ addhl flag_lines magenta git_blame_flags }
try %{ addhl flag_lines GitBlame git_blame_flags }
set buffer=$kak_bufname git_blame_flags ''
}" | kak -p ${kak_session}
git blame "$@" --incremental ${kak_buffile} | awk -e '
@ -66,10 +68,10 @@ def -shell-params \
if (line == "") { return; }
text=substr(sha,1,8) " " dates[sha] " " authors[sha]
gsub(":", "\\:", text)
gsub(",", "\\,", text)
flag=line ",black," text
# gsub("|", "\\|", text)
flag=line "|default|" text
for ( i=1; i < count; i++ ) {
flag=flag ":" line+i ",black," text
flag=flag ":" line+i "|default|" text
}
cmd = "kak -p " ENVIRON["kak_session"]
print "set -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags %{" flag "}" | cmd
@ -94,7 +96,7 @@ def -shell-params \
git diff -U0 $kak_buffile | awk -e '
BEGIN {
line=0
flags="0,red,."
flags="0|red|."
}
/^---.*/ {}
/^@@ -[0-9]+(,[0-9]+)? \+[0-9]+(,[0-9]+)? @@.*/ {
@ -105,10 +107,10 @@ def -shell-params \
}
}
/^\+/ {
flags=flags ":" line ",green,+"
flags=flags ":" line "|green|+"
line++
}
/^\-/ { flags=flags ":" line ",red,-" }
/^\-/ { flags=flags ":" line "|red|-" }
END { print "set buffer git_diff_flags ", flags }
'
}
@ -150,7 +152,7 @@ def -shell-params \
}"
;;
show-diff)
echo "try %{ addhl flag_lines black git_diff_flags }"
echo "try %{ addhl flag_lines default,black git_diff_flags }"
update_diff
;;
update-diff) update_diff ;;

View File

@ -42,6 +42,13 @@ constexpr bool operator!=(const Face& lhs, const Face& rhs)
return not (lhs == rhs);
}
constexpr Face merge_faces(const Face& base, const Face& face)
{
return { face.fg == Color::Default ? base.fg : face.fg,
face.bg == Color::Default ? base.bg : face.bg,
face.attributes | base.attributes };
}
}
#endif // face_hh_INCLUDED

View File

@ -155,12 +155,7 @@ void apply_highlighter(const Context& context,
auto apply_face = [](const Face& face)
{
return [&face](DisplayAtom& atom) {
if (face.fg != Color::Default)
atom.face.fg = face.fg;
if (face.bg != Color::Default)
atom.face.bg = face.bg;
if (face.attributes != Attribute::Normal)
atom.face.attributes |= face.attributes;
atom.face = merge_faces(atom.face, face);
};
};
@ -891,7 +886,8 @@ HighlighterAndId create_flag_lines_highlighter(HighlighterParameters params)
throw runtime_error("wrong parameter count");
const String& option_name = params[1];
Color bg = str_to_color(params[0]);
String default_face = params[0];
get_face(default_face); // validate param
// throw if wrong option type
GlobalScope::instance().options()[option_name].get<Vector<LineAndFlag, MemoryDomain::Options>>();
@ -902,6 +898,8 @@ HighlighterAndId create_flag_lines_highlighter(HighlighterParameters params)
auto& lines_opt = context.options()[option_name];
auto& lines = lines_opt.get<Vector<LineAndFlag, MemoryDomain::Options>>();
auto def_face = get_face(default_face);
CharCount width = 0;
for (auto& l : lines)
width = std::max(width, std::get<2>(l).char_length());
@ -915,7 +913,7 @@ HighlighterAndId create_flag_lines_highlighter(HighlighterParameters params)
String content = it != lines.end() ? std::get<2>(*it) : empty;
content += String(' ', width - content.char_length());
DisplayAtom atom{std::move(content)};
atom.face = { it != lines.end() ? std::get<1>(*it) : Color::Default , bg };
atom.face = it != lines.end() ? merge_faces(get_face(std::get<1>(*it)), def_face) : def_face;
line.insert(line.begin(), std::move(atom));
}
};

View File

@ -9,7 +9,7 @@ namespace Kakoune
void register_highlighters();
using LineAndFlag = std::tuple<LineCount, Color, String>;
using LineAndFlag = std::tuple<LineCount, String, String>;
}

View File

@ -98,7 +98,7 @@ void option_from_string(StringView str, UnorderedMap<Key, Value, domain>& opt)
}
}
constexpr char tuple_separator = ',';
constexpr char tuple_separator = '|';
template<size_t I, typename... Types>
struct TupleOptionDetail
@ -176,9 +176,9 @@ bool option_add(T&, const T&)
template<typename EffectiveType, typename LineType, typename ColumnType>
inline void option_from_string(StringView str, LineAndColumn<EffectiveType, LineType, ColumnType>& opt)
{
auto vals = split(str, tuple_separator);
auto vals = split(str, ',');
if (vals.size() != 2)
throw runtime_error(format("expected <line>{}<column>", tuple_separator));
throw runtime_error("expected <line>,<column>");
opt.line = str_to_int(vals[0]);
opt.column = str_to_int(vals[1]);
}
@ -186,7 +186,7 @@ inline void option_from_string(StringView str, LineAndColumn<EffectiveType, Line
template<typename EffectiveType, typename LineType, typename ColumnType>
inline String option_to_string(const LineAndColumn<EffectiveType, LineType, ColumnType>& opt)
{
return to_string(opt.line) + tuple_separator + to_string(opt.column);
return format("{},{}", opt.line, opt.column);
}
enum YesNoAsk