feat: new feature idle_callback to allow to set callback function while waiting for input#1015
Conversation
…le waiting for input
|
This sounds cool! How do you plan on using this functionality? |
Thank you for taking a look at this. Without this feature, the R graphics device wouldn't accept any operations, and I couldn't delete or resize the plot window. |
|
@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. |
|
By the way, here is a working example of this branch. |
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), |
There was a problem hiding this comment.
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.
|
@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 |
|
@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 |
|
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. |
# Conflicts: # src/engine.rs
|
Thanks |

Add an
idle_callbackfeature 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:
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.