Skip to content

feat(cli/unstable): Introduce StaticLine#6758

Merged
kt3k merged 32 commits intodenoland:mainfrom
BlackAsLight:ansi_static_line
Feb 16, 2026
Merged

feat(cli/unstable): Introduce StaticLine#6758
kt3k merged 32 commits intodenoland:mainfrom
BlackAsLight:ansi_static_line

Conversation

@BlackAsLight
Copy link
Contributor

@BlackAsLight BlackAsLight commented Jul 9, 2025

Read (#6755) for an overview.

#6756 should be merged before this.

This class uses the scrollable region Ansi code to allow scrolling content to not overwrite lines at the top and bottom of the terminal. It is meant to provide a foundation for anyone looking to easily have a line at the bottom or top of the terminal.

import { delay } from "@std/async/delay";
import { StaticLine } from "@std/cli/unstable-static-line";

const id = setInterval(() => console.log(Math.random()), 1000);

const line = new StaticLine();
await line.write("Hello World!");
await delay(1500);
await line.write("How are you?");
await delay(1500);
await line.write("Doing good?");
await delay(1500);
await line.releaseLine();

No tests as of yet have been written for this class as I am not sure how to write unit tests to test its behaviour.

@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
@codecov
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (4db142b) to head (1caadfb).
⚠️ Report is 157 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6758   +/-   ##
=======================================
  Coverage   94.15%   94.16%           
=======================================
  Files         587      587           
  Lines       42514    42514           
  Branches     6712     6712           
=======================================
+ Hits        40030    40034    +4     
+ Misses       2433     2431    -2     
+ Partials       51       49    -2     

☔ 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 askForCursorPositionSync feat(cli): Introduce StaticLine Jul 11, 2025
@BlackAsLight
Copy link
Contributor Author

Example

import { delay } from "@std/async/delay";
const id = setInterval(() => console.log(Math.random()), 1000);

for (let i = 0; i < 20; ++i) {
  const line = new StaticLine();
  await line.write(`Line (${i}): Placeholder!`);
  const id = setInterval(
    () => line.write(`Line (${i}): ${Math.random()}`),
    Math.random() * 3000 + 1000,
  );
  setTimeout(() => {
    clearInterval(id);
    line.releaseLine();
  }, Math.random() * 5_000 + 25_000);
  await delay(Math.random() * 1000 + 1000);
}

await delay(30_000);
clearInterval(id);
Screen.Recording.2025-07-11.at.21.14.31.mp4

@kt3k
Copy link
Member

kt3k commented Jul 22, 2025

Can you provide some real-world example (cli/library/whatever) in which this type of output is used?

Also does this type of abstraction have prior example?

@BlackAsLight
Copy link
Contributor Author

BlackAsLight commented Jul 22, 2025

Can you provide some real-world example (cli/library/whatever) in which this type of output is used?

Also does this type of abstraction have prior example?

I don't know of any real world examples, but as I learn more and more about ANSI escape sequences it is becoming apparent just how unreliable terminals can be.

This type, or some type, of abstraction is needed to "reliably" support multiple spinners and progress bars at once. As request here: #5037. The word reliably is doing a lot of heavy lifting here as any other area that starts inserting sequences can screw this all up.

If we want something truely robust, we'll need to offer some type of complete abstraction away from ansi codes. A framework so to say that isn't merely offering small functions here and there, but that specifies the entire state and keeps track of it all.

Very little of the terminals state can actually be asked or looked up from the terminal itself. Much of these settings and modes must be remembered in code to know if it's enabled or disabled. With the sync functions this isn't really a problem as you can't have random console logs from other areas screwing everything up by sending their own sequences, but with the spinner and progress bar and any other functionality that allows other code to run, allows for the state to be screwed up.

@tomas-zijdemans
Copy link
Contributor

I support this change, it's a good step forwards and allows us to rewrite Spinner, ProgressBar, and possibly other functions on top of it. I would suggest to:

  • make it internal, _static_line.ts ?
  • add tests
  • consider using Deno.stderr.writeSync instead of Deno.stderr.write. Like Spinner does it.

@kt3k kt3k changed the title feat(cli): Introduce StaticLine feat(cli/unstable): Introduce StaticLine Feb 16, 2026
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. let's try this module

sorry for the delay in review!

@kt3k kt3k merged commit ebb9e4d into denoland:main Feb 16, 2026
20 checks passed
@BlackAsLight BlackAsLight deleted the ansi_static_line branch February 16, 2026 06:15
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.

3 participants