Skip to content

Commit

Permalink
Chore (core): Use public getCursorPos method from the Readline (old r…
Browse files Browse the repository at this point in the history
…eadline didn't expose the method)
  • Loading branch information
SBoudrias committed Jul 28, 2023
1 parent 51c98b9 commit 08b0ab4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"figures": "^3.2.0",
"mute-stream": "^1.0.0",
"run-async": "^3.0.0",
"string-width": "^4.2.3",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^6.0.1"
},
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/lib/screen-manager.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import cliWidth from 'cli-width';
import stripAnsi from 'strip-ansi';
import stringWidth from 'string-width';
import ansiEscapes from 'ansi-escapes';
import { breakLines } from './utils.mjs';
import { InquirerReadline } from '../index.mjs';
Expand Down Expand Up @@ -39,7 +38,7 @@ export default class ScreenManager {
this.rl.setPrompt(prompt);

// SetPrompt will change cursor position, now we can get correct value
const cursorPos = (this.rl as any)._getCursorPos();
const cursorPos = this.rl.getCursorPos();
const width = cliWidth({ defaultWidth: 80, output: this.rl.output });

content = breakLines(content, width);
Expand Down Expand Up @@ -67,10 +66,8 @@ export default class ScreenManager {
// Return cursor to the input position (on top of the bottomContent)
if (bottomContentHeight > 0) output += ansiEscapes.cursorUp(bottomContentHeight);

// Move cursor at the start of the line, then return to the initial left offset.
const backward = stringWidth(lastLine(output));
if (backward > 0) output += ansiEscapes.cursorBackward(backward);
if (cursorPos.cols > 0) output += ansiEscapes.cursorForward(cursorPos.cols);
// Return cursor to the initial left offset.
output += ansiEscapes.cursorTo(cursorPos.cols);

/**
* Set up state for next re-rendering
Expand Down

0 comments on commit 08b0ab4

Please sign in to comment.