]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: (sample) cleanup line separator usage
authorKarel Zak <kzak@redhat.com>
Thu, 12 Oct 2017 10:01:25 +0000 (12:01 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 12 Oct 2017 10:03:57 +0000 (12:03 +0200)
* add comment to explain when nolinesep flag is necessary
* force to print \n before switch to the next line to support

  ./sample-scols-continuous > file

use case.

Addresses: https://github.com/ignatenkobrain/python-smartcols/issues/18
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/samples/continuous.c
libsmartcols/src/table_print.c

index 6cd8b489c0cd1c10882d4bd03ec16e9016a8a1fa..dfe54b604a3dc231fd1246bcd57f19e28ede53df 100644 (file)
@@ -108,8 +108,16 @@ int main(int argc, char *argv[])
                        sprintf(timecell, "%f [%3d%%]", diff,
                                done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
 
-                       /* don't print line separator when in progress */
-                       scols_table_enable_nolinesep(tb, !done);
+                       /* Note that libsmartcols don't print \n for last line
+                        * in the table, but if you print a line somewhere in
+                        * the midle of the table you need
+                        *
+                        *    scols_table_enable_nolinesep(tb, !done);
+                        *
+                        * to disable line breaks. In this example it's
+                        * unnecessary as we print the latest line only.
+                        */
+
                        /* print the line */
                        scols_table_print_range(tb, line, NULL);
 
@@ -118,7 +126,8 @@ int main(int argc, char *argv[])
                                fflush(scols_table_get_stream(tb));
                                /* move to the begin of the line */
                                fputc('\r', scols_table_get_stream(tb));
-                       }
+                       } else
+                               fputc('\n', scols_table_get_stream(tb));
                } while (!done);
 
                last = now;
index 7a2c1a3dca8a3f8de5419be7462c01334c413110..6acaf9b4e868909c37fc3ecf67ab6b88302835be 100644 (file)
@@ -901,6 +901,7 @@ static int print_range(     struct libscols_table *tb,
        struct libscols_line *ln;
 
        assert(tb);
+       DBG(TAB, ul_debugobj(tb, "printing range"));
 
        while (rc == 0 && scols_table_next_line(tb, itr, &ln) == 0) {
 
@@ -1524,7 +1525,7 @@ int scols_table_print_range(      struct libscols_table *tb,
        if (scols_table_is_tree(tb))
                return -EINVAL;
 
-       DBG(TAB, ul_debugobj(tb, "printing range"));
+       DBG(TAB, ul_debugobj(tb, "printing range from API"));
 
        rc = initialize_printing(tb, &buf);
        if (rc)