On 2020-01-13 14:58, Dianne Skoll wrote:
> > SET Esc Char(27)
> > SET Red Esc + "[0;31m"
> > SET Nrm Esc + "[0m"
> > FSET calprefix(x) Red
> > FSET calsuffix(x) Nrm
> > MSG "this is a very important thing"
>
> > things go all bonkers.
>
> However, Remind can color reminders natively. If you have
> something like:
>
> REM Fri SPECIAL COLOR 255 0 0 Friday!!!
>
> and then invoke Remind as: remind -cc ... (or remind -clc ... to
> use line-drawing characters) then it colors the calendar using ANSI
> sequences and doesn't mess up formatting.
Handy for one-offs, but for my use case, I tend to have my reminders
in multiple files (birthdays, anniversaries, one for work, one for the
kids' school calendars, etc), and then have one color per file, using
msgprefix/msgsuffix
# base remind.rem
INCLUDE .../colors.rem
SET calcolor Nrm
FSET msgprefix(x) calcolor
FSET msgsuffix(x) Nrm
INCLUDE .../birthdays.rem
INCLUDE .../anniversaries.rem
INCLUDE .../tim.rem
INCLUDE .../school.rem
# birthdays.rem
SET calcolor Grn
REM Jan 6 MSG Dianne's birthday
REM Feb 14 MSG Tim's birthday
# tim.rem
SET calcolor Blu
REM Jan 14 2020 MSG Reply to email about colors in remind
# school.rem
SET calcolor Cyn
REM Aug 13 2019 MSG School begins
This lets me set the color a mere 41 (as reported by `grep
"SET calcolor" ~/.config/remind/*.rem | wc -l`) times rather than
individually for all my (roughly) 1560 individual REM statements (as
determined by a `grep "MS[GF]" ~/.config/remind | wc -l`).
I know you've been busy hacking in some new functionality for JSON
output and the like, but I'll put a bug in your ear hoping for a
global default color that could be tweaked as above. It wouldn't be
onorous to adjust my files to change the "SET calcolor Foo" to
something like
# birthdays.rem
COLOR 0 128 0
# or
SET $DefaultColor "0 128 0"
[an hour passes]
As matter of fact, I wanted it badly enough to implement it and
attach at least the code changes as a .diff :-)
I'm afraid I don't have tests for it or updates for the man-page but
my manual testing worked (almost) exactly as desired:
$ cat ~/.reminders
MSG Normal daily%
SPECIAL COLOR 128 0 0 MSG Explicitly red%
SET $DefaultColor "0 0 128"
MSG Normal but blue?%
SPECIAL COLOR 0 128 0 MSG Explicitly green now%
MSG Back to blue?%
MSG Look, more blue with no further effort%
SET $DefaultColor "128 0 128"
MSG And purple now?%
MSG The default color is [$DefaultColor]%
and tested with
$ remind -cc+ ~/.reminders
It built and worked on the first try! (I love it when that happens!)
The "almost" aspect of it is that because of how the repeat days
work, the "Normal daily" comes out normal for the first day, but in
subsequent iterations, it's the new default color (at this point, the
purple that the previous one ended with). It's expected yet also a
bit of a surprise. Just kinda requires that you set the $DefaultColor
at the very top before any reminders trigger.
I'm not sure if the patch adheres to your coding style but consider it
licsensed WTFPL/CC0/BSD/GPLv{whatever} so you're welcome to do as you
please with it.
-tim
diff --git a/src/calendar.c b/src/calendar.c
index 67c62e6..52cdee8 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -954,7 +954,15 @@ static int DoCalRem(ParsePtr p, int col)
int is_color, col_r, col_g, col_b;
- is_color = 0;
+ is_color = (
+ DefaultColorR != -1
+ || DefaultColorG != -1
+ || DefaultColorB != -1);
+ if (is_color) {
+ col_r = DefaultColorR;
+ col_g = DefaultColorG;
+ col_b = DefaultColorB;
+ }
DBufInit(&buf);
DBufInit(&pre_buf);
DBufInit(&raw_buf);
diff --git a/src/globals.h b/src/globals.h
index 976279c..ea6e6f1 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -73,6 +73,9 @@ EXTERN INIT( int Daemon, 0);
EXTERN INIT( char DateSep, DATESEP);
EXTERN INIT( char TimeSep, TIMESEP);
EXTERN INIT( char DateTimeSep, DATETIMESEP);
+EXTERN INIT( int DefaultColorR, -1);
+EXTERN INIT( int DefaultColorB, -1);
+EXTERN INIT( int DefaultColorG, -1);
EXTERN INIT( int SynthesizeTags, 0);
EXTERN INIT( int ScFormat, SC_AMPM);
EXTERN INIT( int MaxSatIter, 150);
diff --git a/src/var.c b/src/var.c
index cc01ae3..fb4761b 100644
--- a/src/var.c
+++ b/src/var.c
@@ -168,6 +168,40 @@ static int datetime_sep_func(int do_set, Value *val)
return OK;
}
+static int default_color_func(int do_set, Value *val)
+{
+ int col_r, col_g, col_b;
+ if (!do_set) {
+ /* 12 = strlen("255 255 255\0") */
+ val->v.str = malloc(12);
+ if (!val->v.str) return E_NO_MEM;
+ snprintf(val->v.str, 12, "%d %d %d",
+ DefaultColorR,
+ DefaultColorB,
+ DefaultColorG
+ );
+ val->type = STR_TYPE;
+ return OK;
+ }
+ if (val->type != STR_TYPE) return E_BAD_TYPE;
+ if (sscanf(val->v.str, "%d %d %d", &col_r, &col_g, &col_b) != 3) {
+ return E_BAD_TYPE;
+ }
+ if (col_r != -1 || col_g != -1 || col_b != -1) {
+ /* if any of them aren't -1, clamp them all as set */
+ if (col_r < 0) col_r = 0;
+ else if (col_r > 255) col_r = 255;
+ if (col_g < 0) col_g = 0;
+ else if (col_g > 255) col_g = 255;
+ if (col_b < 0) col_b = 0;
+ else if (col_b > 255) col_b = 255;
+ }
+ DefaultColorR = col_r;
+ DefaultColorB = col_b;
+ DefaultColorG = col_g;
+ return OK;
+}
+
static int date_sep_func(int do_set, Value *val)
{
if (!do_set) {
@@ -608,6 +642,7 @@ static SysVar SysVarArr[] = {
{"Daemon", 0, INT_TYPE, &Daemon, 0, 0 },
{"DateSep", 1, SPECIAL_TYPE, date_sep_func, 0, 0 },
{"DateTimeSep", 1, SPECIAL_TYPE, datetime_sep_func, 0, 0 },
+ {"DefaultColor", 1, SPECIAL_TYPE, default_color_func, 0, 0 },
{"DefaultPrio", 1, INT_TYPE, &DefaultPrio, 0, 9999},
{"DeltaOffset", 0, INT_TYPE, &DeltaOffset, 0, 0 },
{"DontFork", 0, INT_TYPE, &DontFork, 0, 0 },
_______________________________________________
Remind-fans mailing list
[email protected]
https://dianne.skoll.ca/mailman/listinfo/remind-fans
Remind is at https://dianne.skoll.ca/projects/remind/