Gem-Colored Terminal Output
# Gem-Colored Terminal Output
**Archetype:** fid **Status:** gap **Description:** Render gem content with palette colors in gaze and other terminal output
---
## Vision
When Portal displays gem values in the terminal (gaze, search results, Thing inspection), use the gem swatch colors as background colors. This makes gem types instantly recognizable by color, not just name.
## Color Application
| Gem | Background | Foreground | ANSI | |-----|------------|------------|------| | onyx | `#1a1a1a` | white | `\x1b[48;2;26;26;26m\x1b[97m` | | sapphire | `#2563eb` | white | `\x1b[48;2;37;99;235m\x1b[97m` | | ruby | `#dc2626` | white | `\x1b[48;2;220;38;38m\x1b[97m` | | emerald | `#059669` | white | `\x1b[48;2;5;150;105m\x1b[97m` | | amethyst | `#7c3aed` | white | `\x1b[48;2;124;58;237m\x1b[97m` | | diamond | `#f8fafc` | black | `\x1b[48;2;248;250;252m\x1b[30m` | | pearl | `#fef3c7` | black | `\x1b[48;2;254;243;199m\x1b[30m` | | obsidian | `#0f0f0f` | white | `\x1b[48;2;15;15;15m\x1b[97m` | | topaz | `#f59e0b` | black | `\x1b[48;2;245;158;11m\x1b[30m` | | citrine | `#eab308` | black | `\x1b[48;2;234;179;8m\x1b[30m` |
Reset: `\x1b[0m`
## Implementation
### 1. Load Swatches at Startup
In `forge/gems.rs`, add swatch loading alongside gem definitions:
```rust static GEM_SWATCHES: OnceLock<HashMap<String, GemSwatch>> = OnceLock::new();
pub struct GemSwatch { pub hex: String, pub shape: String, pub ansi_bg: String, pub ansi_fg: String, }
pub async fn load_gem_swatches(pool: &PgPool) -> Result<(), String> { // Query Things where sapphire='swatch' and onyx starts with 'gem-' // Parse hex, determine fg (white for dark, black for light) // Build ANSI codes }
pub fn get_gem_color(gem_name: &str) -> Option<&'static GemSwatch> { GEM_SWATCHES.get().and_then(|s| s.get(&format!("gem-{}", gem_name))) } ```
### 2. Color Helper Function
```rust pub fn colorize_gem_name(gem_name: &str) -> String { if let Some(swatch) = get_gem_color(gem_name) { format!("{}{} {} {}\x1b[0m", swatch.ansi_bg, swatch.ansi_fg, gem_name, " " // padding ) } else { gem_name.to_string() } } ```
### 3. Apply in Commands
Update gaze output in `commands/mod.rs`:
```rust // Before: lines.push(format!(" {}: {}", gem_name, value));
// After: lines.push(format!(" {}: {}", colorize_gem_name(gem_name), value)); ```
### 4. Terminal Capability Check
Only use true color if terminal supports it:
```rust fn supports_true_color() -> bool { std::env::var("COLORTERM") .map(|v| v == "truecolor" || v == "24bit") .unwrap_or(false) } ```
Fallback to 256-color or basic ANSI if not supported.
## Affected Commands
- `/△ gem` - gaze by gem value - `/0 <thing>` - Thing inspection - `/xo search` - search results with gem highlights - `/1 1` - creation confirmation - Any output showing gem names or values
## Example Output
``` 💎 Things with sapphire=product
1. ceramic-vase-001 ████ onyx ████ ceramic-vase-001 ████ sapphire ████ product ████ ruby ████ {"price": 89.00} ████ pearl ████ Hand-thrown stoneware... ████ amethyst ████ ["ceramics", "handmade"] ```
## Gaps
- [ ] Add `load_gem_swatches()` to startup sequence - [ ] Create `colorize_gem_name()` helper - [ ] Update gaze output formatting - [ ] Update search result formatting - [ ] Add terminal capability detection - [ ] Test in various terminals (iTerm2, Terminal.app, VS Code)