Skip to content

Add Giphy ASCII animation widget#65

Open
muk2 wants to merge 1 commit intomainfrom
feature/giphy-ascii-widget
Open

Add Giphy ASCII animation widget#65
muk2 wants to merge 1 commit intomainfrom
feature/giphy-ascii-widget

Conversation

@muk2
Copy link
Owner

@muk2 muk2 commented Feb 20, 2026

Summary

Adds a new widget that fetches GIFs from the Giphy API, decodes them frame-by-frame, converts each frame to ASCII art, and animates them directly in the terminal.

  • Giphy API integration (src/feeds/giphy.rs): Supports three modes — search (query-based), trending, and random. Fetches the small fixed-height variant for optimal terminal rendering. Downloads the GIF binary and decodes all frames.
  • ASCII frame conversion: Each GIF frame is decoded to RGBA pixels, downsampled to fit terminal dimensions (max 60×20), converted to grayscale via luminance weighting (0.299R + 0.587G + 0.114B), then mapped to an ASCII character gradient: " .:-=+*#%@".
  • Animation widget (src/ui/widgets/giphy.rs): Renders ASCII frames sequentially with configurable frame delay (default 150ms). Supports pause/resume and manual frame stepping via scroll keys. Shows frame counter and GIF title in the border.
  • Configuration via config.toml:
    [[widgets]]
    type = "giphy"
    title = "GIF Player"
    api_key = "YOUR_GIPHY_API_KEY"
    query = "cats"
    mode = "search"          # search | trending | random
    frame_delay_ms = 150
    position = { row = 0, col = 2 }

Files changed

File Change
Cargo.toml Add gif crate dependency
src/feeds/giphy.rs New — Giphy API fetcher + GIF→ASCII decoder
src/feeds/mod.rs Add Giphy variant to FeedData, GiphyGif struct
src/ui/widgets/giphy.rs New — Animated ASCII art widget
src/ui/widgets/mod.rs Register giphy module
src/config.rs Add GiphyConfig struct + Giphy widget variant
src/app.rs Wire up widget creation + animation tick loop

Performance considerations

  • Frames capped at 30 per GIF to prevent memory issues
  • Terminal output sized to max 60×20 characters regardless of source resolution
  • Frame delay configurable to prevent excessive redraws

Test plan

  • CI passes (check, fmt, clippy, build on all platforms)
  • Widget renders loading state before GIF is fetched
  • Widget renders error state when API key is invalid
  • ASCII animation plays smoothly with correct frame timing
  • Scroll up/down manually steps through frames
  • Widget resizes correctly with terminal

Closes #55

🤖 Generated with Claude Code

Implement a new widget that fetches GIFs from the Giphy API, decodes
them frame-by-frame, converts each frame to ASCII art using luminance
mapping, and animates them in the terminal.

New files:
- src/feeds/giphy.rs: Giphy API client supporting search, trending,
  and random modes. Downloads GIFs and decodes frames into ASCII art
  using brightness-to-character mapping (" .:-=+*#%@").
- src/ui/widgets/giphy.rs: TUI widget that renders ASCII frames with
  configurable animation speed, pause/resume, and manual frame stepping
  via scroll keys.

Modified files:
- Cargo.toml: Add gif crate for GIF frame decoding
- src/feeds/mod.rs: Add Giphy variant to FeedData enum, GiphyGif struct
- src/config.rs: Add GiphyConfig with api_key, query, mode,
  frame_delay_ms options
- src/ui/widgets/mod.rs: Register giphy widget module
- src/app.rs: Wire up GiphyWidget creation and animation ticking

Configuration example (config.toml):
  [[widgets]]
  type = "giphy"
  title = "GIF Player"
  api_key = "YOUR_GIPHY_API_KEY"
  query = "cats"
  mode = "search"
  frame_delay_ms = 150
  position = { row = 0, col = 2 }

Closes #55

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

giphy support

1 participant