MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / SettingsList

Class SettingsList

packages/pi-tui/src/components/settings-list.ts:34–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34export class SettingsList implements Component {
35 private items: SettingItem[];
36 private filteredItems: SettingItem[];
37 private theme: SettingsListTheme;
38 private selectedIndex = 0;
39 private maxVisible: number;
40 private onChange: (id: string, newValue: string) => void;
41 private onCancel: () => void;
42 private searchInput?: Input;
43 private searchEnabled: boolean;
44
45 // Submenu state
46 private submenuComponent: Component | null = null;
47 private submenuItemIndex: number | null = null;
48
49 constructor(
50 items: SettingItem[],
51 maxVisible: number,
52 theme: SettingsListTheme,
53 onChange: (id: string, newValue: string) => void,
54 onCancel: () => void,
55 options: SettingsListOptions = {},
56 ) {
57 this.items = items;
58 this.filteredItems = items;
59 this.maxVisible = maxVisible;
60 this.theme = theme;
61 this.onChange = onChange;
62 this.onCancel = onCancel;
63 this.searchEnabled = options.enableSearch ?? false;
64 if (this.searchEnabled) {
65 this.searchInput = new Input();
66 }
67 }
68
69 /** Update an item's currentValue */
70 updateValue(id: string, newValue: string): void {
71 const item = this.items.find((i) => i.id === id);
72 if (item) {
73 item.currentValue = newValue;
74 }
75 }
76
77 invalidate(): void {
78 this.submenuComponent?.invalidate?.();
79 }
80
81 render(width: number): string[] {
82 // If submenu is active, render it instead
83 if (this.submenuComponent) {
84 return this.submenuComponent.render(width);
85 }
86
87 return this.renderMainList(width);
88 }
89
90 private renderMainList(width: number): string[] {
91 const lines: string[] = [];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected