diff --git a/lib/modules/Calendar.pmod/Gregorian.pmod b/lib/modules/Calendar.pmod/Gregorian.pmod index 5b4dd8249511b3058f27ac7cacaed3ea936f73eb..75439ea409748eeb9b247e0bbd6e952705010eba 100644 --- a/lib/modules/Calendar.pmod/Gregorian.pmod +++ b/lib/modules/Calendar.pmod/Gregorian.pmod @@ -1,6 +1,6 @@ // by Mirar -//! +//! module Calendar //! submodule Gregorian //! time units: //! <ref>Year</ref>, <ref>Month</ref>, <ref>Week</ref>, <ref>Day</ref> diff --git a/lib/modules/Calendar.pmod/module.pmod b/lib/modules/Calendar.pmod/module.pmod index 3dcbc4602254e1f69057a0482b26f197e031b7c5..8c453855ced9e3ea678e910c794c81e82853ebaa 100644 --- a/lib/modules/Calendar.pmod/module.pmod +++ b/lib/modules/Calendar.pmod/module.pmod @@ -198,35 +198,81 @@ string print_month(void|object month,void|mapping options) if (!month) // resolv thing here is to avoid compile-time resolve month=master()->resolv("Calendar")["Gregorian"]["Month"](); + options=(["mark_today":1, + "week_space":3, + "weeks":1, + "days":1, + "title":1, + "notes":([])]) | (options || ([])); + options=(["date_space":(options->mark_today?3:2)])|options; + + today=function_object(object_program(month))->Day(); - res=sprintf(" %|28s\n", - String.capitalize(month->name()+" ") - +month->year()->name()); - w=month->day(1)->week(); - res+=" "; - foreach (Array.map(w->days(),w->day)->week_day_name(),string n) - res+=sprintf("%3s ",n[0..2]); - res+="\n"; + res=""; + if (options->weeks) res+=" "+" "*options->week_space; + if (options->title) + res+=sprintf("%|*s\n", + (1+options->date_space)*sizeof(w->days())-1, + intp(options->title) + ?(String.capitalize(month->name()+" ") + +month->year()->name()) + :options->title); + + if (options->days) + { + if (options->weeks) res+=" "+" "*options->week_space; + foreach (Array.map(w->days(),w->day)->week_day_name(),string n) + res+=sprintf("%*s ",options->date_space,n[0..options->date_space-1]); + res+="\n"; + } + + string daynotes=""; + + if (sizeof(Array.filter( + Array.map(month->days(),month->day), + lambda(object d) { return !!options->notes[d]; }))) + daynotes="\n%-|"+options->date_space+"s"; do { array a; + array b; object d; + string format=""; + a=Array.map(Array.map(w->days(),w->day), lambda(object d) { if (d->month()!=month) return 0; else return d; }); - res+=sprintf("%3s ",w->name()); + if (options->weeks) + res+=sprintf("%*s ",options->week_space,w->name()); foreach (a,d) if (d) - if (d!=today) res+=sprintf(" %2d ",d->month_day()); - else res+=sprintf(">%2d<",d->month_day()); - else res+=" "; + if (!options->mark_today || d!=today) + res+=sprintf("%* |d ", + options->date_space, + d->month_day()); + else + res+=sprintf(">%* |d<", + options->date_space-1, + d->month_day()); + else res+=" "+" "*options->date_space; + + if (options->notes[w]) + res+=sprintf("%-=*s", + options->week_note_column_width, + options->notes[w]); res+="\n"; + + if (daynotes) + { + + } + w++; } while (w->day(0)->month()==month);