Hi Ted,
Ted Unangst wrote on Sun, Aug 11, 2013 at 10:32:42AM -0400:
> One machine I use has terminals that happen to be very nicely sized at
> 75 columns wide. Day to day, this is almost perfect, except when trying
> to view a man page, because just a little too much text goes on each
> line.
>
> I think mandoc should adjust its default output width based on the
> terminal size. At least in the case where the terminal is narrow. This
> diff doesn't change anything if you have wider than 80 column terminals.
I agree with your idea for the case when somebody is viewing a manual
page interactively, but i disagree with your patch for the following
reason. I started an xterm, reduced its width, then typed:
ischwarze@isnote $ mandoc mandoc.1 > tmp.txt
ischwarze@isnote $ less tmp.txt
MANDOC(1) OpenBSD Reference Manual
NAME
mandoc - format and display
UNIX manuals
SYNOPSIS
mandoc [-V] [-Ios=name]
[-mformat] [-Ooption]
[-Toutput] [-Wlevel]
[file ...]
So, that's reduced width output. Ouch. That means you cannot run
builds or regression tests in a smaller terminal. I don't think
that's acceptable.
Do you have any idea how to solve this?
One common approach is doing weird stuff when stdout is a terminal.
I don't like that in general in the first place.
Even if i would accept it in this particular case, i don't think it
would solve your problem: Usually, mandoc(1) is run in a pipe to a
pager, so even during interactive use, stdout is *not* usually a
terminal.
How can we possibly distinguish interactive pipes like
mandoc | less
which might profit from variable defrmargin
from typical build system or regeression system pipes like
mandoc | sed
which want defrmargin = 78, period?
If nobody comes up with a smart idea for that,
i fear you will have to put -Owidth=73 into man.conf(5) on your box,
leaving the defaults alone... :-(
Besides, is your code portable?
If i understand correctly, ioctl(2), sys/ioctl.h and even TIOCGWINSZ
seem to be reasonably common (though i'm not sure on which systems
they might not be available - do you have any idea?).
But what about /dev/tty? Is your argument that, if a system doesn't
provide that device file, your code simply does nothing?
Finally, *if* we decide to go down that route or a similar one,
i think the patch appended at the end should be included.
Joerg Sonnenberger added the lower boundary on May 15, 2010,
in bsd.lv term.c rev. 1.134. The commit message does not even
mention the lower boundary, much less provide a rationale.
Given that the boundary is completely arbitrary, i never liked
it, and with your patch, the boundary really becomes a hindrance.
Yours,
Ingo
Index: term_ascii.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term_ascii.c,v
retrieving revision 1.10
diff -u -p -r1.10 term_ascii.c
--- term_ascii.c 1 Jun 2013 14:27:13 -0000 1.10
+++ term_ascii.c 14 Aug 2013 14:41:07 -0000
@@ -104,10 +116,6 @@ ascii_init(enum termenc enc, char *outop
default:
break;
}
-
- /* Enforce a lower boundary. */
- if (p->defrmargin < 58)
- p->defrmargin = 58;
return(p);
}
> Index: term_ascii.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mandoc/term_ascii.c,v
> retrieving revision 1.10
> diff -u -p -r1.10 term_ascii.c
> --- term_ascii.c 1 Jun 2013 14:27:13 -0000 1.10
> +++ term_ascii.c 21 Jul 2013 14:24:58 -0000
> @@ -15,8 +15,10 @@
> * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> */
> #include <sys/types.h>
> +#include <sys/ioctl.h>
>
> #include <assert.h>
> +#include <fcntl.h>
> #include <locale.h>
> #include <stdint.h>
> #include <stdio.h>
> @@ -50,11 +52,21 @@ ascii_init(enum termenc enc, char *outop
> const char *toks[4];
> char *v;
> struct termp *p;
> + struct winsize ws;
> + int tfd;
>
> p = mandoc_calloc(1, sizeof(struct termp));
>
> p->tabwidth = 5;
> p->defrmargin = 78;
> + if ((tfd = open("/dev/tty", O_RDWR, 0)) != -1) {
> + if (ioctl(tfd, TIOCGWINSZ, &ws) != -1) {
> + if (ws.ws_col < 80)
> + p->defrmargin = ws.ws_col - 2;
> + }
> + close(tfd);
> + }
> +
>
> p->begin = ascii_begin;
> p->end = ascii_end;