|
@@ -3,6 +3,7 @@
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
|
|
+#include <sys/ioctl.h>
|
|
#include "pager.h"
|
|
#include "pager.h"
|
|
#include "run-command.h"
|
|
#include "run-command.h"
|
|
#include "sigchain.h"
|
|
#include "sigchain.h"
|
|
@@ -14,6 +15,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
static int spawned_pager;
|
|
static int spawned_pager;
|
|
|
|
+static int pager_columns;
|
|
|
|
|
|
void pager_init(const char *pager_env)
|
|
void pager_init(const char *pager_env)
|
|
{
|
|
{
|
|
@@ -58,9 +60,12 @@ static void wait_for_pager_signal(int signo)
|
|
void setup_pager(void)
|
|
void setup_pager(void)
|
|
{
|
|
{
|
|
const char *pager = getenv(subcmd_config.pager_env);
|
|
const char *pager = getenv(subcmd_config.pager_env);
|
|
|
|
+ struct winsize sz;
|
|
|
|
|
|
if (!isatty(1))
|
|
if (!isatty(1))
|
|
return;
|
|
return;
|
|
|
|
+ if (ioctl(1, TIOCGWINSZ, &sz) == 0)
|
|
|
|
+ pager_columns = sz.ws_col;
|
|
if (!pager)
|
|
if (!pager)
|
|
pager = getenv("PAGER");
|
|
pager = getenv("PAGER");
|
|
if (!(pager || access("/usr/bin/pager", X_OK)))
|
|
if (!(pager || access("/usr/bin/pager", X_OK)))
|
|
@@ -98,3 +103,14 @@ int pager_in_use(void)
|
|
{
|
|
{
|
|
return spawned_pager;
|
|
return spawned_pager;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+int pager_get_columns(void)
|
|
|
|
+{
|
|
|
|
+ char *s;
|
|
|
|
+
|
|
|
|
+ s = getenv("COLUMNS");
|
|
|
|
+ if (s)
|
|
|
|
+ return atoi(s);
|
|
|
|
+
|
|
|
|
+ return (pager_columns ? pager_columns : 80) - 2;
|
|
|
|
+}
|