CUI

Components / Developer tools

Schedule picker

A cron schedule edited through plain choices instead of the expression, with the next runs listed.

Functions: cui_cron_next, cui_schedule_picker

Schedule picker

Usage

static char cron[64] = "30 9 * * 1-5";
cui_schedule_result r = cui_schedule_picker(ui, "backup", cron, sizeof cron);
if (r.changed && r.valid) save_schedule(cron);

A cron expression edited the friendly way: every N minutes, hourly at a minute, daily at a time, weekly on chosen days, monthly on a day, or a custom expression typed in. It reads the expression you give it, picks the mode it is written in, and writes it back only when you change something. Below the controls it says what the schedule means, shows the expression, and lists the next runs (next_count, three by default) in local time or in UTC (utc). Weekday and month names come from cui_set_strings.

The same parser is public. cui_cron_next(cron, after, utc_offset, &next) finds the next run after a time, in a time zone given in minutes east of UTC. It supports lists, ranges, steps, the names JAN to DEC and SUN to SAT, and 0 or 7 for Sunday. When both the day of the month and the weekday are restricted, either one matches, as in cron. It returns false for an invalid expression, or one that never runs within five years (February 31). cui_cron_describe returns the sentence ("Every weekday at 09:30").

Keyboard

  • Tab moves through the controls. Left and Right change the mode, Up and Down change a focused number or select, and Enter or Space toggles a focused weekday.

Options of cui_schedule_picker

OptionTypeDefaultDescription
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.nowint64_tthe next runs are counted from here, Unix seconds; 0: the clock
.utcbooltimes in UTC instead of local time
.next_countint3, 0 hides themruns listed, default 3, 0 hides them

cui_schedule_result

FieldTypeDescription
changedboolcron was edited this frame
validboolcron is a valid expression
nextint64_tthe next run, Unix seconds, 0 none

Related

  • Keymap: A keyboard with the shortcuts on it.
  • Query builder: A filter built from conditions joined by all or any, in groups that nest.
  • Commit graph: Version history with its branch lanes.
  • Pipeline: A CI or CD run: each stage is a column of its jobs with their status and duration, and connectors run between the stages.