[view_curses] add a unit type to line_range

Fixes #1033
This commit is contained in:
Tim Stack 2022-09-03 08:49:47 -07:00
parent a813482a54
commit 7309352c97
8 changed files with 34 additions and 14 deletions

View File

@ -47,11 +47,17 @@
* Encapsulates a range in a string.
*/
struct line_range {
enum class unit {
bytes,
codepoint,
};
int lr_start;
int lr_end;
unit lr_unit;
explicit line_range(int start = -1, int end = -1)
: lr_start(start), lr_end(end)
explicit line_range(int start = -1, int end = -1, unit u = unit::bytes)
: lr_start(start), lr_end(end), lr_unit(u)
{
}

View File

@ -123,7 +123,7 @@ hist_source2::add_value(time_t row,
this->hs_last_row = row;
}
bucket_t& bucket = this->find_bucket(this->hs_last_bucket);
auto& bucket = this->find_bucket(this->hs_last_bucket);
bucket.b_time = row;
bucket.b_values[htype].hv_value += value;
}

View File

@ -175,6 +175,8 @@ public:
struct line_range lr;
vis_line_t height;
lr.lr_unit = line_range::unit::codepoint;
size_t ident_to_show = this->sbc_show_state.match(
[](const show_none) { return -1; },
[ident_index](const show_all) { return ident_index; },

View File

@ -251,18 +251,20 @@ view_curses::mvwattrline(WINDOW* window,
continue;
}
for (const auto& adj : utf_adjustments) {
// If the UTF adjustment is in the viewport, we need to adjust this
// attribute.
if (adj.uda_origin < iter->sa_range.lr_start) {
attr_range.lr_start += adj.uda_offset;
}
}
if (attr_range.lr_end != -1) {
if (attr_range.lr_unit == line_range::unit::bytes) {
for (const auto& adj : utf_adjustments) {
if (adj.uda_origin < iter->sa_range.lr_end) {
attr_range.lr_end += adj.uda_offset;
// If the UTF adjustment is in the viewport, we need to adjust
// this attribute.
if (adj.uda_origin < iter->sa_range.lr_start) {
attr_range.lr_start += adj.uda_offset;
}
}
if (attr_range.lr_end != -1) {
for (const auto& adj : utf_adjustments) {
if (adj.uda_origin < iter->sa_range.lr_end) {
attr_range.lr_end += adj.uda_offset;
}
}
}
}

View File

@ -536,6 +536,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_sql.sh_b2694e4fbecdd128798af25ee0d069e7e35fb499.out \
$(srcdir)/%reldir%/test_sql.sh_b5aa0561a65de7e8e22085db184c72a94b1a89a9.err \
$(srcdir)/%reldir%/test_sql.sh_b5aa0561a65de7e8e22085db184c72a94b1a89a9.out \
$(srcdir)/%reldir%/test_sql.sh_bad03a996c0750733ab99c592b9011851f521a69.err \
$(srcdir)/%reldir%/test_sql.sh_bad03a996c0750733ab99c592b9011851f521a69.out \
$(srcdir)/%reldir%/test_sql.sh_bd46ca4560f8be6307a914e39539bbac0368080a.err \
$(srcdir)/%reldir%/test_sql.sh_bd46ca4560f8be6307a914e39539bbac0368080a.out \
$(srcdir)/%reldir%/test_sql.sh_c20b0320096342c180146a5d18a6de82319d70b2.err \

View File

@ -0,0 +1,5 @@
match_index  content  case match_index when 2 then replicate('abc', 1000) else '' end 
  0 {"col_0":10}  
 1 {"col_0":50}  
 2 {"col_0":50} abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc⋯bcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc 
 3 {"col_0":50}  

View File

@ -1092,3 +1092,6 @@ run_cap_test ${lnav_test} -n \
-c ':switch-to-view db' \
-c ';SELECT lnav_top_file()' \
${test_dir}/logfile_access_log.0
run_cap_test ${lnav_test} -Nn \
-c ";select *,case match_index when 2 then replicate('abc', 1000) else '' end from regexp_capture_into_json('10;50;50;50;', '(\d+);')"