[attr_line] tweak shifting of attributes

Fixes #1017
pull/1031/head
Tim Stack 2 years ago
parent 40037b0fd1
commit 3cafcf3c77

@ -343,10 +343,9 @@ attr_line_t::subline(size_t start, size_t len) const
continue; continue;
} }
retval.al_attrs.emplace_back( auto ilr = lr.intersection(sa.sa_range).shift(0, -lr.lr_start);
lr.intersection(sa.sa_range).shift(lr.lr_start, -lr.lr_start), retval.al_attrs.emplace_back(ilr,
std::make_pair(sa.sa_type, sa.sa_value)); std::make_pair(sa.sa_type, sa.sa_value));
const auto& last_lr = retval.al_attrs.back().sa_range; const auto& last_lr = retval.al_attrs.back().sa_range;
ensure(last_lr.lr_end <= (int) retval.al_string.length()); ensure(last_lr.lr_end <= (int) retval.al_string.length());
@ -508,7 +507,17 @@ line_range::intersection(const line_range& other) const
line_range& line_range&
line_range::shift(int32_t start, int32_t amount) line_range::shift(int32_t start, int32_t amount)
{ {
if (start <= this->lr_start) { if (start == this->lr_start) {
if (amount > 0) {
this->lr_start += amount;
}
if (this->lr_end != -1) {
this->lr_end += amount;
if (this->lr_end < this->lr_start) {
this->lr_end = this->lr_start;
}
}
} else if (start < this->lr_start) {
this->lr_start = std::max(0, this->lr_start + amount); this->lr_start = std::max(0, this->lr_start + amount);
if (this->lr_end != -1) { if (this->lr_end != -1) {
this->lr_end = std::max(0, this->lr_end + amount); this->lr_end = std::max(0, this->lr_end + amount);

@ -160,7 +160,17 @@ struct string_attr {
bool operator<(const struct string_attr& rhs) const bool operator<(const struct string_attr& rhs) const
{ {
return this->sa_range < rhs.sa_range; if (this->sa_range < rhs.sa_range) {
return true;
}
if (this->sa_range == rhs.sa_range && this->sa_type == rhs.sa_type
&& this->sa_type == &VC_ROLE
&& this->sa_value.get<role_t>() < rhs.sa_value.get<role_t>())
{
return true;
}
return false;
} }
struct line_range sa_range; struct line_range sa_range;

@ -515,7 +515,7 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
lnav_data.ld_active_files.fc_files lnav_data.ld_active_files.fc_files
| lnav::itertools::for_each(&logfile::dump_stats); | lnav::itertools::for_each(&logfile::dump_stats);
if (!ec.ec_accumulator->empty()) { if (ec.ec_sql_callback != sql_callback) {
retval = ec.ec_accumulator->get_string(); retval = ec.ec_accumulator->get_string();
} else if (!dls.dls_rows.empty()) { } else if (!dls.dls_rows.empty()) {
if (lnav_data.ld_flags & LNF_HEADLESS) { if (lnav_data.ld_flags & LNF_HEADLESS) {
@ -532,7 +532,8 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
retval = row[0]; retval = row[0];
} else { } else {
for (unsigned int lpc = 0; lpc < dls.dls_headers.size(); for (unsigned int lpc = 0; lpc < dls.dls_headers.size();
lpc++) { lpc++)
{
if (lpc > 0) { if (lpc > 0) {
retval.append("; "); retval.append("; ");
} }

@ -2194,7 +2194,7 @@ ltrim(*str*, *\[chars\]*)
* **chars** --- The characters to trim. Defaults to spaces. * **chars** --- The characters to trim. Defaults to spaces.
**Examples** **Examples**
To trim the leading whitespace from the string ' abc': To trim the leading space characters from the string ' abc':
.. code-block:: custsqlite .. code-block:: custsqlite
@ -3029,7 +3029,7 @@ rtrim(*str*, *\[chars\]*)
* **chars** --- The characters to trim. Defaults to spaces. * **chars** --- The characters to trim. Defaults to spaces.
**Examples** **Examples**
To trim the whitespace from the end of the string 'abc ': To trim the space characters from the end of the string 'abc ':
.. code-block:: custsqlite .. code-block:: custsqlite
@ -3577,7 +3577,7 @@ trim(*str*, *\[chars\]*)
* **chars** --- The characters to trim. Defaults to spaces. * **chars** --- The characters to trim. Defaults to spaces.
**Examples** **Examples**
To trim whitespace from the start and end of the string ' abc ': To trim spaces from the start and end of the string ' abc ':
.. code-block:: custsqlite .. code-block:: custsqlite

@ -1226,12 +1226,13 @@ external_log_format::rewrite(exec_context& ec,
} else { } else {
field_value = exec_res.unwrapErr().to_attr_line().get_string(); field_value = exec_res.unwrapErr().to_attr_line().get_string();
} }
struct line_range adj_origin auto adj_origin
= iter->origin_in_full_msg(value_out.c_str(), value_out.length()); = iter->origin_in_full_msg(value_out.c_str(), value_out.length());
value_out.erase(adj_origin.lr_start, adj_origin.length()); value_out.erase(adj_origin.lr_start, adj_origin.length());
int32_t shift_amount = field_value.length() - adj_origin.length(); int32_t shift_amount
= ((int32_t) field_value.length()) - adj_origin.length();
value_out.insert(adj_origin.lr_start, field_value); value_out.insert(adj_origin.lr_start, field_value);
for (shift_iter = values.lvv_values.begin(); for (shift_iter = values.lvv_values.begin();
shift_iter != values.lvv_values.end(); shift_iter != values.lvv_values.end();

@ -58,7 +58,8 @@
STRONG_INT_TYPE(uint64_t, content_line); STRONG_INT_TYPE(uint64_t, content_line);
struct sqlite3_stmt; struct sqlite3_stmt;
extern "C" { extern "C"
{
int sqlite3_finalize(sqlite3_stmt* pStmt); int sqlite3_finalize(sqlite3_stmt* pStmt);
} }
@ -327,10 +328,7 @@ public:
log_level_t get_min_log_level() const { return this->lss_min_log_level; } log_level_t get_min_log_level() const { return this->lss_min_log_level; }
void set_force_rebuild() void set_force_rebuild() { this->lss_force_rebuild = true; }
{
this->lss_force_rebuild = true;
}
void set_min_log_level(log_level_t level) void set_min_log_level(log_level_t level)
{ {
@ -669,10 +667,7 @@ public:
return this->get_file_ptr() != nullptr && this->ld_visible; return this->get_file_ptr() != nullptr && this->ld_visible;
} }
void set_visibility(bool vis) void set_visibility(bool vis) { this->ld_visible = vis; }
{
this->ld_visible = vis;
}
size_t ld_file_index; size_t ld_file_index;
line_filter_observer ld_filter_state; line_filter_observer ld_filter_state;
@ -996,7 +991,7 @@ private:
size_t lss_longest_line{0}; size_t lss_longest_line{0};
meta_grepper lss_meta_grepper; meta_grepper lss_meta_grepper;
log_location_history lss_location_history; log_location_history lss_location_history;
exec_context* lss_exec_context; exec_context* lss_exec_context{nullptr};
bool lss_in_value_for_line{false}; bool lss_in_value_for_line{false};
bool lss_line_meta_changed{false}; bool lss_line_meta_changed{false};

@ -145,7 +145,8 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
last_block.append("\n"); last_block.append("\n");
} }
if (this->ml_list_stack.empty() if (this->ml_list_stack.empty()
&& !endswith(last_block.get_string(), "\n\n")) { && !endswith(last_block.get_string(), "\n\n"))
{
last_block.append("\n"); last_block.append("\n");
} }
} }
@ -313,7 +314,8 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
} }
} }
for (size_t line_index = 0; line_index < max_cell_lines; for (size_t line_index = 0; line_index < max_cell_lines;
line_index++) { line_index++)
{
size_t col = 0; size_t col = 0;
for (const auto& cell : cells) { for (const auto& cell : cells) {
block_text.append(" "); block_text.append(" ");

@ -49,7 +49,6 @@ static void readline_shlex_highlighter_int(attr_line_t& al,
int x, int x,
line_range sub); line_range sub);
static bool static bool
is_bracket(const std::string& str, int index, bool is_lit) is_bracket(const std::string& str, int index, bool is_lit)
{ {
@ -263,7 +262,8 @@ readline_sqlite_highlighter_int(attr_line_t& al, int x, line_range sub)
sub.lr_start + attr.sa_range.lr_end, sub.lr_start + attr.sa_range.lr_end,
}; };
if (attr.sa_type == &SQL_COMMAND_ATTR if (attr.sa_type == &SQL_COMMAND_ATTR
|| attr.sa_type == &SQL_KEYWORD_ATTR) { || attr.sa_type == &SQL_KEYWORD_ATTR)
{
alb.overlay_attr(lr, VC_ROLE.value(role_t::VCR_KEYWORD)); alb.overlay_attr(lr, VC_ROLE.value(role_t::VCR_KEYWORD));
} else if (attr.sa_type == &SQL_IDENTIFIER_ATTR) { } else if (attr.sa_type == &SQL_IDENTIFIER_ATTR) {
if (!attr.sa_range.contains(x) && attr.sa_range.lr_end != x) { if (!attr.sa_range.contains(x) && attr.sa_range.lr_end != x) {

@ -210,21 +210,23 @@ spectrogram_source::list_value_for_overlay(const listview_curses& lv,
+ this->ss_cursor_column.value() * sr.sr_column_size; + this->ss_cursor_column.value() * sr.sr_column_size;
auto range_max = range_min + sr.sr_column_size; auto range_max = range_min + sr.sr_column_size;
auto desc = attr_line_t() auto desc
.append(lnav::roles::number( = attr_line_t()
fmt::to_string(bucket.rb_counter))) .append(lnav::roles::number(
.append(lnav::roles::comment(fmt::format( fmt::to_string(bucket.rb_counter)))
FMT_STRING(" value{} in the range "), .append(fmt::format(FMT_STRING(" value{} in the range "),
bucket.rb_counter == 1 ? "" : "s"))) bucket.rb_counter == 1 ? "" : "s"))
.append(lnav::roles::number( .append(lnav::roles::number(
fmt::format(FMT_STRING("{:.2Lf}"), range_min))) fmt::format(FMT_STRING("{:.2Lf}"), range_min)))
.append(lnav::roles::comment("-")) .append("-")
.append(lnav::roles::number( .append(lnav::roles::number(
fmt::format(FMT_STRING("{:.2Lf}"), range_max))) fmt::format(FMT_STRING("{:.2Lf}"), range_max)))
.append(" "); .append(" ");
auto mark_offset = this->ss_cursor_column.value(); auto mark_offset = this->ss_cursor_column.value();
auto mark_is_before = true; auto mark_is_before = true;
value_out.al_attrs.emplace_back(
line_range{0, -1}, VC_ROLE.value(role_t::VCR_STATUS_INFO));
if (desc.length() + 8 > width) { if (desc.length() + 8 > width) {
desc.clear(); desc.clear();
} }

@ -37,7 +37,8 @@
#include "config.h" #include "config.h"
#include "sql_help.hh" #include "sql_help.hh"
extern "C" { extern "C"
{
struct sqlite3_api_routines; struct sqlite3_api_routines;
int sqlite3_series_init(sqlite3* db, int sqlite3_series_init(sqlite3* db,
@ -270,12 +271,15 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
"The characters to trim. Defaults to spaces.") "The characters to trim. Defaults to spaces.")
.optional()) .optional())
.with_tags({"string"}) .with_tags({"string"})
.with_example( .with_example({
{"To trim the leading whitespace from the string ' abc'", "To trim the leading space characters from the string ' abc'",
"SELECT ltrim(' abc')"}) "SELECT ltrim(' abc')",
.with_example({"To trim the characters 'a' or 'b' from the left " })
"side of the string 'aaaabbbc'", .with_example({
"SELECT ltrim('aaaabbbc', 'ab')"}), "To trim the characters 'a' or 'b' from the left side of the "
"string 'aaaabbbc'",
"SELECT ltrim('aaaabbbc', 'ab')",
}),
help_text("max", help_text("max",
"Returns the argument with the maximum value, or return NULL " "Returns the argument with the maximum value, or return NULL "
@ -402,12 +406,16 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
"The characters to trim. Defaults to spaces.") "The characters to trim. Defaults to spaces.")
.optional()) .optional())
.with_tags({"string"}) .with_tags({"string"})
.with_example( .with_example({
{"To trim the whitespace from the end of the string 'abc '", "To trim the space characters from the end of the string 'abc "
"SELECT rtrim('abc ')"}) " '",
.with_example({"To trim the characters 'b' and 'c' from the string " "SELECT rtrim('abc ')",
"'abbbbcccc'", })
"SELECT rtrim('abbbbcccc', 'bc')"}), .with_example({
"To trim the characters 'b' and 'c' from the string "
"'abbbbcccc'",
"SELECT rtrim('abbbbcccc', 'bc')",
}),
help_text("sqlite_compileoption_get", help_text("sqlite_compileoption_get",
"Returns the N-th compile-time option used to build SQLite " "Returns the N-th compile-time option used to build SQLite "
@ -487,12 +495,15 @@ register_sqlite_funcs(sqlite3* db, sqlite_registration_func_t* reg_funcs)
"The characters to trim. Defaults to spaces.") "The characters to trim. Defaults to spaces.")
.optional()) .optional())
.with_tags({"string"}) .with_tags({"string"})
.with_example({"To trim whitespace from the start and end of the " .with_example({
"string ' abc '", "To trim spaces from the start and end of the string ' abc "
"SELECT trim(' abc ')"}) " '",
.with_example( "SELECT trim(' abc ')",
{"To trim the characters '-' and '+' from the string '-+abc+-'", })
"SELECT trim('-+abc+-', '-+')"}), .with_example({
"To trim the characters '-' and '+' from the string '-+abc+-'",
"SELECT trim('-+abc+-', '-+')",
}),
help_text( help_text(
"typeof", "typeof",

@ -303,12 +303,10 @@ open_pretty_view()
std::vector<std::unique_ptr<lnav::document::hier_node>> hier_nodes; std::vector<std::unique_ptr<lnav::document::hier_node>> hier_nodes;
std::vector<pretty_sub_source::hier_interval_t> hier_tree_vec; std::vector<pretty_sub_source::hier_interval_t> hier_tree_vec;
if (top_tc == log_tc) { if (top_tc == log_tc) {
logfile_sub_source& lss = lnav_data.ld_log_source; auto& lss = lnav_data.ld_log_source;
bool first_line = true; bool first_line = true;
for (vis_line_t vl = log_tc->get_top(); vl <= log_tc->get_bottom(); for (auto vl = log_tc->get_top(); vl <= log_tc->get_bottom(); ++vl) {
++vl)
{
content_line_t cl = lss.at(vl); content_line_t cl = lss.at(vl);
auto lf = lss.find(cl); auto lf = lss.find(cl);
auto ll = lf->begin() + cl; auto ll = lf->begin() + cl;

@ -318,6 +318,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_meta.sh_fdf4a91aa55262255816dff7d605f1f0a5d6fe92.out \ $(srcdir)/%reldir%/test_meta.sh_fdf4a91aa55262255816dff7d605f1f0a5d6fe92.out \
$(srcdir)/%reldir%/test_pretty_print.sh_3c255c3c8b28df9d694b329a265e8b8140dae4a2.err \ $(srcdir)/%reldir%/test_pretty_print.sh_3c255c3c8b28df9d694b329a265e8b8140dae4a2.err \
$(srcdir)/%reldir%/test_pretty_print.sh_3c255c3c8b28df9d694b329a265e8b8140dae4a2.out \ $(srcdir)/%reldir%/test_pretty_print.sh_3c255c3c8b28df9d694b329a265e8b8140dae4a2.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 \ $(srcdir)/%reldir%/test_pretty_print.sh_7192f8f68adb14705c8a60e73ff8248c61c7fd03.err \
$(srcdir)/%reldir%/test_pretty_print.sh_7192f8f68adb14705c8a60e73ff8248c61c7fd03.out \ $(srcdir)/%reldir%/test_pretty_print.sh_7192f8f68adb14705c8a60e73ff8248c61c7fd03.out \
$(srcdir)/%reldir%/test_pretty_print.sh_a5bee322ea3374690e44a88a16cb6b84feaa11d3.err \ $(srcdir)/%reldir%/test_pretty_print.sh_a5bee322ea3374690e44a88a16cb6b84feaa11d3.err \

@ -1 +1 @@
 2009-07-20 22:59:30,221:ERROR:Goodbye, World! 2009-07-20 22:59:30,221:ERROR:Goodbye, World!

@ -1,2 +1,2 @@
2009-07-20 22:59:30,221:ERROR:Goodbye, World! 2009-07-20 22:59:30,221:ERROR:Goodbye, World!
 2009-07-20 22:59:30,221:ERROR:Goodbye, World! 2009-07-20 22:59:30,221:ERROR:Goodbye, World!

@ -2990,7 +2990,7 @@ lnav@googlegroups.com[1] support@lnav.org[2]
rtrim(), sparkline(), spooky_hash(), startswith(), strfilter(), rtrim(), sparkline(), spooky_hash(), startswith(), strfilter(),
substr(), trim(), unicode(), upper(), xpath() substr(), trim(), unicode(), upper(), xpath()
Examples Examples
#1 To trim the leading whitespace from the string ' abc': #1 To trim the leading space characters from the string ' abc':
;SELECT ltrim(' abc')  ;SELECT ltrim(' abc') 
@ -3614,7 +3614,7 @@ lnav@googlegroups.com[1] support@lnav.org[2]
rightstr(), sparkline(), spooky_hash(), startswith(), strfilter(), rightstr(), sparkline(), spooky_hash(), startswith(), strfilter(),
substr(), trim(), unicode(), upper(), xpath() substr(), trim(), unicode(), upper(), xpath()
Examples Examples
#1 To trim the whitespace from the end of the string 'abc ': #1 To trim the space characters from the end of the string 'abc ':
;SELECT rtrim('abc ')  ;SELECT rtrim('abc ') 
@ -4005,7 +4005,7 @@ lnav@googlegroups.com[1] support@lnav.org[2]
rightstr(), rtrim(), sparkline(), spooky_hash(), startswith(), rightstr(), rtrim(), sparkline(), spooky_hash(), startswith(),
strfilter(), substr(), unicode(), upper(), xpath() strfilter(), substr(), unicode(), upper(), xpath()
Examples Examples
#1 To trim whitespace from the start and end of the string ' abc ': #1 To trim spaces from the start and end of the string ' abc ':
;SELECT trim(' abc ')  ;SELECT trim(' abc ') 

@ -0,0 +1,5 @@
[2020-12-10 06:56:41,061] INFO [:108] Calling 'x' with params:
[2020-12-10 06:56:41,092] DEBUG [:69] Full request text:
/a-request, /a-request/head, /a-request/source, /a-request/request, /a-request/request/name
[2020-12-10 06:56:41,099] DEBUG [:85] Full reply text:
/a-reply, /a-reply/head, /a-reply/reply, /a-reply/reply/status, /a-reply/reply/status/result, /a-reply/reply/name, /a-reply/technical-track

@ -1,4 +1,4 @@
Min: 0   1-23   24-48   49+ Max: 291690 Min: 0   1-23   24-48   49+ Max: 291690
 Thu Nov 03 00:15:00                 Thu Nov 03 00:15:00               
70 values in the range 0.00-3788.18 70 values in the range 0.00-3788.18
 Thu Nov 03 00:20:00  Thu Nov 03 00:20:00

@ -5,7 +5,7 @@
"description": "", "description": "",
"regex": { "regex": {
"std": { "std": {
"pattern": "^\\[(?<timestamp>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3})\\]\\s+(?<level>\\w+)\\s+\\[(?<module>[^:]*):(?<line>\\d+)\\]\\s*(?<body>[^\\n]*)\\n?(?<msg_data>(?:.|\\n)*)" "pattern": "^\\[(?<timestamp>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3})\\]\\s+(?<level>\\w+)\\s+\\[(?<module>[^:]*):(?<line>\\d+)\\]\\s*(?<body>[^\\n]*)\\n?(?<msg_data>.*)"
} }
}, },
"level": { "level": {
@ -19,7 +19,8 @@
"module": { "module": {
"kind": "string", "kind": "string",
"identifier": true, "identifier": true,
"description": "Python source module which emitted log entry" "description": "Python source module which emitted log entry",
"rewriter": ";SELECT ''"
}, },
"line": { "line": {
"kind": "integer", "kind": "integer",
@ -36,7 +37,8 @@
"hidden": true "hidden": true
}, },
"msg_data": { "msg_data": {
"kind": "xml" "kind": "xml",
"rewriter": ";SELECT node_path FROM xpath('//*', :msg_data)"
} }
}, },
"highlights": { "highlights": {

@ -30,3 +30,8 @@ Hello\\nWorld\\n
EOF EOF
run_cap_test ${lnav_test} -d /tmp/lnav.err -n -c ":switch-to-view pretty" test_pretty_in.3 run_cap_test ${lnav_test} -d /tmp/lnav.err -n -c ":switch-to-view pretty" test_pretty_in.3
run_cap_test ${lnav_test} -d /tmp/lnav.err -n \
-I ${test_dir} \
-c ":switch-to-view pretty" \
${test_dir}/logfile_xml_msg.0

Loading…
Cancel
Save