Skip to content

feat(fetcher): add code_language_logo for repo-language Devicon hero - #169

Merged
unhappychoice merged 1 commit into
mainfrom
feat/code-language-logo
Apr 27, 2026
Merged

unhappychoice merged 1 commit into
mainfrom
feat/code-language-logo

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Apr 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds code_language_logo, a new code_* family fetcher that detects the dominant programming language from the discovered git repo's tracked files and renders the matching Devicon PNG via the Image shape. Designed as the hero widget for the upcoming project_codebase preset (#164).

  • File-count-based language detection (cheap — no blob reads, uses the new for_each_tracked_path scan helper alongside the existing for_each_tracked_file).
  • 35 bundled Devicon PNGs (Rust, Go, Python, Ruby, TypeScript, JavaScript, Java, Kotlin, Scala, Swift, C, C++, C#, PHP, Elixir, Erlang, Haskell, Clojure, OCaml, Dart, Lua, R, Julia, Zig, Nim, Shell, PowerShell, HTML, CSS, Vue, Svelte, Dockerfile, Terraform, Perl, Groovy) plus a generic </> fallback.
  • Assets ship as 256×256 PNGs (rasterised from upstream SVGs via rsvg-convert); both the SVG sources and PNGs are committed. ~480 KB total.
  • Bundled bytes extract once per language under $SPLASHBOARD_HOME/cache/logos/<slug>.png so media_image (which only takes a path) can render from a stable location.
  • Optional language override skips auto-detection — useful for repos where the file-count majority isn't the language you want to lead with, and for non-repo contexts.

Ticks the code_language_logo box on the code_* checklist in #62; closes the hero slot for the project_codebase preset tracked in #164.

Reference

Kind Safety Shapes
cached Safe image

Options

Option Type Required Default Description
language string no auto-detected from the dominant language in the repo Override the detected language. Accepts the labels emitted by the shared code_* classifier (Rust, Go, Python, …); unknown values fall back to the generic </> glyph.

Compatible renderers

Shape Renderers
image animated_boot, animated_postfx, animated_scanlines, animated_splitflap, animated_wave, media_image

Licensing

Devicon assets are MIT-licensed; the upstream LICENSE is committed verbatim at assets/logos/LICENSE-devicon.txt. Generic </> glyph is a hand-authored SVG (no third-party content).

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test — 945 passed / 0 failed (8 new tests cover dominant-language detection, empty / unclassified paths, asset extraction idempotence, options parsing, and cache-key uniqueness)
  • Smoke-tested locally via a 3-slot dashboard (auto-detect / explicit language = "Python" / unknown language → generic) using the media_image renderer

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added automatic programming language detection with visual logo display for repositories
    • Language detection can be customized via configuration override
    • Logos are cached locally for improved performance
  • Chores

    • Added license file for embedded logo assets

Detects the dominant language across the discovered repo's tracked files
(file-count, no blob reads via the new `for_each_tracked_path` scan helper)
and emits the matching Devicon PNG via the `Image` shape. Bundles 35 logos
plus a generic `</>` fallback; assets extract once into
`$SPLASHBOARD_HOME/cache/logos/<slug>.png` so `media_image` can render
from a stable path.

The intended hero for the upcoming `project_codebase` preset (#164).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds a new code language logo fetcher that detects the dominant programming language in a git repository and returns the corresponding bundled devicon PNG asset. It includes embedded language logos, an asset lookup module, path scanning utilities, and license documentation.

Changes

Cohort / File(s) Summary
Logo Assets & Registry
src/fetcher/code/logo_assets.rs, src/fetcher/code/mod.rs
New logo_assets module embeds language PNG files and provides asset_for lookup; mod.rs registers new fetcher and declares related modules.
Language Logo Fetcher
src/fetcher/code/language_logo.rs
New CodeLanguageLogo fetcher that detects dominant repo language (or accepts override), maps to bundled asset, writes to cache directory, implements cache keying with SHA-256 salt, and includes comprehensive test coverage.
Repo Scanning
src/fetcher/code/scan.rs
New for_each_tracked_path function traverses git index entries without filesystem I/O, applying existing filters and exclusion rules.
Licensing
assets/logos/LICENSE-devicon.txt
New MIT License file for devicon asset attribution.

Sequence Diagram

sequenceDiagram
    actor User
    participant Fetcher as CodeLanguageLogo<br/>Fetcher
    participant Repo as Git Repository
    participant LangDetect as Language<br/>Detection
    participant AssetLookup as Logo Assets
    participant Cache as Cache<br/>Directory
    participant Disk as Disk

    User->>Fetcher: fetch(repo, options)
    
    alt Language option provided
        Fetcher->>LangDetect: use override language
    else Auto-detect
        Fetcher->>Repo: for_each_tracked_path()
        Repo-->>Fetcher: iterate paths
        Fetcher->>LangDetect: classify & count by language
        LangDetect-->>Fetcher: dominant language label
    end
    
    Fetcher->>AssetLookup: asset_for(language)
    AssetLookup-->>Fetcher: (slug, png_bytes)
    
    Fetcher->>Cache: ensure logos/ subdir exists
    Cache-->>Disk: create directory
    
    Fetcher->>Disk: write PNG bytes to file
    Disk-->>Fetcher: file path
    
    Fetcher->>User: return image Payload
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 A logo for each tongue I find,
From git repos and code combined!
Devicons bundled, cache-kissed tight,
Language detection, pure delight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the primary change: it announces the addition of a new code_language_logo fetcher that detects repository language and provides Devicon assets.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/code-language-logo

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.

@codecov

codecov Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.10345% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.50%. Comparing base (b9c5675) to head (45d66ea).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/fetcher/code/language_logo.rs 89.85% 14 Missing ⚠️
src/fetcher/code/scan.rs 80.95% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #169      +/-   ##
==========================================
+ Coverage   78.34%   78.50%   +0.15%     
==========================================
  Files         128      130       +2     
  Lines       24394    24654     +260     
==========================================
+ Hits        19112    19354     +242     
- Misses       5282     5300      +18     
Files with missing lines Coverage Δ
src/fetcher/code/logo_assets.rs 100.00% <100.00%> (ø)
src/fetcher/code/mod.rs 100.00% <100.00%> (ø)
src/fetcher/code/scan.rs 88.04% <80.95%> (-2.10%) ⬇️
src/fetcher/code/language_logo.rs 89.85% <89.85%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/fetcher/code/language_logo.rs`:
- Around line 117-130: ensure_extracted currently skips writing when a file
exists, causing stale cached PNGs to persist across releases; update
ensure_extracted to compare the existing file size to bytes.len() (use
std::fs::metadata(&path)?.len()) and if lengths differ, overwrite the file
(std::fs::write) so updated bundled bytes replace the cached file, mapping any
IO errors to FetchError::Failed as done now; keep the same stable slug-based
path logic (dir = logos_cache_dir(), path = dir.join(format!("{slug}.png"))).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22b706a0-b0c0-481e-8fa0-c04adef80808

📥 Commits

Reviewing files that changed from the base of the PR and between b9c5675 and 45d66ea.

⛔ Files ignored due to path filters (72)
  • assets/logos/png/_generic.png is excluded by !**/*.png
  • assets/logos/png/c.png is excluded by !**/*.png
  • assets/logos/png/clojure.png is excluded by !**/*.png
  • assets/logos/png/cpp.png is excluded by !**/*.png
  • assets/logos/png/csharp.png is excluded by !**/*.png
  • assets/logos/png/css.png is excluded by !**/*.png
  • assets/logos/png/dart.png is excluded by !**/*.png
  • assets/logos/png/dockerfile.png is excluded by !**/*.png
  • assets/logos/png/elixir.png is excluded by !**/*.png
  • assets/logos/png/erlang.png is excluded by !**/*.png
  • assets/logos/png/go.png is excluded by !**/*.png
  • assets/logos/png/groovy.png is excluded by !**/*.png
  • assets/logos/png/haskell.png is excluded by !**/*.png
  • assets/logos/png/html.png is excluded by !**/*.png
  • assets/logos/png/java.png is excluded by !**/*.png
  • assets/logos/png/javascript.png is excluded by !**/*.png
  • assets/logos/png/julia.png is excluded by !**/*.png
  • assets/logos/png/kotlin.png is excluded by !**/*.png
  • assets/logos/png/lua.png is excluded by !**/*.png
  • assets/logos/png/nim.png is excluded by !**/*.png
  • assets/logos/png/ocaml.png is excluded by !**/*.png
  • assets/logos/png/perl.png is excluded by !**/*.png
  • assets/logos/png/php.png is excluded by !**/*.png
  • assets/logos/png/powershell.png is excluded by !**/*.png
  • assets/logos/png/python.png is excluded by !**/*.png
  • assets/logos/png/r.png is excluded by !**/*.png
  • assets/logos/png/ruby.png is excluded by !**/*.png
  • assets/logos/png/rust.png is excluded by !**/*.png
  • assets/logos/png/scala.png is excluded by !**/*.png
  • assets/logos/png/shell.png is excluded by !**/*.png
  • assets/logos/png/svelte.png is excluded by !**/*.png
  • assets/logos/png/swift.png is excluded by !**/*.png
  • assets/logos/png/terraform.png is excluded by !**/*.png
  • assets/logos/png/typescript.png is excluded by !**/*.png
  • assets/logos/png/vue.png is excluded by !**/*.png
  • assets/logos/png/zig.png is excluded by !**/*.png
  • assets/logos/svg/_generic.svg is excluded by !**/*.svg
  • assets/logos/svg/c.svg is excluded by !**/*.svg
  • assets/logos/svg/clojure.svg is excluded by !**/*.svg
  • assets/logos/svg/cpp.svg is excluded by !**/*.svg
  • assets/logos/svg/csharp.svg is excluded by !**/*.svg
  • assets/logos/svg/css.svg is excluded by !**/*.svg
  • assets/logos/svg/dart.svg is excluded by !**/*.svg
  • assets/logos/svg/dockerfile.svg is excluded by !**/*.svg
  • assets/logos/svg/elixir.svg is excluded by !**/*.svg
  • assets/logos/svg/erlang.svg is excluded by !**/*.svg
  • assets/logos/svg/go.svg is excluded by !**/*.svg
  • assets/logos/svg/groovy.svg is excluded by !**/*.svg
  • assets/logos/svg/haskell.svg is excluded by !**/*.svg
  • assets/logos/svg/html.svg is excluded by !**/*.svg
  • assets/logos/svg/java.svg is excluded by !**/*.svg
  • assets/logos/svg/javascript.svg is excluded by !**/*.svg
  • assets/logos/svg/julia.svg is excluded by !**/*.svg
  • assets/logos/svg/kotlin.svg is excluded by !**/*.svg
  • assets/logos/svg/lua.svg is excluded by !**/*.svg
  • assets/logos/svg/nim.svg is excluded by !**/*.svg
  • assets/logos/svg/ocaml.svg is excluded by !**/*.svg
  • assets/logos/svg/perl.svg is excluded by !**/*.svg
  • assets/logos/svg/php.svg is excluded by !**/*.svg
  • assets/logos/svg/powershell.svg is excluded by !**/*.svg
  • assets/logos/svg/python.svg is excluded by !**/*.svg
  • assets/logos/svg/r.svg is excluded by !**/*.svg
  • assets/logos/svg/ruby.svg is excluded by !**/*.svg
  • assets/logos/svg/rust.svg is excluded by !**/*.svg
  • assets/logos/svg/scala.svg is excluded by !**/*.svg
  • assets/logos/svg/shell.svg is excluded by !**/*.svg
  • assets/logos/svg/svelte.svg is excluded by !**/*.svg
  • assets/logos/svg/swift.svg is excluded by !**/*.svg
  • assets/logos/svg/terraform.svg is excluded by !**/*.svg
  • assets/logos/svg/typescript.svg is excluded by !**/*.svg
  • assets/logos/svg/vue.svg is excluded by !**/*.svg
  • assets/logos/svg/zig.svg is excluded by !**/*.svg
📒 Files selected for processing (5)
  • assets/logos/LICENSE-devicon.txt
  • src/fetcher/code/language_logo.rs
  • src/fetcher/code/logo_assets.rs
  • src/fetcher/code/mod.rs
  • src/fetcher/code/scan.rs

Comment on lines +117 to +130
/// Materialises the bundled bytes onto disk so `media_image` (which only takes a path) can
/// open them. Stable per-slug filename under the cache dir means repeat invocations reuse the
/// same file and ratatui-image's protocol can warm-cache decoded frames.
fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> {
let dir = logos_cache_dir()?;
std::fs::create_dir_all(&dir)
.map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?;
let path = dir.join(format!("{slug}.png"));
if !path.exists() {
std::fs::write(&path, bytes)
.map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?;
}
Ok(path)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Stale-cache hazard across upgrades: path.exists() short-circuits even when bundled bytes change.

ensure_extracted only writes when the file is missing, so once a slug's PNG exists in $SPLASHBOARD_HOME/cache/logos/, the bundled-byte version is never picked up again. If a future release re-rasterizes the Devicon SVGs (or the image pipeline produces different PNG bytes), upgraded users will keep rendering the old logo until they manually wipe the cache. Worth invalidating on byte-length drift now while the surface is small.

🛡️ Proposed fix — invalidate when bundled length differs from cached length
 fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> {
     let dir = logos_cache_dir()?;
     std::fs::create_dir_all(&dir)
         .map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?;
     let path = dir.join(format!("{slug}.png"));
-    if !path.exists() {
+    let stale = std::fs::metadata(&path)
+        .map(|m| m.len() != bytes.len() as u64)
+        .unwrap_or(true);
+    if stale {
         std::fs::write(&path, bytes)
             .map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?;
     }
     Ok(path)
 }

Alternatively, embed a short content-hash in the on-disk filename (e.g., rust-<8hex>.png) so byte changes pick a fresh path and old files become harmless orphans — slightly more robust against same-length-but-different-bytes drift, at the cost of an extra hash on every fetch.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// Materialises the bundled bytes onto disk so `media_image` (which only takes a path) can
/// open them. Stable per-slug filename under the cache dir means repeat invocations reuse the
/// same file and ratatui-image's protocol can warm-cache decoded frames.
fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> {
let dir = logos_cache_dir()?;
std::fs::create_dir_all(&dir)
.map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?;
let path = dir.join(format!("{slug}.png"));
if !path.exists() {
std::fs::write(&path, bytes)
.map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?;
}
Ok(path)
}
/// Materialises the bundled bytes onto disk so `media_image` (which only takes a path) can
/// open them. Stable per-slug filename under the cache dir means repeat invocations reuse the
/// same file and ratatui-image's protocol can warm-cache decoded frames.
fn ensure_extracted(slug: &str, bytes: &[u8]) -> Result<PathBuf, FetchError> {
let dir = logos_cache_dir()?;
std::fs::create_dir_all(&dir)
.map_err(|e| FetchError::Failed(format!("create logos cache dir: {e}")))?;
let path = dir.join(format!("{slug}.png"));
let stale = std::fs::metadata(&path)
.map(|m| m.len() != bytes.len() as u64)
.unwrap_or(true);
if stale {
std::fs::write(&path, bytes)
.map_err(|e| FetchError::Failed(format!("write logo {slug}: {e}")))?;
}
Ok(path)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fetcher/code/language_logo.rs` around lines 117 - 130, ensure_extracted
currently skips writing when a file exists, causing stale cached PNGs to persist
across releases; update ensure_extracted to compare the existing file size to
bytes.len() (use std::fs::metadata(&path)?.len()) and if lengths differ,
overwrite the file (std::fs::write) so updated bundled bytes replace the cached
file, mapping any IO errors to FetchError::Failed as done now; keep the same
stable slug-based path logic (dir = logos_cache_dir(), path =
dir.join(format!("{slug}.png"))).

@unhappychoice
unhappychoice merged commit 67e8185 into main Apr 27, 2026
7 checks passed
@unhappychoice
unhappychoice deleted the feat/code-language-logo branch April 27, 2026 04:23
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.

1 participant