Skip to content

Commit dc0ba78

Browse files
committed
bug fixes and & update readme
1 parent 9139ead commit dc0ba78

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ If you are using a [NerdFont](https://www.nerdfonts.com/) patched font, you can
136136
useNerdFont = true
137137
```
138138

139+
### Max Suggestions
140+
141+
You can change the maximum number of suggestions displayed in the autocomplete list at one time in your config file:
142+
143+
144+
```toml
145+
maxSuggestions = 10
146+
```
147+
148+
139149
## Unsupported Specs
140150

141151
Specs for the `az`, `gcloud`, & `aws` CLIs are not supported in inshellisense due to their large size.

src/ui/suggestionManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { Shell } from "../utils/shell.js";
1010
import log from "../utils/log.js";
1111
import { getConfig } from "../utils/config.js";
1212

13-
const maxSuggestions = getConfig().maxSuggestions ?? 5;
13+
const getMaxSuggestions = () => getConfig().maxSuggestions ?? 5;
1414
const suggestionWidth = 40;
1515
const descriptionWidth = 30;
1616
const descriptionHeight = 5;
1717
const borderWidth = 2;
1818
const activeSuggestionBackgroundColor = "#7D56F4";
19-
export const MAX_LINES = borderWidth + Math.max(maxSuggestions, descriptionHeight) + 1; // accounts when there is a unhandled newline at the end of the command
19+
export const getMaxLines = () => borderWidth + Math.max(getMaxSuggestions(), descriptionHeight) + 1; // accounts when there is a unhandled newline at the end of the command
2020
export const MIN_WIDTH = borderWidth + descriptionWidth;
2121

2222
export type KeyPressEvent = [string | null | undefined, KeyPress];
@@ -110,6 +110,7 @@ export class SuggestionManager {
110110
}
111111
const { suggestions, argumentDescription } = this.#suggestBlob;
112112

113+
const maxSuggestions = getMaxSuggestions();
113114
const page = Math.min(Math.floor(this.#activeSuggestionIdx / maxSuggestions) + 1, Math.floor(suggestions.length / maxSuggestions) + 1);
114115
const pagedSuggestions = suggestions.filter((_, idx) => idx < page * maxSuggestions && idx >= (page - 1) * maxSuggestions);
115116
const activePagedSuggestionIndex = this.#activeSuggestionIdx % maxSuggestions;

src/ui/ui-root.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Command } from "commander";
99
import log from "../utils/log.js";
1010
import { getBackspaceSequence, Shell } from "../utils/shell.js";
1111
import { enableWin32InputMode, resetToInitialState } from "../utils/ansi.js";
12-
import { MAX_LINES, type KeyPressEvent, type SuggestionManager } from "./suggestionManager.js";
12+
import { getMaxLines, type KeyPressEvent, type SuggestionManager } from "./suggestionManager.js";
1313
import type { ISTerm } from "../isterm/pty.js";
1414
import { v4 as uuidV4 } from "uuid";
1515

@@ -30,7 +30,7 @@ const writeOutput = (data: string) => {
3030
const _render = (term: ISTerm, suggestionManager: SuggestionManager, data: string, handlingBackspace: boolean, handlingSuggestion: boolean): boolean => {
3131
const direction = _direction(term);
3232
const { hidden: cursorHidden, shift: cursorShift } = term.getCursorState();
33-
const linesOfInterest = MAX_LINES;
33+
const linesOfInterest = getMaxLines();
3434

3535
const suggestion = suggestionManager.render(direction);
3636
const hasSuggestion = suggestion.length != 0;
@@ -60,18 +60,18 @@ const _render = (term: ISTerm, suggestionManager: SuggestionManager, data: strin
6060
const _clear = (term: ISTerm): void => {
6161
const clearDirection = _direction(term) == "above" ? "below" : "above"; // invert direction to clear what was previously rendered
6262
const { hidden: cursorHidden } = term.getCursorState();
63-
const patch = term.getPatch(MAX_LINES, [], clearDirection);
63+
const patch = term.getPatch(getMaxLines(), [], clearDirection);
6464

6565
const ansiCursorShow = cursorHidden ? "" : ansi.cursorShow;
6666
if (clearDirection == "above") {
67-
writeOutput(ansi.cursorHide + ansi.cursorSavePosition + ansi.cursorPrevLine.repeat(MAX_LINES) + patch + ansi.cursorRestorePosition + ansiCursorShow);
67+
writeOutput(ansi.cursorHide + ansi.cursorSavePosition + ansi.cursorPrevLine.repeat(getMaxLines()) + patch + ansi.cursorRestorePosition + ansiCursorShow);
6868
} else {
6969
writeOutput(ansi.cursorHide + ansi.cursorSavePosition + ansi.cursorNextLine + patch + ansi.cursorRestorePosition + ansiCursorShow);
7070
}
7171
};
7272

7373
const _direction = (term: ISTerm): "above" | "below" => {
74-
return term.getCursorState().remainingLines > MAX_LINES ? "below" : "above";
74+
return term.getCursorState().remainingLines > getMaxLines() ? "below" : "above";
7575
};
7676

7777
export const render = async (program: Command, shell: Shell, underTest: boolean, login: boolean) => {

0 commit comments

Comments
 (0)