[cmds] change :write-raw-to to write all the lines in the view

Fixes #606
This commit is contained in:
Timothy Stack 2019-01-29 07:30:37 -08:00
parent 8a3bdbfb2f
commit 3d77fb2acf
6 changed files with 46 additions and 13 deletions

3
NEWS
View File

@ -40,6 +40,9 @@ lnav v0.8.5:
* Hidden fields now show up as a unicode vertical ellipsis (⋮) instead of
three-dot ellipsis to save space.
* Pressing 7/8 will now move to the previous/next minute.
* The ":write-raw-to" command has been changed to write the entire
contents of the current view and a ":write-screen-to" command has been
added to write only the current screen contents.
Fixes:
* The ":write-json-to" command will now pass through JSON cells as their

View File

@ -135,6 +135,9 @@ Output
* write-to <file> - Overwrite the given file with any bookmarked lines in
the current view. Use '-' to write the lines to the terminal and '/dev/clipboard'
to write to the system clipboard.
* write-raw-to <file> - Overwrite the given file with all the lines in the
current view. Use '-' to write the lines to the terminal and '/dev/clipboard'
to write to the system clipboard.
* write-csv-to <file> - Write SQL query results to the given file in CSV format.
Use '-' to write the lines to the terminal and '/dev/clipboard' to write to
the system clipboard.

View File

@ -20,7 +20,7 @@
],
"x0c": [
":write-raw-to -"
":write-screen-to -"
],
"x12": [

View File

@ -645,7 +645,7 @@ static string com_save_to(exec_context &ec, string cmdline, vector<string> &args
return "error: no query result to write, use ';' to execute a query";
}
}
else if (args[0] != "write-raw-to") {
else if (args[0] != "write-raw-to" && args[0] != "write-screen-to") {
if (bv.empty()) {
return "error: no lines marked to write, use 'm' to mark lines";
}
@ -786,6 +786,26 @@ static string com_save_to(exec_context &ec, string cmdline, vector<string> &args
}
}
}
else if (args[0] == "write-screen-to") {
bool wrapped = tc->get_word_wrap();
vis_line_t orig_top = tc->get_top();
tc->set_word_wrap(to_term);
vis_line_t top = tc->get_top();
vis_line_t bottom = tc->get_bottom();
vector<attr_line_t> rows(bottom - top + 1);
tc->listview_value_for_rows(*tc, top, rows);
for (auto &al : rows) {
write_line_to(outfile, al);
line_count += 1;
}
tc->set_word_wrap(wrapped);
tc->set_top(orig_top);
}
else if (args[0] == "write-raw-to") {
if (tc == &lnav_data.ld_views[LNV_DB]) {
std::vector<std::vector<const char *> >::iterator row_iter;
@ -810,23 +830,20 @@ static string com_save_to(exec_context &ec, string cmdline, vector<string> &args
}
} else {
bool wrapped = tc->get_word_wrap();
vis_line_t orig_top = tc->get_top();
auto tss = tc->get_sub_source();
tc->set_word_wrap(to_term);
vis_line_t top = tc->get_top();
vis_line_t bottom = tc->get_bottom();
vector<attr_line_t> rows(bottom - top + 1);
for (size_t lpc = 0; lpc < tss->text_line_count(); lpc++) {
string line;
tc->listview_value_for_rows(*tc, top, rows);
for (auto &al : rows) {
write_line_to(outfile, al);
tss->text_value_for_line(*tc, lpc, line, text_sub_source::RF_RAW);
fprintf(outfile, "%s\n", line.c_str());
line_count += 1;
}
tc->set_word_wrap(wrapped);
tc->set_top(orig_top);
}
}
else {
@ -3958,6 +3975,16 @@ readline_context::command_t STD_COMMANDS[] = {
com_save_to,
help_text(":write-raw-to")
.with_summary("Write the text in the top view to the given file without any formatting")
.with_parameter(help_text("path", "The path to the file to write"))
.with_tags({"io", "scripting", "sql"})
.with_example({"/tmp/table.txt"})
},
{
"write-screen-to",
com_save_to,
help_text(":write-screen-to")
.with_summary("Write the displayed text or SQL results to the given file without any formatting")
.with_parameter(help_text("path", "The path to the file to write"))
.with_tags({"io", "scripting", "sql"})

View File

@ -479,10 +479,10 @@ EOF
run_test ${lnav_test} -n \
-c ":goto 1" \
-c ":write-raw-to -" \
-c ":write-screen-to -" \
"${test_dir}/logfile_access_log.0"
check_output "write-raw-to not working" <<EOF
check_output "write-screen-to not working" <<EOF
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkernel.gz HTTP/1.0" 200 78929 "-" "gPXE/0.9.7"
EOF

View File

@ -10,7 +10,7 @@ run_test ${lnav_test} -n \
-c ":comment Hello, World!" \
-c ":tag foo" \
-c ":save-session" \
-c ":write-raw-to -" \
-c ":write-screen-to -" \
${test_dir}/logfile_access_log.0
check_output ":tag did not work?" <<EOF