diff --git a/README.md b/README.md index c99e22e..4571b77 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,16 @@ If you are using a [NerdFont](https://www.nerdfonts.com/) patched font, you can useNerdFont = true ``` +### Max Suggestions + +You can change the maximum number of suggestions displayed in the autocomplete list at one time in your config file: + + +```toml +maxSuggestions = 10 +``` + + ## Unsupported Specs Specs for the `az`, `gcloud`, & `aws` CLIs are not supported in inshellisense due to their large size. diff --git a/src/runtime/runtime.ts b/src/runtime/runtime.ts index 36e2b82..614a44b 100644 --- a/src/runtime/runtime.ts +++ b/src/runtime/runtime.ts @@ -399,4 +399,4 @@ const runCommand = async (token: CommandToken): Promise getConfig().maxSuggestions ?? 5; const suggestionWidth = 40; const descriptionWidth = 30; const descriptionHeight = 5; const borderWidth = 2; const activeSuggestionBackgroundColor = "#7D56F4"; -export const MAX_LINES = borderWidth + Math.max(maxSuggestions, descriptionHeight) + 1; // accounts when there is a unhandled newline at the end of the command +export const getMaxLines = () => borderWidth + Math.max(getMaxSuggestions(), descriptionHeight) + 1; // accounts when there is a unhandled newline at the end of the command export const MIN_WIDTH = borderWidth + descriptionWidth; export type KeyPressEvent = [string | null | undefined, KeyPress]; @@ -110,6 +110,7 @@ export class SuggestionManager { } const { suggestions, argumentDescription } = this.#suggestBlob; + const maxSuggestions = getMaxSuggestions(); const page = Math.min(Math.floor(this.#activeSuggestionIdx / maxSuggestions) + 1, Math.floor(suggestions.length / maxSuggestions) + 1); const pagedSuggestions = suggestions.filter((_, idx) => idx < page * maxSuggestions && idx >= (page - 1) * maxSuggestions); const activePagedSuggestionIndex = this.#activeSuggestionIdx % maxSuggestions; @@ -190,4 +191,4 @@ export class SuggestionManager { log.debug({ msg: "handled keypress", ...keyPress }); return true; } -} +} \ No newline at end of file diff --git a/src/ui/ui-root.ts b/src/ui/ui-root.ts index 8e66676..7fe56ae 100644 --- a/src/ui/ui-root.ts +++ b/src/ui/ui-root.ts @@ -9,7 +9,7 @@ import { Command } from "commander"; import log from "../utils/log.js"; import { getBackspaceSequence, Shell } from "../utils/shell.js"; import { enableWin32InputMode, resetToInitialState } from "../utils/ansi.js"; -import { MAX_LINES, type KeyPressEvent, type SuggestionManager } from "./suggestionManager.js"; +import { getMaxLines, type KeyPressEvent, type SuggestionManager } from "./suggestionManager.js"; import type { ISTerm } from "../isterm/pty.js"; import { v4 as uuidV4 } from "uuid"; @@ -30,7 +30,7 @@ const writeOutput = (data: string) => { const _render = (term: ISTerm, suggestionManager: SuggestionManager, data: string, handlingBackspace: boolean, handlingSuggestion: boolean): boolean => { const direction = _direction(term); const { hidden: cursorHidden, shift: cursorShift } = term.getCursorState(); - const linesOfInterest = MAX_LINES; + const linesOfInterest = getMaxLines(); const suggestion = suggestionManager.render(direction); const hasSuggestion = suggestion.length != 0; @@ -60,18 +60,18 @@ const _render = (term: ISTerm, suggestionManager: SuggestionManager, data: strin const _clear = (term: ISTerm): void => { const clearDirection = _direction(term) == "above" ? "below" : "above"; // invert direction to clear what was previously rendered const { hidden: cursorHidden } = term.getCursorState(); - const patch = term.getPatch(MAX_LINES, [], clearDirection); + const patch = term.getPatch(getMaxLines(), [], clearDirection); const ansiCursorShow = cursorHidden ? "" : ansi.cursorShow; if (clearDirection == "above") { - writeOutput(ansi.cursorHide + ansi.cursorSavePosition + ansi.cursorPrevLine.repeat(MAX_LINES) + patch + ansi.cursorRestorePosition + ansiCursorShow); + writeOutput(ansi.cursorHide + ansi.cursorSavePosition + ansi.cursorPrevLine.repeat(getMaxLines()) + patch + ansi.cursorRestorePosition + ansiCursorShow); } else { writeOutput(ansi.cursorHide + ansi.cursorSavePosition + ansi.cursorNextLine + patch + ansi.cursorRestorePosition + ansiCursorShow); } }; const _direction = (term: ISTerm): "above" | "below" => { - return term.getCursorState().remainingLines > MAX_LINES ? "below" : "above"; + return term.getCursorState().remainingLines > getMaxLines() ? "below" : "above"; }; export const render = async (program: Command, shell: Shell, underTest: boolean, login: boolean) => { @@ -140,4 +140,4 @@ export const render = async (program: Command, shell: Shell, underTest: boolean, process.stdout.on("resize", () => { term.resize(process.stdout.columns, process.stdout.rows); }); -}; +}; \ No newline at end of file diff --git a/src/utils/config.ts b/src/utils/config.ts index d9f7f43..b3fb170 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -31,6 +31,7 @@ type Config = { }; useAliases: boolean; useNerdFont: boolean; + maxSuggestions?: number; }; const bindingSchema: JSONSchemaType = { @@ -81,6 +82,11 @@ const configSchema = { nullable: true, default: false, }, + maxSuggestions: { + type: "number", + nullable: true, + default: 5, + } }, additionalProperties: false, }; @@ -133,6 +139,7 @@ export const loadConfig = async (program: Command) => { }, useAliases: config.useAliases ?? false, useNerdFont: config?.useNerdFont ?? false, + maxSuggestions: config?.maxSuggestions ?? 5, }; } });