diff options
author | Karel Zak | 2017-10-12 12:01:25 +0200 |
---|---|---|
committer | Karel Zak | 2017-10-12 12:03:57 +0200 |
commit | f086478af427914e019251548d6457738661d92a (patch) | |
tree | d676d0e107a6b17497fe78cd3d8c3e3770dc4522 /libsmartcols/samples | |
parent | libsmartcols: (docs) add note about line separators (diff) | |
download | kernel-qcow2-util-linux-f086478af427914e019251548d6457738661d92a.tar.gz kernel-qcow2-util-linux-f086478af427914e019251548d6457738661d92a.tar.xz kernel-qcow2-util-linux-f086478af427914e019251548d6457738661d92a.zip |
libsmartcols: (sample) cleanup line separator usage
* 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>
Diffstat (limited to 'libsmartcols/samples')
-rw-r--r-- | libsmartcols/samples/continuous.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libsmartcols/samples/continuous.c b/libsmartcols/samples/continuous.c index 6cd8b489c..dfe54b604 100644 --- a/libsmartcols/samples/continuous.c +++ b/libsmartcols/samples/continuous.c @@ -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; |