58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import type { Effort } from "@oh-my-pi/pi-ai";
|
|
import { Container, type SelectItem, SelectList, type SgrMouseEvent } from "@oh-my-pi/pi-tui";
|
|
import { getSelectListTheme } from "../../modes/theme/theme";
|
|
import { getThinkingLevelMetadata } from "../../thinking";
|
|
import { DynamicBorder } from "./dynamic-border";
|
|
import { routeSelectListMouseWithTopBorder } from "./select-list-mouse-routing";
|
|
|
|
/**
|
|
* Component that renders a thinking level selector with borders
|
|
*/
|
|
export class ThinkingSelectorComponent extends Container {
|
|
#selectList: SelectList;
|
|
|
|
constructor(
|
|
currentLevel: Effort,
|
|
availableLevels: Effort[],
|
|
onSelect: (level: Effort) => void,
|
|
onCancel: () => void,
|
|
) {
|
|
super();
|
|
|
|
const thinkingLevels: SelectItem[] = availableLevels.map(getThinkingLevelMetadata);
|
|
|
|
// Add top border
|
|
this.addChild(new DynamicBorder());
|
|
|
|
// Create selector
|
|
this.#selectList = new SelectList(thinkingLevels, thinkingLevels.length, getSelectListTheme());
|
|
|
|
// Preselect current level
|
|
const currentIndex = thinkingLevels.findIndex(item => item.value === currentLevel);
|
|
if (currentIndex !== -1) {
|
|
this.#selectList.setSelectedIndex(currentIndex);
|
|
}
|
|
|
|
this.#selectList.onSelect = item => {
|
|
onSelect(item.value as Effort);
|
|
};
|
|
|
|
this.#selectList.onCancel = () => {
|
|
onCancel();
|
|
};
|
|
|
|
this.addChild(this.#selectList);
|
|
|
|
// Add bottom border
|
|
this.addChild(new DynamicBorder());
|
|
}
|
|
|
|
getSelectList(): SelectList {
|
|
return this.#selectList;
|
|
}
|
|
|
|
routeMouse(event: SgrMouseEvent, line: number, col: number): void {
|
|
routeSelectListMouseWithTopBorder(this.#selectList, event, line, col);
|
|
}
|
|
}
|