|
30 | 30 | #include "base/intern_string.hh" |
31 | 31 | #include "lnav.hh" |
32 | 32 | #include "readline_context.hh" |
| 33 | +#include "timeline_source.hh" |
33 | 34 |
|
34 | 35 | static Result<std::string, lnav::console::user_message> |
35 | 36 | com_set_text_view_mode(exec_context& ec, |
@@ -157,6 +158,67 @@ com_toggle_field(exec_context& ec, |
157 | 158 | return Ok(retval); |
158 | 159 | } |
159 | 160 |
|
| 161 | +static Result<std::string, lnav::console::user_message> |
| 162 | +com_timeline_row_type_visibility(exec_context& ec, |
| 163 | + std::string cmdline, |
| 164 | + std::vector<std::string>& args) |
| 165 | +{ |
| 166 | + std::string retval; |
| 167 | + |
| 168 | + if (args.size() < 2) { |
| 169 | + auto* tss = static_cast<timeline_source*>( |
| 170 | + lnav_data.ld_views[LNV_TIMELINE].get_sub_source()); |
| 171 | + tss->gs_preview_hidden_row_types.clear(); |
| 172 | + lnav_data.ld_views[LNV_TIMELINE].set_needs_update(); |
| 173 | + return ec.make_error("Expecting a row type"); |
| 174 | + } |
| 175 | + |
| 176 | + const auto hide = args[0] == "hide-in-timeline"; |
| 177 | + std::vector<std::string> found_types, unknown_types; |
| 178 | + |
| 179 | + for (size_t lpc = 1; lpc < args.size(); lpc++) { |
| 180 | + auto rt_opt = timeline_source::row_type_from_string(args[lpc]); |
| 181 | + if (rt_opt) { |
| 182 | + found_types.emplace_back(args[lpc]); |
| 183 | + } else { |
| 184 | + unknown_types.emplace_back(args[lpc]); |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + if (!unknown_types.empty()) { |
| 189 | + return ec.make_error("unknown row type(s) -- {}", |
| 190 | + fmt::join(unknown_types, ", ")); |
| 191 | + } |
| 192 | + |
| 193 | + auto* tss = static_cast<timeline_source*>( |
| 194 | + lnav_data.ld_views[LNV_TIMELINE].get_sub_source()); |
| 195 | + if (ec.ec_dry_run) { |
| 196 | + tss->gs_preview_hidden_row_types.clear(); |
| 197 | + if (hide) { |
| 198 | + for (const auto& type_name : found_types) { |
| 199 | + auto rt_opt = timeline_source::row_type_from_string(type_name); |
| 200 | + tss->gs_preview_hidden_row_types.insert(rt_opt.value()); |
| 201 | + } |
| 202 | + } |
| 203 | + lnav_data.ld_views[LNV_TIMELINE].set_needs_update(); |
| 204 | + retval = ""; |
| 205 | + } else { |
| 206 | + tss->gs_preview_hidden_row_types.clear(); |
| 207 | + for (const auto& type_name : found_types) { |
| 208 | + auto rt_opt = timeline_source::row_type_from_string(type_name); |
| 209 | + tss->set_row_type_visibility(rt_opt.value(), !hide); |
| 210 | + } |
| 211 | + tss->text_filters_changed(); |
| 212 | + |
| 213 | + auto visibility = hide ? "hiding" : "showing"; |
| 214 | + retval = fmt::format(FMT_STRING("info: {} row type(s) -- {}"), |
| 215 | + visibility, |
| 216 | + fmt::join(found_types, ", ")); |
| 217 | + } |
| 218 | + |
| 219 | + return Ok(retval); |
| 220 | +} |
| 221 | + |
160 | 222 | static readline_context::command_t DISPLAY_COMMANDS[] = { |
161 | 223 | { |
162 | 224 | "set-text-view-mode", |
@@ -208,6 +270,46 @@ static readline_context::command_t DISPLAY_COMMANDS[] = { |
208 | 270 | .with_opposites({"hide-fields"}) |
209 | 271 | .with_tags({"display"}), |
210 | 272 | }, |
| 273 | + { |
| 274 | + "hide-in-timeline", |
| 275 | + com_timeline_row_type_visibility, |
| 276 | + |
| 277 | + help_text(":hide-in-timeline") |
| 278 | + .with_summary("Hide rows of the given type(s) in the timeline " |
| 279 | + "view") |
| 280 | + .with_parameter(help_text("row-type", "The type of row to hide") |
| 281 | + .one_or_more() |
| 282 | + .with_enum_values({ |
| 283 | + "logfile"_frag, |
| 284 | + "thread"_frag, |
| 285 | + "opid"_frag, |
| 286 | + "tag"_frag, |
| 287 | + "partition"_frag, |
| 288 | + })) |
| 289 | + .with_example({"To hide logfile and thread rows", "logfile thread"}) |
| 290 | + .with_opposites({"show-in-timeline"}) |
| 291 | + .with_tags({"display"}), |
| 292 | + }, |
| 293 | + { |
| 294 | + "show-in-timeline", |
| 295 | + com_timeline_row_type_visibility, |
| 296 | + |
| 297 | + help_text(":show-in-timeline") |
| 298 | + .with_summary("Show rows of the given type(s) that were " |
| 299 | + "previously hidden in the timeline view") |
| 300 | + .with_parameter(help_text("row-type", "The type of row to show") |
| 301 | + .one_or_more() |
| 302 | + .with_enum_values({ |
| 303 | + "logfile"_frag, |
| 304 | + "thread"_frag, |
| 305 | + "opid"_frag, |
| 306 | + "tag"_frag, |
| 307 | + "partition"_frag, |
| 308 | + })) |
| 309 | + .with_example({"To show logfile and thread rows", "logfile thread"}) |
| 310 | + .with_opposites({"hide-in-timeline"}) |
| 311 | + .with_tags({"display"}), |
| 312 | + }, |
211 | 313 | }; |
212 | 314 |
|
213 | 315 | void |
|
0 commit comments