Skip to content

Commit

Permalink
fix: suggestions when command wraps terminal (#226)
Browse files Browse the repository at this point in the history
* fix: suggestions when command wraps terminal

Signed-off-by: Chapman Pendery <[email protected]>

* style: fix lint

Signed-off-by: Chapman Pendery <[email protected]>

---------

Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Apr 8, 2024
1 parent 1b04467 commit 334f5b3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/isterm/commandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export class CommandManager {
let lineY = this.#activeCommand.promptEndMarker!.line;
let line = this.#terminal.buffer.active.getLine(this.#activeCommand.promptEndMarker!.line);
let command = "";
let wrappedCommand = "";
let suggestions = "";
let isWrapped = false;
for (;;) {
for (let i = lineY == this.#activeCommand.promptEndMarker!.line ? this.#activeCommand.promptText.length : 0; i < this.#terminal.cols; i++) {
if (command.endsWith(" ")) break; // assume that a command that ends with 4 spaces is terminated, avoids capturing right prompts
Expand All @@ -266,19 +268,27 @@ export class CommandManager {
const cleanedChars = chars == "" ? " " : chars;
if (!this._isSuggestion(cell) && suggestions.length == 0) {
command += cleanedChars;
wrappedCommand += cleanedChars;
} else {
suggestions += cleanedChars;
}
}
lineY += 1;
line = this.#terminal.buffer.active.getLine(lineY);
if (!line?.isWrapped) {

const wrapped = line?.isWrapped || this.#terminal.buffer.active.cursorY + this.#terminal.buffer.active.baseY != lineY - 1;
isWrapped = isWrapped || wrapped;

if (!wrapped) {
break;
}
wrappedCommand = "";
}

const cursorAtEndOfInput =
(this.#activeCommand.promptText.length + command.trimEnd().length) % this.#terminal.cols <= this.#terminal.buffer.active.cursorX;
const cursorAtEndOfInput = isWrapped
? wrappedCommand.trim().length % this.#terminal.cols <= this.#terminal.buffer.active.cursorX
: (this.#activeCommand.promptText.length + command.trimEnd().length) % this.#terminal.cols <= this.#terminal.buffer.active.cursorX;

let hasOutput = false;

let cell = undefined;
Expand All @@ -291,7 +301,11 @@ export class CommandManager {
}
}

const commandPostfix = this.#activeCommand.promptText.length + command.trimEnd().length < this.#terminal.buffer.active.cursorX ? " " : "";
const postfixActive = isWrapped
? wrappedCommand.trim().length < this.#terminal.buffer.active.cursorX
: this.#activeCommand.promptText.length + command.trimEnd().length < this.#terminal.buffer.active.cursorX;

const commandPostfix = postfixActive ? " " : "";
this.#activeCommand.persistentOutput = this.#activeCommand.hasOutput && hasOutput;
this.#activeCommand.hasOutput = hasOutput;
this.#activeCommand.suggestionsText = suggestions.trim();
Expand Down

0 comments on commit 334f5b3

Please sign in to comment.