mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 15:03:31 +00:00
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { Container, type SelectItem, SelectList } from "@mariozechner/pi-tui";
|
|
import { getAvailableThemes, getSelectListTheme } from "../theme/theme.js";
|
|
import { DynamicBorder } from "./dynamic-border.js";
|
|
|
|
/**
|
|
* Component that renders a theme selector
|
|
*/
|
|
export class ThemeSelectorComponent extends Container {
|
|
private selectList: SelectList;
|
|
private onPreview: (themeName: string) => void;
|
|
|
|
constructor(
|
|
currentTheme: string,
|
|
onSelect: (themeName: string) => void,
|
|
onCancel: () => void,
|
|
onPreview: (themeName: string) => void,
|
|
) {
|
|
super();
|
|
this.onPreview = onPreview;
|
|
|
|
// Get available themes and create select items
|
|
const themes = getAvailableThemes();
|
|
const themeItems: SelectItem[] = themes.map((name) => ({
|
|
value: name,
|
|
label: name,
|
|
description: name === currentTheme ? "(current)" : undefined,
|
|
}));
|
|
|
|
// Add top border
|
|
this.addChild(new DynamicBorder());
|
|
|
|
// Create selector
|
|
this.selectList = new SelectList(themeItems, 10, getSelectListTheme());
|
|
|
|
// Preselect current theme
|
|
const currentIndex = themes.indexOf(currentTheme);
|
|
if (currentIndex !== -1) {
|
|
this.selectList.setSelectedIndex(currentIndex);
|
|
}
|
|
|
|
this.selectList.onSelect = (item) => {
|
|
onSelect(item.value);
|
|
};
|
|
|
|
this.selectList.onCancel = () => {
|
|
onCancel();
|
|
};
|
|
|
|
this.selectList.onSelectionChange = (item) => {
|
|
this.onPreview(item.value);
|
|
};
|
|
|
|
this.addChild(this.selectList);
|
|
|
|
// Add bottom border
|
|
this.addChild(new DynamicBorder());
|
|
}
|
|
|
|
getSelectList(): SelectList {
|
|
return this.selectList;
|
|
}
|
|
}
|