# Microprints Compact visual representations of source code files. ## What is a microprint? A microprint is a compact visual fingerprint where each line of code becomes a colored stripe based on its syntax elements. The result is a small, informative visualization that shows the structure and composition of a file at a glance. ## Features - **Syntax-aware colorization** — Uses the Erlang/Elixir tokenizer for accurate token classification (functions, strings, comments, atoms, etc.) - **Multi-language support** — Works with Elixir, Erlang, and falls back to regex-based detection for other languages - **Indentation-aware** — Preserves indentation levels to show nesting structure - **SVG rendering** — Phoenix LiveView components for inline SVG visualization - **Caching** — ETS-based cache with automatic invalidation via PubSub - **Zero dependencies** — Core analysis has no external dependencies ## Installation Add to your `mix.exs`: ```elixir def deps do [ {:microprints, "~> 0.1"} ] end ``` ## Usage ### Generate a microprint ```elixir Microprints.generate("path/to/file.ex") # => {:ok, %{lines: [...], line_count: 42}} ``` ### Get color for a syntax type ```elixir Microprints.color_for(:function_def) # => "#EF4444" ``` ### Get the color legend ```elixir Microprints.color_legend() # => [{"Function", "#EF4444"}, {"Module", "#EC4899"}, ...] ``` ### Render in Phoenix LiveView ```elixir <%= live_component @live_view, MicroprintComponent, microprint: microprint, width: 200, max_height: 100, clickable: true, file_path: file_path %> ``` ### Cache with automatic invalidation ```elixir # Start the cache (usually in your dev tools supervision tree) MicroprintCache.start_link(pubsub: MyApp.PubSub) # Get or generate {:ok, microprint} = MicroprintCache.get_microprint("path/to/file.ex") ``` ## Color Legend | Syntax Element | Color | |----------------|-------| | Function def | 🔴 Red | | Module | 🩷 Pink | | Keyword | 🟣 Purple | | String | 🟢 Green | | Comment | ⚫ Gray | | Atom | 🟠 Amber | | Number | 🔵 Blue | | Other | ⚪ Light gray | ## Development ```bash cd microprints-git mix test ``` ## License MIT