summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2017-01-09 13:28:24 +0100
committerKarel Zak2017-01-09 13:28:24 +0100
commit6ffbd28359104c75015c260b84c804fb893b8620 (patch)
tree1e2a45a83ec2d73c178ec3b2fbf026314dce2e5e /libsmartcols
parentMerge branch 'ignatenko/libsmartcols-dead' of https://github.com/ignatenkobra... (diff)
downloadkernel-qcow2-util-linux-6ffbd28359104c75015c260b84c804fb893b8620.tar.gz
kernel-qcow2-util-linux-6ffbd28359104c75015c260b84c804fb893b8620.tar.xz
kernel-qcow2-util-linux-6ffbd28359104c75015c260b84c804fb893b8620.zip
libsmartcols: add scols_cell_get_alignment()
Just to hide that we use cell flags (bitwise operations) to define cell content alignment. The patch also more explicitly specifies the flags in the header file. The alignment is evaluated in the order: right, center, left. The default is left. Note that SCOLS_CELL_FL_* are used for for table title only. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/docs/libsmartcols-sections.txt1
-rw-r--r--libsmartcols/src/cell.c16
-rw-r--r--libsmartcols/src/libsmartcols.h.in8
-rw-r--r--libsmartcols/src/libsmartcols.sym6
-rw-r--r--libsmartcols/src/table_print.c17
5 files changed, 39 insertions, 9 deletions
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt
index ee696642a..7e31cdda2 100644
--- a/libsmartcols/docs/libsmartcols-sections.txt
+++ b/libsmartcols/docs/libsmartcols-sections.txt
@@ -2,6 +2,7 @@
<FILE>cell</FILE>
libscols_cell
scols_cell_copy_content
+scols_cell_get_alignment
scols_cell_get_color
scols_cell_get_data
scols_cell_get_flags
diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c
index 4450c576b..04e9bfc20 100644
--- a/libsmartcols/src/cell.c
+++ b/libsmartcols/src/cell.c
@@ -215,6 +215,22 @@ int scols_cell_get_flags(const struct libscols_cell *ce)
}
/**
+ * scols_cell_get_alignment:
+ * @ce: a pointer to a struct libscols_cell instance
+ *
+ * Returns: SCOLS_CELL_FL_{RIGHT,CELNTER,LEFT}
+ */
+int scols_cell_get_alignment(const struct libscols_cell *ce)
+{
+ if (ce->flags & SCOLS_CELL_FL_RIGHT)
+ return SCOLS_CELL_FL_RIGHT;
+ else if (ce->flags & SCOLS_CELL_FL_CENTER)
+ return SCOLS_CELL_FL_CENTER;
+
+ return SCOLS_CELL_FL_LEFT; /* default */
+}
+
+/**
* scols_cell_copy_content:
* @dest: a pointer to a struct libscols_cell instance
* @src: a pointer to an immutable struct libscols_cell instance
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in
index 4a00fed1b..e9df9333c 100644
--- a/libsmartcols/src/libsmartcols.h.in
+++ b/libsmartcols/src/libsmartcols.h.in
@@ -91,9 +91,10 @@ enum {
* Cell flags, see scols_cell_set_flags() before use
*/
enum {
- SCOLS_CELL_FL_LEFT = 0,
- SCOLS_CELL_FL_CENTER,
- SCOLS_CELL_FL_RIGHT
+ /* alignment evaluated in order: right,center,left */
+ SCOLS_CELL_FL_LEFT = 0,
+ SCOLS_CELL_FL_CENTER = (1 << 0),
+ SCOLS_CELL_FL_RIGHT = (1 << 1)
};
extern struct libscols_iter *scols_new_iter(int direction);
@@ -131,6 +132,7 @@ extern const char *scols_cell_get_color(const struct libscols_cell *ce);
extern int scols_cell_set_flags(struct libscols_cell *ce, int flags);
extern int scols_cell_get_flags(const struct libscols_cell *ce);
+extern int scols_cell_get_alignment(const struct libscols_cell *ce);
extern void *scols_cell_get_userdata(struct libscols_cell *ce);
extern int scols_cell_set_userdata(struct libscols_cell *ce, void *data);
diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym
index 2bf2b4ee4..b8a3a5b4c 100644
--- a/libsmartcols/src/libsmartcols.sym
+++ b/libsmartcols/src/libsmartcols.sym
@@ -157,3 +157,9 @@ global:
scols_wrapnl_chunksize;
scols_wrapnl_nextchunk;
} SMARTCOLS_2.28;
+
+
+SMARTCOLS_2.30 {
+global:
+ scols_cell_get_alignment;
+} SMARTCOLS_2.29;
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index 65f261245..afcbc1647 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -782,14 +782,19 @@ static int print_title(struct libscols_table *tb)
goto done;
}
- if (tb->title.flags & SCOLS_CELL_FL_LEFT)
- align = MBS_ALIGN_LEFT;
- else if (tb->title.flags & SCOLS_CELL_FL_RIGHT)
+ switch (scols_cell_get_alignment(&tb->title)) {
+ case SCOLS_CELL_FL_RIGHT:
align = MBS_ALIGN_RIGHT;
- else if (tb->title.flags & SCOLS_CELL_FL_CENTER)
+ break;
+ case SCOLS_CELL_FL_CENTER:
align = MBS_ALIGN_CENTER;
- else
- align = MBS_ALIGN_LEFT; /* default */
+ break;
+ case SCOLS_CELL_FL_LEFT:
+ default:
+ align = MBS_ALIGN_LEFT;
+ break;
+
+ }
/* copy from buf to title and align to width with title_padding */
rc = mbsalign_with_padding(buf, title, titlesz,