From e24b44e5c3120c9b5c8e9b7440bc10c8b7413bfb Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Wed, 10 Oct 2018 09:14:03 +0300 Subject: 9879 more should have better screen size detection Reviewed by: Andy Fiddaman Reviewed by: Alexander Pyhalov Reviewed by: Yuri Pankov Approved by: Richard Lowe --- usr/src/cmd/more/more.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'usr/src') diff --git a/usr/src/cmd/more/more.c b/usr/src/cmd/more/more.c index 4ed3046629..14742fc6b2 100644 --- a/usr/src/cmd/more/more.c +++ b/usr/src/cmd/more/more.c @@ -1520,15 +1520,40 @@ initterm(void) dumb++; ul_opt = 0; } else { + int row, col; + struct winsize w; + char *s; + reset_shell_mode(); - if (((Lpp = lines) < 0) || hard_copy) { + row = col = -1; + if (ioctl(fileno(stdout), TIOCGWINSZ, &w) == 0) { + if (w.ws_row > 0) + row = w.ws_row; + if (w.ws_col > 0) + col = w.ws_col; + } + if (row < 0) { + if ((s = getenv("LINES")) != NULL) + row = atoi(s); + } + if (col < 0) { + if ((s = getenv("COLUMNS")) != NULL) + col = atoi(s); + } + + if (row > 0) + Lpp = row; + else if (((Lpp = lines) < 0) || hard_copy) { hard++; /* Hard copy terminal */ Lpp = 24; } + if (col > 0) + Mcol = col; + else if ((Mcol = columns) < 0) + Mcol = 80; + if (tailequ(fnames[0], "page") || !hard && (scroll_forward == NULL)) noscroll++; - if ((Mcol = columns) < 0) - Mcol = 80; Wrap = tigetflag("am"); /* * Set up for underlining: some terminals don't need it; -- cgit v1.2.3