Commit 17930dd7 17930dd7cacf60c375408a26154301934a17609e by Sergey Poznyakoff

mail: honor columns/screen variables

* mail/util.c (util_command_list): Use util_screen_columns instead of
util_getcols.
(util_getcols): Don't use COLUMNS.
(util_getlines): Don't use LINES.
* mail/mail.c: Don't force COLUMNS and LINES (they are normally not
exported, so setting them will cause util_getcols and util_getlines
to return wrong results).
Set variable "columns" from envvar COLUMNS, if set to a numeric value.
Set variable "screen" from envvar LINES, if set to a numeric value.
* mail/from.c (format_headline): Use util_screen_columns instead of
util_getcols.
* mail/mailvar.c (mailvar_print,mail_variable): Likewise.
* mail/print.c (mail_print_msg): Likewise.
1 parent 131ddb25
......@@ -78,7 +78,7 @@ format_pad (size_t n)
static void
format_headline (struct header_segm *seg, msgset_t *mspec, mu_message_t msg)
{
int screen_cols = util_getcols () - 2;
int screen_cols = util_screen_columns () - 2;
int out_cols = 0;
struct header_call_args args;
......
......@@ -376,10 +376,7 @@ main (int argc, char **argv)
/* set up the default environment */
if (!getenv ("HOME"))
{
char *p = util_get_homedir ();
setenv ("HOME", p, 0);
}
setenv ("HOME", util_get_homedir (), 0);
/* Set up the default environment */
setenv ("DEAD", util_fullpath ("~/dead.letter"), 0);
......@@ -390,14 +387,22 @@ main (int argc, char **argv)
setenv ("PAGER", "more", 0);
setenv ("SHELL", "sh", 0);
setenv ("VISUAL", "vi", 0);
setenv ("COLUMNS", "80", 0);
setenv ("LINES", "24", 0);
/* set defaults for execution */
for (i = 0; i < sizeof (default_setup)/sizeof (default_setup[0]); i++)
util_do_command ("%s", default_setup[i]);
util_do_command ("set screen=%d", util_getlines ());
util_do_command ("set columns=%d", util_getcols ());
p = getenv ("LINES");
if (p && p[strspn (p, "0123456789")] == 0)
util_do_command ("set screen=%s", p);
else
util_do_command ("set screen=%d", util_getlines ());
p = getenv ("COLUMNS");
if (p && p[strspn (p, "0123456789")] == 0)
util_do_command ("set columns=%s", p);
else
util_do_command ("set columns=%d", util_getcols ());
/* Set the default mailer to sendmail. */
mailvar_set ("sendmail",
......
......@@ -39,8 +39,8 @@ sig_handler (int signo)
break;
#if defined (SIGWINCH)
case SIGWINCH:
util_do_command ("set screen=%d", util_getlines());
util_do_command ("set columns=%d", util_getcols());
util_do_command ("set screen=%d", util_getlines ());
util_do_command ("set columns=%d", util_getcols ());
page_invalidate (1);
break;
#endif
......
......@@ -749,7 +749,7 @@ mailvar_print (int set)
clos.out = open_pager (count);
clos.prettyprint = mailvar_get (NULL, "variable-pretty-print",
mailvar_type_boolean, 0) == 0;
clos.width = util_getcols ();
clos.width = util_screen_columns ();
mu_list_foreach (varlist, mailvar_printer, &clos);
mu_list_destroy (&varlist);
......@@ -845,7 +845,7 @@ int
mail_variable (int argc, char **argv)
{
int pagelines = util_get_crt ();
int width = util_getcols ();
int width = util_screen_columns ();
mu_stream_t out = open_pager (pagelines + 1);
if (argc == 1)
......
......@@ -45,7 +45,7 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data)
{
if (pagelines)
{
size_t col = (size_t)util_getcols ();
size_t col = (size_t) util_screen_columns ();
if (col)
{
size_t size = 0;
......
......@@ -311,7 +311,7 @@ util_command_list (void *table, size_t nmemb, size_t size)
{
int i;
char *p;
int cols = util_getcols ();
int cols = util_screen_columns ();
int pos;
for (p = table, i = 0; i < nmemb; i++, p += size)
......@@ -349,16 +349,9 @@ int
util_getcols (void)
{
struct winsize ws;
ws.ws_col = ws.ws_row = 0;
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0)
{
const char *columns = getenv ("COLUMNS");
if (columns)
ws.ws_col = strtol (columns, NULL, 10);
}
/* FIXME: Should we exit()/abort() if col <= 0 ? */
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_col == 0)
return 80; /* FIXME: Should we exit()/abort() if col <= 0 ? */
return ws.ws_col;
}
......@@ -370,17 +363,9 @@ int
util_getlines (void)
{
struct winsize ws;
ws.ws_col = ws.ws_row = 0;
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0)
{
const char *lines = getenv ("LINES");
if (lines)
ws.ws_row = strtol (lines, NULL, 10);
}
/* FIXME: Should we exit()/abort() if row <= 0 ? */
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row <= 2)
ws.ws_row = 24; /* FIXME: Should we exit()/abort() if row <= 2 ? */
/* Reserve at least 2 line for the prompt. */
return ws.ws_row - 2;
}
......