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

RFC/Announcement: cursive_hexview #175

Closed
hellow554 opened this issue Dec 21, 2017 · 15 comments
Closed

RFC/Announcement: cursive_hexview #175

hellow554 opened this issue Dec 21, 2017 · 15 comments

Comments

@hellow554
Copy link
Contributor

Hi everyone,

for my project in needed some kind of displaying hexdata so I created a hexview which is accessable via https://github.com/hellow554/cursive_hexview

Please, feel free to file any issues, pullrequests, doc changes, more cats pics, everything.
I would really like to get some feedback, because it's my first published rust project.

One particular thing I noticed is, that I can't use with_id or *_height/width methods on the view. What is necessary to be able to use them @gyscos ?

Anyhow, you are welcome to use is, commend it, fork it, change it with any ideas you might have.

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

Those methods are part of extension traits implemented for all Views: you just need to use the trait.
https://docs.rs/cursive/0.7.5/cursive/traits/index.html

@hellow554
Copy link
Contributor Author

hellow554 commented Dec 21, 2017

Hm, it does not work :(

error[E0599]: no method named `with_id` found for type `cursive_hexview::HexView` in the current scope
   --> src/gui.rs:130:35
    |
130 |         .child("", HexView::new().with_id("reserved2_send"))
    |                                   ^^^^^^^
    |
    = note: the method `with_id` exists but the following trait bounds were not satisfied:
            `cursive_hexview::HexView : cursive::traits::Identifiable`
            `&cursive_hexview::HexView : cursive::traits::Identifiable`
            `&mut cursive_hexview::HexView : cursive::traits::Identifiable`
    = help: items from traits can only be used if the trait is in scope
    = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
            candidate #1: `use cursive::view::identifiable::Identifiable;`

also call_on_id does not work

error[E0277]: the trait bound `cursive_hexview::HexView: std::ops::DerefMut` is not satisfied
   --> src/gui.rs:386:7
    |
386 |     s.call_on_id("data_recv", |bv: &mut HexView| bv.set_data(sp.data.to_raw()));
    |       ^^^^^^^^^^ the trait `std::ops::DerefMut` is not implemented for `cursive_hexview::HexView`
    |
    = note: required because of the requirements on the impl of `cursive::view::ViewWrapper` for `cursive_hexview::HexView`
    = note: required because of the requirements on the impl of `cursive::traits::View` for `cursive_hexview::HexView`

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

So the error messages is unfortunately using the wrong (private) path, but the trait itself is present in the link I posted:
https://docs.rs/cursive/0.7.5/cursive/view/trait.Identifiable.html

@hellow554
Copy link
Contributor Author

I included the use directive but still the error. Is it possible, that it does not automatically implement it for external structs and I have to implement them "manually"?

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

Here is the default example from hexview using with_id, fixed_width and call_on_id:

extern crate cursive;
extern crate cursive_hexview;

use cursive_hexview::{DisplayState, HexView};
use cursive::Cursive;
use cursive::views::{Dialog, DummyView, LinearLayout, TextView};

use cursive::traits::{Boxable, Identifiable};

fn main() {
    let mut cur = Cursive::new();
    let explanation =
        TextView::new("Use the keys + - ↑ ↓ ← → 0-9 a-f for the HexView.\nUse q to exit.");
    let view = HexView::new().display_state(DisplayState::Editable);

    cur.add_layer(
        Dialog::around(
            LinearLayout::vertical()
                .child(explanation)
                .child(DummyView)
                .child(view.with_id("view").fixed_width(80)),
        ).title("HexView"),
    );

    cur.add_global_callback('q', |cur| cur.quit());
    cur.add_global_callback('o', |cur| {
        cur.call_on_id("view", |v: &mut HexView| ());
    });
    cur.run();
}

I just use the Identifiable and Boxable traits, and this compiles fine.

@hellow554
Copy link
Contributor Author

I indeed can confirm that it works in the examples, strange though it does not work in my project :D I will investigate that. But thank you netherless

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

Anyway - it looks really nice! Congratulations for the good work! :)
I'll add a mention in the Readme if you're ok with that?

@hellow554
Copy link
Contributor Author

Sure, I would be pleased :)

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

You may want to add a screenshot on the Readme to impress visitors ;)

@hellow554
Copy link
Contributor Author

It looks like the trait thing might be a regression to 0.7.5. I build my project with your git linked to this repository and then it tells me about all the strange things (to use the private trait and that is it not possible to use with_id). You may want to test that and verify it with my experience?

Sure, I can include a picture of the default example :)

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

The example I posted compiles fine with this in Cargo.toml:

[dependencies]
cursive = { git = "https://github.com/gyscos/cursive", default-features = false }

@hellow554
Copy link
Contributor Author

Maybe a cargo update?! I can "verify" that it really is a problem with the git branch instead of the crates package.

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

You can try the example and see that it compiles fine after any combination of clean/update/... The Cargo.lock contains:

[[package]]
name = "cursive"
version = "0.7.6-alpha.0"
source = "git+https://github.com/gyscos/cursive#ba0bc6dc564f714ce234e64595e9db70c7dc126d"

Maybe you're pulling two different versions of Cursive? Can you check your Cargo.lock if there's any duplicate entry?

@hellow554
Copy link
Contributor Author

Yeah... that's the problem. One from the cursive_hexview itself (namely the stable version 0.7.5) and one from "my" cargo.toml namely the git version. Any method to get around this, e.g. just tell cursive_hexview to use the version the user wants?

@gyscos
Copy link
Owner

gyscos commented Dec 21, 2017

Not sure how to do that. I tried using the [patch] section, but it doesn't seem to work as intended. Somehow cargo still things 0.7.6-alpha and 0.7.5 aren't compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants