@@ -53,6 +53,65 @@ com_mark(exec_context& ec, std::string cmdline, std::vector<std::string>& args)
5353 return Ok (retval);
5454}
5555
56+ static Result<std::string, lnav::console::user_message>
57+ com_sticky_header (exec_context& ec,
58+ std::string cmdline,
59+ std::vector<std::string>& args)
60+ {
61+ std::string retval;
62+
63+ if (lnav_data.ld_view_stack .empty ()) {
64+ } else if (!ec.ec_dry_run ) {
65+ auto * tc = *lnav_data.ld_view_stack .top ();
66+ auto sel = tc->get_selection ();
67+ if (sel) {
68+ auto result = tc->toggle_user_mark (
69+ &textview_curses::BM_STICKY , sel.value ());
70+ tc->set_needs_update ();
71+
72+ if (result.mtr_marked > 0 ) {
73+ retval = fmt::format (
74+ FMT_STRING (" info: line {} pinned as a sticky header" ),
75+ (int ) sel.value ());
76+ } else {
77+ retval = fmt::format (
78+ FMT_STRING (" info: line {} unpinned from sticky headers" ),
79+ (int ) sel.value ());
80+ }
81+ }
82+ }
83+
84+ return Ok (retval);
85+ }
86+
87+ static Result<std::string, lnav::console::user_message>
88+ com_clear_sticky_headers (exec_context& ec,
89+ std::string cmdline,
90+ std::vector<std::string>& args)
91+ {
92+ std::string retval;
93+
94+ if (lnav_data.ld_view_stack .empty ()) {
95+ } else if (!ec.ec_dry_run ) {
96+ auto * tc = *lnav_data.ld_view_stack .top ();
97+ auto & bv = tc->get_bookmarks ()[&textview_curses::BM_STICKY ];
98+ auto count = bv.size ();
99+ // Copy to avoid modifying while iterating
100+ std::vector<vis_line_t > sticky_lines;
101+ for (const auto & row : bv.bv_tree ) {
102+ sticky_lines.push_back (row);
103+ }
104+ for (const auto & row : sticky_lines) {
105+ tc->toggle_user_mark (&textview_curses::BM_STICKY , row);
106+ }
107+ tc->set_needs_update ();
108+ retval = fmt::format (
109+ FMT_STRING (" info: cleared {} sticky header(s)" ), count);
110+ }
111+
112+ return Ok (retval);
113+ }
114+
56115static Result<std::string, lnav::console::user_message>
57116com_goto_mark (exec_context& ec,
58117 std::string cmdline,
@@ -65,6 +124,7 @@ com_goto_mark(exec_context& ec,
65124 &textview_curses::BM_USER_EXPR ,
66125 &textview_curses::BM_META ,
67126 &textview_curses::BM_PARTITION ,
127+ &textview_curses::BM_STICKY ,
68128 };
69129
70130 auto * tc = get_textview_for_mode (lnav_data.ld_mode );
@@ -204,6 +264,26 @@ init_lnav_bookmark_commands(readline_context::command_map_t& cmd_map)
204264 .with_example ({" To go to the previous error" , " error" })
205265 .with_tags ({" bookmarks" , " navigation" }),
206266 },
267+
268+ {
269+ " toggle-sticky-header" ,
270+ com_sticky_header,
271+
272+ help_text (" :toggle-sticky-header" )
273+ .with_summary (
274+ " Toggle the sticky header state for the focused line "
275+ " in the current view" )
276+ .with_tags ({" bookmarks" , " display" }),
277+ },
278+ {
279+ " clear-all-sticky-headers" ,
280+ com_clear_sticky_headers,
281+
282+ help_text (" :clear-all-sticky-headers" )
283+ .with_summary (
284+ " Clear all sticky header bookmarks in the current view" )
285+ .with_tags ({" bookmarks" , " display" }),
286+ },
207287 };
208288
209289 for (auto & cmd : BOOKMARK_COMMANDS ) {
0 commit comments