AMythicDev / minus

An asynchronous, runtime data feedable terminal paging library for Rust
https://crates.io/crates/minus/
Apache License 2.0
321 stars 23 forks source link

PagerState.message is private #90

Closed dalance closed 1 year ago

dalance commented 1 year ago

Describe the bug

I want to add a bit change to DefaultInputClassifier to customize keybinding. So I copied DefaultInputClassifier to my CustomInputClassifier. But it can't be compiled.

To Reproduce

The error message is below:

error[E0616]: field `message` of struct `PagerState` is private
  --> src/custom_input_classifier.rs:46:23
   |
46 |                 if ps.message.is_some() {
   |                       ^^^^^^^ private field

Expected behavior

Changing message to public or adding an API which has the same behavior as message.is_some().

AMythicDev commented 1 year ago

Hey thanks for filling rhe issue, It's surely a bug.

Now regarding the actual thing, it is quite simple to fix this if you just want to check or unwrap messages contents, I just need to make it a public item.

But it's currently not possible to change it from the implementation of the trait.

Btw if you are trying to overwrite the default input events, I wanna tell you that I have merged a PR(#75 ) to give a much more ergonomic API for better overwriting the defaults. If you give me a couple of days, I will get both of the above completed.

dalance commented 1 year ago

Thanks. I'll try to use the native API.

AMythicDev commented 1 year ago

Ok, I just pushed a patch (#91) which should solve this issue. Can you just bring minus as a dependency from that branch and check if everything works, then we can close this.

dalance commented 1 year ago

91 works fine.

AMythicDev commented 1 year ago

There we go then.... I will make a patch release from that branch by today.

AMythicDev commented 1 year ago

Hi @dalance. Sorry I was busy for a while but I completed all the stuff that were needed in the native inputs API and it's ready for use. I will make out a release tomorrow with all these updates.

dalance commented 1 year ago

Thanks. I tried to use the native input API, but HashedEventRegister::default() seems to be empty. Should I add all input event by myself?

AMythicDev commented 1 year ago

You need to call generate_default_bindings() on the HashedEventRegister. I missed it in the docs but the upcoming releases have it.

dalance commented 1 year ago

OK. It works fine. I think get_key_event method may be useful. I want to add some alias key bindings, but copy and paste of callback implementation is required.

input_register.add_key_events(&["c-v", "f", "c-f"], |_, ps| {
    InputEvent::UpdateUpperMark(ps.upper_mark.saturating_add(ps.rows - 1))
});

If the existing callback can be got, I can avoid the duplication.

input_register.add_key_events(&["c-v", "f", "c-f"], input_register.get_key_event("pagedown"));
AMythicDev commented 1 year ago

Hey @dalance sorry for the late reply, it's actually easy to get the above done because there is already a HashedEventRegister::get() function which returns the callback associated with an event. It's just that it isn't public. I will get it done by today/tomorrow.

AMythicDev commented 1 year ago

Hi @dalance sorry I was out for awhile but I wanna share you why I didn't make a patch on the basis of my previous comment. Actually there are layers that minus adds over the crossterm event API which aren't public. So to get a function out of the HashedEventRegister isn't as easy as I mentioned in my previous comment. I am currently exploring on what can be done to get this feature. I will get back to you as I get some results.