Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,4 @@ const runCommand = async (token: CommandToken): Promise<SuggestionBlob | undefin
],
charactersToDrop: token.tokenLength,
};
};
};
7 changes: 4 additions & 3 deletions src/ui/suggestionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { Shell } from "../utils/shell.js";
import log from "../utils/log.js";
import { getConfig } from "../utils/config.js";

const maxSuggestions = 5;
const getMaxSuggestions = () => 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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -190,4 +191,4 @@ export class SuggestionManager {
log.debug({ msg: "handled keypress", ...keyPress });
return true;
}
}
}
12 changes: 6 additions & 6 deletions src/ui/ui-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
});
};
};
7 changes: 7 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config = {
};
useAliases: boolean;
useNerdFont: boolean;
maxSuggestions?: number;
};

const bindingSchema: JSONSchemaType<Binding> = {
Expand Down Expand Up @@ -81,6 +82,11 @@ const configSchema = {
nullable: true,
default: false,
},
maxSuggestions: {
type: "number",
nullable: true,
default: 5,
}
},
additionalProperties: false,
};
Expand Down Expand Up @@ -133,6 +139,7 @@ export const loadConfig = async (program: Command) => {
},
useAliases: config.useAliases ?? false,
useNerdFont: config?.useNerdFont ?? false,
maxSuggestions: config?.maxSuggestions ?? 5,
};
}
});
Expand Down