1extern crate cursive;
2extern crate cursive_hexview;
3
4use cursive::views::{Dialog, DummyView, LinearLayout, TextView};
5use cursive_hexview::{DisplayState, HexView, HexViewConfig};
6
7fn main() {
8 let mut cur = cursive::default();
9 let explanation = TextView::new("Use the keys + - ↑ ↓ ← → 0-9 a-f for the HexView.\nUse q to exit.");
10 let data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".as_bytes();
11
12 let view1 = HexView::new_from_iter(data).display_state(DisplayState::Editable);
14
15 let config = HexViewConfig {
17 hex_ascii_separator: " - ",
18 ..Default::default()
19 };
20 let view2 = HexView::new_from_iter(data)
21 .config(config)
22 .display_state(DisplayState::Editable);
23
24 let mut view3 = HexView::new_from_iter(data).display_state(DisplayState::Editable);
26 let config2 = HexViewConfig {
27 bytes_per_line: 8,
28 bytes_per_group: 4,
29 byte_group_separator: " ",
30 show_ascii: false,
31 ..Default::default()
32 };
33 view3.set_config(config2);
34
35 cur.add_layer(
36 Dialog::around(
37 LinearLayout::vertical()
38 .child(explanation)
39 .child(DummyView)
40 .child(view1)
41 .child(DummyView)
42 .child(view2)
43 .child(DummyView)
44 .child(view3),
45 )
46 .title("HexView"),
47 );
48 cur.add_global_callback('q', |cur| cur.quit());
49 cur.run();
50}