rustyline icon indicating copy to clipboard operation
rustyline copied to clipboard

mutable `Helper` in functions

Open zao111222333 opened this issue 1 year ago • 6 comments

See https://github.com/gwenn/rustyline/pull/4 And I add a new example/bracket_parser.rs to demo Parser trait. bracket_parser

btw, rightnow I have no idea how to represent change: InputEdit.

zao111222333 avatar Oct 05 '24 09:10 zao111222333

Thank you for all your proposals. But please only one feature at a time: either mut Helper or Parser but not both in the same PR.

gwenn avatar Oct 05 '24 09:10 gwenn

See https://github.com/kkawakam/rustyline/blob/ceafb7f8057974201d0e76ac9fc7aaac3998a048/src/undo.rs#L9 for a possible InputEdit impl (except for Begin / End)

gwenn avatar Oct 05 '24 10:10 gwenn

But please only one feature at a time: either mut Helper or Parser but not both in the same PR.

Understand, and since the Parser::parse requires &mut self, I think I can firstly fix all issue (like create ValidationContext from State) for mut Helper. Merge it firstly. And then create another PR for Parser (as well as InputEdit)

zao111222333 avatar Oct 05 '24 10:10 zao111222333

Here is the update under your suggestions. I think the Invoke should impl for LineBuffer and String, rather than State and &str. The &str could be replaced to String since itself will be changed in invoke. And State could be replaced to LineBuffer since Invoke seems only require LineBuffer. How do you think that?

I haven't fixed fn invoke(&mut self, cmd: Cmd) in this commit, I will try to implement this feature in future.

zao111222333 avatar Oct 05 '24 10:10 zao111222333

You need the State to invoke a Cmd on a LineBuffer for Undo / Kill ring. Like Changeset here: https://github.com/kkawakam/rustyline/blob/ceafb7f8057974201d0e76ac9fc7aaac3998a048/src/completion.rs#L102-L105

gwenn avatar Oct 05 '24 11:10 gwenn

Or at least use a part of State to create a ValidationContext? Since here we already make a mutable reference from State.helper, then it's difficult to have another mutable refence from entire State (will be ValidationContext::new(self) in code). https://github.com/kkawakam/rustyline/blob/8fc00376936939a948014eadd878b8a8898c375e/src/edit.rs#L250-L253

Now I am not sure which State attributs are needed for fn invoke.

zao111222333 avatar Oct 05 '24 22:10 zao111222333