Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ANSI escape sequences offsetting cursor #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion lib/LocalEchoController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ansiRegex from "ansi-regex";
import { HistoryController } from "./HistoryController";
import {
closestLeftBoundary,
Expand Down Expand Up @@ -234,7 +235,7 @@ export default class LocalEchoController {
*/
applyPromptOffset(input, offset) {
const newInput = this.applyPrompts(input.substr(0, offset));
return newInput.length;
return newInput.replace(ansiRegex(), "").length;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ansiRegex from "ansi-regex";
import { parse } from "shell-quote";

/**
Expand Down Expand Up @@ -65,7 +66,7 @@ export function offsetToColRow(input, offset, maxCols) {
* Counts the lines in the given input
*/
export function countLines(input, maxCols) {
return offsetToColRow(input, input.length, maxCols).row + 1;
return offsetToColRow(input, input.replace(ansiRegex(), "").length, maxCols).row + 1;
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
}
},
"dependencies": {
"ansi-regex": "^6.0.1",
"shell-quote": "^1.6.1"
}
}