add a lo-fi mode

Fixes #113
This commit is contained in:
Timothy Stack 2014-11-11 08:44:44 -08:00
parent ba83382b38
commit 17db6e38fe
8 changed files with 80 additions and 10 deletions

5
NEWS
View File

@ -1,6 +1,11 @@
lnav v0.7.2:
* Added a log format for vdsm.
* Added a "lo-fi" mode (L hotkey) that dumps the displayed log lines
to the terminal without any decorations. The write-to, write-json-to,
and write-csv-to commands will also write their output to the terminal
when passed '-' as the file name. This mode can be useful for copying
plain text lines to the clipboard.
lnav v0.7.1:
Features:

View File

@ -59,7 +59,8 @@ Output
* append-to <file> - Append any bookmarked lines in the current view to the
given file.
* write-to <file> - Overwrite the given file with any bookmarked lines in
the current view.
the current view. Use '-' to write the lines to the terminal.
* write-csv-to <file> - Write SQL query results to the given file in CSV format.
Use '-' to write the lines to the terminal.
* write-json-to <file> - Write SQL query results to the given file in JSON
format.
format. Use '-' to write the lines to the terminal.

View File

@ -191,6 +191,9 @@ Display
- Toggle the display of the log parser results
* - |ks| Tab |ke|
- Cycle through colums to graph in the SQL result view
* - |ks| L |ke|
- Switch to lo-fi mode. The displayed log lines will be dumped to the
terminal without any decorations so they can be copied easily.
Query
-----

View File

@ -164,6 +164,12 @@ through the file.
t Switch to/from the text file view. The text file view is
for any files that are not recognized as log files.
L (Lo-fi mode) Exit screen-mode and write the
displayed log lines in plain text to the terminal
until a key is pressed. Useful for copying long lines
from the terminal without picking up any of the extra
decorations.
o/O Move forward/backward 60 minutes from the current
position in the log file.
@ -417,19 +423,22 @@ COMMANDS
append-to <file> Append any marked lines to the given file.
write-to <file> Write any marked lines to the given file.
write-to <file> Write any marked lines to the given file. Use '-' to
write the lines to the terminal.
write-csv-to <file>
Write the results of a SQL query to a CSV-formatted file.
When running in non-interactive mode, a dash can be used
to write to standard out.
to write to standard out. Use '-' to write the data to
the terminal.
write-json-to <file>
Write the results of a SQL query to a JSON-formatted file.
The contents of the file will be an array of objects with
each column in the query being a field in the objects.
When running in non-interactive mode, a dash can be used
to write to standard out.
to write to standard out. Use '-' to write the data to
the terminal.
session <cmd> Add the given command to the session file
(~/.lnav/session). Any commands listed in the session file

View File

@ -1645,6 +1645,36 @@ static void handle_paging_key(int ch)
}
break;
case 'L': {
vis_line_t top = tc->get_top();
vis_line_t bottom = tc->get_bottom();
char line_break[80];
nodelay(lnav_data.ld_window, 0);
endwin();
{
guard_termios tguard(STDOUT_FILENO);
struct termios new_termios = *tguard.get_termios();
new_termios.c_oflag |= ONLCR | OPOST | OXTABS;
tcsetattr(STDOUT_FILENO, TCSANOW, &new_termios);
snprintf(line_break, sizeof(line_break),
"\n---------------- Lines %'d-%'d ----------------\n\n",
(int) top, (int) bottom);
write(STDOUT_FILENO, line_break, strlen(line_break));
for (; top <= bottom; ++top) {
attr_line_t al;
tc->listview_value_for_row(*tc, top, al);
write(STDOUT_FILENO, al.get_string().c_str(), al.length());
write(STDOUT_FILENO, "\n", 1);
}
}
cbreak();
getch();
refresh();
nodelay(lnav_data.ld_window, 1);
break;
}
case 'M':
if (lnav_data.ld_last_user_mark.find(tc) ==
lnav_data.ld_last_user_mark.end()) {

View File

@ -315,6 +315,7 @@ static string com_save_to(string cmdline, vector<string> &args)
FILE * outfile = NULL;
const char *mode = "";
string fn, retval;
bool to_term = false;
if (args.size() == 0) {
args.push_back("filename");
@ -322,7 +323,7 @@ static string com_save_to(string cmdline, vector<string> &args)
}
if (args.size() < 2) {
return "error: expecting file name";
return "error: expecting file name or '-' to write to the terminal";
}
fn = trim(cmdline.substr(cmdline.find(args[1], args[0].size())));
@ -364,11 +365,24 @@ static string com_save_to(string cmdline, vector<string> &args)
}
if (strcmp(wordmem->we_wordv[0], "-") == 0) {
if (!(lnav_data.ld_flags & LNF_HEADLESS)) {
return "error: writing to stdout is only available in headless mode";
}
outfile = stdout;
lnav_data.ld_stdout_used = true;
if (lnav_data.ld_flags & LNF_HEADLESS) {
lnav_data.ld_stdout_used = true;
}
else {
nodelay(lnav_data.ld_window, 0);
endwin();
struct termios curr_termios;
tcgetattr(1, &curr_termios);
curr_termios.c_oflag |= ONLCR|OPOST|OXTABS;
tcsetattr(1, TCSANOW, &curr_termios);
setvbuf(stdout, NULL, _IONBF, 0);
to_term = true;
fprintf(outfile,
"\n---------------- %s output, press any key to exit "
"----------------\n\n",
args[0].c_str());
}
}
else if ((outfile = fopen(wordmem->we_wordv[0], mode)) == NULL) {
return "error: unable to open file -- " + string(wordmem->we_wordv[0]);
@ -437,6 +451,12 @@ static string com_save_to(string cmdline, vector<string> &args)
}
}
if (to_term) {
cbreak();
getch();
refresh();
nodelay(lnav_data.ld_window, 1);
}
if (outfile != stdout) {
fclose(outfile);
}

View File

@ -223,6 +223,7 @@ dist_noinst_DATA = \
logfile_tcf.0 \
logfile_tcf.1 \
logfile_tcsh_history.0 \
logfile_vdsm.0 \
logfile_with_a_really_long_name_to_test_a_bug_with_long_names.0 \
mvwattrline_output.0 \
simple-db.sql \

View File

@ -805,6 +805,7 @@ dist_noinst_DATA = \
logfile_tcf.0 \
logfile_tcf.1 \
logfile_tcsh_history.0 \
logfile_vdsm.0 \
logfile_with_a_really_long_name_to_test_a_bug_with_long_names.0 \
mvwattrline_output.0 \
simple-db.sql \