Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExecuteHostCommand & current line buffer usage #423

Open
RustyJoeM opened this issue May 8, 2022 · 4 comments
Open

ExecuteHostCommand & current line buffer usage #423

RustyJoeM opened this issue May 8, 2022 · 4 comments
Labels
A-API Area: Changes to the consumer facing API A-Events Area: Handling of incoming events (e.g. desired keypress not registered) enhancement New feature or request

Comments

@RustyJoeM
Copy link

RustyJoeM commented May 8, 2022

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 reedline together with clap crate in REPL mode
    (clap's try_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 its Command/Subcommand types
@RustyJoeM RustyJoeM added the enhancement New feature or request label May 8, 2022
@fdncred
Copy link
Collaborator

fdncred commented May 8, 2022

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.

@sholderbach
Copy link
Member

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:

  1. Yield from Reedline::read_line with more different signals and recall the same Reedline object 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))
  2. attach closures as callbacks that get the current line buffer and return a new line buffer (for the case where that is relevant).

@RustyJoeM
Copy link
Author

RustyJoeM commented May 8, 2022

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 :)

@sholderbach
Copy link
Member

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 (nushell/nushell#6492)

@sholderbach sholderbach added A-Events Area: Handling of incoming events (e.g. desired keypress not registered) A-API Area: Changes to the consumer facing API labels Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-API Area: Changes to the consumer facing API A-Events Area: Handling of incoming events (e.g. desired keypress not registered) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants