summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2019-01-04 03:20:44 +0000
committerschwarze <schwarze@openbsd.org>2019-01-04 03:20:44 +0000
commitb306689c20c77dc3f9e33ba8d6eeff16ff887073 (patch)
treec6919be57bfa0523e4bc60f7306ed43d0b16b12f
parentOops, i forgot to adjust this file to the changes in roff.h rev. 1.49. (diff)
downloadwireguard-openbsd-b306689c20c77dc3f9e33ba8d6eeff16ff887073.tar.xz
wireguard-openbsd-b306689c20c77dc3f9e33ba8d6eeff16ff887073.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--usr.bin/mandoc/term.c18
-rw-r--r--usr.bin/mandoc/term.h6
2 files changed, 20 insertions, 4 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);
/*
diff --git a/usr.bin/mandoc/term.h b/usr.bin/mandoc/term.h
index 792fc093b8d..525aa3f2d1a 100644
--- a/usr.bin/mandoc/term.h
+++ b/usr.bin/mandoc/term.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: term.h,v 1.74 2017/07/08 14:51:01 schwarze Exp $ */
+/* $OpenBSD: term.h,v 1.75 2019/01/04 03:20:44 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. */