[pretty] handle ANSI escapes

Fixes #1020
pull/1031/head
Tim Stack 2 years ago
parent 056754a926
commit 7c3df44fc4

@ -117,6 +117,7 @@ lnav v0.11.0:
executed instead of just the first one.
* In cases where there were many different colors on screen, some
text would be colored incorrectly.
* The pretty-print view now handles ANSI escape sequences.
lnav v0.10.1:
Features:

@ -325,6 +325,7 @@ open_pretty_view()
al.get_string(),
text_sub_source::RF_FULL | text_sub_source::RF_REWRITE);
lss.text_attrs_for_line(*log_tc, vl, al.get_attrs());
scrub_ansi_string(al.get_string(), al.get_attrs());
if (log_tc->get_hide_fields()) {
al.apply_hide();
}
@ -404,22 +405,19 @@ open_pretty_view()
}
} else if (top_tc == text_tc) {
if (text_tc->listview_rows(*text_tc)) {
auto lf = lnav_data.ld_text_source.current_file();
std::string all_lines;
for (vis_line_t vl = text_tc->get_top();
vl <= text_tc->get_bottom();
++vl)
{
auto ll = lf->begin() + vl;
shared_buffer_ref sbr;
lf->read_full_message(ll, sbr);
all_lines.append(sbr.get_data(), sbr.length());
std::vector<attr_line_t> rows;
rows.resize(text_tc->get_bottom() - text_tc->get_top() + 1);
text_tc->listview_value_for_rows(
*text_tc, text_tc->get_top(), rows);
attr_line_t orig_al;
for (const auto& row : rows) {
orig_al.append(row);
}
data_scanner ds(all_lines);
data_scanner ds(orig_al.get_string());
string_attrs_t sa;
pretty_printer pp(&ds, sa);
pretty_printer pp(&ds, orig_al.get_attrs());
pp.append_to(full_text);
all_intervals = pp.take_intervals();

@ -270,6 +270,7 @@ dist_noinst_DATA = \
log.clog \
logfile_access_log.0 \
logfile_access_log.1 \
logfile_ansi.0 \
logfile_bad_access_log.0 \
logfile_bad_syslog.0 \
logfile_block.1 \

@ -318,6 +318,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_meta.sh_fdf4a91aa55262255816dff7d605f1f0a5d6fe92.out \
$(srcdir)/%reldir%/test_pretty_print.sh_3c255c3c8b28df9d694b329a265e8b8140dae4a2.err \
$(srcdir)/%reldir%/test_pretty_print.sh_3c255c3c8b28df9d694b329a265e8b8140dae4a2.out \
$(srcdir)/%reldir%/test_pretty_print.sh_4111e649fb49c0a377e552fa0b56c60c370633da.err \
$(srcdir)/%reldir%/test_pretty_print.sh_4111e649fb49c0a377e552fa0b56c60c370633da.out \
$(srcdir)/%reldir%/test_pretty_print.sh_675a2ff6306df7c54127e39319cf06a2dd353145.err \
$(srcdir)/%reldir%/test_pretty_print.sh_675a2ff6306df7c54127e39319cf06a2dd353145.out \
$(srcdir)/%reldir%/test_pretty_print.sh_7192f8f68adb14705c8a60e73ff8248c61c7fd03.err \
@ -328,6 +330,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_pretty_print.sh_a6d9042e5e95f2a49194bd80c1eed154813ddf41.out \
$(srcdir)/%reldir%/test_pretty_print.sh_cd361eeca7e91bfab942b75d6c3422c7a456a111.err \
$(srcdir)/%reldir%/test_pretty_print.sh_cd361eeca7e91bfab942b75d6c3422c7a456a111.out \
$(srcdir)/%reldir%/test_pretty_print.sh_f8feb52a321026d9562b271eb37a2c56dfaed329.err \
$(srcdir)/%reldir%/test_pretty_print.sh_f8feb52a321026d9562b271eb37a2c56dfaed329.out \
$(srcdir)/%reldir%/test_regex101.sh_0fa3663a45aca6a328cb728872af7ed7ee896f1c.err \
$(srcdir)/%reldir%/test_regex101.sh_0fa3663a45aca6a328cb728872af7ed7ee896f1c.out \
$(srcdir)/%reldir%/test_regex101.sh_182ae9244db314a953af2bee969726e381bc5a32.err \

@ -1,11 +1,11 @@
''
{
"foo bar" : null,
"array" : [
1,
2,
3
],
''
{
 "foo bar" : null,
  "array" : [
  1,
  2,
  3
 ],
"obj" : {
"one" : 1,
"two" : true

@ -1,12 +1,12 @@
{
"foo bar" : null,
"array" : [
1,
2,
3
],
"obj" : {
"one" : 1,
"two" : true
 "foo bar" : null,
 "array" : [
 1,
 2,
 3
 ],
 "obj" : {
"one" : 1,
 "two" : true
}
}

@ -1,8 +1,8 @@
{
"wrapper": [
{"message":""
select Id from Account where id = $sfid
^
ERROR at Row:1:Column:34
line 1:34 no viable alternative at character '$'
""}]}
 "wrapper": [
{"message":""
 select Id from Account where id = $sfid
 ^
 ERROR at Row:1:Column:34
 line 1:34 no viable alternative at character '$'
""}]}

@ -0,0 +1 @@
2022-06-22T10:20:33 Example foo

@ -35,3 +35,11 @@ run_cap_test ${lnav_test} -d /tmp/lnav.err -n \
-I ${test_dir} \
-c ":switch-to-view pretty" \
${test_dir}/logfile_xml_msg.0
run_cap_test ${lnav_test} -n \
-c ":switch-to-view pretty" \
${test_dir}/logfile_ansi.0
run_cap_test ${lnav_test} -n \
-c ":switch-to-view pretty" \
${test_dir}/textfile_ansi.0

@ -0,0 +1 @@
{ Example: foo, bar: baz }
Loading…
Cancel
Save