libsmartcols: use symbols for title wrap
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
parent
b3256efff2
commit
cd32dc248c
|
@ -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_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_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_right(struct libscols_symbols *sb, const char *str);
|
||||||
|
extern int scols_symbols_set_title_wrap(struct libscols_symbols *sb, const char *str);
|
||||||
|
|
||||||
/* cell.c */
|
/* cell.c */
|
||||||
extern int scols_reset_cell(struct libscols_cell *ce);
|
extern int scols_reset_cell(struct libscols_cell *ce);
|
||||||
|
|
|
@ -126,6 +126,7 @@ SMARTCOLS_2.28 {
|
||||||
global:
|
global:
|
||||||
scols_line_refer_column_data;
|
scols_line_refer_column_data;
|
||||||
scols_line_set_column_data;
|
scols_line_set_column_data;
|
||||||
|
scols_symbols_set_title_wrap;
|
||||||
scols_table_enable_nowrap;
|
scols_table_enable_nowrap;
|
||||||
scols_table_set_title;
|
scols_table_set_title;
|
||||||
} SMARTCOLS_2.27;
|
} SMARTCOLS_2.27;
|
||||||
|
|
|
@ -52,6 +52,7 @@ struct libscols_symbols {
|
||||||
char *branch;
|
char *branch;
|
||||||
char *vert;
|
char *vert;
|
||||||
char *right;
|
char *right;
|
||||||
|
char *title_wrap;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* symbols.c - routines for symbol handling
|
* symbols.c - routines for symbol handling
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
|
* Copyright (C) 2014 Ondrej Oprala <ooprala@redhat.com>
|
||||||
|
* Copyright (C) 2016 Igor Gnatenko <i.gnatenko.brain@gmail.com>
|
||||||
*
|
*
|
||||||
* This file may be redistributed under the terms of the
|
* This file may be redistributed under the terms of the
|
||||||
* GNU Lesser General Public License.
|
* GNU Lesser General Public License.
|
||||||
|
@ -61,6 +62,7 @@ void scols_unref_symbols(struct libscols_symbols *sy)
|
||||||
free(sy->branch);
|
free(sy->branch);
|
||||||
free(sy->vert);
|
free(sy->vert);
|
||||||
free(sy->right);
|
free(sy->right);
|
||||||
|
free(sy->title_wrap);
|
||||||
free(sy);
|
free(sy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,6 +142,31 @@ int scols_symbols_set_right(struct libscols_symbols *sb, const char *str)
|
||||||
return 0;
|
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:
|
* scols_copy_symbols:
|
||||||
* @sb: a pointer to a struct libscols_symbols instance
|
* @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);
|
rc = scols_symbols_set_vertical(ret, sb->vert);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
rc = scols_symbols_set_right(ret, sb->right);
|
rc = scols_symbols_set_right(ret, sb->right);
|
||||||
|
if (!rc)
|
||||||
|
rc = scols_symbols_set_title_wrap(ret, sb->title_wrap);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -171,5 +200,3 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sb)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -737,6 +737,7 @@ int scols_table_set_symbols(struct libscols_table *tb,
|
||||||
scols_symbols_set_vertical(tb->symbols, "| ");
|
scols_symbols_set_vertical(tb->symbols, "| ");
|
||||||
scols_symbols_set_right(tb->symbols, "`-");
|
scols_symbols_set_right(tb->symbols, "`-");
|
||||||
}
|
}
|
||||||
|
scols_symbols_set_title_wrap(tb->symbols, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -567,23 +567,23 @@ static void print_title(struct libscols_table *tb)
|
||||||
fputs(tb->title, tb->out);
|
fputs(tb->title, tb->out);
|
||||||
|
|
||||||
for (i = len; i < tb->termwidth; i++)
|
for (i = len; i < tb->termwidth; i++)
|
||||||
fputs(" ", tb->out);
|
fputs(tb->symbols->title_wrap, tb->out);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SCOLS_TITLE_CENTER:
|
case SCOLS_TITLE_CENTER:
|
||||||
for (i = 0; i <= (tb->termwidth - len) / 2; i++)
|
for (i = 0; i <= (tb->termwidth - len) / 2; i++)
|
||||||
fputs(" ", tb->out);
|
fputs(tb->symbols->title_wrap, tb->out);
|
||||||
|
|
||||||
fputs(tb->title, tb->out);
|
fputs(tb->title, tb->out);
|
||||||
i += len;
|
i += len;
|
||||||
|
|
||||||
for (; i < tb->termwidth; i++)
|
for (; i < tb->termwidth; i++)
|
||||||
fputs(" ", tb->out);
|
fputs(tb->symbols->title_wrap, tb->out);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SCOLS_TITLE_RIGHT:
|
case SCOLS_TITLE_RIGHT:
|
||||||
for (i = 0; i < tb->termwidth - len; i++)
|
for (i = 0; i < tb->termwidth - len; i++)
|
||||||
fputs(" ", tb->out);
|
fputs(tb->symbols->title_wrap, tb->out);
|
||||||
|
|
||||||
fputs(tb->title, tb->out);
|
fputs(tb->title, tb->out);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue