libsmartcols: add scols_table_{set,get}_termheight()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
f46a8d7e66
commit
e33b387483
|
@ -282,6 +282,8 @@ extern int scols_table_set_termforce(struct libscols_table *tb, int force);
|
||||||
extern int scols_table_get_termforce(const struct libscols_table *tb);
|
extern int scols_table_get_termforce(const struct libscols_table *tb);
|
||||||
extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
|
extern int scols_table_set_termwidth(struct libscols_table *tb, size_t width);
|
||||||
extern size_t scols_table_get_termwidth(const struct libscols_table *tb);
|
extern size_t scols_table_get_termwidth(const struct libscols_table *tb);
|
||||||
|
extern int scols_table_set_termheight(struct libscols_table *tb, size_t height);
|
||||||
|
extern size_t scols_table_get_termheight(const struct libscols_table *tb);
|
||||||
|
|
||||||
|
|
||||||
/* table_print.c */
|
/* table_print.c */
|
||||||
|
|
|
@ -146,7 +146,8 @@ struct libscols_table {
|
||||||
size_t ncols; /* number of columns */
|
size_t ncols; /* number of columns */
|
||||||
size_t ntreecols; /* number of columns with SCOLS_FL_TREE */
|
size_t ntreecols; /* number of columns with SCOLS_FL_TREE */
|
||||||
size_t nlines; /* number of lines */
|
size_t nlines; /* number of lines */
|
||||||
size_t termwidth; /* terminal width */
|
size_t termwidth; /* terminal width (number of columns) */
|
||||||
|
size_t termheight; /* terminal height (number of lines) */
|
||||||
size_t termreduce; /* extra blank space */
|
size_t termreduce; /* extra blank space */
|
||||||
int termforce; /* SCOLS_TERMFORCE_* */
|
int termforce; /* SCOLS_TERMFORCE_* */
|
||||||
FILE *out; /* output stream */
|
FILE *out; /* output stream */
|
||||||
|
|
|
@ -61,6 +61,7 @@ static void check_padding_debug(struct libscols_table *tb)
|
||||||
struct libscols_table *scols_new_table(void)
|
struct libscols_table *scols_new_table(void)
|
||||||
{
|
{
|
||||||
struct libscols_table *tb;
|
struct libscols_table *tb;
|
||||||
|
int c, l;
|
||||||
|
|
||||||
tb = calloc(1, sizeof(struct libscols_table));
|
tb = calloc(1, sizeof(struct libscols_table));
|
||||||
if (!tb)
|
if (!tb)
|
||||||
|
@ -68,7 +69,10 @@ struct libscols_table *scols_new_table(void)
|
||||||
|
|
||||||
tb->refcount = 1;
|
tb->refcount = 1;
|
||||||
tb->out = stdout;
|
tb->out = stdout;
|
||||||
tb->termwidth = get_terminal_width(80);
|
|
||||||
|
get_terminal_dimension(&c, &l);
|
||||||
|
tb->termwidth = c > 0 ? c : 80;
|
||||||
|
tb->termheight = l > 0 ? l : 24;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&tb->tb_lines);
|
INIT_LIST_HEAD(&tb->tb_lines);
|
||||||
INIT_LIST_HEAD(&tb->tb_columns);
|
INIT_LIST_HEAD(&tb->tb_columns);
|
||||||
|
@ -1426,9 +1430,41 @@ int scols_table_set_termwidth(struct libscols_table *tb, size_t width)
|
||||||
* scols_table_get_termwidth
|
* scols_table_get_termwidth
|
||||||
* @tb: table
|
* @tb: table
|
||||||
*
|
*
|
||||||
* Returns: terminal width or a negative value in case of an error.
|
* Returns: terminal width.
|
||||||
*/
|
*/
|
||||||
size_t scols_table_get_termwidth(const struct libscols_table *tb)
|
size_t scols_table_get_termwidth(const struct libscols_table *tb)
|
||||||
{
|
{
|
||||||
return tb->termwidth;
|
return tb->termwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scols_table_set_termheight
|
||||||
|
* @tb: table
|
||||||
|
* @height: terminal height (number of lines)
|
||||||
|
*
|
||||||
|
* The library automatically detects terminal height or defaults to 24 lines if
|
||||||
|
* detections is unsuccessful. This function override this behaviour.
|
||||||
|
*
|
||||||
|
* Returns: 0, a negative value in case of an error.
|
||||||
|
*
|
||||||
|
* Since: 2.31
|
||||||
|
*/
|
||||||
|
int scols_table_set_termheight(struct libscols_table *tb, size_t height)
|
||||||
|
{
|
||||||
|
DBG(TAB, ul_debugobj(tb, "set terminatl height: %zu", height));
|
||||||
|
tb->termheight = height;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scols_table_get_termheight
|
||||||
|
* @tb: table
|
||||||
|
*
|
||||||
|
* Returns: terminal height (number of lines).
|
||||||
|
*
|
||||||
|
* Since: 2.31
|
||||||
|
*/
|
||||||
|
size_t scols_table_get_termheight(const struct libscols_table *tb)
|
||||||
|
{
|
||||||
|
return tb->termheight;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue