Skip to content

feat(fetcher): real clock + multi-line static text (#7) - #31

Merged
unhappychoice merged 2 commits into
mainfrom
feat/7-clock
Apr 21, 2026
Merged

unhappychoice merged 2 commits into
mainfrom
feat/7-clock

Conversation

@unhappychoice

Copy link
Copy Markdown
Owner

Replaces two placeholder fetchers with their v1 implementations and reorganizes the fetcher module so future widget PRs (#8 git, #9 system, #10 todo, #11 github) can slot in without further churn.

What changes

  • `clock`: `chrono::Local::now().format(fmt)` with default `%H:%M`. Invalid strftime directives no longer panic — chrono's `to_string()` escalates `fmt::Error` into a `.expect()` panic, so the fetch is wrapped in `write!` and falls back to the default format on error. Output stays as Bignum so the default layout's big-text renderer gets used.
  • `static`: `format` splits on `\n` into multiple Text lines. Empty / missing format emits an empty line list (widget renders nothing rather than a spurious blank). Trailing `\n` preserves the trailing blank to match split semantics.
  • Module split: `src/fetcher/clock.rs` and `src/fetcher/static_text.rs` each own their fetcher + tests. `stub.rs` is trimmed to the remaining placeholder fetchers (disk / git_commits / system / github_prs) and renames its aggregator from `builtins()` to `stubs()`. `Registry::with_builtins` composes from all three.

`greeting` was considered and dropped: time-of-day salutations in splash screens are filler. Users who want fixed text can use `static`.

Test plan

  • `cargo fmt --check`
  • `cargo clippy --all-targets -- -D warnings`
  • `cargo test` (125 passed, incl. default clock format is HH:MM, custom format, invalid-format fallback without panic, static single-line / multi-line / empty / trailing-newline)
  • Manual: run `splashboard` and confirm the clock slot shows the real time
  • Manual: `format = "line one\nline two"` in a widget config and confirm two-line render

Closes #7.

Replace two placeholder fetchers with their v1 implementations.

- `clock`: `chrono::Local::now().format(fmt)` with a default of
  `%H:%M`. `format` in the widget config flows through as the
  strftime pattern, so users can opt into a date or 12h display.
  Output is still Bignum — paired with the default layout's big-
  text renderer for visual weight.
- `static`: split `format` on `\n` into separate Text lines so
  users can ship a multi-line fixed block (project welcome, notes,
  etc.) without a dedicated fetcher. Empty / missing format emits
  an empty line list so the widget renders nothing rather than a
  blank line. Trailing `\n` preserves the trailing blank, matching
  split semantics byte-for-byte.

`greeting` was considered and dropped: time-of-day salutations in
splash screens are filler — users who want a static greeting can
write `static` + `format = "..."`, and anything else is out of
scope for v1.

Adds `chrono` (default-features=false, "clock" + "std") and tests
covering default clock format length, custom format, single-line
static, multi-line split, empty-format-is-empty, trailing-newline
retention.
Two things I cut corners on in the previous commit.

**Module split.** Real fetchers (static, clock) lived alongside
placeholder stubs in a single \`stub.rs\`, which was already
stretching at 6 fetchers and would have gotten worse as #8 / #9 /
#10 / #11 replace the remaining stubs one by one. Splitting now so
each fetcher owns its own file with its own tests:

  src/fetcher/
    mod.rs         — trait, Registry, with_builtins
    clock.rs       — ClockFetcher
    static_text.rs — StaticText
    stub.rs        — remaining stubs only

\`stub.rs\` gets a top-of-file comment marking it as "placeholder
only" and a \`stubs()\` helper (renamed from \`builtins()\`) so the
name matches what's inside.

**Clock format panic.** \`chrono::format(fmt).to_string()\` panics
when \`fmt\` contains an unrecognised strftime directive — the
formatter returns \`fmt::Error\` and \`ToString::to_string\` panics on
that via its internal \`.expect(...)\`. A user typo in \`format = "%Q"\`
would have crashed the fetch daemon. Wrap the format call in
\`write!\` so the error is caught instead of escalating, then fall
back to the default \`%H:%M\`. Test added that exercises \`%Q\`.
@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@unhappychoice has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 51 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 10 minutes and 51 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5e7e2045-79bf-492e-ba62-877fddc36c11

📥 Commits

Reviewing files that changed from the base of the PR and between 0a2379a and 834f84b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • Cargo.toml
  • src/fetcher/clock.rs
  • src/fetcher/mod.rs
  • src/fetcher/static_text.rs
  • src/fetcher/stub.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/7-clock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@unhappychoice
unhappychoice merged commit 23adc05 into main Apr 21, 2026
5 checks passed
@unhappychoice
unhappychoice deleted the feat/7-clock branch April 21, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

widget: Clock / date / greeting

1 participant