Make Remind adjust calendar to fit terminal.

This commit is contained in:
Dianne Skoll
2020-01-18 15:11:28 -05:00
parent 828a0d6589
commit a9430fea5f
4 changed files with 41 additions and 8 deletions

View File

@@ -82,14 +82,19 @@ greater than 128, the color is considered "bright".
.B \-w\fR\fIcol\fR[,\fIpad\fR[,\fIspc\fR]]]
The \fB\-w\fR option specifies the output width, padding and spacing
of the formatted calendar output. \fICol\fR specifies the number of
columns in the output device, and defaults to 80. \fIPad\fR specifies
how many lines to use to "pad" empty calendar boxes. This defaults to
5. If you have many reminders on certain days that make your calendar
too large to fit on a page, you can try reducing \fIpad\fR to make the
empty boxes smaller. \fISpc\fR specifies how many blank lines to leave
between the day number and the first reminder entry. It defaults to 1.
columns in the output device. If not specified, or specified as 0,
it defaults to the larger of 71 or the actual width of your terminal,
or to 80 if standard output is not a terminal.
.RS
.PP
\fIPad\fR specifies how many lines
to use to "pad" empty calendar boxes. This defaults to 5. If you
have many reminders on certain days that make your calendar too large
to fit on a page, you can try reducing \fIpad\fR to make the empty
boxes smaller. \fISpc\fR specifies how many blank lines to leave
between the day number and the first reminder entry. It defaults to
1.
.PP
Any of \fIcol\fR, \fIpad\fR or \fIspc\fR can be omitted, providing you
provide the correct number of commas. Don't use any spaces in the option.
.RE

View File

@@ -16,6 +16,8 @@
#include <ctype.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#ifdef REM_USE_WCHAR
#include <wctype.h>
@@ -302,6 +304,27 @@ static void Colorize(CalEntry const *e)
printf("%s", VT100Colors[bright][r][g][b]);
}
static int
ComputeCalWidth(int x)
{
struct winsize w;
if (x >= 71) {
/* Has been set with -w option */
return x;
}
if (!isatty(STDOUT_FILENO)) {
/* Output is not a TTY... assume 80 */
return 80;
}
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) {
return 80;
}
if (w.ws_col < 71) {
return 80;
}
return w.ws_col;
}
/***************************************************************/
/* */
/* ProduceCalendar */
@@ -322,6 +345,8 @@ void ProduceCalendar(void)
}
ShouldCache = 1;
CalWidth = ComputeCalWidth(CalWidth);
ColSpaces = (CalWidth - 9) / 7;
CalWidth = 7*ColSpaces + 8;

View File

@@ -46,7 +46,7 @@ EXTERN INIT( int DoPrefixLineNo, 0);
EXTERN INIT( int MondayFirst, 0);
EXTERN INIT( int Iterations, 1);
EXTERN INIT( int PsCal, 0);
EXTERN INIT( int CalWidth, 80);
EXTERN INIT( int CalWidth, -1);
EXTERN INIT( int CalWeeks, 0);
EXTERN INIT( int CalMonths, 0);
EXTERN INIT( int Hush, 0);

View File

@@ -430,7 +430,10 @@ void InitRemind(int argc, char const *argv[])
case 'W':
if (*arg != ',') {
PARSENUM(CalWidth, arg);
if (CalWidth < 71) CalWidth = 71;
if (CalWidth != 0 && CalWidth < 71) CalWidth = 71;
if (CalWidth == 0) {
CalWidth = -1;
}
}
if (*arg == ',') {
arg++;