diff --git a/lib/LocalEchoController.js b/lib/LocalEchoController.js index b2212a2..93ce84d 100644 --- a/lib/LocalEchoController.js +++ b/lib/LocalEchoController.js @@ -1,3 +1,4 @@ +import ansiRegex from "ansi-regex"; import { HistoryController } from "./HistoryController"; import { closestLeftBoundary, @@ -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; } /** diff --git a/lib/Utils.js b/lib/Utils.js index 6d4f103..c4096f4 100644 --- a/lib/Utils.js +++ b/lib/Utils.js @@ -1,3 +1,4 @@ +import ansiRegex from "ansi-regex"; import { parse } from "shell-quote"; /** @@ -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; } /** diff --git a/package.json b/package.json index 1cd9331..4e21dc1 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ } }, "dependencies": { + "ansi-regex": "^6.0.1", "shell-quote": "^1.6.1" } }