From: Phillip Susi <psusi@ubuntu.com>
To: util-linux <util-linux@vger.kernel.org>
Subject: libsmartcols patch
Date: Sun, 28 Dec 2014 20:30:00 -0500 [thread overview]
Message-ID: <54A0AE98.70503@ubuntu.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 61 bytes --]
Forwarding patch from https://launchpad.net/bugs/1406133:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: libsmartcols-art-fix.diff --]
[-- Type: text/x-patch; name="libsmartcols-art-fix.diff", Size: 2987 bytes --]
--- libsmartcols/src/table_print.c 2014-12-24 23:59:55.780110296 +0200
+++ libsmartcols/src/table_print.c 2014-12-28 22:45:20.347285226 +0200
@@ -151,6 +151,32 @@
return bytes;
}
+/* returns pointer to the end of used data */
+static int line_ascii_art_to_buffer(struct libscols_table *tb,
+ struct libscols_line *ln,
+ struct libscols_buffer *buf)
+{
+ const char *art;
+ int rc;
+
+ assert(ln);
+ assert(buf);
+
+ if (!ln->parent)
+ return 0;
+
+ rc = line_ascii_art_to_buffer(tb, ln->parent, buf);
+ if (rc)
+ return rc;
+
+ if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch))
+ art = " ";
+ else
+ art = tb->symbols->vert;
+
+ return buffer_append_data(buf, art);
+}
+
#define is_last_column(_tb, _cl) \
list_entry_is_last(&(_cl)->cl_columns, &(_tb)->tb_columns)
@@ -258,8 +284,33 @@
if (len > width && !scols_column_is_trunc(cl)) {
fputs(linesep(tb), tb->out);
for (i = 0; i <= (size_t) cl->seqnum; i++) {
- struct libscols_column *x = scols_table_get_column(tb, i);
- fprintf(tb->out, "%*s ", -((int)x->width), " ");
+ size_t len_pad = 0; /* in screen cells as opposed to bytes */
+ struct libscols_column* cl_pad = scols_table_get_column(tb, i);
+ if(ln && scols_column_is_tree(cl_pad)) {
+ if (!ln->parent) { /* Root cell needs special treatment. */
+ if (!list_empty(&ln->ln_branch)) { /* only print symbols->vert if followed by something */
+ fputs(tb->symbols->vert, tb->out);
+ len_pad = mbs_safe_width(tb->symbols->vert);
+ }
+ } else { /* use the same draw function as though we were intending to draw an L-shape */
+ struct libscols_buffer* b_art = new_buffer(1024); /* TODO: FIXME proper size */
+ char* data = 0;
+
+ if(b_art) {
+ line_ascii_art_to_buffer(tb, ln, b_art); /* whatever the rc, len_pad will be sensible */
+ data = buffer_get_safe_data(b_art, &len_pad);
+ if(data && len_pad) {
+ fputs(data, tb->out);
+ }
+
+ free_buffer(b_art);
+ }
+ }
+ }
+ for(; len_pad <= cl_pad->width; ++len_pad)
+ {
+ fputc(' ', tb->out);
+ }
}
} else
fputs(colsep(tb), tb->out); /* columns separator */
@@ -268,32 +319,6 @@
return 0;
}
-/* returns pointer to the end of used data */
-static int line_ascii_art_to_buffer(struct libscols_table *tb,
- struct libscols_line *ln,
- struct libscols_buffer *buf)
-{
- const char *art;
- int rc;
-
- assert(ln);
- assert(buf);
-
- if (!ln->parent)
- return 0;
-
- rc = line_ascii_art_to_buffer(tb, ln->parent, buf);
- if (rc)
- return rc;
-
- if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch))
- art = " ";
- else
- art = tb->symbols->vert;
-
- return buffer_append_data(buf, art);
-}
-
static int cell_to_buffer(struct libscols_table *tb,
struct libscols_line *ln,
struct libscols_column *cl,
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next reply other threads:[~2014-12-29 1:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-29 1:30 Phillip Susi [this message]
2015-01-07 14:26 ` libsmartcols patch Karel Zak
2015-02-16 5:00 ` Mike Frysinger
2015-02-16 10:27 ` Karel Zak
2015-02-16 10:48 ` Mike Frysinger
2015-02-16 13:46 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54A0AE98.70503@ubuntu.com \
--to=psusi@ubuntu.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox