From 7e55f7401fc07acaad32ed14b0a779e698b3d55c Mon Sep 17 00:00:00 2001 From: Timothy Stack Date: Sat, 8 Apr 2017 07:45:51 -0700 Subject: [PATCH] [filter-in] highlight matches in green --- src/lnav_commands.cc | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/lnav_commands.cc b/src/lnav_commands.cc index 288ba3ca..60462b86 100644 --- a/src/lnav_commands.cc +++ b/src/lnav_commands.cc @@ -1042,19 +1042,33 @@ static string com_filter(exec_context &ec, string cmdline, vector &args) retval = "error: " + string(errptr); } else if (ec.ec_dry_run) { - textview_curses::highlight_map_t &hm = tc->get_highlights(); - view_colors &vc = view_colors::singleton(); - highlighter hl(code.release()); + if (args[0] == "filter-in" && !fs.empty()) { + lnav_data.ld_preview_status_source.get_description() + .set_value("Match preview for :filter-in only works if there are no other filters"); + } else { + textview_curses::highlight_map_t &hm = tc->get_highlights(); + view_colors &vc = view_colors::singleton(); + highlighter hl(code.release()); + int color; - hl.with_attrs(vc.ansi_color_pair(COLOR_BLACK, COLOR_RED) | A_BLINK); + if (args[0] == "filter-out") { + color = COLOR_RED; + } else { + color = COLOR_GREEN; + } + hl.with_attrs( + vc.ansi_color_pair(COLOR_BLACK, color) | A_BLINK); - hm["$preview"] = hl; - tc->reload_data(); + hm["$preview"] = hl; + tc->reload_data(); - lnav_data.ld_preview_status_source.get_description() - .set_value("Matches are highlighted in red in the text view"); + lnav_data.ld_preview_status_source.get_description() + .set_value( + "Matches are highlighted in %s in the text view", + color == COLOR_RED ? "red" : "green"); - retval = ""; + retval = ""; + } } else { text_filter::type_t lt = (args[0] == "filter-out") ?