aboutsummaryrefslogtreecommitdiffstatshomepage
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
commitf6aa1baa5ceeef9b9eb07bfb1be21257d01a42dc (patch)
tree3900dfe65a69a28b81b6d8ac910a49a2b1e030f2
parente513db850fd979df72529ff1e74db44e82704e92 (diff)
downloadmandoc-f6aa1baa5ceeef9b9eb07bfb1be21257d01a42dc.tar.gz
mandoc-f6aa1baa5ceeef9b9eb07bfb1be21257d01a42dc.tar.zst
mandoc-f6aa1baa5ceeef9b9eb07bfb1be21257d01a42dc.zip
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.
-rw-r--r--term.c18
-rw-r--r--term.h6
2 files changed, 20 insertions, 4 deletions
diff --git a/term.c b/term.c
index a807150e..76fdeab0 100644
--- 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.279 2019/01/04 03:21:02 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);
/*
diff --git a/term.h b/term.h
index 493191d7..f0a033a4 100644
--- a/term.h
+++ b/term.h
@@ -1,7 +1,7 @@
-/* $Id: term.h,v 1.130 2017/07/08 14:51:05 schwarze Exp $ */
+/* $Id: term.h,v 1.131 2019/01/04 03:21:02 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2015, 2017, 2019 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -99,6 +99,8 @@ struct termp {
#define TERMP_NEWMC (1 << 18) /* No .mc printed yet. */
#define TERMP_ENDMC (1 << 19) /* Next break ends .mc mode. */
#define TERMP_MULTICOL (1 << 20) /* Multiple column mode. */
+#define TERMP_CENTER (1 << 21) /* Center output lines. */
+#define TERMP_RIGHT (1 << 22) /* Adjust to the right margin. */
enum termtype type; /* Terminal, PS, or PDF. */
enum termenc enc; /* Type of encoding. */
enum termfont fontl; /* Last font set. */