Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
1.5 kB · 59 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import { Container, type SelectItem, SelectList, type SelectListLayoutOptions } from "@earendil-works/pi-tui";import { getAvailableThemes, getSelectListTheme } from "../theme/theme.js";import { DynamicBorder } from "./dynamic-border.js";
const THEME_SELECT_LIST_LAYOUT: SelectListLayoutOptions = { minPrimaryColumnWidth: 12, maxPrimaryColumnWidth: 32,};
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;
const themes = getAvailableThemes(); const themeItems: SelectItem[] = themes.map((name) => ({ value: name, label: name, description: name === currentTheme ? "(current)" : undefined, }));
this.addChild(new DynamicBorder());
this.selectList = new SelectList(themeItems, 10, getSelectListTheme(), THEME_SELECT_LIST_LAYOUT);
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);
this.addChild(new DynamicBorder()); }
getSelectList(): SelectList { return this.selectList; }}