summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2019-01-04 03:20:45 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2019-01-04 03:20:45 +0000
commitf48556c5f78960f3ddc3b9dcb70f856081ac35c9 (patch)
treea27226c3689b7e42498ea17bda96115c93d6971a /usr.bin/mandoc/term.c
parent7a3d7b2cf049fa89ab864a9023d7b9858c7b2ab6 (diff)
Implement centering and adjustment to the right margin directly in
the terminal filling routine, controlled by new flags TERMP_CENTER and TERMP_RIGHT. This became possible by the recent term_flushln() rewrite. No functional change yet, but to be used by upcoming commits.
Diffstat (limited to 'usr.bin/mandoc/term.c')
-rw-r--r--usr.bin/mandoc/term.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index f1a790fe643..ceebbb86141 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: term.c,v 1.138 2019/01/03 19:59:11 schwarze Exp $ */
+/* $OpenBSD: term.c,v 1.139 2019/01/04 03:20:44 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -133,13 +133,27 @@ term_flushln(struct termp *p)
/*
* Figure out how much text will fit in the field.
* If there is whitespace only, print nothing.
- * Otherwise, print the field content.
*/
term_fill(p, &nbr, &vbr, vtarget);
if (nbr == 0)
break;
+ /*
+ * With the CENTER or RIGHT flag, increase the indentation
+ * to center the text between the left and right margins
+ * or to adjust it to the right margin, respectively.
+ */
+
+ if (vbr < vtarget) {
+ if (p->flags & TERMP_CENTER)
+ vbl += (vtarget - vbr) / 2;
+ else if (p->flags & TERMP_RIGHT)
+ vbl += vtarget - vbr;
+ }
+
+ /* Finally, print the field content. */
+
term_field(p, vbl, nbr, vbr, vtarget);
/*