Skip to content

Commit

Permalink
docs: add documentation about widget usage
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Mar 30, 2024
1 parent 255fac0 commit 17f38c5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,43 @@ pacman -S heh
apk add heh
```

## Using as a Ratatui widget

`heh` can be used a library and embedded into other TUI applications which use [Ratatui](https://ratatui.rs) and [crossterm](https://github.com/crossterm-rs/crossterm).

Add `heh` to your dependencies in `Cargo.toml`:

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

Create the application:

```rust
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();
```

Then you can render a frame as follows:

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

To handle key events:

```rust
heh.handle_input(crossterm::event::Event::Key(/* */)).unwrap();
```

# Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).

0 comments on commit 17f38c5

Please sign in to comment.