Skip to content

feat(cli): Introduce askForCursorPositionSync #6757

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

BlackAsLight
Copy link
Contributor

@BlackAsLight BlackAsLight commented Jul 9, 2025

Read (#6755) for an overview.

#6756 should be merged before this.

This function asks the terminal for the current position of the cursor. It is sync to prevent race conditions and its contents in complex in the hopes to guarantee reading the terminals response. It should not be used frequently as it does seem to introduce a noticeable delay, but in rare times the exact position of the cursor needs to be asked for.

This example is how it can be used but honestly using Ansi.saveCursorPosition and Ansi.restoreCursorPosition would have been much better and reliable.

import { Ansi } from "@std/cli/unstable-ansi";
import { askForCursorPositionSync } from "@std/cli/unstable-get-cursor";

const { column, row } = askForCursorPositionSync()!;
await Deno.stderr.write(new TextEncoder().encode(
  Ansi.setCursorPosition() +
    "Hello World!" +
    Ansi.setCursorPosition(row, column),
));

No tests as of yet have been written for this class as I don't know how to reliably check that its cursor position hasn't changed between writing and reading, especially with all the other tests also writing to the terminal.

@BlackAsLight BlackAsLight requested a review from kt3k as a code owner July 9, 2025 10:57
@github-actions github-actions bot added the cli label Jul 9, 2025
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.15%. Comparing base (fc59ca6) to head (f95ff2d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6757   +/-   ##
=======================================
  Coverage   94.14%   94.15%           
=======================================
  Files         586      586           
  Lines       42465    42465           
  Branches     6701     6701           
=======================================
+ Hits        39980    39983    +3     
+ Misses       2435     2433    -2     
+ Partials       50       49    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BlackAsLight BlackAsLight changed the title feat(cli): Introduce StaticLine feat(cli): Introduce askForCursorPositionSync Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant