Skip to content

Add a self-contained theme editor example#146

Open
Azteriisk wants to merge 3 commits into
jdx:mainfrom
Azteriisk:theme-editor-example
Open

Add a self-contained theme editor example#146
Azteriisk wants to merge 3 commits into
jdx:mainfrom
Azteriisk:theme-editor-example

Conversation

@Azteriisk
Copy link
Copy Markdown

Summary

This adds a self-contained theme_editor example that uses demand to build an interactive theme editing workflow for demand itself.

The goal is to provide a practical showcase example that is also useful on its own for exploring and tuning theme values.

What changed

  • add examples/theme_editor.rs
  • add a palette-first editing flow with live preview
  • keep an advanced mode for direct field-level editing
  • support saving, updating, deleting, importing, and exporting custom themes
  • add a short README entry for running the example

Why this is isolated

This PR does not change the library API or core prompt behavior.

All of the functionality lives in an example, so the review surface is limited to:

  • example code
  • a small README entry

That makes it easier to evaluate as an additive showcase without taking on risk in the main library.

Why this example is useful

It demonstrates a more realistic demand application than the smaller examples by combining:

  • menus and selections
  • input validation
  • persistence
  • live preview
  • theming
  • multi-step terminal workflows

It also gives users a concrete way to understand how the built-in theme fields affect real UI output.

Validation

  • cargo check --example theme_editor

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the README.md file to include a new section for the 'Theme Editor Example', providing instructions on how to run it using Cargo. I have no feedback to provide.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 27, 2026

Greptile Summary

This PR adds a self-contained examples/theme_editor.rs (~3000 lines) implementing an interactive palette-first theme editor for demand itself, along with a brief README entry. The example covers palette editing with live preview, a color picker, persistence via a custom text format, import/export, and an advanced field-level editing hub — a realistic multi-step demand showcase that does not touch the library API.

The code is well-structured and the previously flagged issues (breadcrumb separator width measurement, preview_palette stderr routing, non-exhaustive Color fallback comment) have all been addressed in follow-up commits.

One remaining issue was identified:

  • select_theme_from_simple silently drops the active theme selection — when the user presses t to switch themes in the simple editor, store.active_theme is updated in memory but store.save() is never called. Because the new PaletteEditorState sets dirty = false, the quit guard produces no warning, and the selection is silently reverted to the previous theme on next launch. Every other write path that changes active_theme (delete_theme_from_simple, the advanced hub's select_active_theme) correctly calls store.save(), making this an inconsistency that causes silent data loss.

Confidence Score: 4/5

Safe to merge after fixing the one P1 active-theme persistence bug in select_theme_from_simple.

Three previously flagged P1s have been addressed. One new P1 remains: select_theme_from_simple updates store.active_theme in memory but never calls store.save(), causing the theme switch to be silently lost on quit. All other paths that write active_theme call store.save(), making this a clear inconsistency. A one-line fix is available. No other blocking issues found.

examples/theme_editor.rs — specifically the select_theme_from_simple function around line 468.

Important Files Changed

Filename Overview
examples/theme_editor.rs New 3000-line self-contained theme editor example; well-structured overall but select_theme_from_simple silently drops the active theme selection on quit because it never calls store.save().
README.md Adds three-line section pointing users to cargo run --example theme_editor; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([run]) --> B[ThemeStore::load]
    B --> C[run_simple_editor\nPaletteEditorState]

    C --> |"e / enter"| D[edit_palette_slot\npick_color_with_picker]
    C --> |"s"| E[save_palette_state\nstore.save ✓]
    C --> |"t"| F[select_theme_from_simple\nstore.active_theme updated\nstore.save ✗ BUG]
    C --> |"n"| G[create_theme_from_simple\nstate.dirty = true]
    C --> |"d"| H[delete_theme_from_simple\nstore.save ✓]
    C --> |"a"| I[run_advanced_hub]
    C --> |"p"| J[preview_palette\nterm.stderr]
    C --> |"v"| K[run_live_demo\nreal demand widgets]
    C --> |"q / esc"| L{confirm_discard_if_dirty?}
    L --> |dirty=false| M([exit])
    L --> |dirty=true| N[Confirm discard]
    N --> M

    I --> |"Select active theme"| O[select_active_theme\nstore.save ✓]
    I --> |"Create new"| P[create_theme → edit_theme_loop\nstore.save ✓]
    I --> |"Edit custom"| Q[edit_custom_theme\nstore.save ✓]
    I --> |"Delete"| R[delete_custom_theme\nstore.save ✓]
    I --> |"Export"| S[export_active_theme\nfs::write]
    I --> |"Import"| T[import_theme\nstore.save ✓]

    style F fill:#f99,stroke:#c00
Loading

Reviews (3): Last reviewed commit: "Fix preview border width calculation" | Re-trigger Greptile

Comment thread examples/theme_editor.rs Outdated
Comment thread examples/theme_editor.rs Outdated
Comment thread examples/theme_editor.rs
@roele
Copy link
Copy Markdown
Collaborator

roele commented Mar 28, 2026

Amazing example! Thanks for your contribution.

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.

2 participants