summaryrefslogtreecommitdiffstats
path: root/term.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2019-01-04 03:21:02 +0000
committerIngo Schwarze <schwarze@openbsd.org>2019-01-04 03:21:02 +0000
commit246a96d69c628a5c6aa18bf731dddc2c8723a518 (patch)
treed2d330998930b31c1e79461479d4d5def0153f59 /term.c
parentfef738d3d7e452c2c278c16a710c696968d41718 (diff)
downloadmandoc-246a96d69c628a5c6aa18bf731dddc2c8723a518.tar.gz
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 'term.c')
-rw-r--r--term.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/term.c b/term.c
index 8644a776..af97796a 100644
--- a/term.c
+++ b/term.c
@@ -135,13 +135,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);
/*