[cmds] the output of the :pipe commands should go to the top of the output stack and not to a temp file

pull/627/head
Timothy Stack 6 years ago
parent 53c1f03205
commit ea5ac46c0e

@ -731,29 +731,47 @@ int sql_callback(exec_context &ec, sqlite3_stmt *stmt)
future<string> pipe_callback(exec_context &ec, const string &cmdline, auto_fd &fd) future<string> pipe_callback(exec_context &ec, const string &cmdline, auto_fd &fd)
{ {
auto pp = make_shared<piper_proc>(fd, false); if (lnav_data.ld_output_stack.empty()) {
static int exec_count = 0; auto pp = make_shared<piper_proc>(fd, false);
char desc[128]; static int exec_count = 0;
char desc[128];
lnav_data.ld_pipers.push_back(pp);
snprintf(desc,
sizeof(desc), "[%d] Output of %s",
exec_count++,
cmdline.c_str());
lnav_data.ld_file_names[desc]
.with_fd(pp->get_fd())
.with_detect_format(false);
lnav_data.ld_files_to_front.emplace_back(desc, 0);
if (lnav_data.ld_rl_view != nullptr) {
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
X, "to close the file"));
}
lnav_data.ld_pipers.push_back(pp); packaged_task<string()> task([]() { return ""; });
snprintf(desc,
sizeof(desc), "[%d] Output of %s", task();
exec_count++,
cmdline.c_str()); return task.get_future();
lnav_data.ld_file_names[desc] } else {
.with_fd(pp->get_fd()) return std::async(std::launch::async, [&]() {
.with_detect_format(false); FILE *file = lnav_data.ld_output_stack.top();
lnav_data.ld_files_to_front.emplace_back(desc, 0); char buffer[1024];
if (lnav_data.ld_rl_view != nullptr) { ssize_t rc;
lnav_data.ld_rl_view->set_alt_value(HELP_MSG_1(
X, "to close the file"));
}
packaged_task<string()> task([]() { return ""; }); if (file == stdout) {
lnav_data.ld_stdout_used = true;
}
task(); while ((rc = read(fd, buffer, sizeof(buffer))) > 0) {
fwrite(buffer, rc, 1, file);
}
return task.get_future(); return string();
});
}
} }
void add_global_vars(exec_context &ec) void add_global_vars(exec_context &ec)

@ -562,10 +562,12 @@ check_output "pipe-to is not working" <<EOF
EOF EOF
run_test ${lnav_test} -n \ run_test ${lnav_test} -n \
-c ":echo Hello, World!" \
-c ":goto 2" \ -c ":goto 2" \
-c ":pipe-line-to sed -e 's/World!/Bork!/g' -e 's/2009//g'" \ -c ":pipe-line-to sed -e 's/World!/Bork!/g' -e 's/2009//g'" \
${test_dir}/logfile_multiline.0 ${test_dir}/logfile_multiline.0
check_output "pipe-line-to is not working" <<EOF check_output "pipe-line-to is not working" <<EOF
Hello, World!
-07-20 22:59:30,221:ERROR:Goodbye, Bork! -07-20 22:59:30,221:ERROR:Goodbye, Bork!
EOF EOF

Loading…
Cancel
Save