Skip to content

Commit

Permalink
docs(example): add demo example and update documentation (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun authored Aug 25, 2024
1 parent 92826eb commit 6c27b4a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ categories = ["command-line-utilities", "text-editors"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ratatui = "0.28.0"
clap = { version = "4.5.16", features = ["derive"] }
ratatui = "0.28.1"
clap = { version = "4.5.15", features = ["derive"] }
arboard = { version = "3.4.0", default-features = false }
memmap2 = "0.9.4"
crossbeam = "0.8.4"
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ Add `heh` to your dependencies in `Cargo.toml`:

```toml
[dependencies]
ratatui = "0.24"
crossterm = "0.27"
heh = "0.4"
ratatui = "0.28"
heh = "0.6"
```

Create the application:
Expand All @@ -104,14 +103,14 @@ use heh::app::Application as Heh;
use heh::decoder::Encoding;

let file = std::fs::OpenOptions::new().read(true).write(true).open(path).unwrap();
let heh = Heh::new(file, Encoding::Ascii, 0).unwrap();
let mut heh = Heh::new(file, Encoding::Ascii, 0).unwrap();
```

Then you can render a frame as follows:

```rust
terminal.draw(|frame| {
heh.render_frame(frame, frame.size());
heh.render_frame(frame, frame.area());
});
```

Expand All @@ -121,7 +120,9 @@ To handle key events:
heh.handle_input(&ratatui::crossterm::event::Event::Key(/* */)).unwrap();
```

See the [binsider](https://github.com/orhun/binsider) project for an example use case.
See the [demo example](examples/demo.rs) for full code.

See the [binsider](https://github.com/orhun/binsider) project for an example application that uses `heh`.

# Contributing

Expand Down
31 changes: 31 additions & 0 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::path::PathBuf;

use heh::app::Application as Heh;
use heh::decoder::Encoding;

use ratatui::{
crossterm::event::{self, Event, KeyCode},
Frame,
};

fn main() {
let path = PathBuf::from("Cargo.toml");
let file = std::fs::OpenOptions::new().read(true).write(true).open(path).unwrap();
let mut heh = Heh::new(file, Encoding::Ascii, 0).unwrap();

let mut terminal = ratatui::init();
loop {
terminal
.draw(|frame: &mut Frame| {
heh.render_frame(frame, frame.area());
})
.expect("failed to draw frame");
if let Event::Key(key) = event::read().expect("failed to read event") {
if key.code == KeyCode::Char('q') {
break;
}
heh.handle_input(&ratatui::crossterm::event::Event::Key(key)).unwrap();
}
}
ratatui::restore();
}

0 comments on commit 6c27b4a

Please sign in to comment.