]> git.cameronkatri.com Git - mandoc.git/blobdiff - term.c
If messages are shown and output is printed without a pager, display
[mandoc.git] / term.c
diff --git a/term.c b/term.c
index a807150eba8655746c007dbf68cacaa7f6a3a266..3b9277aaabbc371105c39dbc0e521e2b181bd102 100644 (file)
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/*     $Id: term.c,v 1.278 2019/01/03 19:59:55 schwarze Exp $ */
+/*     $Id: term.c,v 1.281 2019/06/03 20:23:41 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2019 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
 
                /*
@@ -267,6 +281,8 @@ term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget)
                        case ASCII_BREAK:
                                vn = vis;
                                break;
+                       default:
+                               abort();
                        }
                        /* Can break at the end of a word. */
                        if (breakline || vn > vtarget)
@@ -360,8 +376,9 @@ term_field(struct termp *p, size_t vbl, size_t nbr, size_t vbr, size_t vtarget)
                        continue;
                case ' ':
                case ASCII_NBRSP:
-                       vbl++;
-                       vis++;
+                       dv = (*p->width)(p, ' ');
+                       vbl += dv;
+                       vis += dv;
                        continue;
                default:
                        break;