Merge pull request #4243 from samjonester/samjonester/config-selector-dynamic-height
config selector: scale maxVisible to terminal height
This commit is contained in:
@@ -43,6 +43,7 @@ export async function selectConfig(options: ConfigSelectorOptions): Promise<void
|
||||
process.exit(0);
|
||||
},
|
||||
() => ui.requestRender(),
|
||||
ui.terminal.rows,
|
||||
);
|
||||
|
||||
ui.addChild(selector);
|
||||
|
||||
@@ -201,7 +201,7 @@ class ResourceList implements Component, Focusable {
|
||||
private filteredItems: FlatEntry[] = [];
|
||||
private selectedIndex = 0;
|
||||
private searchInput: Input;
|
||||
private maxVisible = 15;
|
||||
private maxVisible: number;
|
||||
private settingsManager: SettingsManager;
|
||||
private cwd: string;
|
||||
private agentDir: string;
|
||||
@@ -219,12 +219,21 @@ class ResourceList implements Component, Focusable {
|
||||
this.searchInput.focused = value;
|
||||
}
|
||||
|
||||
constructor(groups: ResourceGroup[], settingsManager: SettingsManager, cwd: string, agentDir: string) {
|
||||
constructor(
|
||||
groups: ResourceGroup[],
|
||||
settingsManager: SettingsManager,
|
||||
cwd: string,
|
||||
agentDir: string,
|
||||
terminalHeight?: number,
|
||||
) {
|
||||
this.groups = groups;
|
||||
this.settingsManager = settingsManager;
|
||||
this.cwd = cwd;
|
||||
this.agentDir = agentDir;
|
||||
this.searchInput = new Input();
|
||||
// 8 lines of chrome: top spacer + top border + spacer + header (2 lines) + spacer + bottom spacer + bottom border
|
||||
const chrome = 8;
|
||||
this.maxVisible = Math.max(5, (terminalHeight ?? 24) - chrome);
|
||||
this.buildFlatList();
|
||||
this.filteredItems = [...this.flatItems];
|
||||
}
|
||||
@@ -588,6 +597,7 @@ export class ConfigSelectorComponent extends Container implements Focusable {
|
||||
onClose: () => void,
|
||||
onExit: () => void,
|
||||
requestRender: () => void,
|
||||
terminalHeight?: number,
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -601,7 +611,7 @@ export class ConfigSelectorComponent extends Container implements Focusable {
|
||||
this.addChild(new Spacer(1));
|
||||
|
||||
// Resource list
|
||||
this.resourceList = new ResourceList(groups, settingsManager, cwd, agentDir);
|
||||
this.resourceList = new ResourceList(groups, settingsManager, cwd, agentDir, terminalHeight);
|
||||
this.resourceList.onCancel = onClose;
|
||||
this.resourceList.onExit = onExit;
|
||||
this.resourceList.onToggle = () => requestRender();
|
||||
|
||||
Reference in New Issue
Block a user