astro-terminal-themes
Version:
Astro integration to convert terminal themes (Ghostty, Warp, etc.) to Tailwind CSS themes
295 lines (231 loc) • 6.55 kB
Markdown
Convert terminal theme configurations (Ghostty, Warp, iTerm2, etc.) into Tailwind CSS themes for your Astro website.
## Features
- 🎨 **Multiple Terminal Support**: Ghostty, Warp (more coming soon)
- 🔥 **Hot Reloading**: Automatically regenerate CSS when theme files change
- 🚀 **Tailwind 4 Ready**: Uses the new `@theme` directive syntax
- 🔧 **Modular Adapters**: Easy to extend with new terminal formats
- 📁 **Auto-Discovery**: Automatically finds themes in your themes directory
- 🎯 **Two Mapping Modes**: Direct ANSI colors or semantic color names
## Requirements
- **Node.js**: v22.0.0 or higher
- **Astro**: v5.0.0 or higher
## Installation
```bash
npm install astro-terminal-themes
```
## Setup
### 1. Add to Astro Config
```js
// astro.config.mjs
import { defineConfig } from 'astro/config';
import terminalThemes from 'astro-terminal-themes';
export default defineConfig({
integrations: [
terminalThemes({
themesDir: './themes', // Where your theme files are stored
outputFile: './src/styles/theme.css', // Generated CSS output
semanticMapping: false, // Use semantic names (primary, accent) vs direct (red, blue)
defaultTheme: 'my-theme' // Default theme name (optional)
})
]
});
```
```bash
mkdir themes
```
**Ghostty Theme** (`themes/my-theme.conf`):
```conf
palette = 0=
palette = 1=
palette = 2=
palette = 3=
palette = 4=
palette = 5=
palette = 6=
palette = 7=
palette = 8=
palette = 9=
palette = 10=
palette = 11=
palette = 12=
palette = 13=
palette = 14=
palette = 15=
background =
foreground =
cursor-color =
selection-background =
selection-foreground =
```
**Warp Theme** (`themes/my-theme.yaml`):
```yaml
name: Custom Theme
accent: '#268bd2'
cursor: '#95D886'
background: '#002b36'
foreground: '#839496'
details: darker
terminal_colors:
bright:
black: '#002b36'
blue: '#839496'
cyan: '#93a1a1'
green: '#586e75'
magenta: '#6c71c4'
red: '#cb4b16'
white: '#fdf6e3'
yellow: '#657b83'
normal:
black: '#073642'
blue: '#268bd2'
cyan: '#2aa198'
green: '#859900'
magenta: '#d33682'
red: '#dc322f'
white: '#eee8d5'
yellow: '#b58900'
```
Add the generated theme CSS to your main stylesheet:
```css
/* src/styles/global.css */
@import './theme.css';
@import 'tailwindcss';
```
Or import it in your Astro layout:
```astro
---
// src/layouts/Layout.astro
import '../styles/theme.css';
---
```
With `semanticMapping: false`, colors map directly to ANSI names:
```html
<div class="bg-background text-foreground">
<h1 class="text-red">Error Message</h1>
<p class="text-green">Success Message</p>
<button class="bg-blue text-white">Primary Button</button>
<div class="border-bright-black">Card with border</div>
</div>
```
Available colors:
- `background`, `foreground`
- `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
- `bright-black`, `bright-red`, `bright-green`, `bright-yellow`, `bright-blue`, `bright-magenta`, `bright-cyan`, `bright-white`
- `cursor`, `selection` (if defined in theme)
With `semanticMapping: true`, colors map to semantic UI names:
```html
<div class="bg-background text-foreground">
<h1 class="text-destructive">Error Message</h1>
<p class="text-success">Success Message</p>
<button class="bg-primary text-primary-foreground">Primary Button</button>
<div class="border-border">Card with border</div>
</div>
```
Available semantic colors:
- `background`, `foreground`
- `primary`, `secondary`, `accent`, `destructive`
- `muted`, `border`, `input`, `ring`
- `success`, `warning`, `info`
Set the `THEME` environment variable to choose a theme:
```bash
THEME=my-dark-theme npm run dev
```
Specify a default in your config:
```js
terminalThemes({
defaultTheme: 'my-theme' // Will use this if THEME env var not set
})
```
### Auto-Selection
If no theme is specified, the first theme found alphabetically will be used.
## Hot Reloading
During development (`astro dev`), the integration watches your themes directory for changes:
- **File modified**: Theme CSS regenerated
- **File added**: New theme becomes available
- **File deleted**: Theme CSS regenerated
## Extending with Custom Adapters
You can add support for additional terminal formats:
```js
// src/adapters/iterm-adapter.js
import { ThemeProcessor } from 'astro-terminal-themes';
class iTerm2Adapter {
name = 'iterm2';
extensions = ['.itermcolors'];
parse(content) {
// Parse iTunes plist format
// Return ThemeColors object
}
}
// In your astro config
const processor = new ThemeProcessor();
processor.registerAdapter(new iTerm2Adapter());
```
```typescript
interface TerminalThemeIntegrationOptions {
themesDir?: string; // Default: './themes'
outputFile?: string; // Default: './src/styles/theme.css'
defaultTheme?: string; // Default: first theme found
semanticMapping?: boolean; // Default: false
}
```
```typescript
interface ThemeColors {
background: string;
foreground: string;
cursor?: string;
selection?: {
background: string;
foreground?: string;
};
colors: {
black: string;
red: string;
green: string;
yellow: string;
blue: string;
magenta: string;
cyan: string;
white: string;
brightBlack: string;
brightRed: string;
brightGreen: string;
brightYellow: string;
brightBlue: string;
brightMagenta: string;
brightCyan: string;
brightWhite: string;
};
}
```
- **Ghostty** (`.conf`, `.config`) - Full support
- **Warp** (`.yaml`, `.yml`) - Full support
- **iTerm2** (`.itermcolors`)
- **VS Code** (`.json`)
- **Alacritty** (`.yml`, `.yaml`)
- **Kitty** (`.conf`)
Check out the `examples/` directory for complete Astro project setups using various terminal themes.
1. Fork the repository
2. Create a feature branch
3. Add your terminal adapter in `src/adapters/`
4. Add tests and examples
5. Submit a pull request
MIT