diff options
author | 2018-04-13 19:55:30 +0000 | |
---|---|---|
committer | 2018-04-13 19:55:30 +0000 | |
commit | 06eb86b87d44317103ec40cf10b2ed1e9f5d0927 (patch) | |
tree | c49ba9798cf58182e84eee8156504c0944a3f36e /main.c | |
parent | 44b03451934776b1030c9d5109114e98520bb4c2 (diff) | |
download | mandoc-06eb86b87d44317103ec40cf10b2ed1e9f5d0927.tar.gz mandoc-06eb86b87d44317103ec40cf10b2ed1e9f5d0927.tar.zst mandoc-06eb86b87d44317103ec40cf10b2ed1e9f5d0927.zip |
Use TIOCGWINSZ to reduce the default -Owidth during interactive use
on terminals narrower than 79 columns and the default -Oindent on
terminals narrower than 66 columns.
Requested by and feedback from pirofti@;
mpi@ and juanfra@ also like the general direction.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -1,7 +1,7 @@ -/* $Id: main.c,v 1.303 2018/02/23 16:47:10 schwarze Exp $ */ +/* $Id: main.c,v 1.304 2018/04/13 19:55:30 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org> * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org> * * Permission to use, copy, modify, and distribute this software for any @@ -19,7 +19,9 @@ #include "config.h" #include <sys/types.h> +#include <sys/ioctl.h> #include <sys/param.h> /* MACHINE */ +#include <sys/termios.h> #include <sys/wait.h> #include <assert.h> @@ -120,6 +122,7 @@ main(int argc, char *argv[]) struct manconf conf; struct mansearch search; struct curparse curp; + struct winsize ws; struct tag_files *tag_files; struct manpage *res, *resp; const char *progname, *sec, *thisarg; @@ -316,6 +319,15 @@ main(int argc, char *argv[]) !isatty(STDOUT_FILENO)) use_pager = 0; + if (use_pager && + (conf.output.width == 0 || conf.output.indent == 0) && + ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1) { + if (conf.output.width == 0 && ws.ws_col < 79) + conf.output.width = ws.ws_col - 1; + if (conf.output.indent == 0 && ws.ws_col < 66) + conf.output.indent = 3; + } + #if HAVE_PLEDGE if (!use_pager) if (pledge("stdio rpath", NULL) == -1) |