Skip to content

Commit ac73ef9

Browse files
committed
[TEXT] add bookmarks for stderr lines
1 parent 5d53e06 commit ac73ef9

7 files changed

Lines changed: 42 additions & 0 deletions

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ Bug Fixes:
327327
passed on the command-line.
328328
* Marks in the TEXT view are now stable after filtering
329329
is applied.
330+
* Error bookmarks are now added for stderr content when
331+
executing a command in the shell using `-e` or `:sh`.
330332

331333
Internal:
332334
* Added operation IDs (OpIDs) to lnav's internal logging

src/textfile_sub_source.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,31 @@ textfile_sub_source::text_update_marks(vis_bookmarks& bm)
520520
}
521521
}
522522
}
523+
524+
if (lf->has_line_metadata()) {
525+
auto& bm_errors = bm[&textview_curses::BM_ERRORS];
526+
auto& bm_warnings = bm[&textview_curses::BM_WARNINGS];
527+
528+
bm_errors.clear();
529+
bm_warnings.clear();
530+
531+
auto& tfs = lfo->lfo_filter_state.tfs_index;
532+
for (uint32_t vl = 0; vl < tfs.size(); ++vl) {
533+
auto ll = lf->begin() + tfs[vl];
534+
switch (ll->get_msg_level()) {
535+
case log_level_t::LEVEL_FATAL:
536+
case log_level_t::LEVEL_CRITICAL:
537+
case log_level_t::LEVEL_ERROR:
538+
bm_errors.insert_once(vis_line_t(vl));
539+
break;
540+
case log_level_t::LEVEL_WARNING:
541+
bm_warnings.insert_once(vis_line_t(vl));
542+
break;
543+
default:
544+
break;
545+
}
546+
}
547+
}
523548
}
524549

525550
void

test/expected/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,8 @@ dist_noinst_DATA = \
17741774
test_text_file.sh_ac872aadda29b9a824361a2c711d62ec1c75d40f.out \
17751775
test_text_file.sh_b0945bb63076f4d84fe01c9863557a1f935fcb13.err \
17761776
test_text_file.sh_b0945bb63076f4d84fe01c9863557a1f935fcb13.out \
1777+
test_text_file.sh_b166346955b5ad775836204f6eba79802a57f73c.err \
1778+
test_text_file.sh_b166346955b5ad775836204f6eba79802a57f73c.out \
17771779
test_text_file.sh_b2cf922c24f5ef2e99b85f49560b5b0b3e210c46.err \
17781780
test_text_file.sh_b2cf922c24f5ef2e99b85f49560b5b0b3e210c46.out \
17791781
test_text_file.sh_b35e7066a419e46f57a6c93a593dae2c8988af49.err \

test/expected/test_text_file.sh_b166346955b5ad775836204f6eba79802a57f73c.err

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: something went wrong
2+
warning: be careful

test/test_text_file.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ run_cap_test ${lnav_test} -n \
218218

219219
run_cap_test ${lnav_test} -n ${test_dir}/textfile_ctrl.0
220220

221+
# Test that error/warning bookmarks are set for piper text files
222+
run_cap_test ${lnav_test} -n \
223+
-e "bash ${test_dir}/textfile_stderr_levels.sh" \
224+
-c ':goto 0' \
225+
-c ':next-mark error'
221226

222227
#####
223228

test/textfile_stderr_levels.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
echo "info message one"
4+
echo "info message two"
5+
echo "error: something went wrong" >&2
6+
echo "warning: be careful" >&2

0 commit comments

Comments
 (0)