libsmartcols: allow to change cell padding char
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
7208ef864b
commit
64ce7cbbc0
|
@ -86,6 +86,7 @@ scols_symbols_set_branch
|
||||||
scols_symbols_set_right
|
scols_symbols_set_right
|
||||||
scols_symbols_set_vertical
|
scols_symbols_set_vertical
|
||||||
scols_symbols_set_title_padding
|
scols_symbols_set_title_padding
|
||||||
|
scols_symbols_set_cell_padding
|
||||||
scols_unref_symbols
|
scols_unref_symbols
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ 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_padding(struct libscols_symbols *sb, const char *str);
|
extern int scols_symbols_set_title_padding(struct libscols_symbols *sb, const char *str);
|
||||||
|
extern int scols_symbols_set_cell_padding(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);
|
||||||
|
|
|
@ -140,4 +140,5 @@ global:
|
||||||
SMARTCOLS_2.29 {
|
SMARTCOLS_2.29 {
|
||||||
global:
|
global:
|
||||||
scols_column_is_wrapnl;
|
scols_column_is_wrapnl;
|
||||||
|
scols_symbols_set_cell_padding;
|
||||||
} SMARTCOLS_2.28;
|
} SMARTCOLS_2.28;
|
||||||
|
|
|
@ -54,6 +54,7 @@ struct libscols_symbols {
|
||||||
char *vert;
|
char *vert;
|
||||||
char *right;
|
char *right;
|
||||||
char *title_padding;
|
char *title_padding;
|
||||||
|
char *cell_padding;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -106,7 +106,7 @@ int scols_symbols_set_right(struct libscols_symbols *sb, const char *str)
|
||||||
/**
|
/**
|
||||||
* scols_symbols_set_title_padding:
|
* scols_symbols_set_title_padding:
|
||||||
* @sb: a pointer to a struct libscols_symbols instance
|
* @sb: a pointer to a struct libscols_symbols instance
|
||||||
* @str: a string which will represent the symbols which wraps title output
|
* @str: a string which will represent the symbols which fill title output
|
||||||
*
|
*
|
||||||
* The current implementation uses only the first byte from the padding string.
|
* The current implementation uses only the first byte from the padding string.
|
||||||
* A multibyte chars are not supported yet.
|
* A multibyte chars are not supported yet.
|
||||||
|
@ -120,6 +120,22 @@ int scols_symbols_set_title_padding(struct libscols_symbols *sb, const char *str
|
||||||
return strdup_to_struct_member(sb, title_padding, str);
|
return strdup_to_struct_member(sb, title_padding, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* scols_symbols_set_cell_padding:
|
||||||
|
* @sb: a pointer to a struct libscols_symbols instance
|
||||||
|
* @str: a string which will represent the symbols which fill cells
|
||||||
|
*
|
||||||
|
* The padding char has to take up just one cell on the terminal.
|
||||||
|
*
|
||||||
|
* Returns: 0, a negative value in case of an error.
|
||||||
|
*
|
||||||
|
* Since: 2.29
|
||||||
|
*/
|
||||||
|
int scols_symbols_set_cell_padding(struct libscols_symbols *sb, const char *str)
|
||||||
|
{
|
||||||
|
return strdup_to_struct_member(sb, cell_padding, str);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* scols_copy_symbols:
|
* scols_copy_symbols:
|
||||||
* @sb: a pointer to a struct libscols_symbols instance
|
* @sb: a pointer to a struct libscols_symbols instance
|
||||||
|
@ -146,6 +162,8 @@ struct libscols_symbols *scols_copy_symbols(const struct libscols_symbols *sb)
|
||||||
rc = scols_symbols_set_right(ret, sb->right);
|
rc = scols_symbols_set_right(ret, sb->right);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
rc = scols_symbols_set_title_padding(ret, sb->title_padding);
|
rc = scols_symbols_set_title_padding(ret, sb->title_padding);
|
||||||
|
if (!rc)
|
||||||
|
rc = scols_symbols_set_cell_padding(ret, sb->cell_padding);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
|
@ -695,6 +695,7 @@ int scols_table_set_symbols(struct libscols_table *tb,
|
||||||
scols_symbols_set_right(tb->symbols, "`-");
|
scols_symbols_set_right(tb->symbols, "`-");
|
||||||
}
|
}
|
||||||
scols_symbols_set_title_padding(tb->symbols, " ");
|
scols_symbols_set_title_padding(tb->symbols, " ");
|
||||||
|
scols_symbols_set_cell_padding(tb->symbols, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -27,6 +27,11 @@
|
||||||
#include "carefulputc.h"
|
#include "carefulputc.h"
|
||||||
#include "smartcolsP.h"
|
#include "smartcolsP.h"
|
||||||
|
|
||||||
|
#define colsep(tb) ((tb)->colsep ? (tb)->colsep : " ")
|
||||||
|
#define linesep(tb) ((tb)->linesep ? (tb)->linesep : "\n")
|
||||||
|
#define cellpadding(tb) ((tb) && (tb)->symbols && (tb)->symbols->cell_padding ? (tb)->symbols->cell_padding : " ")
|
||||||
|
|
||||||
|
|
||||||
/* This is private struct to work with output data */
|
/* This is private struct to work with output data */
|
||||||
struct libscols_buffer {
|
struct libscols_buffer {
|
||||||
char *begin; /* begin of the buffer */
|
char *begin; /* begin of the buffer */
|
||||||
|
@ -190,9 +195,6 @@ static int is_last_column(struct libscols_column *cl)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define colsep(tb) ((tb)->colsep ? (tb)->colsep : " ")
|
|
||||||
#define linesep(tb) ((tb)->linesep ? (tb)->linesep : "\n")
|
|
||||||
|
|
||||||
|
|
||||||
static int has_pending_data(struct libscols_table *tb)
|
static int has_pending_data(struct libscols_table *tb)
|
||||||
{
|
{
|
||||||
|
@ -248,7 +250,7 @@ static void print_empty_cell(struct libscols_table *tb,
|
||||||
|
|
||||||
/* fill rest of cell with space */
|
/* fill rest of cell with space */
|
||||||
for(; len_pad < cl->width; ++len_pad)
|
for(; len_pad < cl->width; ++len_pad)
|
||||||
fputc(' ', tb->out);
|
fputs(cellpadding(tb), tb->out);
|
||||||
|
|
||||||
fputs(colsep(tb), tb->out);
|
fputs(colsep(tb), tb->out);
|
||||||
}
|
}
|
||||||
|
@ -393,7 +395,7 @@ static int print_pending_data(
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = len; i < width; i++)
|
for (i = len; i < width; i++)
|
||||||
fputc(' ', tb->out); /* padding */
|
fputs(cellpadding(tb), tb->out); /* padding */
|
||||||
|
|
||||||
fputs(colsep(tb), tb->out); /* columns separator */
|
fputs(colsep(tb), tb->out); /* columns separator */
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -505,7 +507,7 @@ static int print_data(struct libscols_table *tb,
|
||||||
if (color)
|
if (color)
|
||||||
fputs(color, tb->out);
|
fputs(color, tb->out);
|
||||||
for (i = len; i < width; i++)
|
for (i = len; i < width; i++)
|
||||||
fputc(' ', tb->out);
|
fputs(cellpadding(tb), tb->out);
|
||||||
fputs(data, tb->out);
|
fputs(data, tb->out);
|
||||||
if (color)
|
if (color)
|
||||||
fputs(UL_COLOR_RESET, tb->out);
|
fputs(UL_COLOR_RESET, tb->out);
|
||||||
|
@ -528,7 +530,7 @@ static int print_data(struct libscols_table *tb,
|
||||||
fputs(data, tb->out);
|
fputs(data, tb->out);
|
||||||
}
|
}
|
||||||
for (i = len; i < width; i++)
|
for (i = len; i < width; i++)
|
||||||
fputc(' ', tb->out); /* padding */
|
fputs(cellpadding(tb), tb->out); /* padding */
|
||||||
|
|
||||||
if (is_last_column(cl))
|
if (is_last_column(cl))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue