Skip to content

feat: new feature idle_callback to allow to set callback function while waiting for input#1015

Merged
fdncred merged 3 commits intonushell:mainfrom
eitsupi:feat/idle-callback
Feb 6, 2026
Merged

feat: new feature idle_callback to allow to set callback function while waiting for input#1015
fdncred merged 3 commits intonushell:mainfrom
eitsupi:feat/idle-callback

Conversation

@eitsupi
Copy link
Copy Markdown
Contributor

@eitsupi eitsupi commented Jan 20, 2026

Add an idle_callback feature that allows applications to register a callback function that is invoked periodically while waiting for user input.

Some applications need to perform periodic work while the editor is waiting for input. Examples include:

  • Processing GUI/window events for embedded graphical applications
  • Updating progress indicators or spinners
  • Handling background timers or scheduled tasks
  • Processing events from external systems

Currently, read_line() blocks until input arrives, making it impossible to handle such periodic tasks.
This feature provides a simple opt-in mechanism for applications that need this capability.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Jan 20, 2026

This sounds cool! How do you plan on using this functionality?

@eitsupi
Copy link
Copy Markdown
Contributor Author

eitsupi commented Jan 21, 2026

How do you plan on using this functionality?

Thank you for taking a look at this.
I was testing an R console app I'm developing that isn't released yet and I noticed a problem.

Without this feature, the R graphics device wouldn't accept any operations, and I couldn't delete or resize the plot window.

plot

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Jan 30, 2026

@ysthakur Do you see any problems here? I think I'm ok with it as it's adding a feature and I don't see any breaking changes. I'm thinking this may be good if we can hook into it with nushell for keeping a git prompt fresh.

@eitsupi
Copy link
Copy Markdown
Contributor Author

eitsupi commented Jan 30, 2026

By the way, here is a working example of this branch.
https://github.com/eitsupi/arf

src/engine.rs Outdated
// We need polling if external_printer or idle_callback is configured.
#[cfg(all(feature = "external_printer", feature = "idle_callback"))]
let poll_config = match (&self.external_printer, &self.idle_callback) {
(Some(_), _) => Some(EXTERNAL_PRINTER_WAIT),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like this means that even if you set an idle callback with its own interval, that internal will be overridden by EXTERNAL_PRINTER_WAIT. I think that's confusing behavior.

I'd prefer it if we had a separate, shared poll_interval setting that was used for both the external printer and idle callback (it can default to what's currently EXTERNAL_PRINTER_WAIT). If neither external printer nor idle callback are set, the poll interval can just be ignored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, how about 00ed995?

@ysthakur
Copy link
Copy Markdown
Member

ysthakur commented Feb 6, 2026

@fdncred It looks fine to me (besides the comment about an interval setting above), but I'm not qualified to review this. I think asking Stefan would be best.

That said, it's a very small change (love how simple this is btw) and I don't think it would break existing functionality even if the idle callback functionality ships with problems.


Outside the scope of this PR, but we really need a way to write proper tests for Reedline

@ysthakur
Copy link
Copy Markdown
Member

ysthakur commented Feb 6, 2026

@sholderbach If you have time, could you see if this change looks alright to you? I'm not sure if there are any edge cases to be concerned about with the interplay between this feature and external printers

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Feb 6, 2026

ya, generally this looks ok to me, one question i had above. Also, reedline has changed quite significantly in the last 24 hours so there are conflict and we'd need to make sure it still works as designed. Probably a good idea to rebase on the latest main.

@fdncred fdncred merged commit 5d2c4fa into nushell:main Feb 6, 2026
6 checks passed
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Feb 6, 2026

Thanks

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.

3 participants