diff --git a/libsmartcols/src/buffer.c b/libsmartcols/src/buffer.c index 20953a5dc..d376e8fb8 100644 --- a/libsmartcols/src/buffer.c +++ b/libsmartcols/src/buffer.c @@ -122,8 +122,8 @@ char *buffer_get_safe_data(struct libscols_table *tb, goto nothing; } - if (tb->no_encode) { - *cells = mbs_safe_width(data); + if (scols_table_is_noencoding(tb)) { + *cells = mbs_width(data); strcpy(buf->encdata, data); res = buf->encdata; } else { diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index 360c7e0c1..b6137fd23 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -50,6 +50,8 @@ static int count_cell_width(struct libscols_table *tb, len = 0; else if (scols_column_is_customwrap(cl)) len = cl->wrap_chunksize(cl, data, cl->wrapfunc_data); + else if (scols_table_is_noencoding(tb)) + len = mbs_width(data); else len = mbs_safe_width(data); @@ -101,13 +103,18 @@ static int count_column_width(struct libscols_table *tb, cl->width = 0; if (!cl->width_min) { + const char *data; + if (cl->width_hint < 1 && scols_table_is_maxout(tb) && tb->is_term) { cl->width_min = (size_t) (cl->width_hint * tb->termwidth); if (cl->width_min && !is_last_column(cl)) cl->width_min--; } - if (scols_cell_get_data(&cl->header)) { - size_t len = mbs_safe_width(scols_cell_get_data(&cl->header)); + + data = scols_cell_get_data(&cl->header); + if (data) { + size_t len = scols_table_is_noencoding(tb) ? + mbs_width(data) : mbs_safe_width(data); cl->width_min = max(cl->width_min, len); } else no_header = 1; @@ -189,7 +196,9 @@ int __scols_calculate(struct libscols_table *tb, struct libscols_buffer *buf) DBG(TAB, ul_debugobj(tb, "-----calculate-(termwidth=%zu)-----", tb->termwidth)); tb->is_dummy_print = 1; - colsepsz = mbs_safe_width(colsep(tb)); + colsepsz = scols_table_is_noencoding(tb) ? + mbs_width(colsep(tb)) : + mbs_safe_width(colsep(tb)); if (has_groups(tb)) group_ncolumns = 1; diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index 4b42938f6..f95264b36 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -338,11 +338,15 @@ size_t scols_wrapnl_chunksize(const struct libscols_column *cl __attribute__((un p = strchr(data, '\n'); if (p) { - sz = mbs_safe_nwidth(data, p - data, NULL); + sz = cl->table && scols_table_is_noencoding(cl->table) ? + mbs_nwidth(data, p - data) : + mbs_safe_nwidth(data, p - data, NULL); p++; - } else - sz = mbs_safe_width(data); - + } else { + sz = cl->table && scols_table_is_noencoding(cl->table) ? + mbs_width(data) : + mbs_safe_width(data); + } sum = max(sum, sz); data = p; } diff --git a/libsmartcols/src/print.c b/libsmartcols/src/print.c index c92154219..117253360 100644 --- a/libsmartcols/src/print.c +++ b/libsmartcols/src/print.c @@ -233,7 +233,9 @@ static void print_empty_cell(struct libscols_table *tb, /* only print symbols->vert if followed by child */ if (!list_empty(&ln->ln_branch)) { fputs(vertical_symbol(tb), tb->out); - len_pad = mbs_safe_width(vertical_symbol(tb)); + len_pad = scols_table_is_noencoding(tb) ? + mbs_width(vertical_symbol(tb)) : + mbs_safe_width(vertical_symbol(tb)); } } else { /* use the same draw function as though we were intending to draw an L-shape */ @@ -393,7 +395,9 @@ static int print_pending_data( && (nextchunk = cl->wrap_nextchunk(cl, data, cl->wrapfunc_data))) { bytes = nextchunk - data; - len = mbs_safe_nwidth(data, bytes, NULL); + len = scols_table_is_noencoding(tb) ? + mbs_nwidth(data, bytes) : + mbs_safe_nwidth(data, bytes, NULL); } else bytes = mbs_truncate(data, &len); @@ -511,7 +515,10 @@ static int print_data(struct libscols_table *tb, && (nextchunk = cl->wrap_nextchunk(cl, data, cl->wrapfunc_data))) { set_pending_data(cl, nextchunk, bytes - (nextchunk - data)); bytes = nextchunk - data; - len = mbs_safe_nwidth(data, bytes, NULL); + + len = scols_table_is_noencoding(tb) ? + mbs_nwidth(data, bytes) : + mbs_safe_nwidth(data, bytes, NULL); } if (is_last