-
Notifications
You must be signed in to change notification settings - Fork 157
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
[WIP][Draft] Refactor ideas (Extension on #61) #62
Conversation
While trying this interface I had to make a few methods public which I am not a fan of, will eventually circle back and fix them
I am using the trait here as an interface that is so popular in a lot of OO langs. I am not super keen on using this I would prefer if there was a way to get this trait changed into a struct and modify the current ViLineEditor and EmacsLineEditor to adhere a common interface that we will plug in that LineEditor struct. (And obviously we need to call it Reedline)
Wow! I was pondering if we could manage the necessary repaints with a respective flag enum InvalidationLevel {
/// The fastest case
Cursor,
/// as soon as something is typed or changed
BufferOnly,
/// Delayable more expensive version in the future for validation and syntax aware stuff (only makes sense if it doesn't interact with the prompt)
BufferWithAnnotation,
/// e.g. switching vi modes, Clock, they MUST be fixed sized and not shift buffer around, thus the rest would not have to be recomputed as well
PromptStatus,
/// On clear or resize, or other operations where the content changes starting at the Prompt
Full
} I haven't fully checked yet if we truly have to poll the termina with painting outside regular repaints for the unicode and wrapping detection. |
So i found some time to compare the two versions so here are my two cents. (I did not try to implement a new feature with your version so grains of salt warranted)
Very subjective: I'm not currently convinced of the solution of having the main entry-point type "subclassed" on the key-map. I would probably prefer a more compositional approach of having swappable decoders like you describe in your first suggestion. Pros for subclassing solution:
Contra
Yes the current state around the key handling is messy and on one side we don't have fully encountered the complexity around vi mode yet but on the other side we also havent't included a bunch of additional features that would all have to tie back into several core components of the line editor including key input. So I can't foresee if this proposed API would shrink into nicely factored bits over time or rather grow. I have to admit that I don't have enough experience with Rust API patterns for that, so probably JT @jonathandturner should weigh in on that. |
I like the idea of extracting out the Painter. Though I am not super happy with the API it offers presently. Though this is something we can improve further down the road.
Yeah, initially I thought that this was a good idea. I had not thought of completions, hinting, (or generally the plugin architecture?) outlined in #63. Thinking more about it, if we pull everything into the edit engine, would entail it having way more responsibilities for any struct/class and more importantly the API it will expose will be massive (making any changes to it require significant effort). On the other hand, if we keep the edit engine core and make everything extensible by Another idea here would be to pull out stuff from it into to
I think completion engine and hinting can potentially be done without having a lot of interaction with any of the components. This is based on the assumption that these components don't worry about painting the screen.
I am in 100% agreement with you on this. Swappable decoders is what I want to achieve, but I was not able to do so cleanly. Some ways to go about it probably include communication between these decoders and the main struct via some enum. |
I think we can close this one, as mentioned I will try to pick up some of these items in pieces trying to achieve the first design where we are using composition over inheritence. |
Closing this as, this is being taken care of in smaller pieces in separate PRs, will link to this PR from the smaller pieces. |
Extends on #61
This PR is to demonstrate how these ideas actually might look like. I like some aspects of this PR some not so much. The
EditEngine
seems like a clean-cut and it houses a lot of the core logic that we have, we talk to this object via theEditCommand
enum.I wanted to house all the painting logic in the
Painter
class but I am not super excited with the interface that it ended up having. I want to look into it a bit more and see if we can get a better interface.Lastly, the structure with the trait LineEditor is implemented in an inheritance-y way very similar to how a lot of people do in any OO lang. I really want these to compose. I want to chase the first way that I outlined in the issue that I created, but it will require more time investment from my side to look if this is possible or not.
Let me know what are your thoughts on this.
P.S. I am making this as a draft pull as I would like to get your feedback before I proceed any further than this.
Note (to reviewers): This is a massive PR I have tried to organize commits in a way that are self-contained. The best way to approach reviewing (IMO) is by first looking at the commit messages to get a high-level gist of what I was trying to do. And then look at stuff one commit at a time.
(Edit): ----------
This PR is just to showcase one approach. I don't intend for this to be merged. I think this serves as a base on which discussions can be made. Then if there are parts that the authors like, then I can work on them individually.