Skip to content

Proof of concept: concurrent progress bars#819

Merged
gaborcsardi merged 9 commits into
r-lib:mainfrom
simonpcouch:multi
May 20, 2026
Merged

Proof of concept: concurrent progress bars#819
gaborcsardi merged 9 commits into
r-lib:mainfrom
simonpcouch:multi

Conversation

@simonpcouch
Copy link
Copy Markdown
Contributor

Related to #818. Largely vibe-coded and not intended to be merged--just a proof of concept.

A simple example in Positron:

pkgload::load_all()
options(cli.ansi = TRUE, cli.progress_show_after = 0)

fun <- function() {
  id1 <- cli_progress_bar("Downloads ", total = 20, current = FALSE, clear = FALSE)
  id2 <- cli_progress_bar("Processing", total = 20, current = FALSE, clear = FALSE)
  for (i in 1:20) {
    Sys.sleep(0.15)
    cli_progress_update(id = id1)
    Sys.sleep(0.15)
    cli_progress_update(id = id2)
  }
}
fun()
simple-concurrent-progress-bars.mov

@simonpcouch
Copy link
Copy Markdown
Contributor Author

Noting that, via this entry point, this is only possible in Positron (and not RStudio).

@gaborcsardi
Copy link
Copy Markdown
Member

Cool, so the R console in Positron now supports ANSI control sequences? All of them? How does one learn about this? How could we detect this?

@simonpcouch
Copy link
Copy Markdown
Contributor Author

Okay, just did some exploration. Positron's R console uses a custom ANSI renderer.

It supports:

  • Cursor movement: \033[A (up), \033[B (down), \033[C (forward), \033[D (backward), \033[H (absolute position)
  • Line erasing: \033[K (to end), \033[2K (whole line)
  • Display erasing: \033[J / \033[2J
  • Carriage return: \r
  • Full SGR: colors (16/256/truecolor), bold, italic, etc.
  • Hyperlinks: OSC 8

These ones are not supported (silently consumed):

  • \033[?25l / \033[?25h (hide/show cursor)
  • Scroll regions, insert/delete line, save/restore cursor, alternate screen buffer

The needed biys were all present in the earliest commit to that file, in October 2023 (aeef2f28). This was before Sys.getenv("POSITRON") was introduced (July 2024), so anywhere Sys.getenv("POSITRON") == "1" is present should have those sequences.

@gaborcsardi
Copy link
Copy Markdown
Member

so anywhere Sys.getenv("POSITRON") == "1" is present should have those sequences.

I am afraid that's probably not true, because env vars are inherited, so e.g. a job in the job pane will have POSITRON=1, or even just a plain subprocess will also have it.

@gaborcsardi
Copy link
Copy Markdown
Member

This is probably unique to Positron, though:

> .Platform$GUI
[1] "Positron"

Copy link
Copy Markdown
Member

@gaborcsardi gaborcsardi left a comment

Choose a reason for hiding this comment

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

Can you write some summary about how this actually works? E.g. why do we need status_bar_lines (isn't that the length of status_bar?), what is status_bar_prev_content, etc?
Never mind, I understand it now.

We'll probably also need an opt-out mechanism, but we can do that later.

Comment thread R/status-bar.R Outdated
@gaborcsardi
Copy link
Copy Markdown
Member

One thing I am not sure about is whether this should apply to status bars. (Which maybe nobody uses...) A status bar is just one line, even in a GUI.

Also add an `R_CLI_ANSI` env var.
On Windows a subprocess will have `is_ansi_tty() = TRUE` now
if the main process is running in a terminal. That's the price
for supporting ANSI constrol sequences on Windows.

We'll see if we need an update for this later.
@gaborcsardi
Copy link
Copy Markdown
Member

@simonpcouch Thanks for the great PR!

@gaborcsardi gaborcsardi merged commit 33c9c7b into r-lib:main May 20, 2026
13 checks passed
@simonpcouch
Copy link
Copy Markdown
Contributor Author

Awesome, thanks for sprucing this up! Excited to have this in.

@simonpcouch simonpcouch deleted the multi branch May 20, 2026 12:40
gaborcsardi added a commit that referenced this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants