mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
feature/custom terminal configs (#717)
* feat(terminal): Add core infrastructure for custom terminal configurations - Add TerminalConfig types to settings schema (global & project-specific) - Create RC generator with hex-to-xterm-256 color mapping - Create RC file manager for .automaker/terminal/ directory - Add terminal theme color data (40 themes) to platform package - Integrate terminal config injection into TerminalService - Support bash, zsh, and sh with proper env var injection (BASH_ENV, ZDOTDIR, ENV) - Add onThemeChange hook for theme synchronization Part of custom terminal configurations feature implementation. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * feat(terminal): Wire terminal service with settings service - Pass SettingsService to TerminalService constructor - Initialize terminal service with settings service dependency - Enable terminal config injection to work with actual settings This completes Steps 1-4 of the terminal configuration plan: - RC Generator (color mapping, prompt formats) - RC File Manager (file I/O, atomic writes) - Settings Schema (GlobalSettings + ProjectSettings) - Terminal Service Integration (env var injection) Next steps: Settings UI and theme change hooks. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * feat(terminal): Add Settings UI and theme change synchronization Complete Steps 5 & 6 of terminal configuration implementation: Settings UI Components: - Add PromptPreview component with live theme-aware rendering - Add TerminalConfigSection with comprehensive controls: * Enable/disable toggle with confirmation dialog * Custom prompt toggle * Prompt format selector (4 formats) * Git branch/status toggles * Custom aliases textarea * Custom env vars key-value editor with validation * Info box explaining behavior - Integrate into existing TerminalSection Theme Change Hook: - Add theme detection in update-global settings route - Regenerate RC files for all projects when theme changes - Skip projects with terminal config disabled - Error handling with per-project logging - Inject terminal service with settings service dependency This completes the full terminal configuration feature: ✓ RC Generator (color mapping, prompts) ✓ RC File Manager (file I/O, versioning) ✓ Settings Schema (types, defaults) ✓ Terminal Service Integration (env vars, PTY spawn) ✓ Settings UI (comprehensive controls, preview) ✓ Theme Synchronization (automatic RC regeneration) New terminals will use custom prompts matching app theme. Existing terminals unaffected. User RC files preserved. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix(terminal): Add error handling and explicit field mapping for terminal config - Add try-catch block to handleToggleEnabled - Explicitly set all required terminalConfig fields - Add console logging for debugging - Show error toast if update fails - Include rcFileVersion: 1 in config object This should fix the issue where the toggle doesn't enable after clicking OK in the confirmation dialog. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix(terminal): Use React Query mutation hook for settings updates The issue was that `updateGlobalSettings` doesn't exist in the app store. The correct pattern is to use the `useUpdateGlobalSettings` hook from use-settings-mutations.ts, which is a React Query mutation. Changes: - Import useUpdateGlobalSettings from mutations hook - Use mutation.mutate() instead of direct function call - Add proper onSuccess/onError callbacks - Remove async/await pattern (React Query handles this) This fixes the toggle not enabling after clicking OK in the confirmation dialog. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * fix(terminal): Use React Query hook for globalSettings instead of store The root cause: Component was reading globalSettings from the app store, which doesn't update reactively when the mutation completes. Solution: Use useGlobalSettings() React Query hook which: - Automatically refetches when the mutation invalidates the cache - Triggers re-render with updated data - Makes the toggle reflect the new state Now the flow is: 1. User clicks toggle → confirmation dialog 2. Click OK → mutation.mutate() called 3. Mutation succeeds → invalidates queryKeys.settings.global() 4. Query refetches → component re-renders with new globalSettings 5. Toggle shows enabled state ✓ Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * debug(terminal): Add detailed logging for terminal config application Add logging to track: - When terminal config check happens - CWD being used - Global and project enabled states - Effective enabled state This will help diagnose why RC files aren't being generated when opening terminals in Automaker. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Fix terminal rc updates and bash rcfile loading * feat(terminal): add banner on shell start * feat(terminal): colorize banner per theme * chore(terminal): bump rc version for banner colors * feat(terminal): match banner colors to launcher * feat(terminal): add prompt customization controls * feat: integrate oh-my-posh prompt themes * fix: resolve oh-my-posh theme path * fix: correct oh-my-posh config invocation * docs: add terminal theme screenshot * fix: address review feedback and stabilize e2e test * ui: split terminal config into separate card * fix: enable cross-platform Warp terminal detection - Remove macOS-only platform restriction for Warp - Add Linux CLI alias 'warp-terminal' (primary on Linux) - Add CLI launch handler using --cwd flag - Fixes issue where Warp was not detected on Linux systems Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -186,3 +186,37 @@ export {
|
||||
findTerminalById,
|
||||
openInExternalTerminal,
|
||||
} from './terminal.js';
|
||||
|
||||
// RC Generator - Shell configuration file generation
|
||||
export {
|
||||
hexToXterm256,
|
||||
getThemeANSIColors,
|
||||
generateBashrc,
|
||||
generateZshrc,
|
||||
generateCommonFunctions,
|
||||
generateThemeColors,
|
||||
getShellName,
|
||||
type TerminalConfig,
|
||||
type TerminalTheme,
|
||||
type ANSIColors,
|
||||
} from './rc-generator.js';
|
||||
|
||||
// RC File Manager - Shell configuration file I/O
|
||||
export {
|
||||
RC_FILE_VERSION,
|
||||
getTerminalDir,
|
||||
getThemesDir,
|
||||
getRcFilePath,
|
||||
ensureTerminalDir,
|
||||
checkRcFileVersion,
|
||||
needsRegeneration,
|
||||
writeAllThemeFiles,
|
||||
writeThemeFile,
|
||||
writeRcFiles,
|
||||
ensureRcFilesUpToDate,
|
||||
deleteTerminalDir,
|
||||
ensureUserCustomFile,
|
||||
} from './rc-file-manager.js';
|
||||
|
||||
// Terminal Theme Colors - Raw theme color data for all 40 themes
|
||||
export { terminalThemeColors, getTerminalThemeColors } from './terminal-theme-colors.js';
|
||||
|
||||
308
libs/platform/src/rc-file-manager.ts
Normal file
308
libs/platform/src/rc-file-manager.ts
Normal file
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* RC File Manager - Manage shell configuration files in .automaker/terminal/
|
||||
*
|
||||
* This module handles file I/O operations for generating and managing shell RC files,
|
||||
* including version checking and regeneration logic.
|
||||
*/
|
||||
|
||||
import * as fs from 'node:fs/promises';
|
||||
import * as path from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
import type { ThemeMode } from '@automaker/types';
|
||||
import {
|
||||
generateBashrc,
|
||||
generateZshrc,
|
||||
generateCommonFunctions,
|
||||
generateThemeColors,
|
||||
type TerminalConfig,
|
||||
type TerminalTheme,
|
||||
} from './rc-generator.js';
|
||||
|
||||
/**
|
||||
* Current RC file format version
|
||||
*/
|
||||
export const RC_FILE_VERSION = 11;
|
||||
|
||||
const RC_SIGNATURE_FILENAME = 'config.sha256';
|
||||
|
||||
/**
|
||||
* Get the terminal directory path
|
||||
*/
|
||||
export function getTerminalDir(projectPath: string): string {
|
||||
return path.join(projectPath, '.automaker', 'terminal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the themes directory path
|
||||
*/
|
||||
export function getThemesDir(projectPath: string): string {
|
||||
return path.join(getTerminalDir(projectPath), 'themes');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RC file path for specific shell
|
||||
*/
|
||||
export function getRcFilePath(projectPath: string, shell: 'bash' | 'zsh' | 'sh'): string {
|
||||
const terminalDir = getTerminalDir(projectPath);
|
||||
switch (shell) {
|
||||
case 'bash':
|
||||
return path.join(terminalDir, 'bashrc.sh');
|
||||
case 'zsh':
|
||||
return path.join(terminalDir, '.zshrc'); // Zsh looks for .zshrc in ZDOTDIR
|
||||
case 'sh':
|
||||
return path.join(terminalDir, 'common.sh');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure terminal directory exists
|
||||
*/
|
||||
export async function ensureTerminalDir(projectPath: string): Promise<void> {
|
||||
const terminalDir = getTerminalDir(projectPath);
|
||||
const themesDir = getThemesDir(projectPath);
|
||||
|
||||
await fs.mkdir(terminalDir, { recursive: true, mode: 0o755 });
|
||||
await fs.mkdir(themesDir, { recursive: true, mode: 0o755 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Write RC file with atomic write (write to temp, then rename)
|
||||
*/
|
||||
async function atomicWriteFile(
|
||||
filePath: string,
|
||||
content: string,
|
||||
mode: number = 0o644
|
||||
): Promise<void> {
|
||||
const tempPath = `${filePath}.tmp`;
|
||||
await fs.writeFile(tempPath, content, { encoding: 'utf8', mode });
|
||||
await fs.rename(tempPath, filePath);
|
||||
}
|
||||
|
||||
function sortObjectKeys(value: unknown): unknown {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => sortObjectKeys(item));
|
||||
}
|
||||
|
||||
if (value && typeof value === 'object') {
|
||||
const sortedEntries = Object.entries(value as Record<string, unknown>)
|
||||
.filter(([, entryValue]) => entryValue !== undefined)
|
||||
.sort(([left], [right]) => left.localeCompare(right));
|
||||
|
||||
const sortedObject: Record<string, unknown> = {};
|
||||
for (const [key, entryValue] of sortedEntries) {
|
||||
sortedObject[key] = sortObjectKeys(entryValue);
|
||||
}
|
||||
return sortedObject;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function buildConfigSignature(theme: ThemeMode, config: TerminalConfig): string {
|
||||
const payload = { theme, config: sortObjectKeys(config) };
|
||||
const serializedPayload = JSON.stringify(payload);
|
||||
return createHash('sha256').update(serializedPayload).digest('hex');
|
||||
}
|
||||
|
||||
async function readSignatureFile(projectPath: string): Promise<string | null> {
|
||||
const signaturePath = path.join(getTerminalDir(projectPath), RC_SIGNATURE_FILENAME);
|
||||
try {
|
||||
const signature = await fs.readFile(signaturePath, 'utf8');
|
||||
return signature.trim() || null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function writeSignatureFile(projectPath: string, signature: string): Promise<void> {
|
||||
const signaturePath = path.join(getTerminalDir(projectPath), RC_SIGNATURE_FILENAME);
|
||||
await atomicWriteFile(signaturePath, `${signature}\n`, 0o644);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check current RC file version
|
||||
*/
|
||||
export async function checkRcFileVersion(projectPath: string): Promise<number | null> {
|
||||
const versionPath = path.join(getTerminalDir(projectPath), 'version.txt');
|
||||
try {
|
||||
const content = await fs.readFile(versionPath, 'utf8');
|
||||
const version = parseInt(content.trim(), 10);
|
||||
return isNaN(version) ? null : version;
|
||||
} catch (error) {
|
||||
return null; // File doesn't exist or can't be read
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write version file
|
||||
*/
|
||||
async function writeVersionFile(projectPath: string, version: number): Promise<void> {
|
||||
const versionPath = path.join(getTerminalDir(projectPath), 'version.txt');
|
||||
await atomicWriteFile(versionPath, `${version}\n`, 0o644);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if RC files need regeneration
|
||||
*/
|
||||
export async function needsRegeneration(
|
||||
projectPath: string,
|
||||
theme: ThemeMode,
|
||||
config: TerminalConfig
|
||||
): Promise<boolean> {
|
||||
const currentVersion = await checkRcFileVersion(projectPath);
|
||||
|
||||
// Regenerate if version doesn't match or files don't exist
|
||||
if (currentVersion !== RC_FILE_VERSION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const expectedSignature = buildConfigSignature(theme, config);
|
||||
const existingSignature = await readSignatureFile(projectPath);
|
||||
if (!existingSignature || existingSignature !== expectedSignature) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if critical files exist
|
||||
const bashrcPath = getRcFilePath(projectPath, 'bash');
|
||||
const zshrcPath = getRcFilePath(projectPath, 'zsh');
|
||||
const commonPath = path.join(getTerminalDir(projectPath), 'common.sh');
|
||||
const themeFilePath = path.join(getThemesDir(projectPath), `${theme}.sh`);
|
||||
|
||||
try {
|
||||
await Promise.all([
|
||||
fs.access(bashrcPath),
|
||||
fs.access(zshrcPath),
|
||||
fs.access(commonPath),
|
||||
fs.access(themeFilePath),
|
||||
]);
|
||||
return false; // All files exist
|
||||
} catch {
|
||||
return true; // Some files are missing
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write all theme color files (all 40 themes)
|
||||
*/
|
||||
export async function writeAllThemeFiles(
|
||||
projectPath: string,
|
||||
terminalThemes: Record<ThemeMode, TerminalTheme>
|
||||
): Promise<void> {
|
||||
const themesDir = getThemesDir(projectPath);
|
||||
await fs.mkdir(themesDir, { recursive: true, mode: 0o755 });
|
||||
|
||||
const themeEntries = Object.entries(terminalThemes);
|
||||
await Promise.all(
|
||||
themeEntries.map(async ([themeName, theme]) => {
|
||||
const themeFilePath = path.join(themesDir, `${themeName}.sh`);
|
||||
const content = generateThemeColors(theme);
|
||||
await atomicWriteFile(themeFilePath, content, 0o644);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a single theme color file
|
||||
*/
|
||||
export async function writeThemeFile(
|
||||
projectPath: string,
|
||||
theme: ThemeMode,
|
||||
themeColors: TerminalTheme
|
||||
): Promise<void> {
|
||||
const themesDir = getThemesDir(projectPath);
|
||||
await fs.mkdir(themesDir, { recursive: true, mode: 0o755 });
|
||||
|
||||
const themeFilePath = path.join(themesDir, `${theme}.sh`);
|
||||
const content = generateThemeColors(themeColors);
|
||||
await atomicWriteFile(themeFilePath, content, 0o644);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write all RC files
|
||||
*/
|
||||
export async function writeRcFiles(
|
||||
projectPath: string,
|
||||
theme: ThemeMode,
|
||||
config: TerminalConfig,
|
||||
themeColors: TerminalTheme,
|
||||
allThemes: Record<ThemeMode, TerminalTheme>
|
||||
): Promise<void> {
|
||||
await ensureTerminalDir(projectPath);
|
||||
|
||||
// Write common functions file
|
||||
const commonPath = path.join(getTerminalDir(projectPath), 'common.sh');
|
||||
const commonContent = generateCommonFunctions(config);
|
||||
await atomicWriteFile(commonPath, commonContent, 0o644);
|
||||
|
||||
// Write bashrc
|
||||
const bashrcPath = getRcFilePath(projectPath, 'bash');
|
||||
const bashrcContent = generateBashrc(themeColors, config);
|
||||
await atomicWriteFile(bashrcPath, bashrcContent, 0o644);
|
||||
|
||||
// Write zshrc
|
||||
const zshrcPath = getRcFilePath(projectPath, 'zsh');
|
||||
const zshrcContent = generateZshrc(themeColors, config);
|
||||
await atomicWriteFile(zshrcPath, zshrcContent, 0o644);
|
||||
|
||||
// Write all theme files (40 themes)
|
||||
await writeAllThemeFiles(projectPath, allThemes);
|
||||
|
||||
// Write version file
|
||||
await writeVersionFile(projectPath, RC_FILE_VERSION);
|
||||
|
||||
// Write config signature for change detection
|
||||
const signature = buildConfigSignature(theme, config);
|
||||
await writeSignatureFile(projectPath, signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure RC files are up to date
|
||||
*/
|
||||
export async function ensureRcFilesUpToDate(
|
||||
projectPath: string,
|
||||
theme: ThemeMode,
|
||||
config: TerminalConfig,
|
||||
themeColors: TerminalTheme,
|
||||
allThemes: Record<ThemeMode, TerminalTheme>
|
||||
): Promise<void> {
|
||||
const needsRegen = await needsRegeneration(projectPath, theme, config);
|
||||
if (needsRegen) {
|
||||
await writeRcFiles(projectPath, theme, config, themeColors, allThemes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete terminal directory (for disable flow)
|
||||
*/
|
||||
export async function deleteTerminalDir(projectPath: string): Promise<void> {
|
||||
const terminalDir = getTerminalDir(projectPath);
|
||||
try {
|
||||
await fs.rm(terminalDir, { recursive: true, force: true });
|
||||
} catch (error) {
|
||||
// Ignore errors if directory doesn't exist
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user-custom.sh placeholder if it doesn't exist
|
||||
*/
|
||||
export async function ensureUserCustomFile(projectPath: string): Promise<void> {
|
||||
const userCustomPath = path.join(getTerminalDir(projectPath), 'user-custom.sh');
|
||||
try {
|
||||
await fs.access(userCustomPath);
|
||||
} catch {
|
||||
// File doesn't exist, create it
|
||||
const content = `#!/bin/sh
|
||||
# Automaker User Customizations
|
||||
# Add your custom shell configuration here
|
||||
# This file will not be overwritten by Automaker
|
||||
|
||||
# Example: Add custom aliases
|
||||
# alias myalias='command'
|
||||
|
||||
# Example: Add custom environment variables
|
||||
# export MY_VAR="value"
|
||||
`;
|
||||
await atomicWriteFile(userCustomPath, content, 0o644);
|
||||
}
|
||||
}
|
||||
972
libs/platform/src/rc-generator.ts
Normal file
972
libs/platform/src/rc-generator.ts
Normal file
@@ -0,0 +1,972 @@
|
||||
/**
|
||||
* RC Generator - Generate shell configuration files for custom terminal prompts
|
||||
*
|
||||
* This module generates bash/zsh/sh configuration files that sync with Automaker's themes,
|
||||
* providing custom prompts with theme-matched colors while preserving user's existing RC files.
|
||||
*/
|
||||
|
||||
import type { ThemeMode } from '@automaker/types';
|
||||
|
||||
/**
|
||||
* Terminal configuration options
|
||||
*/
|
||||
export interface TerminalConfig {
|
||||
enabled: boolean;
|
||||
customPrompt: boolean;
|
||||
promptFormat: 'standard' | 'minimal' | 'powerline' | 'starship';
|
||||
showGitBranch: boolean;
|
||||
showGitStatus: boolean;
|
||||
showUserHost: boolean;
|
||||
showPath: boolean;
|
||||
pathStyle: 'full' | 'short' | 'basename';
|
||||
pathDepth: number;
|
||||
showTime: boolean;
|
||||
showExitStatus: boolean;
|
||||
customAliases: string;
|
||||
customEnvVars: Record<string, string>;
|
||||
rcFileVersion?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminal theme colors (hex values)
|
||||
*/
|
||||
export interface TerminalTheme {
|
||||
background: string;
|
||||
foreground: string;
|
||||
cursor: string;
|
||||
cursorAccent: string;
|
||||
selectionBackground: string;
|
||||
selectionForeground?: string;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* ANSI color codes for shell prompts
|
||||
*/
|
||||
export interface ANSIColors {
|
||||
user: string;
|
||||
host: string;
|
||||
path: string;
|
||||
gitBranch: string;
|
||||
gitDirty: string;
|
||||
prompt: string;
|
||||
reset: string;
|
||||
}
|
||||
|
||||
const STARTUP_COLOR_PRIMARY = 51;
|
||||
const STARTUP_COLOR_SECONDARY = 39;
|
||||
const STARTUP_COLOR_ACCENT = 33;
|
||||
const DEFAULT_PATH_DEPTH = 0;
|
||||
const DEFAULT_PATH_STYLE: TerminalConfig['pathStyle'] = 'full';
|
||||
const OMP_THEME_ENV_VAR = 'AUTOMAKER_OMP_THEME';
|
||||
const OMP_BINARY = 'oh-my-posh';
|
||||
const OMP_SHELL_BASH = 'bash';
|
||||
const OMP_SHELL_ZSH = 'zsh';
|
||||
|
||||
/**
|
||||
* Convert hex color to RGB
|
||||
*/
|
||||
function hexToRgb(hex: string): { r: number; g: number; b: number } {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
if (!result) {
|
||||
throw new Error(`Invalid hex color: ${hex}`);
|
||||
}
|
||||
return {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Euclidean distance between two RGB colors
|
||||
*/
|
||||
function colorDistance(
|
||||
c1: { r: number; g: number; b: number },
|
||||
c2: { r: number; g: number; b: number }
|
||||
): number {
|
||||
return Math.sqrt(Math.pow(c1.r - c2.r, 2) + Math.pow(c1.g - c2.g, 2) + Math.pow(c1.b - c2.b, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* xterm-256 color palette (simplified - standard colors + 6x6x6 RGB cube + grayscale)
|
||||
*/
|
||||
const XTERM_256_PALETTE: Array<{ r: number; g: number; b: number }> = [];
|
||||
|
||||
// Standard colors (0-15) - already handled by ANSI basic colors
|
||||
// RGB cube (16-231): 6x6x6 cube with levels 0, 95, 135, 175, 215, 255
|
||||
const levels = [0, 95, 135, 175, 215, 255];
|
||||
for (let r = 0; r < 6; r++) {
|
||||
for (let g = 0; g < 6; g++) {
|
||||
for (let b = 0; b < 6; b++) {
|
||||
XTERM_256_PALETTE.push({ r: levels[r], g: levels[g], b: levels[b] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Grayscale (232-255): 24 shades from #080808 to #eeeeee
|
||||
for (let i = 0; i < 24; i++) {
|
||||
const gray = 8 + i * 10;
|
||||
XTERM_256_PALETTE.push({ r: gray, g: gray, b: gray });
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert hex color to closest xterm-256 color code
|
||||
*/
|
||||
export function hexToXterm256(hex: string): number {
|
||||
const rgb = hexToRgb(hex);
|
||||
let closestIndex = 16; // Start from RGB cube
|
||||
let minDistance = Infinity;
|
||||
|
||||
XTERM_256_PALETTE.forEach((color, index) => {
|
||||
const distance = colorDistance(rgb, color);
|
||||
if (distance < minDistance) {
|
||||
minDistance = distance;
|
||||
closestIndex = index + 16; // Offset by 16 (standard colors)
|
||||
}
|
||||
});
|
||||
|
||||
return closestIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ANSI color codes from theme colors
|
||||
*/
|
||||
export function getThemeANSIColors(theme: TerminalTheme): ANSIColors {
|
||||
return {
|
||||
user: `\\[\\e[38;5;${hexToXterm256(theme.cyan)}m\\]`,
|
||||
host: `\\[\\e[38;5;${hexToXterm256(theme.blue)}m\\]`,
|
||||
path: `\\[\\e[38;5;${hexToXterm256(theme.yellow)}m\\]`,
|
||||
gitBranch: `\\[\\e[38;5;${hexToXterm256(theme.magenta)}m\\]`,
|
||||
gitDirty: `\\[\\e[38;5;${hexToXterm256(theme.red)}m\\]`,
|
||||
prompt: `\\[\\e[38;5;${hexToXterm256(theme.green)}m\\]`,
|
||||
reset: '\\[\\e[0m\\]',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape shell special characters in user input
|
||||
*/
|
||||
function shellEscape(str: string): string {
|
||||
return str.replace(/([`$\\"])/g, '\\$1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate environment variable name
|
||||
*/
|
||||
function isValidEnvVarName(name: string): boolean {
|
||||
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name);
|
||||
}
|
||||
|
||||
function stripPromptEscapes(ansiColor: string): string {
|
||||
return ansiColor.replace(/\\\[/g, '').replace(/\\\]/g, '');
|
||||
}
|
||||
|
||||
function normalizePathStyle(
|
||||
pathStyle: TerminalConfig['pathStyle'] | undefined
|
||||
): TerminalConfig['pathStyle'] {
|
||||
if (pathStyle === 'short' || pathStyle === 'basename') {
|
||||
return pathStyle;
|
||||
}
|
||||
return DEFAULT_PATH_STYLE;
|
||||
}
|
||||
|
||||
function normalizePathDepth(pathDepth: number | undefined): number {
|
||||
const depth =
|
||||
typeof pathDepth === 'number' && Number.isFinite(pathDepth) ? pathDepth : DEFAULT_PATH_DEPTH;
|
||||
return Math.max(DEFAULT_PATH_DEPTH, Math.floor(depth));
|
||||
}
|
||||
|
||||
function generateOhMyPoshInit(
|
||||
shell: typeof OMP_SHELL_BASH | typeof OMP_SHELL_ZSH,
|
||||
fallback: string
|
||||
) {
|
||||
const themeVar = `$${OMP_THEME_ENV_VAR}`;
|
||||
const initCommand = `${OMP_BINARY} init ${shell} --config`;
|
||||
return `if [ -n "${themeVar}" ] && command -v ${OMP_BINARY} >/dev/null 2>&1; then
|
||||
automaker_omp_theme="$(automaker_resolve_omp_theme)"
|
||||
if [ -n "$automaker_omp_theme" ]; then
|
||||
eval "$(${initCommand} "$automaker_omp_theme")"
|
||||
else
|
||||
${fallback}
|
||||
fi
|
||||
else
|
||||
${fallback}
|
||||
fi`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate common shell functions (git prompt, etc.)
|
||||
*/
|
||||
export function generateCommonFunctions(config: TerminalConfig): string {
|
||||
const gitPrompt = config.showGitBranch
|
||||
? `
|
||||
automaker_git_prompt() {
|
||||
local branch=""
|
||||
local dirty=""
|
||||
|
||||
# Check if we're in a git repository
|
||||
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||
# Get current branch name
|
||||
branch=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)
|
||||
|
||||
${
|
||||
config.showGitStatus
|
||||
? `
|
||||
# Check if working directory is dirty
|
||||
if [ -n "$(git status --porcelain 2>/dev/null)" ]; then
|
||||
dirty="*"
|
||||
fi
|
||||
`
|
||||
: ''
|
||||
}
|
||||
|
||||
if [ -n "$branch" ]; then
|
||||
echo -n " ($branch$dirty)"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
`
|
||||
: `
|
||||
automaker_git_prompt() {
|
||||
# Git prompt disabled
|
||||
echo -n ""
|
||||
}
|
||||
`;
|
||||
|
||||
return `#!/bin/sh
|
||||
# Automaker Terminal Configuration - Common Functions v1.0
|
||||
|
||||
${gitPrompt}
|
||||
|
||||
AUTOMAKER_INFO_UNKNOWN="Unknown"
|
||||
AUTOMAKER_BANNER_LABEL_WIDTH=12
|
||||
AUTOMAKER_BYTES_PER_KIB=1024
|
||||
AUTOMAKER_KIB_PER_MIB=1024
|
||||
AUTOMAKER_MIB_PER_GIB=1024
|
||||
AUTOMAKER_COLOR_PRIMARY="\\033[38;5;${STARTUP_COLOR_PRIMARY}m"
|
||||
AUTOMAKER_COLOR_SECONDARY="\\033[38;5;${STARTUP_COLOR_SECONDARY}m"
|
||||
AUTOMAKER_COLOR_ACCENT="\\033[38;5;${STARTUP_COLOR_ACCENT}m"
|
||||
AUTOMAKER_COLOR_RESET="\\033[0m"
|
||||
AUTOMAKER_SHOW_TIME="${config.showTime === true ? 'true' : 'false'}"
|
||||
AUTOMAKER_SHOW_EXIT_STATUS="${config.showExitStatus === true ? 'true' : 'false'}"
|
||||
AUTOMAKER_SHOW_USER_HOST="${config.showUserHost === false ? 'false' : 'true'}"
|
||||
AUTOMAKER_SHOW_PATH="${config.showPath === false ? 'false' : 'true'}"
|
||||
AUTOMAKER_PATH_STYLE="${normalizePathStyle(config.pathStyle)}"
|
||||
AUTOMAKER_PATH_DEPTH=${normalizePathDepth(config.pathDepth)}
|
||||
automaker_default_themes_dir="\${XDG_DATA_HOME:-\$HOME/.local/share}/oh-my-posh/themes"
|
||||
if [ -z "$POSH_THEMES_PATH" ] || [ ! -d "$POSH_THEMES_PATH" ]; then
|
||||
POSH_THEMES_PATH="$automaker_default_themes_dir"
|
||||
fi
|
||||
export POSH_THEMES_PATH
|
||||
|
||||
automaker_resolve_omp_theme() {
|
||||
automaker_theme_name="$AUTOMAKER_OMP_THEME"
|
||||
if [ -z "$automaker_theme_name" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -f "$automaker_theme_name" ]; then
|
||||
printf '%s' "$automaker_theme_name"
|
||||
return 0
|
||||
fi
|
||||
|
||||
automaker_themes_base="\${POSH_THEMES_PATH%/}"
|
||||
if [ -n "$automaker_themes_base" ]; then
|
||||
if [ -f "$automaker_themes_base/$automaker_theme_name.omp.json" ]; then
|
||||
printf '%s' "$automaker_themes_base/$automaker_theme_name.omp.json"
|
||||
return 0
|
||||
fi
|
||||
if [ -f "$automaker_themes_base/$automaker_theme_name.omp.yaml" ]; then
|
||||
printf '%s' "$automaker_themes_base/$automaker_theme_name.omp.yaml"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
automaker_command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
automaker_get_os() {
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
if [ -n "$PRETTY_NAME" ]; then
|
||||
echo "$PRETTY_NAME"
|
||||
return
|
||||
fi
|
||||
if [ -n "$NAME" ] && [ -n "$VERSION" ]; then
|
||||
echo "$NAME $VERSION"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if automaker_command_exists sw_vers; then
|
||||
echo "$(sw_vers -productName) $(sw_vers -productVersion)"
|
||||
return
|
||||
fi
|
||||
|
||||
uname -s 2>/dev/null || echo "$AUTOMAKER_INFO_UNKNOWN"
|
||||
}
|
||||
|
||||
automaker_get_uptime() {
|
||||
if automaker_command_exists uptime; then
|
||||
if uptime -p >/dev/null 2>&1; then
|
||||
uptime -p
|
||||
return
|
||||
fi
|
||||
uptime 2>/dev/null | sed 's/.*up \\([^,]*\\).*/\\1/' || uptime 2>/dev/null
|
||||
return
|
||||
fi
|
||||
|
||||
echo "$AUTOMAKER_INFO_UNKNOWN"
|
||||
}
|
||||
|
||||
automaker_get_cpu() {
|
||||
if automaker_command_exists lscpu; then
|
||||
lscpu | sed -n 's/Model name:[[:space:]]*//p' | head -n 1
|
||||
return
|
||||
fi
|
||||
|
||||
if automaker_command_exists sysctl; then
|
||||
sysctl -n machdep.cpu.brand_string 2>/dev/null || sysctl -n hw.model 2>/dev/null
|
||||
return
|
||||
fi
|
||||
|
||||
uname -m 2>/dev/null || echo "$AUTOMAKER_INFO_UNKNOWN"
|
||||
}
|
||||
|
||||
automaker_get_memory() {
|
||||
if automaker_command_exists free; then
|
||||
free -h | awk '/Mem:/ {print $3 " / " $2}'
|
||||
return
|
||||
fi
|
||||
|
||||
if automaker_command_exists vm_stat; then
|
||||
local page_size
|
||||
local pages_free
|
||||
local pages_active
|
||||
local pages_inactive
|
||||
local pages_wired
|
||||
local pages_total
|
||||
page_size=$(vm_stat | awk '/page size of/ {print $8}')
|
||||
pages_free=$(vm_stat | awk '/Pages free/ {print $3}' | tr -d '.')
|
||||
pages_active=$(vm_stat | awk '/Pages active/ {print $3}' | tr -d '.')
|
||||
pages_inactive=$(vm_stat | awk '/Pages inactive/ {print $3}' | tr -d '.')
|
||||
pages_wired=$(vm_stat | awk '/Pages wired down/ {print $4}' | tr -d '.')
|
||||
pages_total=$((pages_free + pages_active + pages_inactive + pages_wired))
|
||||
awk -v total="$pages_total" -v free="$pages_free" -v size="$page_size" \
|
||||
-v bytes_kib="$AUTOMAKER_BYTES_PER_KIB" \
|
||||
-v kib_mib="$AUTOMAKER_KIB_PER_MIB" \
|
||||
-v mib_gib="$AUTOMAKER_MIB_PER_GIB" \
|
||||
'BEGIN {
|
||||
total_gb = total * size / bytes_kib / kib_mib / mib_gib;
|
||||
used_gb = (total - free) * size / bytes_kib / kib_mib / mib_gib;
|
||||
printf("%.1f GB / %.1f GB", used_gb, total_gb);
|
||||
}'
|
||||
return
|
||||
fi
|
||||
|
||||
if automaker_command_exists sysctl; then
|
||||
local total_bytes
|
||||
total_bytes=$(sysctl -n hw.memsize 2>/dev/null)
|
||||
if [ -n "$total_bytes" ]; then
|
||||
awk -v total="$total_bytes" \
|
||||
-v bytes_kib="$AUTOMAKER_BYTES_PER_KIB" \
|
||||
-v kib_mib="$AUTOMAKER_KIB_PER_MIB" \
|
||||
-v mib_gib="$AUTOMAKER_MIB_PER_GIB" \
|
||||
'BEGIN {printf("%.1f GB", total / bytes_kib / kib_mib / mib_gib)}'
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$AUTOMAKER_INFO_UNKNOWN"
|
||||
}
|
||||
|
||||
automaker_get_disk() {
|
||||
if automaker_command_exists df; then
|
||||
df -h / 2>/dev/null | awk 'NR==2 {print $3 " / " $2}'
|
||||
return
|
||||
fi
|
||||
|
||||
echo "$AUTOMAKER_INFO_UNKNOWN"
|
||||
}
|
||||
|
||||
automaker_get_ip() {
|
||||
if automaker_command_exists hostname; then
|
||||
local ip_addr
|
||||
ip_addr=$(hostname -I 2>/dev/null | awk '{print $1}')
|
||||
if [ -n "$ip_addr" ]; then
|
||||
echo "$ip_addr"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if automaker_command_exists ipconfig; then
|
||||
local ip_addr
|
||||
ip_addr=$(ipconfig getifaddr en0 2>/dev/null)
|
||||
if [ -n "$ip_addr" ]; then
|
||||
echo "$ip_addr"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$AUTOMAKER_INFO_UNKNOWN"
|
||||
}
|
||||
|
||||
automaker_trim_path_depth() {
|
||||
local path="$1"
|
||||
local depth="$2"
|
||||
if [ -z "$depth" ] || [ "$depth" -le 0 ]; then
|
||||
echo "$path"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "$path" | awk -v depth="$depth" -F/ '{
|
||||
prefix=""
|
||||
start=1
|
||||
if ($1=="") { prefix="/"; start=2 }
|
||||
else if ($1=="~") { prefix="~/"; start=2 }
|
||||
n=NF
|
||||
if (n < start) {
|
||||
if (prefix=="/") { print "/" }
|
||||
else if (prefix=="~/") { print "~" }
|
||||
else { print $0 }
|
||||
next
|
||||
}
|
||||
segCount = n - start + 1
|
||||
d = depth
|
||||
if (d > segCount) { d = segCount }
|
||||
out=""
|
||||
for (i = n - d + 1; i <= n; i++) {
|
||||
out = out (out=="" ? "" : "/") $i
|
||||
}
|
||||
if (prefix=="/") {
|
||||
if (out=="") { out="/" } else { out="/" out }
|
||||
} else if (prefix=="~/") {
|
||||
if (out=="") { out="~" } else { out="~/" out }
|
||||
}
|
||||
print out
|
||||
}'
|
||||
}
|
||||
|
||||
automaker_shorten_path() {
|
||||
local path="$1"
|
||||
echo "$path" | awk -F/ '{
|
||||
prefix=""
|
||||
start=1
|
||||
if ($1=="") { prefix="/"; start=2 }
|
||||
else if ($1=="~") { prefix="~/"; start=2 }
|
||||
n=NF
|
||||
if (n < start) {
|
||||
if (prefix=="/") { print "/" }
|
||||
else if (prefix=="~/") { print "~" }
|
||||
else { print $0 }
|
||||
next
|
||||
}
|
||||
out=""
|
||||
for (i = start; i <= n; i++) {
|
||||
seg = $i
|
||||
if (i < n && length(seg) > 0) { seg = substr(seg, 1, 1) }
|
||||
out = out (out=="" ? "" : "/") seg
|
||||
}
|
||||
if (prefix=="/") { out="/" out }
|
||||
else if (prefix=="~/") { out="~/" out }
|
||||
print out
|
||||
}'
|
||||
}
|
||||
|
||||
automaker_prompt_path() {
|
||||
if [ "$AUTOMAKER_SHOW_PATH" != "true" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local current_path="$PWD"
|
||||
if [ -n "$HOME" ] && [ "\${current_path#"$HOME"}" != "$current_path" ]; then
|
||||
current_path="~\${current_path#$HOME}"
|
||||
fi
|
||||
|
||||
if [ "$AUTOMAKER_PATH_DEPTH" -gt 0 ]; then
|
||||
current_path=$(automaker_trim_path_depth "$current_path" "$AUTOMAKER_PATH_DEPTH")
|
||||
fi
|
||||
|
||||
case "$AUTOMAKER_PATH_STYLE" in
|
||||
basename)
|
||||
if [ "$current_path" = "/" ] || [ "$current_path" = "~" ]; then
|
||||
echo -n "$current_path"
|
||||
else
|
||||
echo -n "\${current_path##*/}"
|
||||
fi
|
||||
;;
|
||||
short)
|
||||
echo -n "$(automaker_shorten_path "$current_path")"
|
||||
;;
|
||||
full|*)
|
||||
echo -n "$current_path"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
automaker_prompt_time() {
|
||||
if [ "$AUTOMAKER_SHOW_TIME" != "true" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
date +%H:%M
|
||||
}
|
||||
|
||||
automaker_prompt_status() {
|
||||
automaker_last_status=$?
|
||||
if [ "$AUTOMAKER_SHOW_EXIT_STATUS" != "true" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$automaker_last_status" -eq 0 ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
printf "✗ %s" "$automaker_last_status"
|
||||
}
|
||||
|
||||
automaker_show_banner() {
|
||||
local label_width="$AUTOMAKER_BANNER_LABEL_WIDTH"
|
||||
local logo_line_1=" █▀▀█ █ █ ▀▀█▀▀ █▀▀█ █▀▄▀█ █▀▀█ █ █ █▀▀ █▀▀█ "
|
||||
local logo_line_2=" █▄▄█ █ █ █ █ █ █ ▀ █ █▄▄█ █▀▄ █▀▀ █▄▄▀ "
|
||||
local logo_line_3=" ▀ ▀ ▀▀▀ ▀ ▀▀▀▀ ▀ ▀ ▀ ▀ ▀ ▀ ▀▀▀ ▀ ▀▀ "
|
||||
local accent_color="\${AUTOMAKER_COLOR_PRIMARY}"
|
||||
local secondary_color="\${AUTOMAKER_COLOR_SECONDARY}"
|
||||
local tertiary_color="\${AUTOMAKER_COLOR_ACCENT}"
|
||||
local label_color="\${AUTOMAKER_COLOR_SECONDARY}"
|
||||
local reset_color="\${AUTOMAKER_COLOR_RESET}"
|
||||
|
||||
printf "%b%s%b\n" "$accent_color" "$logo_line_1" "$reset_color"
|
||||
printf "%b%s%b\n" "$secondary_color" "$logo_line_2" "$reset_color"
|
||||
printf "%b%s%b\n" "$tertiary_color" "$logo_line_3" "$reset_color"
|
||||
printf "\n"
|
||||
|
||||
local shell_name="\${SHELL##*/}"
|
||||
if [ -z "$shell_name" ]; then
|
||||
shell_name=$(basename "$0" 2>/dev/null || echo "shell")
|
||||
fi
|
||||
local user_host="\${USER:-unknown}@$(hostname 2>/dev/null || echo unknown)"
|
||||
printf "%b%s%b\n" "$label_color" "$user_host" "$reset_color"
|
||||
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "OS:" "$reset_color" "$(automaker_get_os)"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "Uptime:" "$reset_color" "$(automaker_get_uptime)"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "Shell:" "$reset_color" "$shell_name"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "Terminal:" "$reset_color" "\${TERM_PROGRAM:-$TERM}"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "CPU:" "$reset_color" "$(automaker_get_cpu)"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "Memory:" "$reset_color" "$(automaker_get_memory)"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "Disk:" "$reset_color" "$(automaker_get_disk)"
|
||||
printf "%b%-\${label_width}s%b %s\n" "$label_color" "Local IP:" "$reset_color" "$(automaker_get_ip)"
|
||||
printf "\n"
|
||||
}
|
||||
|
||||
automaker_show_banner_once() {
|
||||
case "$-" in
|
||||
*i*) ;;
|
||||
*) return ;;
|
||||
esac
|
||||
|
||||
if [ "$AUTOMAKER_BANNER_SHOWN" = "true" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
automaker_show_banner
|
||||
export AUTOMAKER_BANNER_SHOWN="true"
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate prompt based on format
|
||||
*/
|
||||
function generatePrompt(
|
||||
format: TerminalConfig['promptFormat'],
|
||||
colors: ANSIColors,
|
||||
config: TerminalConfig
|
||||
): string {
|
||||
const userHostSegment = config.showUserHost
|
||||
? `${colors.user}\\u${colors.reset}@${colors.host}\\h${colors.reset}`
|
||||
: '';
|
||||
const pathSegment = config.showPath
|
||||
? `${colors.path}\\$(automaker_prompt_path)${colors.reset}`
|
||||
: '';
|
||||
const gitSegment = config.showGitBranch
|
||||
? `${colors.gitBranch}\\$(automaker_git_prompt)${colors.reset}`
|
||||
: '';
|
||||
const timeSegment = config.showTime
|
||||
? `${colors.gitBranch}[\\$(automaker_prompt_time)]${colors.reset}`
|
||||
: '';
|
||||
const statusSegment = config.showExitStatus
|
||||
? `${colors.gitDirty}\\$(automaker_prompt_status)${colors.reset}`
|
||||
: '';
|
||||
|
||||
switch (format) {
|
||||
case 'minimal': {
|
||||
const minimalSegments = [timeSegment, userHostSegment, pathSegment, gitSegment, statusSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PS1="${minimalSegments ? `${minimalSegments} ` : ''}${colors.prompt}\\$${colors.reset} "`;
|
||||
}
|
||||
|
||||
case 'powerline': {
|
||||
const powerlineCoreSegments = [
|
||||
userHostSegment ? `[${userHostSegment}]` : '',
|
||||
pathSegment ? `[${pathSegment}]` : '',
|
||||
].filter((segment) => segment.length > 0);
|
||||
const powerlineCore = powerlineCoreSegments.join('─');
|
||||
const powerlineExtras = [gitSegment, timeSegment, statusSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
const powerlineLine = [powerlineCore, powerlineExtras]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PS1="┌─${powerlineLine}\\n└─${colors.prompt}\\$${colors.reset} "`;
|
||||
}
|
||||
|
||||
case 'starship': {
|
||||
let starshipLine = '';
|
||||
if (userHostSegment && pathSegment) {
|
||||
starshipLine = `${userHostSegment} in ${pathSegment}`;
|
||||
} else {
|
||||
starshipLine = [userHostSegment, pathSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
}
|
||||
if (gitSegment) {
|
||||
starshipLine = `${starshipLine}${starshipLine ? ' on ' : ''}${gitSegment}`;
|
||||
}
|
||||
const starshipSegments = [timeSegment, starshipLine, statusSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PS1="${starshipSegments}\\n${colors.prompt}❯${colors.reset} "`;
|
||||
}
|
||||
|
||||
case 'standard':
|
||||
default: {
|
||||
const standardSegments = [
|
||||
timeSegment,
|
||||
userHostSegment ? `[${userHostSegment}]` : '',
|
||||
pathSegment,
|
||||
gitSegment,
|
||||
statusSegment,
|
||||
]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PS1="${standardSegments ? `${standardSegments} ` : ''}${colors.prompt}\\$${colors.reset} "`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Zsh prompt based on format
|
||||
*/
|
||||
function generateZshPrompt(
|
||||
format: TerminalConfig['promptFormat'],
|
||||
colors: ANSIColors,
|
||||
config: TerminalConfig
|
||||
): string {
|
||||
// Convert bash-style \u, \h, \w to zsh-style %n, %m, %~
|
||||
// Remove bash-style escaping \[ \] (not needed in zsh)
|
||||
const zshColors = {
|
||||
user: colors.user
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
host: colors.host
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
path: colors.path
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
gitBranch: colors.gitBranch
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
gitDirty: colors.gitDirty
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
prompt: colors.prompt
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
reset: colors.reset
|
||||
.replace(/\\[\[\]\\e]/g, '')
|
||||
.replace(/\\e/g, '%{')
|
||||
.replace(/m\\]/g, 'm%}'),
|
||||
};
|
||||
|
||||
const userHostSegment = config.showUserHost
|
||||
? `[${zshColors.user}%n${zshColors.reset}@${zshColors.host}%m${zshColors.reset}]`
|
||||
: '';
|
||||
const pathSegment = config.showPath
|
||||
? `${zshColors.path}$(automaker_prompt_path)${zshColors.reset}`
|
||||
: '';
|
||||
const gitSegment = config.showGitBranch
|
||||
? `${zshColors.gitBranch}$(automaker_git_prompt)${zshColors.reset}`
|
||||
: '';
|
||||
const timeSegment = config.showTime
|
||||
? `${zshColors.gitBranch}[$(automaker_prompt_time)]${zshColors.reset}`
|
||||
: '';
|
||||
const statusSegment = config.showExitStatus
|
||||
? `${zshColors.gitDirty}$(automaker_prompt_status)${zshColors.reset}`
|
||||
: '';
|
||||
const segments = [timeSegment, userHostSegment, pathSegment, gitSegment, statusSegment].filter(
|
||||
(segment) => segment.length > 0
|
||||
);
|
||||
const inlineSegments = segments.join(' ');
|
||||
const inlineWithSpace = inlineSegments ? `${inlineSegments} ` : '';
|
||||
|
||||
switch (format) {
|
||||
case 'minimal': {
|
||||
return `PROMPT="${inlineWithSpace}${zshColors.prompt}%#${zshColors.reset} "`;
|
||||
}
|
||||
|
||||
case 'powerline': {
|
||||
const powerlineCoreSegments = [
|
||||
userHostSegment ? `[${userHostSegment}]` : '',
|
||||
pathSegment ? `[${pathSegment}]` : '',
|
||||
].filter((segment) => segment.length > 0);
|
||||
const powerlineCore = powerlineCoreSegments.join('─');
|
||||
const powerlineExtras = [gitSegment, timeSegment, statusSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
const powerlineLine = [powerlineCore, powerlineExtras]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PROMPT="┌─${powerlineLine}
|
||||
└─${zshColors.prompt}%#${zshColors.reset} "`;
|
||||
}
|
||||
|
||||
case 'starship': {
|
||||
let starshipLine = '';
|
||||
if (userHostSegment && pathSegment) {
|
||||
starshipLine = `${userHostSegment} in ${pathSegment}`;
|
||||
} else {
|
||||
starshipLine = [userHostSegment, pathSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
}
|
||||
if (gitSegment) {
|
||||
starshipLine = `${starshipLine}${starshipLine ? ' on ' : ''}${gitSegment}`;
|
||||
}
|
||||
const starshipSegments = [timeSegment, starshipLine, statusSegment]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PROMPT="${starshipSegments}
|
||||
${zshColors.prompt}❯${zshColors.reset} "`;
|
||||
}
|
||||
|
||||
case 'standard':
|
||||
default: {
|
||||
const standardSegments = [
|
||||
timeSegment,
|
||||
userHostSegment ? `[${userHostSegment}]` : '',
|
||||
pathSegment,
|
||||
gitSegment,
|
||||
statusSegment,
|
||||
]
|
||||
.filter((segment) => segment.length > 0)
|
||||
.join(' ');
|
||||
return `PROMPT="${standardSegments ? `${standardSegments} ` : ''}${zshColors.prompt}%#${zshColors.reset} "`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate custom aliases section
|
||||
*/
|
||||
function generateAliases(config: TerminalConfig): string {
|
||||
if (!config.customAliases) return '';
|
||||
|
||||
// Escape and validate aliases
|
||||
const escapedAliases = shellEscape(config.customAliases);
|
||||
return `
|
||||
# Custom aliases
|
||||
${escapedAliases}
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate custom environment variables section
|
||||
*/
|
||||
function generateEnvVars(config: TerminalConfig): string {
|
||||
if (!config.customEnvVars || Object.keys(config.customEnvVars).length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const validEnvVars = Object.entries(config.customEnvVars)
|
||||
.filter(([name]) => isValidEnvVarName(name))
|
||||
.map(([name, value]) => `export ${name}="${shellEscape(value)}"`)
|
||||
.join('\n');
|
||||
|
||||
return validEnvVars
|
||||
? `
|
||||
# Custom environment variables
|
||||
${validEnvVars}
|
||||
`
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate bashrc configuration
|
||||
*/
|
||||
export function generateBashrc(theme: TerminalTheme, config: TerminalConfig): string {
|
||||
const colors = getThemeANSIColors(theme);
|
||||
const promptLine = generatePrompt(config.promptFormat, colors, config);
|
||||
const promptInitializer = generateOhMyPoshInit(OMP_SHELL_BASH, promptLine);
|
||||
|
||||
return `#!/bin/bash
|
||||
# Automaker Terminal Configuration v1.0
|
||||
# This file is automatically generated - manual edits will be overwritten
|
||||
|
||||
# Source user's original bashrc first (preserves user configuration)
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
source "$HOME/.bashrc"
|
||||
fi
|
||||
|
||||
# Load Automaker theme colors
|
||||
AUTOMAKER_THEME="\${AUTOMAKER_THEME:-dark}"
|
||||
if [ -f "\${BASH_SOURCE%/*}/themes/$AUTOMAKER_THEME.sh" ]; then
|
||||
source "\${BASH_SOURCE%/*}/themes/$AUTOMAKER_THEME.sh"
|
||||
fi
|
||||
|
||||
# Load common functions (git prompt)
|
||||
if [ -f "\${BASH_SOURCE%/*}/common.sh" ]; then
|
||||
source "\${BASH_SOURCE%/*}/common.sh"
|
||||
fi
|
||||
|
||||
# Show Automaker banner on shell start
|
||||
if command -v automaker_show_banner_once >/dev/null 2>&1; then
|
||||
automaker_show_banner_once
|
||||
fi
|
||||
|
||||
# Set custom prompt (only if enabled)
|
||||
if [ "$AUTOMAKER_CUSTOM_PROMPT" = "true" ]; then
|
||||
${promptInitializer}
|
||||
fi
|
||||
${generateAliases(config)}${generateEnvVars(config)}
|
||||
# Load user customizations (if exists)
|
||||
if [ -f "\${BASH_SOURCE%/*}/user-custom.sh" ]; then
|
||||
source "\${BASH_SOURCE%/*}/user-custom.sh"
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate zshrc configuration
|
||||
*/
|
||||
export function generateZshrc(theme: TerminalTheme, config: TerminalConfig): string {
|
||||
const colors = getThemeANSIColors(theme);
|
||||
const promptLine = generateZshPrompt(config.promptFormat, colors, config);
|
||||
const promptInitializer = generateOhMyPoshInit(OMP_SHELL_ZSH, promptLine);
|
||||
|
||||
return `#!/bin/zsh
|
||||
# Automaker Terminal Configuration v1.0
|
||||
# This file is automatically generated - manual edits will be overwritten
|
||||
|
||||
# Source user's original zshrc first (preserves user configuration)
|
||||
if [ -f "$HOME/.zshrc" ]; then
|
||||
source "$HOME/.zshrc"
|
||||
fi
|
||||
|
||||
# Load Automaker theme colors
|
||||
AUTOMAKER_THEME="\${AUTOMAKER_THEME:-dark}"
|
||||
if [ -f "\${ZDOTDIR:-\${0:a:h}}/themes/$AUTOMAKER_THEME.sh" ]; then
|
||||
source "\${ZDOTDIR:-\${0:a:h}}/themes/$AUTOMAKER_THEME.sh"
|
||||
fi
|
||||
|
||||
# Load common functions (git prompt)
|
||||
if [ -f "\${ZDOTDIR:-\${0:a:h}}/common.sh" ]; then
|
||||
source "\${ZDOTDIR:-\${0:a:h}}/common.sh"
|
||||
fi
|
||||
|
||||
# Enable command substitution in PROMPT
|
||||
setopt PROMPT_SUBST
|
||||
|
||||
# Show Automaker banner on shell start
|
||||
if command -v automaker_show_banner_once >/dev/null 2>&1; then
|
||||
automaker_show_banner_once
|
||||
fi
|
||||
|
||||
# Set custom prompt (only if enabled)
|
||||
if [ "$AUTOMAKER_CUSTOM_PROMPT" = "true" ]; then
|
||||
${promptInitializer}
|
||||
fi
|
||||
${generateAliases(config)}${generateEnvVars(config)}
|
||||
# Load user customizations (if exists)
|
||||
if [ -f "\${ZDOTDIR:-\${0:a:h}}/user-custom.sh" ]; then
|
||||
source "\${ZDOTDIR:-\${0:a:h}}/user-custom.sh"
|
||||
fi
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate theme color exports for shell
|
||||
*/
|
||||
export function generateThemeColors(theme: TerminalTheme): string {
|
||||
const colors = getThemeANSIColors(theme);
|
||||
const rawColors = {
|
||||
user: stripPromptEscapes(colors.user),
|
||||
host: stripPromptEscapes(colors.host),
|
||||
path: stripPromptEscapes(colors.path),
|
||||
gitBranch: stripPromptEscapes(colors.gitBranch),
|
||||
gitDirty: stripPromptEscapes(colors.gitDirty),
|
||||
prompt: stripPromptEscapes(colors.prompt),
|
||||
reset: stripPromptEscapes(colors.reset),
|
||||
};
|
||||
|
||||
return `#!/bin/sh
|
||||
# Automaker Theme Colors
|
||||
# This file is automatically generated - manual edits will be overwritten
|
||||
|
||||
# ANSI color codes for prompt
|
||||
export COLOR_USER="${colors.user}"
|
||||
export COLOR_HOST="${colors.host}"
|
||||
export COLOR_PATH="${colors.path}"
|
||||
export COLOR_GIT_BRANCH="${colors.gitBranch}"
|
||||
export COLOR_GIT_DIRTY="${colors.gitDirty}"
|
||||
export COLOR_PROMPT="${colors.prompt}"
|
||||
export COLOR_RESET="${colors.reset}"
|
||||
|
||||
# ANSI color codes for banner output (no prompt escapes)
|
||||
export COLOR_USER_RAW="${rawColors.user}"
|
||||
export COLOR_HOST_RAW="${rawColors.host}"
|
||||
export COLOR_PATH_RAW="${rawColors.path}"
|
||||
export COLOR_GIT_BRANCH_RAW="${rawColors.gitBranch}"
|
||||
export COLOR_GIT_DIRTY_RAW="${rawColors.gitDirty}"
|
||||
export COLOR_PROMPT_RAW="${rawColors.prompt}"
|
||||
export COLOR_RESET_RAW="${rawColors.reset}"
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shell name from file extension
|
||||
*/
|
||||
export function getShellName(rcFile: string): 'bash' | 'zsh' | 'sh' | null {
|
||||
if (rcFile.endsWith('.sh') && rcFile.includes('bashrc')) return 'bash';
|
||||
if (rcFile.endsWith('.zsh') || rcFile.endsWith('.zshrc')) return 'zsh';
|
||||
if (rcFile.endsWith('.sh')) return 'sh';
|
||||
return null;
|
||||
}
|
||||
468
libs/platform/src/terminal-theme-colors.ts
Normal file
468
libs/platform/src/terminal-theme-colors.ts
Normal file
@@ -0,0 +1,468 @@
|
||||
/**
|
||||
* Terminal Theme Colors - Color definitions for all 40 themes
|
||||
*
|
||||
* This module contains only the raw color data for terminal themes,
|
||||
* extracted from the UI package to avoid circular dependencies.
|
||||
* These colors are used by both UI (xterm.js) and server (RC file generation).
|
||||
*/
|
||||
|
||||
import type { ThemeMode } from '@automaker/types';
|
||||
import type { TerminalTheme } from './rc-generator.js';
|
||||
|
||||
// Dark theme (default)
|
||||
const darkTheme: TerminalTheme = {
|
||||
background: '#0a0a0a',
|
||||
foreground: '#d4d4d4',
|
||||
cursor: '#d4d4d4',
|
||||
cursorAccent: '#0a0a0a',
|
||||
selectionBackground: '#264f78',
|
||||
black: '#1e1e1e',
|
||||
red: '#f44747',
|
||||
green: '#6a9955',
|
||||
yellow: '#dcdcaa',
|
||||
blue: '#569cd6',
|
||||
magenta: '#c586c0',
|
||||
cyan: '#4ec9b0',
|
||||
white: '#d4d4d4',
|
||||
brightBlack: '#808080',
|
||||
brightRed: '#f44747',
|
||||
brightGreen: '#6a9955',
|
||||
brightYellow: '#dcdcaa',
|
||||
brightBlue: '#569cd6',
|
||||
brightMagenta: '#c586c0',
|
||||
brightCyan: '#4ec9b0',
|
||||
brightWhite: '#ffffff',
|
||||
};
|
||||
|
||||
// Light theme
|
||||
const lightTheme: TerminalTheme = {
|
||||
background: '#ffffff',
|
||||
foreground: '#383a42',
|
||||
cursor: '#383a42',
|
||||
cursorAccent: '#ffffff',
|
||||
selectionBackground: '#add6ff',
|
||||
black: '#383a42',
|
||||
red: '#e45649',
|
||||
green: '#50a14f',
|
||||
yellow: '#c18401',
|
||||
blue: '#4078f2',
|
||||
magenta: '#a626a4',
|
||||
cyan: '#0184bc',
|
||||
white: '#fafafa',
|
||||
brightBlack: '#4f525e',
|
||||
brightRed: '#e06c75',
|
||||
brightGreen: '#98c379',
|
||||
brightYellow: '#e5c07b',
|
||||
brightBlue: '#61afef',
|
||||
brightMagenta: '#c678dd',
|
||||
brightCyan: '#56b6c2',
|
||||
brightWhite: '#ffffff',
|
||||
};
|
||||
|
||||
// Retro / Cyberpunk theme - neon green on black
|
||||
const retroTheme: TerminalTheme = {
|
||||
background: '#000000',
|
||||
foreground: '#39ff14',
|
||||
cursor: '#39ff14',
|
||||
cursorAccent: '#000000',
|
||||
selectionBackground: '#39ff14',
|
||||
selectionForeground: '#000000',
|
||||
black: '#000000',
|
||||
red: '#ff0055',
|
||||
green: '#39ff14',
|
||||
yellow: '#ffff00',
|
||||
blue: '#00ffff',
|
||||
magenta: '#ff00ff',
|
||||
cyan: '#00ffff',
|
||||
white: '#39ff14',
|
||||
brightBlack: '#555555',
|
||||
brightRed: '#ff5555',
|
||||
brightGreen: '#55ff55',
|
||||
brightYellow: '#ffff55',
|
||||
brightBlue: '#55ffff',
|
||||
brightMagenta: '#ff55ff',
|
||||
brightCyan: '#55ffff',
|
||||
brightWhite: '#ffffff',
|
||||
};
|
||||
|
||||
// Dracula theme
|
||||
const draculaTheme: TerminalTheme = {
|
||||
background: '#282a36',
|
||||
foreground: '#f8f8f2',
|
||||
cursor: '#f8f8f2',
|
||||
cursorAccent: '#282a36',
|
||||
selectionBackground: '#44475a',
|
||||
black: '#21222c',
|
||||
red: '#ff5555',
|
||||
green: '#50fa7b',
|
||||
yellow: '#f1fa8c',
|
||||
blue: '#bd93f9',
|
||||
magenta: '#ff79c6',
|
||||
cyan: '#8be9fd',
|
||||
white: '#f8f8f2',
|
||||
brightBlack: '#6272a4',
|
||||
brightRed: '#ff6e6e',
|
||||
brightGreen: '#69ff94',
|
||||
brightYellow: '#ffffa5',
|
||||
brightBlue: '#d6acff',
|
||||
brightMagenta: '#ff92df',
|
||||
brightCyan: '#a4ffff',
|
||||
brightWhite: '#ffffff',
|
||||
};
|
||||
|
||||
// Nord theme
|
||||
const nordTheme: TerminalTheme = {
|
||||
background: '#2e3440',
|
||||
foreground: '#d8dee9',
|
||||
cursor: '#d8dee9',
|
||||
cursorAccent: '#2e3440',
|
||||
selectionBackground: '#434c5e',
|
||||
black: '#3b4252',
|
||||
red: '#bf616a',
|
||||
green: '#a3be8c',
|
||||
yellow: '#ebcb8b',
|
||||
blue: '#81a1c1',
|
||||
magenta: '#b48ead',
|
||||
cyan: '#88c0d0',
|
||||
white: '#e5e9f0',
|
||||
brightBlack: '#4c566a',
|
||||
brightRed: '#bf616a',
|
||||
brightGreen: '#a3be8c',
|
||||
brightYellow: '#ebcb8b',
|
||||
brightBlue: '#81a1c1',
|
||||
brightMagenta: '#b48ead',
|
||||
brightCyan: '#8fbcbb',
|
||||
brightWhite: '#eceff4',
|
||||
};
|
||||
|
||||
// Monokai theme
|
||||
const monokaiTheme: TerminalTheme = {
|
||||
background: '#272822',
|
||||
foreground: '#f8f8f2',
|
||||
cursor: '#f8f8f2',
|
||||
cursorAccent: '#272822',
|
||||
selectionBackground: '#49483e',
|
||||
black: '#272822',
|
||||
red: '#f92672',
|
||||
green: '#a6e22e',
|
||||
yellow: '#f4bf75',
|
||||
blue: '#66d9ef',
|
||||
magenta: '#ae81ff',
|
||||
cyan: '#a1efe4',
|
||||
white: '#f8f8f2',
|
||||
brightBlack: '#75715e',
|
||||
brightRed: '#f92672',
|
||||
brightGreen: '#a6e22e',
|
||||
brightYellow: '#f4bf75',
|
||||
brightBlue: '#66d9ef',
|
||||
brightMagenta: '#ae81ff',
|
||||
brightCyan: '#a1efe4',
|
||||
brightWhite: '#f9f8f5',
|
||||
};
|
||||
|
||||
// Tokyo Night theme
|
||||
const tokyonightTheme: TerminalTheme = {
|
||||
background: '#1a1b26',
|
||||
foreground: '#a9b1d6',
|
||||
cursor: '#c0caf5',
|
||||
cursorAccent: '#1a1b26',
|
||||
selectionBackground: '#33467c',
|
||||
black: '#15161e',
|
||||
red: '#f7768e',
|
||||
green: '#9ece6a',
|
||||
yellow: '#e0af68',
|
||||
blue: '#7aa2f7',
|
||||
magenta: '#bb9af7',
|
||||
cyan: '#7dcfff',
|
||||
white: '#a9b1d6',
|
||||
brightBlack: '#414868',
|
||||
brightRed: '#f7768e',
|
||||
brightGreen: '#9ece6a',
|
||||
brightYellow: '#e0af68',
|
||||
brightBlue: '#7aa2f7',
|
||||
brightMagenta: '#bb9af7',
|
||||
brightCyan: '#7dcfff',
|
||||
brightWhite: '#c0caf5',
|
||||
};
|
||||
|
||||
// Solarized Dark theme
|
||||
const solarizedTheme: TerminalTheme = {
|
||||
background: '#002b36',
|
||||
foreground: '#93a1a1',
|
||||
cursor: '#93a1a1',
|
||||
cursorAccent: '#002b36',
|
||||
selectionBackground: '#073642',
|
||||
black: '#073642',
|
||||
red: '#dc322f',
|
||||
green: '#859900',
|
||||
yellow: '#b58900',
|
||||
blue: '#268bd2',
|
||||
magenta: '#d33682',
|
||||
cyan: '#2aa198',
|
||||
white: '#eee8d5',
|
||||
brightBlack: '#002b36',
|
||||
brightRed: '#cb4b16',
|
||||
brightGreen: '#586e75',
|
||||
brightYellow: '#657b83',
|
||||
brightBlue: '#839496',
|
||||
brightMagenta: '#6c71c4',
|
||||
brightCyan: '#93a1a1',
|
||||
brightWhite: '#fdf6e3',
|
||||
};
|
||||
|
||||
// Gruvbox Dark theme
|
||||
const gruvboxTheme: TerminalTheme = {
|
||||
background: '#282828',
|
||||
foreground: '#ebdbb2',
|
||||
cursor: '#ebdbb2',
|
||||
cursorAccent: '#282828',
|
||||
selectionBackground: '#504945',
|
||||
black: '#282828',
|
||||
red: '#cc241d',
|
||||
green: '#98971a',
|
||||
yellow: '#d79921',
|
||||
blue: '#458588',
|
||||
magenta: '#b16286',
|
||||
cyan: '#689d6a',
|
||||
white: '#a89984',
|
||||
brightBlack: '#928374',
|
||||
brightRed: '#fb4934',
|
||||
brightGreen: '#b8bb26',
|
||||
brightYellow: '#fabd2f',
|
||||
brightBlue: '#83a598',
|
||||
brightMagenta: '#d3869b',
|
||||
brightCyan: '#8ec07c',
|
||||
brightWhite: '#ebdbb2',
|
||||
};
|
||||
|
||||
// Catppuccin Mocha theme
|
||||
const catppuccinTheme: TerminalTheme = {
|
||||
background: '#1e1e2e',
|
||||
foreground: '#cdd6f4',
|
||||
cursor: '#f5e0dc',
|
||||
cursorAccent: '#1e1e2e',
|
||||
selectionBackground: '#45475a',
|
||||
black: '#45475a',
|
||||
red: '#f38ba8',
|
||||
green: '#a6e3a1',
|
||||
yellow: '#f9e2af',
|
||||
blue: '#89b4fa',
|
||||
magenta: '#cba6f7',
|
||||
cyan: '#94e2d5',
|
||||
white: '#bac2de',
|
||||
brightBlack: '#585b70',
|
||||
brightRed: '#f38ba8',
|
||||
brightGreen: '#a6e3a1',
|
||||
brightYellow: '#f9e2af',
|
||||
brightBlue: '#89b4fa',
|
||||
brightMagenta: '#cba6f7',
|
||||
brightCyan: '#94e2d5',
|
||||
brightWhite: '#a6adc8',
|
||||
};
|
||||
|
||||
// One Dark theme
|
||||
const onedarkTheme: TerminalTheme = {
|
||||
background: '#282c34',
|
||||
foreground: '#abb2bf',
|
||||
cursor: '#528bff',
|
||||
cursorAccent: '#282c34',
|
||||
selectionBackground: '#3e4451',
|
||||
black: '#282c34',
|
||||
red: '#e06c75',
|
||||
green: '#98c379',
|
||||
yellow: '#e5c07b',
|
||||
blue: '#61afef',
|
||||
magenta: '#c678dd',
|
||||
cyan: '#56b6c2',
|
||||
white: '#abb2bf',
|
||||
brightBlack: '#5c6370',
|
||||
brightRed: '#e06c75',
|
||||
brightGreen: '#98c379',
|
||||
brightYellow: '#e5c07b',
|
||||
brightBlue: '#61afef',
|
||||
brightMagenta: '#c678dd',
|
||||
brightCyan: '#56b6c2',
|
||||
brightWhite: '#ffffff',
|
||||
};
|
||||
|
||||
// Synthwave '84 theme
|
||||
const synthwaveTheme: TerminalTheme = {
|
||||
background: '#262335',
|
||||
foreground: '#ffffff',
|
||||
cursor: '#ff7edb',
|
||||
cursorAccent: '#262335',
|
||||
selectionBackground: '#463465',
|
||||
black: '#262335',
|
||||
red: '#fe4450',
|
||||
green: '#72f1b8',
|
||||
yellow: '#fede5d',
|
||||
blue: '#03edf9',
|
||||
magenta: '#ff7edb',
|
||||
cyan: '#03edf9',
|
||||
white: '#ffffff',
|
||||
brightBlack: '#614d85',
|
||||
brightRed: '#fe4450',
|
||||
brightGreen: '#72f1b8',
|
||||
brightYellow: '#f97e72',
|
||||
brightBlue: '#03edf9',
|
||||
brightMagenta: '#ff7edb',
|
||||
brightCyan: '#03edf9',
|
||||
brightWhite: '#ffffff',
|
||||
};
|
||||
|
||||
// Red theme
|
||||
const redTheme: TerminalTheme = {
|
||||
background: '#1a0a0a',
|
||||
foreground: '#c8b0b0',
|
||||
cursor: '#ff4444',
|
||||
cursorAccent: '#1a0a0a',
|
||||
selectionBackground: '#5a2020',
|
||||
black: '#2a1010',
|
||||
red: '#ff4444',
|
||||
green: '#6a9a6a',
|
||||
yellow: '#ccaa55',
|
||||
blue: '#6688aa',
|
||||
magenta: '#aa5588',
|
||||
cyan: '#558888',
|
||||
white: '#b0a0a0',
|
||||
brightBlack: '#6a4040',
|
||||
brightRed: '#ff6666',
|
||||
brightGreen: '#88bb88',
|
||||
brightYellow: '#ddbb66',
|
||||
brightBlue: '#88aacc',
|
||||
brightMagenta: '#cc77aa',
|
||||
brightCyan: '#77aaaa',
|
||||
brightWhite: '#d0c0c0',
|
||||
};
|
||||
|
||||
// Cream theme
|
||||
const creamTheme: TerminalTheme = {
|
||||
background: '#f5f3ee',
|
||||
foreground: '#5a4a3a',
|
||||
cursor: '#9d6b53',
|
||||
cursorAccent: '#f5f3ee',
|
||||
selectionBackground: '#d4c4b0',
|
||||
black: '#5a4a3a',
|
||||
red: '#c85a4f',
|
||||
green: '#7a9a6a',
|
||||
yellow: '#c9a554',
|
||||
blue: '#6b8aaa',
|
||||
magenta: '#a66a8a',
|
||||
cyan: '#5a9a8a',
|
||||
white: '#b0a090',
|
||||
brightBlack: '#8a7a6a',
|
||||
brightRed: '#e07060',
|
||||
brightGreen: '#90b080',
|
||||
brightYellow: '#e0bb70',
|
||||
brightBlue: '#80a0c0',
|
||||
brightMagenta: '#c080a0',
|
||||
brightCyan: '#70b0a0',
|
||||
brightWhite: '#d0c0b0',
|
||||
};
|
||||
|
||||
// Sunset theme
|
||||
const sunsetTheme: TerminalTheme = {
|
||||
background: '#1e1a24',
|
||||
foreground: '#f2e8dd',
|
||||
cursor: '#dd8855',
|
||||
cursorAccent: '#1e1a24',
|
||||
selectionBackground: '#3a2a40',
|
||||
black: '#1e1a24',
|
||||
red: '#dd6655',
|
||||
green: '#88bb77',
|
||||
yellow: '#ddaa66',
|
||||
blue: '#6699cc',
|
||||
magenta: '#cc7799',
|
||||
cyan: '#66ccaa',
|
||||
white: '#e8d8c8',
|
||||
brightBlack: '#4a3a50',
|
||||
brightRed: '#ee8866',
|
||||
brightGreen: '#99cc88',
|
||||
brightYellow: '#eebb77',
|
||||
brightBlue: '#88aadd',
|
||||
brightMagenta: '#dd88aa',
|
||||
brightCyan: '#88ddbb',
|
||||
brightWhite: '#f5e8dd',
|
||||
};
|
||||
|
||||
// Gray theme
|
||||
const grayTheme: TerminalTheme = {
|
||||
background: '#2a2d32',
|
||||
foreground: '#d0d0d5',
|
||||
cursor: '#8fa0c0',
|
||||
cursorAccent: '#2a2d32',
|
||||
selectionBackground: '#3a3f48',
|
||||
black: '#2a2d32',
|
||||
red: '#d87070',
|
||||
green: '#78b088',
|
||||
yellow: '#d0b060',
|
||||
blue: '#7090c0',
|
||||
magenta: '#a880b0',
|
||||
cyan: '#60a0b0',
|
||||
white: '#b0b0b8',
|
||||
brightBlack: '#606068',
|
||||
brightRed: '#e88888',
|
||||
brightGreen: '#90c8a0',
|
||||
brightYellow: '#e0c878',
|
||||
brightBlue: '#90b0d8',
|
||||
brightMagenta: '#c098c8',
|
||||
brightCyan: '#80b8c8',
|
||||
brightWhite: '#e0e0e8',
|
||||
};
|
||||
|
||||
/**
|
||||
* Theme color mapping for all 40 themes
|
||||
*/
|
||||
export const terminalThemeColors: Record<ThemeMode, TerminalTheme> = {
|
||||
// Special
|
||||
system: darkTheme, // Resolved at runtime based on OS preference
|
||||
// Dark themes (16)
|
||||
dark: darkTheme,
|
||||
retro: retroTheme,
|
||||
dracula: draculaTheme,
|
||||
nord: nordTheme,
|
||||
monokai: monokaiTheme,
|
||||
tokyonight: tokyonightTheme,
|
||||
solarized: solarizedTheme,
|
||||
gruvbox: gruvboxTheme,
|
||||
catppuccin: catppuccinTheme,
|
||||
onedark: onedarkTheme,
|
||||
synthwave: synthwaveTheme,
|
||||
red: redTheme,
|
||||
sunset: sunsetTheme,
|
||||
gray: grayTheme,
|
||||
forest: gruvboxTheme, // Green-ish theme
|
||||
ocean: nordTheme, // Blue-ish theme
|
||||
ember: monokaiTheme, // Warm orange theme
|
||||
'ayu-dark': darkTheme,
|
||||
'ayu-mirage': darkTheme,
|
||||
matcha: nordTheme,
|
||||
// Light themes (16)
|
||||
light: lightTheme,
|
||||
cream: creamTheme,
|
||||
solarizedlight: lightTheme,
|
||||
github: lightTheme,
|
||||
paper: lightTheme,
|
||||
rose: lightTheme,
|
||||
mint: lightTheme,
|
||||
lavender: lightTheme,
|
||||
sand: creamTheme,
|
||||
sky: lightTheme,
|
||||
peach: creamTheme,
|
||||
snow: lightTheme,
|
||||
sepia: creamTheme,
|
||||
gruvboxlight: creamTheme,
|
||||
nordlight: lightTheme,
|
||||
blossom: lightTheme,
|
||||
'ayu-light': lightTheme,
|
||||
onelight: lightTheme,
|
||||
bluloco: lightTheme,
|
||||
feather: lightTheme,
|
||||
};
|
||||
|
||||
/**
|
||||
* Get terminal theme colors for a given theme mode
|
||||
*/
|
||||
export function getTerminalThemeColors(theme: ThemeMode): TerminalTheme {
|
||||
return terminalThemeColors[theme] || darkTheme;
|
||||
}
|
||||
@@ -140,9 +140,9 @@ const SUPPORTED_TERMINALS: TerminalDefinition[] = [
|
||||
{
|
||||
id: 'warp',
|
||||
name: 'Warp',
|
||||
cliCommand: 'warp',
|
||||
cliCommand: 'warp-cli',
|
||||
cliAliases: ['warp-terminal', 'warp'],
|
||||
macAppName: 'Warp',
|
||||
platform: 'darwin',
|
||||
},
|
||||
{
|
||||
id: 'ghostty',
|
||||
@@ -476,6 +476,11 @@ async function executeTerminalCommand(terminal: TerminalInfo, targetPath: string
|
||||
await spawnDetached(command, [`--working-directory=${targetPath}`]);
|
||||
break;
|
||||
|
||||
case 'warp':
|
||||
// Warp: uses --cwd flag (CLI mode, not app bundle)
|
||||
await spawnDetached(command, ['--cwd', targetPath]);
|
||||
break;
|
||||
|
||||
case 'alacritty':
|
||||
// Alacritty: uses --working-directory flag
|
||||
await spawnDetached(command, ['--working-directory', targetPath]);
|
||||
|
||||
100
libs/platform/tests/rc-file-manager.test.ts
Normal file
100
libs/platform/tests/rc-file-manager.test.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import { needsRegeneration, writeRcFiles } from '../src/rc-file-manager';
|
||||
import { terminalThemeColors } from '../src/terminal-theme-colors';
|
||||
import type { TerminalConfig } from '../src/rc-generator';
|
||||
import type { ThemeMode } from '@automaker/types';
|
||||
|
||||
describe('rc-file-manager.ts', () => {
|
||||
let tempDir: string;
|
||||
let projectPath: string;
|
||||
|
||||
const TEMP_DIR_PREFIX = 'platform-rc-files-test-';
|
||||
const PROJECT_DIR_NAME = 'test-project';
|
||||
const THEME_DARK = 'dark' as ThemeMode;
|
||||
const THEME_LIGHT = 'light' as ThemeMode;
|
||||
const PROMPT_FORMAT_STANDARD: TerminalConfig['promptFormat'] = 'standard';
|
||||
const PROMPT_FORMAT_MINIMAL: TerminalConfig['promptFormat'] = 'minimal';
|
||||
const EMPTY_ALIASES = '';
|
||||
const PATH_STYLE_FULL: TerminalConfig['pathStyle'] = 'full';
|
||||
const PATH_DEPTH_DEFAULT = 0;
|
||||
|
||||
const baseConfig: TerminalConfig = {
|
||||
enabled: true,
|
||||
customPrompt: true,
|
||||
promptFormat: PROMPT_FORMAT_STANDARD,
|
||||
showGitBranch: true,
|
||||
showGitStatus: true,
|
||||
showUserHost: true,
|
||||
showPath: true,
|
||||
pathStyle: PATH_STYLE_FULL,
|
||||
pathDepth: PATH_DEPTH_DEFAULT,
|
||||
showTime: false,
|
||||
showExitStatus: false,
|
||||
customAliases: EMPTY_ALIASES,
|
||||
customEnvVars: {},
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), TEMP_DIR_PREFIX));
|
||||
projectPath = path.join(tempDir, PROJECT_DIR_NAME);
|
||||
await fs.mkdir(projectPath, { recursive: true });
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
try {
|
||||
await fs.rm(tempDir, { recursive: true, force: true });
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
});
|
||||
|
||||
it('should not regenerate when signature matches', async () => {
|
||||
await writeRcFiles(
|
||||
projectPath,
|
||||
THEME_DARK,
|
||||
baseConfig,
|
||||
terminalThemeColors[THEME_DARK],
|
||||
terminalThemeColors
|
||||
);
|
||||
|
||||
const needsRegen = await needsRegeneration(projectPath, THEME_DARK, baseConfig);
|
||||
|
||||
expect(needsRegen).toBe(false);
|
||||
});
|
||||
|
||||
it('should regenerate when config changes', async () => {
|
||||
await writeRcFiles(
|
||||
projectPath,
|
||||
THEME_DARK,
|
||||
baseConfig,
|
||||
terminalThemeColors[THEME_DARK],
|
||||
terminalThemeColors
|
||||
);
|
||||
|
||||
const updatedConfig: TerminalConfig = {
|
||||
...baseConfig,
|
||||
promptFormat: PROMPT_FORMAT_MINIMAL,
|
||||
};
|
||||
|
||||
const needsRegen = await needsRegeneration(projectPath, THEME_DARK, updatedConfig);
|
||||
|
||||
expect(needsRegen).toBe(true);
|
||||
});
|
||||
|
||||
it('should regenerate when theme changes', async () => {
|
||||
await writeRcFiles(
|
||||
projectPath,
|
||||
THEME_DARK,
|
||||
baseConfig,
|
||||
terminalThemeColors[THEME_DARK],
|
||||
terminalThemeColors
|
||||
);
|
||||
|
||||
const needsRegen = await needsRegeneration(projectPath, THEME_LIGHT, baseConfig);
|
||||
|
||||
expect(needsRegen).toBe(true);
|
||||
});
|
||||
});
|
||||
55
libs/platform/tests/rc-generator.test.ts
Normal file
55
libs/platform/tests/rc-generator.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { generateCommonFunctions, generateThemeColors } from '../src/rc-generator';
|
||||
import { terminalThemeColors } from '../src/terminal-theme-colors';
|
||||
import type { TerminalConfig } from '../src/rc-generator';
|
||||
import type { ThemeMode } from '@automaker/types';
|
||||
|
||||
describe('rc-generator.ts', () => {
|
||||
const THEME_DARK = 'dark' as ThemeMode;
|
||||
const PROMPT_FORMAT_STANDARD: TerminalConfig['promptFormat'] = 'standard';
|
||||
const EMPTY_ALIASES = '';
|
||||
const EMPTY_ENV_VARS = {};
|
||||
const PATH_STYLE_FULL: TerminalConfig['pathStyle'] = 'full';
|
||||
const PATH_DEPTH_DEFAULT = 0;
|
||||
const EXPECTED_BANNER_FUNCTION = 'automaker_show_banner_once';
|
||||
const RAW_COLOR_PREFIX = 'export COLOR_USER_RAW=';
|
||||
const RAW_COLOR_ESCAPE_START = '\\\\[';
|
||||
const RAW_COLOR_ESCAPE_END = '\\\\]';
|
||||
const STARTUP_PRIMARY_COLOR = '38;5;51m';
|
||||
const STARTUP_SECONDARY_COLOR = '38;5;39m';
|
||||
const STARTUP_ACCENT_COLOR = '38;5;33m';
|
||||
|
||||
const baseConfig: TerminalConfig = {
|
||||
enabled: true,
|
||||
customPrompt: true,
|
||||
promptFormat: PROMPT_FORMAT_STANDARD,
|
||||
showGitBranch: true,
|
||||
showGitStatus: true,
|
||||
showUserHost: true,
|
||||
showPath: true,
|
||||
pathStyle: PATH_STYLE_FULL,
|
||||
pathDepth: PATH_DEPTH_DEFAULT,
|
||||
showTime: false,
|
||||
showExitStatus: false,
|
||||
customAliases: EMPTY_ALIASES,
|
||||
customEnvVars: EMPTY_ENV_VARS,
|
||||
};
|
||||
|
||||
it('includes banner functions in common shell script', () => {
|
||||
const output = generateCommonFunctions(baseConfig);
|
||||
|
||||
expect(output).toContain(EXPECTED_BANNER_FUNCTION);
|
||||
expect(output).toContain(STARTUP_PRIMARY_COLOR);
|
||||
expect(output).toContain(STARTUP_SECONDARY_COLOR);
|
||||
expect(output).toContain(STARTUP_ACCENT_COLOR);
|
||||
});
|
||||
|
||||
it('exports raw banner colors without prompt escape wrappers', () => {
|
||||
const output = generateThemeColors(terminalThemeColors[THEME_DARK]);
|
||||
const rawLine = output.split('\n').find((line) => line.startsWith(RAW_COLOR_PREFIX));
|
||||
|
||||
expect(rawLine).toBeDefined();
|
||||
expect(rawLine).not.toContain(RAW_COLOR_ESCAPE_START);
|
||||
expect(rawLine).not.toContain(RAW_COLOR_ESCAPE_END);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user