Skip to content

Commit 1dcbf4e

Browse files
committed
[pager] if output is redirected, switch to headless mode
1 parent 39dc85b commit 1dcbf4e

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

src/lnav.cc

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,16 +4011,26 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
40114011
|| mode_flags.mf_check_configs)
40124012
{
40134013
} else if (!isatty(STDOUT_FILENO)) {
4014-
lnav::console::print(
4015-
stderr,
4016-
lnav::console::user_message::error(
4017-
"unable to display interactive text UI")
4018-
.with_reason("stdout is not a TTY")
4019-
.with_help(attr_line_t("pass the ")
4020-
.append("-n"_symbol)
4021-
.append(" option to run lnav in headless mode "
4022-
"or don't redirect stdout")));
4023-
retval = EXIT_FAILURE;
4014+
if (load_stdin && !isatty(STDIN_FILENO)
4015+
&& verbosity == verbosity_t::quiet
4016+
&& !lnav_data.ld_flags.is_set<lnav_flags::headless>())
4017+
{
4018+
log_debug("pager mode, but output is redirected")
4019+
lnav_data.ld_flags.set<lnav_flags::headless>();
4020+
verbosity = verbosity_t::standard;
4021+
} else {
4022+
lnav::console::print(
4023+
stderr,
4024+
lnav::console::user_message::error(
4025+
"unable to display interactive text UI")
4026+
.with_reason("stdout is not a TTY")
4027+
.with_help(
4028+
attr_line_t("pass the ")
4029+
.append("-n"_symbol)
4030+
.append(" option to run lnav in headless mode "
4031+
"or don't redirect stdout")));
4032+
retval = EXIT_FAILURE;
4033+
}
40244034
}
40254035

40264036
std::optional<std::string> stdin_url;
@@ -4458,7 +4468,8 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
44584468
auto& tc = lnav_data.ld_views[LNV_TEXT];
44594469
auto& bv = tc.get_bookmarks()[&textview_curses::BM_USER];
44604470
tc.tc_mark_style = std::nullopt;
4461-
bool is_short = tc.get_inner_height() < term_size.ws_row - 3;
4471+
bool is_short
4472+
= tc.get_inner_height() < term_size.ws_row - 3;
44624473
if (is_short || !bv.empty()) {
44634474
for (auto vl = 0_vl; vl < tc.get_inner_height(); ++vl) {
44644475
if (!is_short && !bv.contains(vl)) {

0 commit comments

Comments
 (0)