ExecuteHostCommand & current line buffer usage
Hello,
is it possible to use the immediate contents of the line buffer inside of ReedlineEvent::ExecuteHostCommand when keybinding is used?
Not sure if using API is appropriate for this use-case:
User:
- types some command into CLI, e.g.:
hello --address - presses keybinding e.g. SHIFT + '?'
- keybinding:
- does NOT edit the pendign line itself
- executes host-command that includes the line being written, e.g.
help hello --address - keeps the pending line without any change for firther editing (if applicable)
Is above possible either via keybinding declaration & it's command parameter, or other approach?
Explanation:
- I am using
reedlinetogether withclapcrate in REPL mode (clap'stry_parse_from()insterad of from building from env on binary execution) - Above behavior might greatly complement
clap's ability to provide extensive & automatic help sub-commands that typically come "free" with itsCommand/Subcommandtypes
We've talked about something like this and would probably welcome a PR but maybe it should be a separate command like ReedlineEvent::ExecuteHostCommandReturnResult or so that we can still keep the existing functionality of ExecuteHostCommand.
Yeah it would be great to have more options to hook in there (like using an external comamnd to fill the line buffer with certain content as well). There might be two options to approach this API wise:
- Yield from
Reedline::read_linewith more different signals and recall the sameReedlineobject with a specific method. (Less ownership hassle, having to take care that the editor resumes operation correctly after the external command (that might try to write to the terminal itself)) - attach closures as callbacks that get the current line buffer and return a new line buffer (for the case where that is relevant).
Would be happy to help, though an attempt of PR is far beyond my current Rust skill level...
After an hour of putting together the new enum variant like ExecuteHostCommandWithBuffer(Box<dyn FnOnce(String) -> String + Sync>), i crash into more errors and google mentioning needing Arc to pass closure around.
As there is no similar behavior for any of ReedlineEvent's, i dare not add tons of new "magical words" into the lib's core enum not knowing whether i go into right direction at all :)
We landed some facilities to enable that with #472. Let us know if this API helps you out in this situation. On the nushell side we use this to implement line buffer editing commands via the commandline command (https://github.com/nushell/nushell/pull/6492)