diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 236475a39..70f5df9ea 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -115,6 +115,7 @@ extern struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols extern int scols_symbols_set_branch(struct libscols_symbols *sb, const char *str); extern int scols_symbols_set_vertical(struct libscols_symbols *sb, const char *str); extern int scols_symbols_set_right(struct libscols_symbols *sb, const char *str); +extern int scols_symbols_set_title_wrap(struct libscols_symbols *sb, const char *str); /* cell.c */ extern int scols_reset_cell(struct libscols_cell *ce); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index 18eb5fc26..3923c9db1 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -126,6 +126,7 @@ SMARTCOLS_2.28 { global: scols_line_refer_column_data; scols_line_set_column_data; + scols_symbols_set_title_wrap; scols_table_enable_nowrap; scols_table_set_title; } SMARTCOLS_2.27; diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index 2e6673aa0..68a2a2eae 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -52,6 +52,7 @@ struct libscols_symbols { char *branch; char *vert; char *right; + char *title_wrap; }; /* diff --git a/libsmartcols/src/symbols.c b/libsmartcols/src/symbols.c index c19df0255..dfe2ba7b6 100644 --- a/libsmartcols/src/symbols.c +++ b/libsmartcols/src/symbols.c @@ -2,6 +2,7 @@ * symbols.c - routines for symbol handling * * Copyright (C) 2014 Ondrej Oprala + * Copyright (C) 2016 Igor Gnatenko * * This file may be redistributed under the terms of the * GNU Lesser General Public License. @@ -61,6 +62,7 @@ void scols_unref_symbols(struct libscols_symbols *sy) free(sy->branch); free(sy->vert); free(sy->right); + free(sy->title_wrap); free(sy); } } @@ -140,6 +142,31 @@ int scols_symbols_set_right(struct libscols_symbols *sb, const char *str) return 0; } +/** + * scols_symbols_set_title_wrap: + * @sb: a pointer to a struct libscols_symbols instance + * @str: a string which will represent the symbols which wraps title output + * + * Returns: 0, a negative value in case of an error. + */ +int scols_symbols_set_title_wrap(struct libscols_symbols *sb, const char *str) +{ + char *p = NULL; + + assert(sb); + + if (!sb) + return -EINVAL; + if (str) { + p = strdup(str); + if (!p) + return -ENOMEM; + } + free(sb->title_wrap); + sb->title_wrap = p; + return 0; +} + /** * scols_copy_symbols: * @sb: a pointer to a struct libscols_symbols instance @@ -164,6 +191,8 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sb) rc = scols_symbols_set_vertical(ret, sb->vert); if (!rc) rc = scols_symbols_set_right(ret, sb->right); + if (!rc) + rc = scols_symbols_set_title_wrap(ret, sb->title_wrap); if (!rc) return ret; @@ -171,5 +200,3 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sb) return NULL; } - - diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index b8221f954..57f6ed515 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -737,6 +737,7 @@ int scols_table_set_symbols(struct libscols_table *tb, scols_symbols_set_vertical(tb->symbols, "| "); scols_symbols_set_right(tb->symbols, "`-"); } + scols_symbols_set_title_wrap(tb->symbols, " "); } return 0; diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 2a42c23b0..a0fc68a99 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -567,23 +567,23 @@ static void print_title(struct libscols_table *tb) fputs(tb->title, tb->out); for (i = len; i < tb->termwidth; i++) - fputs(" ", tb->out); + fputs(tb->symbols->title_wrap, tb->out); break; case SCOLS_TITLE_CENTER: for (i = 0; i <= (tb->termwidth - len) / 2; i++) - fputs(" ", tb->out); + fputs(tb->symbols->title_wrap, tb->out); fputs(tb->title, tb->out); i += len; for (; i < tb->termwidth; i++) - fputs(" ", tb->out); + fputs(tb->symbols->title_wrap, tb->out); break; case SCOLS_TITLE_RIGHT: for (i = 0; i < tb->termwidth - len; i++) - fputs(" ", tb->out); + fputs(tb->symbols->title_wrap, tb->out); fputs(tb->title, tb->out);