Documentation
¶
Index ¶
- Constants
- Variables
- func CreateDir(name string) error
- func CreateFileIfMissing(name string) error
- func DisplayCalendar(location *time.Location, fromYear int, fromMonth time.Month, months int, ...) (output string)
- func DisplayCalendarLegend(instance *Instance, events []Event) string
- func DisplayTimeline(instance *Instance, events []Event, showDates bool, lastShownDate time.Time, ...) string
- func DisplayUnsatisfiedRecurrences(instance *Instance, unsatisfiedRecurrences []*Event) string
- func DoPeriodsMeet(period1, period2 TimeRange) bool
- func DurationToString(d time.Duration) string
- func GenerateUid() string
- func GetEventRgbAnsiSeq(event *Event, instance *Instance, background bool) string
- func GetTimeZone() *time.Location
- func IsPeriodConfinedToPeriod(period1, period2 TimeRange) bool
- func IsTimeWithinPeriod(t time.Time, period TimeRange) bool
- func ParseDateTime(input string, timeZone *time.Location) (time.Time, error)
- func ParseIcal(r io.Reader) (*ical.Calendar, error)
- func ParseTimeOnly(input string) (time.Time, error)
- func RgbToAnsiSeq(rgb color.RGBA, background bool) string
- func SanitizeFilepath(p string) string
- func SanitizePath(p string) string
- func SerializeIcal(ics *ical.Calendar) (bytes.Buffer, error)
- func ToIcal(events []Event, calendarName string) *ical.Calendar
- func WriteConfig(root string, config Config) error
- type CacheJournal
- type CacheJournalSource
- type CalendarConfig
- type CalendarSource
- type Config
- type Event
- type EventPath
- type EventProperties
- func (props *EventProperties) FormatName() string
- func (props *EventProperties) GetRruleSet() (rrule.Set, error)
- func (props *EventProperties) GetTimeRange() TimeRange
- func (props *EventProperties) IsAllDay() bool
- func (p *EventProperties) Validate() error
- func (props *EventProperties) Write(file string) error
- type EventType
- type Hook
- type Instance
- func (instance *Instance) CacheEvent(subDir string, props EventProperties) error
- func (instance *Instance) CacheEvents(name string, eventsProps []EventProperties) error
- func (instance *Instance) CleanSources() error
- func (instance *Instance) DeleteCache() error
- func (instance *Instance) NewEvent(props EventProperties, calendar string) (Event, error)
- func (instance *Instance) ReadCachedEvents() ([]Event, error)
- func (instance *Instance) ReadEvents(timeRange TimeRange) ([]Event, []*Event, error)
- func (instance *Instance) Sync(action func() error, eventInfo SyncEvent, ignoreCooldowns bool, ...) error
- func (instance *Instance) UpdateSources() error
- func (instance *Instance) Work() error
- func (instance *Instance) WriteNewEvent(props EventProperties, calendar string) (*Event, error)
- type Recurrence
- type SyncCooldownInfo
- type SyncEvent
- type SyncEventType
- type TimeRange
Constants ¶
const CacheCalendar string = ".sources"
const CacheJournalFileName string = ".cache-journal.toml"
const ConfigFilename string = ".config.toml"
const CooldownJournalFilename string = ".cooldown-journal.toml"
const DefaultCacheLifetime time.Duration = 2 * time.Hour
const DefaultTimeLayout string = "_2 Jan 15:04 MST 2006"
const IcalPropGrabTimestamp string = "X-IAN-GRABBED"
Variables ¶
var TimeZone *time.Location
var Verbose bool
Functions ¶
func CreateFileIfMissing ¶
func DisplayCalendar ¶
func DisplayCalendarLegend ¶
func DisplayTimeline ¶
func DoPeriodsMeet ¶
DoPeriodsMeet compares two periods and returns true if they collide at some point, otherwise false. Period ends are non-inclusive, meaning that if one period's end touches the start of the other period, it does not count.
func DurationToString ¶
DurationToString because time's implementation is ugly.
func GenerateUid ¶
func GenerateUid() string
func GetEventRgbAnsiSeq ¶
GetEventRgbAnsiSeq is a helper function to quickly get the color of an event based on its container.
func GetTimeZone ¶
func IsPeriodConfinedToPeriod ¶
IsPeriodConfinedToPeriod returns true if period1 start is at or after (i.e. inclusive) period2 start, and period1 end is before (i.e. non-inclusive) period2 end.
func IsTimeWithinPeriod ¶
IsTimeWithinPeriod returns true if the start of t is at or after (i.e. inclusive) the start of period, and the end of t is before (i.e. non-inclusive) the end of period.
func ParseDateTime ¶
ParseDateTime parses a string against many different formats. If timezone is omitted, the local is assumed (from global variable `UseTimezone`). If year is omitted, the current one is used.
func SanitizeFilepath ¶
SanitizeFilepath escapes a filepath. It prevents root traversal (/) and parent traversal (..), and just cleans it too.
func SanitizePath ¶
SanitizePath escapes a path. It prevents root traversal (/) and parent traversal (..), and just cleans it too.
func WriteConfig ¶
Types ¶
type CacheJournal ¶
type CacheJournal struct {
Sources map[string]CacheJournalSource
}
type CacheJournalSource ¶
type CalendarConfig ¶
func (*CalendarConfig) GetColor ¶
func (conf *CalendarConfig) GetColor() color.RGBA
type CalendarSource ¶
type CalendarSource struct {
Source string
// Type can be:
// "native" for a native, dynamic ian calendar.
// "caldav" for a dynamic CalDAV.
// "ical" for a static HTTP iCalendar.
Type string
// Parsed with time.ParseDuration...
Lifetime string
// and inserted here:
Lifetime_ time.Duration
}
func (*CalendarSource) Import ¶
func (i *CalendarSource) Import(name string) ([]EventProperties, error)
func (*CalendarSource) ImportAndUse ¶
func (i *CalendarSource) ImportAndUse(instance *Instance, name string) error
type Config ¶
type Config struct {
Calendars map[string]CalendarConfig
Sources map[string]CalendarSource
Hooks map[string]Hook
}
func ReadConfig ¶
func (*Config) GetContainerConfig ¶
func (conf *Config) GetContainerConfig(container string) (*CalendarConfig, error)
type Event ¶
type Event struct {
Path EventPath
Props EventProperties
Type EventType
// Constant is true if the event should not be changed. Used for source events (cache) or the event is generated from a recurrance (RRule).
Constant bool
// Parent is the parent event if this event is generated from a recurrence rule. Otherwise nil.
Parent *Event
}
func BuildEvent ¶
func BuildEvent(path EventPath, props EventProperties, eType EventType) (Event, error)
type EventPath ¶
type EventPath interface {
Calendar() string
Name() string
String() string
Filepath(*Instance) string
}
EventPath specifies where to find an event, and its calendar.
func NewEventPath ¶
NewEventPath safely constructs an EventPath from a calendar and name, which can be easily used for determining paths and filenames. name may be modified.
func NewFreeEventPath ¶
NewFreeEventPath is like NewEventPath, but ensures that the filename is available, possibly by changing it.
func ParseEventPath ¶
type EventProperties ¶
type EventProperties struct {
Uid string
Summary string
Description string
Location string
Url string
// Start is an inclusive datetime representing when the event begins.
Start time.Time
// End is a non-inclusive datetime representing when the event ends.
End time.Time
Recurrence Recurrence
Created time.Time
Modified time.Time
}
func FromIcalEvent ¶
func FromIcalEvent(icalEvent ical.Event) (EventProperties, error)
func (*EventProperties) FormatName ¶
func (props *EventProperties) FormatName() string
func (*EventProperties) GetRruleSet ¶
func (props *EventProperties) GetRruleSet() (rrule.Set, error)
func (*EventProperties) GetTimeRange ¶
func (props *EventProperties) GetTimeRange() TimeRange
func (*EventProperties) IsAllDay ¶
func (props *EventProperties) IsAllDay() bool
func (*EventProperties) Validate ¶
func (p *EventProperties) Validate() error
func (*EventProperties) Write ¶
func (props *EventProperties) Write(file string) error
type Hook ¶
type Hook struct {
// PreCommand is run as a shell command BEFORE an event is updated, in the instance directory.
// PreCommand has the same environment variables as PostCommand.
PreCommand string
// PostCommand is run as a shell command AFTER an event is updated, in the instance directory.
//
// Use $MESSAGE in the command to embed the message describing the event change.
//
// Use $FILES for a space-separated string with the affected file(s).
//
// Use $TYPE for the event type ID.
//
// Any stderr output from the command is printed to the user in the form of a warning.
//
// Example: 'git add . && git commit -m "$MESSAGE" && (git pull; git push)'
PostCommand string
// Type is a bitmask that represents the event(s) to listen to.
Type SyncEventType
// Cooldown is parsed as a time.Duration, and is the duration that has to pass before the command is executed again, to prevent fast-paced command execution.
Cooldown string
Cooldown_ time.Duration
}
type Instance ¶
func CreateInstance ¶
func (*Instance) CacheEvent ¶
func (instance *Instance) CacheEvent(subDir string, props EventProperties) error
func (*Instance) CacheEvents ¶
func (instance *Instance) CacheEvents(name string, eventsProps []EventProperties) error
CacheEvents collectively caches a list of events under a certain directory.
func (*Instance) CleanSources ¶
func (*Instance) DeleteCache ¶
func (*Instance) NewEvent ¶
func (instance *Instance) NewEvent(props EventProperties, calendar string) (Event, error)
NewEvent constructs a standard event based on properties, as a part of calendar. NewEvent does not write anything.
func (*Instance) ReadCachedEvents ¶
func (*Instance) ReadEvents ¶
ReadEvents reads all events in the instance that appear during the time range, and parses their recurrences. If the time range is empty (From.IsZero() && To.IsZero()), then all events are shown, and recurrences are shown within the range of the normal events.
func (*Instance) Sync ¶
func (instance *Instance) Sync(action func() error, eventInfo SyncEvent, ignoreCooldowns bool, stdouterr io.Writer) error
Sync is called whenever changes are made to event(s), with the changes occuring in action, and calls any configured commands.
func (*Instance) UpdateSources ¶
UpdateSources updates the configured sources according to their lifetimes.
func (*Instance) Work ¶
Work performs maintenance work and is run on every instance creation. It is used to e.g. update sources.
func (*Instance) WriteNewEvent ¶
func (instance *Instance) WriteNewEvent(props EventProperties, calendar string) (*Event, error)
WriteNewEvent creates an event in the instance by writing it.
type Recurrence ¶
func (*Recurrence) IsThereRecurrence ¶
func (rec *Recurrence) IsThereRecurrence() bool
type SyncCooldownInfo ¶
type SyncEvent ¶
type SyncEvent struct {
Type SyncEventType
Files []string
Message string
}
type SyncEventType ¶
type SyncEventType int
const ( SyncEventPing SyncEventType = 1 << iota SyncEventCreate SyncEventUpdate SyncEventDelete )